@ -10589,13 +10589,18 @@ drop cascades to foreign table ft7
-- List all the existing cached connections. loopback and loopback3
-- should be output as invalid connections. Also the server name and user name
-- for loopback3 should be NULL because both server and user mapping were
-- dropped.
SELECT server_name, user_name = CURRENT_USER as "user_name = CURRENT_USER", valid, used_in_xact, closed
FROM postgres_fdw_get_connections() ORDER BY 1;
server_name | user_name = CURRENT_USER | valid | used_in_xact | closed
-------------+--------------------------+-------+--------------+--------
loopback | t | f | t |
| | f | t |
-- dropped. In this test, the PIDs of remote backends can be gathered from
-- pg_stat_activity, and remote_backend_pid should match one of those PIDs.
SELECT server_name, user_name = CURRENT_USER as "user_name = CURRENT_USER",
valid, used_in_xact, closed,
remote_backend_pid = ANY(SELECT pid FROM pg_stat_activity
WHERE backend_type = 'client backend' AND pid <> pg_backend_pid())
as remote_backend_pid
FROM postgres_fdw_get_connections() ORDER BY 1;
server_name | user_name = CURRENT_USER | valid | used_in_xact | closed | remote_backend_pid
-------------+--------------------------+-------+--------------+--------+--------------------
loopback | t | f | t | | t
| | f | t | | t
(2 rows)
-- The invalid connections get closed in pgfdw_xact_callback during commit.
@ -12436,25 +12441,34 @@ SELECT 1 FROM ft1 LIMIT 1;
-- Since the remote server is still connected, "closed" should be FALSE,
-- or NULL if the connection status check is not available.
SELECT CASE WHEN closed IS NOT true THEN 1 ELSE 0 END
-- In this test, the remote backend handling this connection should have
-- application_name set to "fdw_conn_check", so remote_backend_pid should
-- match the PID from the pg_stat_activity entry with that application_name.
SELECT server_name,
CASE WHEN closed IS NOT true THEN false ELSE true END AS closed,
remote_backend_pid = (SELECT pid FROM pg_stat_activity
WHERE application_name = 'fdw_conn_check') AS remote_backend_pid
FROM postgres_fdw_get_connections(true);
case
------
1
server_name | closed | remote_backend_pid
-------------+--------+--------------------
loopback | f | t
(1 row)
-- After terminating the remote backend, since the connection is closed,
-- "closed" should be TRUE, or NULL if the connection status check
-- is not available.
-- is not available. Despite the termination, remote_backend_pid should
-- still show the non-zero PID of the terminated remote backend.
DO $$ BEGIN
PERFORM pg_terminate_backend(pid, 180000) FROM pg_stat_activity
WHERE application_name = 'fdw_conn_check';
END $$;
SELECT CASE WHEN closed IS NOT false THEN 1 ELSE 0 END
SELECT server_name,
CASE WHEN closed IS NOT false THEN true ELSE false END AS closed,
remote_backend_pid <> 0 AS remote_backend_pid
FROM postgres_fdw_get_connections(true);
case
------
1
server_name | closed | remote_backend_pid
-------------+--------+--------------------
loopback | t | t
(1 row)
-- Clean up