pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Cc: Zhihong Yu <zyu@yugabyte.com>
Cc: Alexey Kondratov <a.kondratov@postgrespro.ru>
Cc: Hou, Zhijie <houzj.fnst@cn.fujitsu.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: [PATCH] postgres_fdw connection caching - cause remote sessions linger till the local session exit
Date: Tue, 19 Jan 2021 00:41:29 +0900
Message-ID: <0bc2b366-76d4-9480-5812-6f0de2b3f526@oss.nttdata.com> (raw)
In-Reply-To: <CALj2ACUv_+qaoYvsy674Aw8Myo-Ydte7b6vRKi3Q8ZmfG+S5Bg@mail.gmail.com>
References: <CALj2ACVvrp5=AVp2PupEm+nAC8S4buqR3fJMmaCoc7ftT0aD2A@mail.gmail.com>
	<f9bb39dd-628c-1c85-5bce-52a420a2fbef@oss.nttdata.com>
	<CALj2ACUHD4z1dw2g2nGt1G3nyKMDS8qR__Df8aDycbe24EZPaA@mail.gmail.com>
	<82debcd7-b236-0fc5-5ff1-5e6b99c59d64@oss.nttdata.com>
	<CALj2ACX-DzNSV3-mJzi+k0gk6kHKFpt64xYXZy0vLh3+hXqFSg@mail.gmail.com>
	<CALj2ACWFbFau2aUchkLpMOWEPH0ipJEJyh-XjUkZU0985OYJMw@mail.gmail.com>
	<55bd82c5-d133-6fbb-f1f4-e25c1509c96e@oss.nttdata.com>
	<CALj2ACWqsVXK0-Mxcp05KtiUFE2HgWbdiww3uFzVZtdOUSGJ1A@mail.gmail.com>
	<CALj2ACXSQq4XQbpzMYSM3uKUzfqtp3Un9o_yErf1SNxHvDXg6Q@mail.gmail.com>
	<CALNJ-vTHJBFBVnxJ2soHhAg6UrCAD9RgMF9RF6yj5AhTuJM-mg@mail.gmail.com>
	<CALj2ACVEadzaB88ZRVF499nFxdO5pBTMCDJ0xG9kvLVhea0eYg@mail.gmail.com>
	<c2a00f21-a80d-8bce-e2ea-8cd8e16c4da9@oss.nttdata.com>
	<CALj2ACURjjg8wVpfb-s8GE+4ycQcx6z+QGQOM3TC_Cjz+=Lq6w@mail.gmail.com>
	<422884a8-c863-a4d4-cebd-562855c29977@oss.nttdata.com>
	<CALj2ACUv_+qaoYvsy674Aw8Myo-Ydte7b6vRKi3Q8ZmfG+S5Bg@mail.gmail.com>



On 2021/01/18 23:14, Bharath Rupireddy wrote:
> On Mon, Jan 18, 2021 at 11:44 AM Fujii Masao
> <masao.fujii@oss.nttdata.com> wrote:
>>> I will post patches for the other function postgres_fdw_disconnect,
>>> GUC and server level option later.
>>
>> Thanks!
> 
> Attaching v12 patch set. 0001 is for postgres_fdw_disconnect()
> function, 0002 is for keep_connections GUC and 0003 is for
> keep_connection server level option.

Thanks!

> 
> Please review it further.

+		server = GetForeignServerByName(servername, true);
+
+		if (!server)
+			ereport(ERROR,
+					(errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),
+					 errmsg("foreign server \"%s\" does not exist", servername)));

ISTM we can simplify this code as follows.

     server = GetForeignServerByName(servername, false);


+	hash_seq_init(&scan, ConnectionHash);
+	while ((entry = (ConnCacheEntry *) hash_seq_search(&scan)))

When the server name is specified, even if its connection is successfully
closed, postgres_fdw_disconnect() scans through all the entries to check
whether there are active connections. But if "result" is true and
active_conn_exists is true, we can get out of this loop to avoid unnecessary
scans.


+	/*
+	 * Destroy the cache if we discarded all active connections i.e. if there
+	 * is no single active connection, which we can know while scanning the
+	 * cached entries in the above loop. Destroying the cache is better than to
+	 * keep it in the memory with all inactive entries in it to save some
+	 * memory. Cache can get initialized on the subsequent queries to foreign
+	 * server.

How much memory is assumed to be saved by destroying the cache in
many cases? I'm not sure if it's really worth destroying the cache to save
the memory.


+      a warning is issued and <literal>false</literal> is returned. <literal>false</literal>
+      is returned when there are no open connections. When there are some open
+      connections, but there is no connection for the given foreign server,
+      then <literal>false</literal> is returned. When no foreign server exists
+      with the given name, an error is emitted. Example usage of the function:

When a non-existent server name is specified, postgres_fdw_disconnect()
emits an error if there is at least one open connection, but just returns
false otherwise. At least for me, this behavior looks inconsitent and strange.
In that case, IMO the function always should emit an error.

Regards,


-- 
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION





view thread (175+ messages)  latest in thread

Message-ID: <0bc2b366-76d4-9480-5812-6f0de2b3f526@oss.nttdata.com>
Permalink:  ../0bc2b366-76d4-9480-5812-6f0de2b3f526@oss.nttdata.com/
Also on:    postgresql.org/message-id/0bc2b366-76d4-9480-5812-6f0de2b3f526@oss.nttdata.com

 · 

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: masao.fujii@oss.nttdata.com, bharath.rupireddyforpostgres@gmail.com, zyu@yugabyte.com, a.kondratov@postgrespro.ru, houzj.fnst@cn.fujitsu.com
  Subject: Re: [PATCH] postgres_fdw connection caching - cause remote sessions linger till the local session exit
  In-Reply-To: <0bc2b366-76d4-9480-5812-6f0de2b3f526@oss.nttdata.com>
  References: <CALj2ACVvrp5=AVp2PupEm+nAC8S4buqR3fJMmaCoc7ftT0aD2A@mail.gmail.com> <CALj2ACUHD4z1dw2g2nGt1G3nyKMDS8qR__Df8aDycbe24EZPaA@mail.gmail.com> <82debcd7-b236-0fc5-5ff1-5e6b99c59d64@oss.nttdata.com> <CALj2ACX-DzNSV3-mJzi+k0gk6kHKFpt64xYXZy0vLh3+hXqFSg@mail.gmail.com> <CALj2ACWFbFau2aUchkLpMOWEPH0ipJEJyh-XjUkZU0985OYJMw@mail.gmail.com> <55bd82c5-d133-6fbb-f1f4-e25c1509c96e@oss.nttdata.com> <CALj2ACWqsVXK0-Mxcp05KtiUFE2HgWbdiww3uFzVZtdOUSGJ1A@mail.gmail.com> <CALj2ACXSQq4XQbpzMYSM3uKUzfqtp3Un9o_yErf1SNxHvDXg6Q@mail.gmail.com> <CALNJ-vTHJBFBVnxJ2soHhAg6UrCAD9RgMF9RF6yj5AhTuJM-mg@mail.gmail.com> <CALj2ACVEadzaB88ZRVF499nFxdO5pBTMCDJ0xG9kvLVhea0eYg@mail.gmail.com> <c2a00f21-a80d-8bce-e2ea-8cd8e16c4da9@oss.nttdata.com> <CALj2ACURjjg8wVpfb-s8GE+4ycQcx6z+QGQOM3TC_Cjz+=Lq6w@mail.gmail.com> <422884a8-c863-a4d4-cebd-562855c29977@oss.nttdata.com> <CALj2ACUv_+qaoYvsy674Aw8Myo-Ydte7b6vRKi3Q8ZmfG+S5Bg@mail.gmail.com> <0bc2b366-76d4-9480-5812-6f0de2b3f526@oss.nttdata.com>

* 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