If an application stops responding and abnormally terminates for any reason, the connection from the application may remain active on the database server. If this situation continues for an extended period, other applications attempting to connect to the database server may encounter an error, or an error indicating that the tables are unavailable may occur.
It is, therefore, recommended that idle connections be closed automatically at regular intervals.
Set the following parameters in the postgresql.conf file to indicate the time permitted to elapse before a connection is closed.
Parameter name | Setting | Description |
---|---|---|
tcp_keepalives_idle | Time until keepalive is sent (seconds) If 0, the default value of the system is used. | Sends keepalive to an idle connection at the specified interval in seconds It is recommended to specify 30 seconds. |
tcp_keepalives_interval | keepalive send interval (seconds) If 0, the default value of the system is used. | Sends keepalive at the specified interval It is recommended to specify 10 seconds. |
tcp_user_timeout | Time to wait for a response from the server (milliseconds) If 0, the default value of the system is used. If not set, the behavior is the same as if 0 were specified. | After establishing the connection, when sending from the client to the server, if the TCP resend process operates, specify the time until it is considered to be disconnected. If a value other than 0 is specified in this parameter, the time until automatic disconnection is determined by the waiting time specified in this parameter. The actual wait time is until the timing of the first keepalive retransmission after the time specified by this parameter has elapsed. |
Note
If a value other than 0 is specified for the tcp_user_timeout parameter, the waiting time set by the tcp_keepalives_idle parameter and tcp_keepalives_interval parameter will be invalid and the waiting time specified by the tcp_user_timeout parameter will be used.
See
Refer to "Connection Settings" under "Server Administration" in the PostgreSQL Documentation for information on the parameters.