performance query – Postgresql slows the remote execution when using alternative clients

I noticed a strange performance problem when running SQL queries on a remote Postgresql server.

All is well with psql:

Log in via ssh and run things locally

$ ssh user@example.org
user @ example: ~ $ psql -h localhost -U database -d database
database = #  timing
The timing is on.
database = # explain analyze select * in mytable where my_field = & # 39; 14123 & # 39 ;;
Time: 1646.577ms (00: 01.647)
database = # select * from mytable where my_field = & # 39; 14123 & # 39 ;;
Time: 1642.361 ms (00: 01.642)

Transfer postgresql to a local port and connect locally

$ ssh -L 1111: localhost: 5432 user@example.org
$ psql -h localhost -p 1111 -d database -U database
database = # explain analyze select * in mytable where my_field = & # 39; 14123 & # 39 ;;
Time: 1669.424 ms (00: 01.669)
database = # select * from mytable where my_field = & # 39; 14123 & # 39 ;;
Time: 1703.183 ms (00: 01.703)

However, when I use GUI clients such as DBeaver or DataGrip, the following timers are applied:

DBeaver

Use the "SSH tunnel" option in DBeaver

Explain analyze select * in mytable where my_field = 14123 & # 39 ;;
- Running time: 1665.447 ms
select * from mytable where my_field = & # 39; 14123 & # 39 ;;
- Runtime: 6475 ms

"Direct" connection with port transferred locally

Explain analyze select * in mytable where my_field = 14123 & # 39 ;;
- Runtime: 1617,330 ms
select * from mytable where my_field = & # 39; 14123 & # 39 ;;
- Runtime: 6370 ms

DataGrip

Use the option "SSH tunnel" in DataGrip

sql> explain the scan, select * in mytable where my_field = 14123 & # 39;
execution: 1 s 561 ms, recovery: 10 ms
sql> select * from mytable where my_field = 14123 & # 39; LIMIT 35
execution: 6 s 360 ms, recovery: 60 ms

"Direct" connection with port transferred locally

sql> explain the scan, select * in mytable where my_field = 14123 & # 39;
execution: 1 s 900 ms, recovery: 22 ms
sql> select * from mytable where my_field = 14123 & # 39; LIMIT 35
execution: 6 s 565 ms, recovery: 107 ms

Why are the timings so much worse when using these graphical applications? (6s instead of 1.5s) The DataGrip output suggests that this is not the data being transferred, and in fact, the selection produces only 35 rows, which is less than 100 KB in total. Also it is a lot slower in both cases, and it takes about the same time in all unexpected cases. What can cause this? Maybe something in the JDBC driver?

I connect to the server via a virtual private network and then use an SSH tunnel to access the Postgresql server. The VPN server and the database server are light and very close to me (same city).
The version of Postgresql is 10 and runs on Ubuntu 18.04.