Re: BUG #14738: ALTER SERVER for foregin servers not working

From: Amit Langote <Langote_Amit_f8(at)lab(dot)ntt(dot)co(dot)jp>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, fcs1(at)poczta(dot)onet(dot)pl
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #14738: ALTER SERVER for foregin servers not working
Date: 2017-07-11 01:23:05
Message-ID: 76f1487a-6b8a-61a9-ebd9-8ff047d0ba94@lab.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On 2017/07/11 1:18, Tom Lane wrote:
> fcs1(at)poczta(dot)onet(dot)pl writes:
>> PostgreSQL version: 9.4.1
>
>> Command like this doesn't take effect:
>> ALTER SERVER srw_egib_1
>> OPTIONS (
>> SET host 'localhost',
>> SET port '5432',
>> SET dbname 'gml2m1');
>> It changes definition of this server but tables connected to it are still
>> connected to previous definition of this server, for example:
>
> It would help if you provided a concrete example of misbehavior rather
> than abstract claims. However, I *think* this is something we fixed in
> 9.4.11.

Perhaps you are referring to the following item fixed in 9.4.11 [1]:

"Ensure that cached plans are invalidated by changes in foreign-table options"

ISTM, OP's problem is unrelated. Steps to reproduce:

create extension postgres_fdw ;
create server s1 foreign data wrapper postgres_fdw options (dbname 'db1');
create server s2 foreign data wrapper postgres_fdw options (dbname 'db2');
create user mapping for current_user server s1;
create user mapping for current_user server s2;
create foreign table t1 (a int) server s1 options (table_name 't1');

-- in db1
create table t1 (a) as select 1;

-- in db2
create table t1 (a) as select 2;

-- back in the original database; t1's server s1 connected to db1
select * from t1;
a
---
1
(1 row)

-- make s1 point to db2
alter server s1 options (set dbname 'db2');

-- postgres_fdw will still connect to db1
select * from t1;
a
---
1
(1 row)

I think that's because postgres_fdw/connection.c keeps a cache of
connections and does not invalidate it upon pg_foreign_server and/or
pg_user_mapping changes. I think we discussed the possibility of fixing
this back when the above-mentioned fix was being worked on [2], but it
went nowhere.

Thanks,
Amit

[1] https://www.postgresql.org/docs/devel/static/release-9-4-11.html
[2]
https://www.postgresql.org/message-id/20160405.184408.166437663.horiguchi.kyotaro%40lab.ntt.co.jp

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kyotaro HORIGUCHI 2017-07-11 01:28:40 Re: BUG #14738: ALTER SERVER for foregin servers not working
Previous Message Peter J. Holzer 2017-07-10 20:17:15 Re: [HACKERS] Postgres process invoking exit resulting in sh-QUIT core

Browse pgsql-hackers by date

  From Date Subject
Next Message Kyotaro HORIGUCHI 2017-07-11 01:28:40 Re: BUG #14738: ALTER SERVER for foregin servers not working
Previous Message AP 2017-07-11 01:21:56 Re: pgsql 10: hash indexes testing