I have a problem with processing all rows from database (PostgreSQL). I get an error: org.postgresql.util.PSQLException: Ran out of memory retrieving query results.
At lest in my case the problem was on the client that tries to fetch the results.
Wanted to get a .csv with ALL the results.
I found the solution by using
psql -U postgres -d dbname -c "COPY (SELECT * FROM T) TO STDOUT WITH DELIMITER ','"
(where dbname the name of the db...) and redirecting to a file.