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!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
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