pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexey Kondratov <a.kondratov@postgrespro.ru>
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Cc: Hou, Zhijie <houzj.fnst@cn.fujitsu.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Fujii Masao <masao.fujii@oss.nttdata.com>
Subject: Re: [PATCH] postgres_fdw connection caching - cause remote sessions linger till the local session exit
Date: Wed, 30 Dec 2020 20:41:27 +0300
Message-ID: <9b90712303dbecddd8691b95cee93b3a@postgrespro.ru> (raw)
In-Reply-To: <CALj2ACVqunXtPGYGwq=aSJZSZd7nuWeA_66Lo43h28NTfjRDWg@mail.gmail.com>
References: <CALj2ACVvrp5=AVp2PupEm+nAC8S4buqR3fJMmaCoc7ftT0aD2A@mail.gmail.com>
	<CALj2ACX3SiYXodW1vka2RdHMqok9kLvwJ4vNUMO358yL5BeNJA@mail.gmail.com>
	<CALj2ACW2cgfNARmgwK-+_vMpv73F7=uq2vEoRokkEj=6+oRCJQ@mail.gmail.com>
	<fdc8af8f-fc3f-a072-8db6-8fc17ac87e20@oss.nttdata.com>
	<CALj2ACUYS7zgLZgG8qELvK8YRNQ4Fmi0bfvRisUjyj07LtBYPA@mail.gmail.com>
	<CALj2ACX8FgUEJBuzS2bB8+vLENQdEkjLQZ89jk1cqK0y2aDJZA@mail.gmail.com>
	<fe4fe2b9-9de6-1aa0-c7a9-5b5eadae241f@oss.nttdata.com>
	<CALj2ACVFfsmAMyYVidXWfu4URST2xwO20NSYrHUQwxG070poxA@mail.gmail.com>
	<3595a221-d845-c97c-96fe-5d4f739edaad@oss.nttdata.com>
	<CALj2ACUOQYs+ssxkxRvZ6Ja5+sfc6a-s_0e-Nv2A591hEyOgiw@mail.gmail.com>
	<2a0d7305-1cf6-db59-7fc6-241c55c8fc8b@oss.nttdata.com>
	<CALj2ACXrf3VcCVXoKqkyZ4N+B2=ndiJzvcOtA-_uYGM_8ux5yg@mail.gmail.com>
	<6da38393-6ae5-4d87-2690-11c932123403@oss.nttdata.com>
	<CALj2ACV7egGf+LmuUrjirtn4DeOfWCEP9mrOzgKroJ_6Htekyg@mail.gmail.com>
	<CALj2ACX7Yr_X25Lc5DAAw5tdAjz7qMTBXqLjWkN67NeCHL+-jA@mail.gmail.com>
	<0b13f28d-de46-fb06-e946-4c0c00cea591@oss.nttdata.com>
	<CALj2ACVypPe+4L2uAVMNfXCH3B00fqX5Nx01pVFJCU009BTJdg@mail.gmail.com>
	<CALj2ACXghAf_GPOVBVuvuPy=9b5ccB7mtf1Jeeoa0QMav-cxOQ@mail.gmail.com>
	<617e9887b74c4332a5d1e5fb2c56ddfd@G08CNEXMBPEKD05.g08.fujitsu.local>
	<CALj2ACWReYX_OmqYfS-O5Dw-nTsL95VihTAJW8WdWEDFsnPUtQ@mail.gmail.com>
	<919942767cf9a3d4e413c63887aec679@postgrespro.ru>
	<CALj2ACU+u5KGaXHkeDkc_+Lg8U6iiR+G5xM7LjjWC2pugKJhZw@mail.gmail.com>
	<CALj2ACVRZPUB7ZwqLn-6DY8C_UmPs6084gSpHA92YBv++1AJXA@mail.gmail.com>
	<b9dc0f5240ca22c58287e9318b981fe3@postgrespro.ru>
	<CALj2ACVqunXtPGYGwq=aSJZSZd7nuWeA_66Lo43h28NTfjRDWg@mail.gmail.com>

