Re: Terminate the idle sessions

Japin Li <japinli@hotmail.com>

From: Li Japin <japinli@hotmail.com>
To: "David G. Johnston" <david.g.johnston@gmail.com>
Cc: "kuroda.hayato@fujitsu.com" <kuroda.hayato@fujitsu.com>, Kyotaro Horiguchi <horikyota.ntt@gmail.com>, Thomas Munro <thomas.munro@gmail.com>, "bharath.rupireddyforpostgres@gmail.com" <bharath.rupireddyforpostgres@gmail.com>, "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2020-11-17T02:45:12Z
Lists: pgsql-hackers
--
Best regards
Japin Li

On Nov 17, 2020, at 7:59 AM, David G. Johnston <david.g.johnston@gmail.com<mailto:david.g.johnston@gmail.com>> wrote:

On Mon, Nov 16, 2020 at 5:41 AM Li Japin <japinli@hotmail.com<mailto:japinli@hotmail.com>> wrote:
Thanks for your review! Attached.

Reading the doc changes:

I'd rather not name postgres_fdw explicitly, or at least not solely, as a reason for setting this to zero.  Additionally, using postgres_fdw within the server doesn't cause issues, its using postgres_fdw and the remote server having this setting set to zero that causes a problem.

<note>
Consider setting this for specific users instead of as a server default.  Client connections managed by connection poolers, or initiated indirectly like those by a remote postgres_fdw using server, should probably be excluded from this timeout.

Text within <para> should be indented one space (you missed both under listitem).

Thanks for your suggest! How about change document as follows:

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 6c4e2a1fdc..23e691a7c5 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -8281,17 +8281,17 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
       </term>
       <listitem>
        <para>
-       Terminate any session that has been idle for longer than the specified amount of time.
+        Terminate any session that has been idle for longer than the specified amount of time.
        </para>
        <para>
-       If this value is specified without units, it is taken as milliseconds.
-       A value of zero (the default) disables the timeout.
+        If this value is specified without units, it is taken as milliseconds.
+        A value of zero (the default) disables the timeout.
        </para>

        <note>
         <para>
-         This parameter should be set to zero if you use postgres_fdw or some
-         connection-pooling software, because connections might be closed unexpectedly.
+         This parameter should be set to zero if you use some connection-pooling software, or
+         PostgreSQL servers used by postgres_fdw, because connections might be closed unexpectedly.
         </para>
        </note>

I'd suggest a comment that aside from a bit of resource consumption idle sessions do not interfere with the long-running stability of the server, unlike idle-in-transaction sessions which are controlled by the other configuration setting.

Could you please explain how the idle-in-transaction interfere the long-running stability?

--
Best regards
Japin Li

Commits

  1. Rethink SQLSTATE code for ERRCODE_IDLE_SESSION_TIMEOUT.

  2. Improve commentary in timeout.c.

  3. Add idle_session_timeout.

  4. Improve timeout.c's handling of repeated timeout set/cancel.