By PERI PARTS
I’m trying to declare CURSOR on table with ~9M records
DECLARE "name" NO SCROLL CURSOR WITH HOLD FOR SELECT ....
and it fails with error: terminating connection due to administrator command. No logs, nothing.
DigitalOcean, any suggestions?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi @periparts,
You could try these 2 approaches and see if that helps.
Optimize the query to reduce the sorting which will in turn reduce the amount of memory been used, you can do an EXPLAIN ANALYZE on the query to see the optimizers path as well as see the disk sorting done by the query
Adjust the work_mem, the default is 2547 KB you can change it on a session-level first for your test " SET work_mem = ‘80MB’; then “show work_mem” you should see 80MB (Note: You can modify the 80MB to what you like) after which you can execute your query.
The below URL has some good information on declare cursor memory, please review
https://www.cybertec-postgresql.com/en/declare-cursor-in-postgresql-or-how-to-reduce-memory-consumption/ https://stackoverflow.com/questions/33635405/postgres-cursor-with-hold https://bytes.com/topic/postgresql/answers/420717-cursors-transactions-why https://www.postgresql-archive.org/Correct-use-of-cursors-for-very-large-result-sets-in-Postgres-td5944846.html
Regards, Rajkishore
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.