mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +03:00
Re-establish postgres_fdw connections after server or user mapping changes.
Previously, postgres_fdw would keep on using an existing connection even
if the user did ALTER SERVER or ALTER USER MAPPING commands that should
affect connection parameters. Teach it to watch for catcache invals
on these catalogs and re-establish connections when the relevant catalog
entries change. Per bug #14738 from Michal Lis.
In passing, clean up some rather crufty decisions in commit ae9bfc5d6
about where fields of ConnCacheEntry should be reset. We now reset
all the fields whenever we open a new connection.
Kyotaro Horiguchi, reviewed by Ashutosh Bapat and myself.
Back-patch to 9.3 where postgres_fdw appeared.
Discussion: https://postgr.es/m/20170710113917.7727.10247@wrigleys.postgresql.org
This commit is contained in:
@ -191,6 +191,43 @@ ALTER FOREIGN TABLE ft2 ALTER COLUMN c1 OPTIONS (column_name 'C 1');
|
||||
public | ft_pg_type | loopback | (schema_name 'pg_catalog', table_name 'pg_type') |
|
||||
(6 rows)
|
||||
|
||||
-- Test that alteration of server options causes reconnection
|
||||
SELECT c3, c4 FROM ft1 ORDER BY c3, c1 LIMIT 1; -- should work
|
||||
c3 | c4
|
||||
-------+------------------------------
|
||||
00001 | Fri Jan 02 00:00:00 1970 PST
|
||||
(1 row)
|
||||
|
||||
ALTER SERVER loopback OPTIONS (SET dbname 'no such database');
|
||||
SELECT c3, c4 FROM ft1 ORDER BY c3, c1 LIMIT 1; -- should fail
|
||||
ERROR: could not connect to server "loopback"
|
||||
DETAIL: FATAL: database "no such database" does not exist
|
||||
DO $d$
|
||||
BEGIN
|
||||
EXECUTE $$ALTER SERVER loopback
|
||||
OPTIONS (SET dbname '$$||current_database()||$$')$$;
|
||||
END;
|
||||
$d$;
|
||||
SELECT c3, c4 FROM ft1 ORDER BY c3, c1 LIMIT 1; -- should work again
|
||||
c3 | c4
|
||||
-------+------------------------------
|
||||
00001 | Fri Jan 02 00:00:00 1970 PST
|
||||
(1 row)
|
||||
|
||||
-- Test that alteration of user mapping options causes reconnection
|
||||
ALTER USER MAPPING FOR CURRENT_USER SERVER loopback
|
||||
OPTIONS (ADD user 'no such user');
|
||||
SELECT c3, c4 FROM ft1 ORDER BY c3, c1 LIMIT 1; -- should fail
|
||||
ERROR: could not connect to server "loopback"
|
||||
DETAIL: FATAL: role "no such user" does not exist
|
||||
ALTER USER MAPPING FOR CURRENT_USER SERVER loopback
|
||||
OPTIONS (DROP user);
|
||||
SELECT c3, c4 FROM ft1 ORDER BY c3, c1 LIMIT 1; -- should work again
|
||||
c3 | c4
|
||||
-------+------------------------------
|
||||
00001 | Fri Jan 02 00:00:00 1970 PST
|
||||
(1 row)
|
||||
|
||||
-- Now we should be able to run ANALYZE.
|
||||
-- To exercise multiple code paths, we use local stats on ft1
|
||||
-- and remote-estimate mode on ft2.
|
||||
|
Reference in New Issue
Block a user