Declare cursors

I’m trying to declare CURSOR on table with ~9M records


and it fails with error: terminating connection due to administrator command. No logs, nothing.

DigitalOcean, any suggestions?

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

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.

  1. 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

  2. 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

Regards, Rajkishore