Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l7Fm1-00034r-2w for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Feb 2021 10:52:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l7Flz-0006Fr-Sa for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Feb 2021 10:52:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l7Flz-0006Fk-M2 for pgsql-hackers@lists.postgresql.org; Wed, 03 Feb 2021 10:52:35 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l7Flv-0000Jf-Ow for pgsql-hackers@lists.postgresql.org; Wed, 03 Feb 2021 10:52:34 +0000 Received: from hnk.local (sp49-98-209-173.msd.spmode.ne.jp [49.98.209.173]) by oss.nttdata.com (Postfix) with ESMTPSA id A9EF860342; Wed, 3 Feb 2021 19:52:26 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com Subject: Re: [PATCH] postgres_fdw connection caching - cause remote sessions linger till the local session exit To: Bharath Rupireddy Cc: Zhihong Yu , Alexey Kondratov , "Hou, Zhijie" , PostgreSQL Hackers References: <1c643738-6e52-565d-0261-740d490b550e@oss.nttdata.com> <09b3f740-896d-7507-95e1-d2afd87daf2e@oss.nttdata.com> <64ee084b-1368-e044-debd-69cc156276c6@oss.nttdata.com> <39259f30-897c-ceaf-8a1e-78fe2db398cb@oss.nttdata.com> <8ef4979b-85e7-c3f2-0653-f8f444f5dcff@oss.nttdata.com> <93e8fe47-79c2-ed58-c43b-fdb57b238fa8@oss.nttdata.com> From: Fujii Masao Message-ID: Date: Wed, 3 Feb 2021 19:52:26 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2021/02/03 13:56, Bharath Rupireddy wrote: > On Tue, Feb 2, 2021 at 9:45 AM Fujii Masao wrote: >> One merit of keep_connections that I found is that we can use it even >> when connecting to the older PostgreSQL that doesn't support >> idle_session_timeout. Also it seems simpler to use keep_connections >> rather than setting idle_session_timeout in multiple remote servers. >> So I'm inclined to add this feature, but I'd like to hear more opinions. > > Thanks. > >>> And, just using idle_session_timeout on a remote server may not help >>> us completely. Because the remote session may go away, while we are >>> still using that cached connection in an explicit txn on the local >>> session. Our connection retry will also not work because we are in the >>> middle of an xact, so the local explicit txn gets aborted. >> >> Regarding idle_in_transaction_session_timeout, this seems true. But >> I was thinking that idle_session_timeout doesn't cause this issue because >> it doesn't close the connection in the middle of transaction. No? > > You are right. idle_session_timeout doesn't take effect when in the > middle of an explicit txn. I missed this point. > >> Here are some review comments. >> >> - (used_in_current_xact && !keep_connections)) >> + (used_in_current_xact && >> + (!keep_connections || !entry->keep_connection))) >> >> The names of GUC and server-level option should be the same, >> to make the thing less confusing? > > We can have GUC name keep_connections as there can be multiple > connections within a local session and I can change the server level > option keep_connection to keep_connections because a single foreign > server can have multiple connections as we have seen that in the use > case identified by you. I will change that in the next patch set. > >> IMO the server-level option should override GUC. IOW, GUC setting >> should be used only when the server-level option is not specified. >> But the above code doesn't seem to do that. Thought? > > Note that default values for GUC and server level option are on i.e. > connections are cached. > > The main intention of the GUC is to not set server level options to > false for all the foreign servers in case users don't want to keep any > foreign server connections. If the server level option overrides GUC, > then even if users set GUC to off, they have to set the server level > option to false for all the foreign servers. Maybe my explanation in the previous email was unclear. What I think is; If the server-level option is explicitly specified, its setting is used whatever GUC is. On the other hand, if the server-level option is NOT specified, GUC setting is used. For example, if we define the server as follows, GUC setting is used because the server-level option is NOT specified. CREATE SERVER loopback FOREIGN DATA WRAPPER postgres; If we define the server as follows, the server-level setting is used. CREATE SERVER loopback FOREIGN DATA WRAPPER postgres OPTIONS (keep_connections 'on'); For example, log_autovacuum_min_duration GUC and reloption work in the similar way. That is, reloption setting overrides GUC. If reltion is not specified, GUC is used. Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION