I'm working via pgAdmin III on a remote PostgreSQL database. After a not so long period (say 10-15 min.) without doing anything in pgAdmin, the connection automatically expires. I therefore have a error message asking if I want to re-connect. This takes about 10 sec. and the database structure collapses, so I have to re-open the schemas I had open before.

Is there a way to change a timeout parameter somewhere so prevent the connection to expire for a longer period of time?


1 Answer 1


A PostgreSQL server connection dropping after 10-15 minutes is almost certainly being caused by a state-tracking firewall (possibly using Network Address Translation (NAT)) between the client and the server. Many such firewalls have default timeouts of 15 minutes (900 seconds).

The three server-side parameters, tcp_keepalives_idle, tcp_keepalives_interval, tcp_keepalives_count are designed to help in these situations. See the documentation located here: http://www.postgresql.org/docs/9.2/static/runtime-config-connection.html#GUC-TCP-KEEPALIVES-IDLE

There are also client-side parameters for this: keepalives, keepalives_idle, keepalives_interval, keepalives_count, which you can set on connection. See the documentation located here: http://www.postgresql.org/docs/9.2/static/libpq-connect.html#LIBPQ-KEEPALIVES

  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Paul White
    Aug 29, 2017 at 15:47
  • In case of Docker Swarm there is a sysctls: property of a service's configuration for which one can set e.g. - net.ipv4.tcp_keepalive_time=600. This should work since compose file version 3.2.
    – dargmuesli
    Dec 29, 2020 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.