1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Add TCP keepalive support to libpq.

This adds four additional connection parameters to libpq: keepalives,
keepalives_idle, keepalives_count, and keepalives_interval.
keepalives default to on, per discussion, but can be turned off by
specifying keepalives=0.  The remaining parameters, where supported,
can be used to adjust how often keepalives are sent and how many
can be lost before the connection is broken.

The immediate motivation for this patch is to make sure that
walreceiver will eventually notice if the master reboots without
closing the connection cleanly, but it should be helpful in other
cases as well.

Tollef Fog Heen, Fujii Masao, and me.
This commit is contained in:
Robert Haas
2010-06-23 21:54:13 +00:00
parent c1b617987d
commit d8cd283a08
3 changed files with 238 additions and 3 deletions

View File

@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.308 2010/06/17 16:03:30 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.309 2010/06/23 21:54:13 rhaas Exp $ -->
<chapter id="libpq">
<title><application>libpq</application> - C Library</title>
@ -280,6 +280,57 @@
</listitem>
</varlistentry>
<varlistentry id="libpq-keepalives" xreflabel="keepalives">
<term><literal>keepalives</literal></term>
<listitem>
<para>
Controls whether TCP keepalives are used. The default value is 1,
meaning on, but you can change this to 0, meaning off, if keepalives
are not wanted. This parameter is ignored for connections made via
a Unix-domain socket.
</para>
</listitem>
</varlistentry>
<varlistentry id="libpq-keepalives-idle" xreflabel="keepalives_idle">
<term><literal>keepalives_idle</literal></term>
<listitem>
<para>
On systems that support the <symbol>TCP_KEEPIDLE</symbol> socket
option, specifies the number of seconds between sending keepalives
on an otherwise idle connection. 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.
</para>
</listitem>
</varlistentry>
<varlistentry id="libpq-keepalives-interval" xreflabel="keepalives_interval">
<term><literal>keepalives_interval</literal></term>
<listitem>
<para>
On systems that support the <symbol>TCP_KEEPINTVL</symbol> socket
option, specifies how long, in seconds, to wait for a response to a
keepalive before retransmitting. 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.
</para>
</listitem>
</varlistentry>
<varlistentry id="libpq-keepalives-count" xreflabel="keepalives_count">
<term><literal>keepalives_count</literal></term>
<listitem>
<para>
On systems that support the <symbol>TCP_KEEPCNT</symbol> socket
option, specifies how many keepalives can be lost before the
connection is considered dead. 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.
</para>
</listitem>
</varlistentry>
<varlistentry id="libpq-connect-tty" xreflabel="tty">
<term><literal>tty</literal></term>
<listitem>