On 2020-12-30 17:59, Bharath Rupireddy wrote:
> On Wed, Dec 30, 2020 at 5:20 PM Alexey Kondratov
> <a.kondratov@postgrespro.ru> wrote:
>> 
>> On 2020-12-30 09:10, Bharath Rupireddy wrote:
>> I still have some doubts that it is worth of allowing to call
>> postgres_fdw_disconnect() in the explicit transaction block, since it
>> adds a lot of things to care and check for. But otherwise current 
>> logic
>> looks solid.
>> 
>> +                                errdetail("Such connections get 
>> closed either in the next use or
>> at the end of the current transaction.")
>> +                                : errdetail("Such connection gets 
>> closed either in the next use or
>> at the end of the current transaction.")));
>> 
>> Does it really have a chance to get closed on the next use? If foreign
>> server is dropped then user mapping should be dropped as well (either
>> with CASCADE or manually), but we do need user mapping for a local 
>> cache
>> lookup. That way, if I understand all the discussion up-thread
>> correctly, we can only close such connections at the end of xact, do 
>> we?
> 
> The next use of such a connection in the following query whose foreign
> server would have been dropped fails because of the cascading that can
> happen to drop the user mapping and the foreign table as well. During
> the start of the next query such connection will be marked as
> invalidated because xact_depth of that connection is > 1 and when the
> fail happens, txn gets aborted due to which pgfdw_xact_callback gets
> called and in that the connection gets closed. To make it more clear,
> please have a look at the scenarios [1].
> 

In my understanding 'connection gets closed either in the next use' 
means that connection will be closed next time someone will try to use 
it, i.e. GetConnection() will be called and it closes this connection 
because of a bad state. However, if foreign server is dropped 
GetConnection() cannot lookup the connection because it needs a user 
mapping oid as a key.

I had a look on your scenarios. IIUC, under **next use** you mean a 
select attempt from a table belonging to the same foreign server, which 
leads to a transaction abort and connection gets closed in the xact 
callback. Sorry, maybe I am missing something, but this just confirms 
that such connections only get closed in the xact callback (taking into 
account your recently committed patch [1]), so 'next use' looks 
misleading.

[1] 
https://www.postgresql.org/message-id/8b2aa1aa-c638-12a8-cb56-ea0f0a5019cf%40oss.nttdata.com


Regards
-- 
Alexey Kondratov

Postgres Professional https://www.postgrespro.com
Russian Postgres Company





view thread (175+ messages)  latest in thread

Message-ID: <9b90712303dbecddd8691b95cee93b3a@postgrespro.ru>
Permalink:  ../9b90712303dbecddd8691b95cee93b3a@postgrespro.ru/
Also on:    postgresql.org/message-id/9b90712303dbecddd8691b95cee93b3a@postgrespro.ru

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: a.kondratov@postgrespro.ru, bharath.rupireddyforpostgres@gmail.com, houzj.fnst@cn.fujitsu.com, masao.fujii@oss.nttdata.com
  Subject: Re: [PATCH] postgres_fdw connection caching - cause remote sessions linger till the local session exit
  In-Reply-To: <9b90712303dbecddd8691b95cee93b3a@postgrespro.ru>
  References: <CALj2ACVvrp5=AVp2PupEm+nAC8S4buqR3fJMmaCoc7ftT0aD2A@mail.gmail.com> <6da38393-6ae5-4d87-2690-11c932123403@oss.nttdata.com> <CALj2ACV7egGf+LmuUrjirtn4DeOfWCEP9mrOzgKroJ_6Htekyg@mail.gmail.com> <CALj2ACX7Yr_X25Lc5DAAw5tdAjz7qMTBXqLjWkN67NeCHL+-jA@mail.gmail.com> <0b13f28d-de46-fb06-e946-4c0c00cea591@oss.nttdata.com> <CALj2ACVypPe+4L2uAVMNfXCH3B00fqX5Nx01pVFJCU009BTJdg@mail.gmail.com> <CALj2ACXghAf_GPOVBVuvuPy=9b5ccB7mtf1Jeeoa0QMav-cxOQ@mail.gmail.com> <617e9887b74c4332a5d1e5fb2c56ddfd@G08CNEXMBPEKD05.g08.fujitsu.local> <CALj2ACWReYX_OmqYfS-O5Dw-nTsL95VihTAJW8WdWEDFsnPUtQ@mail.gmail.com> <919942767cf9a3d4e413c63887aec679@postgrespro.ru> <CALj2ACU+u5KGaXHkeDkc_+Lg8U6iiR+G5xM7LjjWC2pugKJhZw@mail.gmail.com> <CALj2ACVRZPUB7ZwqLn-6DY8C_UmPs6084gSpHA92YBv++1AJXA@mail.gmail.com> <b9dc0f5240ca22c58287e9318b981fe3@postgrespro.ru> <CALj2ACVqunXtPGYGwq=aSJZSZd7nuWeA_66Lo43h28NTfjRDWg@mail.gmail.com> <9b90712303dbecddd8691b95cee93b3a@postgrespro.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox