diff options
author | Fujii Masao <fujii@postgresql.org> | 2020-12-28 19:57:51 +0900 |
---|---|---|
committer | Fujii Masao <fujii@postgresql.org> | 2020-12-28 19:57:51 +0900 |
commit | 546f143740a07c4d9798f5870af8dad73ae057b5 (patch) | |
tree | 583bcaa0012485900022372404f10075c1ff11bd /contrib/postgres_fdw/sql/postgres_fdw.sql | |
parent | cd7d8cde75063a85ee8c5fd27713061e56a8684d (diff) | |
download | postgresql-546f143740a07c4d9798f5870af8dad73ae057b5.tar.gz postgresql-546f143740a07c4d9798f5870af8dad73ae057b5.zip |
postgres_fdw: Fix connection leak.
In postgres_fdw, the cached connections to foreign servers will not be
closed until the local session exits if the user mappings or foreign servers
that those connections depend on are dropped. Those connections can be
leaked.
To fix that connection leak issue, after a change to a pg_foreign_server
or pg_user_mapping catalog entry, this commit makes postgres_fdw close
the connections depending on that entry immediately if current
transaction has not used those connections yet. Otherwise, mark those
connections as invalid and then close them at the end of current transaction,
since they cannot be closed in the midst of the transaction using them.
Closed connections will be remade at the next opportunity if necessary.
Back-patch to all supported branches.
Author: Bharath Rupireddy
Reviewed-by: Zhihong Yu, Zhijie Hou, Fujii Masao
Discussion: https://postgr.es/m/CALj2ACVNcGH_6qLY-4_tXz8JLvA+4yeBThRfxMz7Oxbk1aHcpQ@mail.gmail.com
Diffstat (limited to 'contrib/postgres_fdw/sql/postgres_fdw.sql')
-rw-r--r-- | contrib/postgres_fdw/sql/postgres_fdw.sql | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql index 83971665e35..29c61e7ff45 100644 --- a/contrib/postgres_fdw/sql/postgres_fdw.sql +++ b/contrib/postgres_fdw/sql/postgres_fdw.sql @@ -2634,3 +2634,17 @@ SELECT count(*) FROM ft1; -- error here PREPARE TRANSACTION 'fdw_tpc'; ROLLBACK; + +-- =================================================================== +-- test connection invalidation cases +-- =================================================================== +-- This test case is for closing the connection in pgfdw_xact_callback +BEGIN; +-- Connection xact depth becomes 1 i.e. the connection is in midst of the xact. +SELECT 1 FROM ft1 LIMIT 1; +-- Connection is not closed at the end of the alter statement in +-- pgfdw_inval_callback. That's because the connection is in midst of this +-- xact, it is just marked as invalid. +ALTER SERVER loopback OPTIONS (ADD use_remote_estimate 'off'); +-- The invalid connection gets closed in pgfdw_xact_callback during commit. +COMMIT; |