I am experiencing an issue where my postGres client connection object goes ‘stale’ if I have not run a query on it for a while (say 1 hour). I believe it probably involves the idle timeout or stay-live process. Attempting to use the connection object causes the code to block for around 5 minutes before throwing an exception with this text:
SQL Error: server closed the connection unexpectedly This probably
means the server terminated abnormally before or while processing the
request.
When I look here it suggests that the psycopg2.connect()
function will recognize various parameters for the connect()
method, some of which seem related to timeouts.
For example keepalives_idle
, the doc says that “Controls the number of seconds of inactivity after which TCP should send a keepalive message to the server. A value of zero uses the system default. This parameter is ignored for connections made via a Unix-domain socket, or if keepalives are disabled. It is only supported on systems where TCP_KEEPIDLE or an equivalent socket option is available, and on Windows; on other systems, it has no effect.” (I am on Windows).
But how do I find out what system default
is being used.
If I try:
conn.info.parameter_status('keepalives_idle')
The result is None
.
4