> I asked the same question when it was reported to me. The response: "pgAdmin4 works fine"...
To my knowledge, pgAdmin loads rows in batches, so it doesn't load the whole 6 million rows.
But to support that, it needs to keep the database cursor open which I think is a not a good thing to do (and would be quite difficult to achieve in a DBMS independent way)
> Even if the query included WHERE etc; our data often returns huge results. Changing the query to:
>
> copy (select * from <table>) to '/tmp/test.csv' with csv delimiter ',' header;
>
> gave:
> 8274872 rows affected
> COPY executed successfully
> Execution time: 15.98s
>
> with barely a notice on CPU utilization; and output:
Well, obviously this doesn't generate any CPU or memory overhead in SQL Workbench as it is processed completely inside the Postgres server itself.
And SQL Workbench does not need to retrieve, process and display 6 million rows.
> $ ls -l /tmp/test.csv
> -rw-r--r-- 1 postgres postgres
3034749918 May 2 06:50 /tmp/test.csv
>
> Finally found SQLWorkbench.cfg.sample... Set: vmarg.mem=-Xmx20g which is way more than enough for 6.1GB expected based on previous query.
> With Max Rows = 50, I got:
> SELECT executed successfully
> Execution time: 24ms
>
> With Max Rows = 0, I get 100% on most CPUs and according to htop after cancellation, there's still ~55 java processes running, although 'ps aux' shows only the main one... Cancelled the query since it only took ~16 seconds (above) to output to a file:
> Statement cancelled.
> Execution time: 1m 3s
>
> Shouldn't 20G on a 128G system be able to handle ~3GB output..?
3GB plain ASCII is typically a lot more when stored inside Java (especially if there are long strings involved).
And as I said: the memory consumption also depends on the configuration of the JDBC driver. It can easily be doubled untile the query is completely finished.
I have no idea why the query _also_ generates CPU load by the Postgres server.
Maybe it switches to a parallel plan which doesn't happen if you limit the number of rows:
https://blog.sql-workbench.eu/post/client-performance-considerations/