I have long idle database connection sessions, will they be kept open? Do you use TCP keep-alive?

Currently on the server side we use the default keepalive timeouts:

  • tcp_keepalives_idle=7200
  • tcp_keepalive_count=9
  • tcp_keepalives_interval=75

Note that you can set the client side keepalive timeouts to whatever values you wish. (see http://www.postgresql.org/docs/9.5/static/libpq-connect.html#LIBPQ-KEEPALIVES ; the libpq configuration keys are the same as on the server side except that the tcp_ prefix is omitted from the configuration keys)

Even though TCP connections usually stay open for extended periods of time you should also make sure that your application(s) can reconnect since TCP connections are liable to break at times, usually at very inconvenient times at that. Also when reconnecting, you should make sure that your client always resolves the DNS address on connect since the underlying address will change during automatic fail over when a master node fails.

Did this answer your question?