Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1grNsR-000116-ML for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Feb 2019 14:08:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1grNsO-0004jg-MM for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Feb 2019 14:08:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1grNXW-0006KX-Nt for pgsql-bugs@lists.postgresql.org; Wed, 06 Feb 2019 13:46:59 +0000 Received: from smtp6-g21.free.fr ([212.27.42.6]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1grNX4-0003e3-HC for pgsql-bugs@postgresql.org; Wed, 06 Feb 2019 13:46:57 +0000 Received: from LHMHXWW1 (unknown [185.105.155.54]) (Authenticated sender: shmv) by smtp6-g21.free.fr (Postfix) with ESMTPSA id AD4DC780326; Wed, 6 Feb 2019 13:46:23 +0000 (UTC) From: "shmv" To: Subject: Query issues on Foreign tables Date: Wed, 6 Feb 2019 14:46:23 +0100 Message-ID: <002801d4be22$5b317380$11945a80$@free.fr> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0029_01D4BE2A.BCF98500" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdS+IVVGqa3mx4qHSt+f0MlvkAkaXA== Content-Language: fr List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multipart message in MIME format. ------=_NextPart_000_0029_01D4BE2A.BCF98500 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hello, =20 I have a strange behavior when selecting data from foreign tables using = =E2=80=9Cpostgres_fdw=E2=80=9D.=20 When you repeatedly select data from a foreign table, as long as the = query finds results, changes made to the original table=E2=80=99s data = are visible.=20 But if at a moment the query does not return any row, future changes to = table=E2=80=99s data are no longer visible. =20 Test platform: I=E2=80=99ve two servers (A and B) with a schema named = =E2=80=9Cvalerie=E2=80=9D on each server. The user name is also =E2=80=9Cvalerie=E2=80=9D. Postgres version is 11.1. Auto commit is enabled on both servers. I use pgAdmin4 for the tests but I have the same issue when using psql = or writing applications with ecpg. =20 On server A: 1) Create the physical table: =20 Create Table my_schema.Test (ID integer Not Null Primary key, Name = varchar (10) Not Null); =20 2) Create a stored procedure inserting data into the table: =20 Create or replace procedure valerie.p_insert() as $$ Declare i integer; _first integer; Begin Select Coalesce (Max(ID), 0) + 1 Into _first From valerie.Test; =20 -- Insert 10 records For i In _first .._first + 9 Loop Insert into valerie.test values =E2=80=8B=E2=80=8B(i, 'name' || = i); End Loop; End; $$ Language plpgsql; =20 =20 On server B: =20 1) Create the foreign server and related mappings: =20 Create Server Server_A Foreign Data Wrapper postgres_fdw=20 Options (host 'PC7CA1', port '5432', dbname 'postgres'); =20 Grant Usage On Foreign Server Server_A To valerie; =20 Create User Mapping For valerie Server Server_A Options(user 'valerie', = password 'secret'); =20 2) Create the foreign table =20 Create Foreign Table valerie.FT_Test (ID integer Not Null, Name varchar = (10) Not Null)=20 Server Server_A Options (schema_name 'valerie', table_name 'test'); =20 Check: Select * From valerie.FT_Test; <- OK (No data found) =20 3) Create a stored procedure reading and deleting data from the = foreign table: =20 Create or replace procedure p_test() as $$ Declare i integer; pk integer; nb integer; Begin For i in 1..30 Loop Select count(*), min(id)=20 Into nb, pk=20 From Valerie.FT_Test; =20 If ( Not Found OR pk is null OR nb =3D 0 )=20 Then Raise Notice '%','Not found.'; Else Raise Notice '%','Count: '||nb||'. Deleting row = '||pk||'...'; =20 Delete from valerie.FT_Test where ID =3D pk; Commit; End if; =20 Perform pg_sleep(2); End Loop; End; $$ LANGUAGE plpgsql; =20 =20 Test 1:=20 =20 Server A Server B The table is empty! =20 =20 =20 Call valerie.p_insert(); =20 =20 =20 ... Call valerie.p_test(); NOTICE: Not found.=20 NOTICE: Not found.=20 NOTICE: Not found. =C3=9F 10 records added and commited NOTICE: Not found.=20 NOTICE: Not found.=20 NOTICE: Not found. ... NOTICE: Not found.=20 NOTICE: Not found. CALL =20 =20 Test 2: =20 Server A Server B Call valerie.p_insert(); =20 =20 =20 =20 =20 =20 =20 =20 =20 Call valerie.p_insert(); =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 Call valerie.p_insert(); =20 =20 <-- The table contains 10 records ... Call valerie.p_test(); =20 NOTICE: Count: 10. Deleting row 1... NOTICE: Count: 9. Deleting row 2... NOTICE: Count: 8. Deleting row 3... NOTICE: Count: 7. Deleting row 4... NOTICE: Count: 6. Deleting row 5... NOTICE: Count: 5. Deleting row 6... NOTICE: Count: 14. Deleting row 7... =C3=9F 10 records added OK! NOTICE: Count: 13. Deleting row 8... NOTICE: Count: 12. Deleting row 9... NOTICE: Count: 11. Deleting row 10... NOTICE: Count: 10. Deleting row 11... NOTICE: Count: 9. Deleting row 12... NOTICE: Count: 8. Deleting row 13... NOTICE: Count: 7. Deleting row 14... NOTICE: Count: 6. Deleting row 15... NOTICE: Count: 5. Deleting row 16... NOTICE: Count: 4. Deleting row 17... NOTICE: Count: 3. Deleting row 18... NOTICE: Count: 2. Deleting row 19... NOTICE: Count: 1. Deleting row 20... NOTICE: Not found. NOTICE: Not found. NOTICE: Not found. NOTICE: Not found.=20 NOTICE: Not found. NOTICE: Not found. =C3=9F 10 records added NOT OK! NOTICE: Not found. NOTICE: Not found. NOTICE: Not found. NOTICE: Not found. CALL =20 =20 Best Regards, =20 Shahram MOINVAZIRI =20 =20 ------=_NextPart_000_0029_01D4BE2A.BCF98500 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable

Hello,

 

I have a strange behavior when = selecting data from foreign tables using =E2=80=9Cpostgres_fdw=E2=80=9D. =

When you = repeatedly select data from a foreign table, as long as the query finds = results, changes made to the original table=E2=80=99s data are visible. =

But if at = a moment the query does not return any row, future changes to = table=E2=80=99s data are no longer visible.

 

Test = platform:

I=E2=80=99ve two servers (A and B) with a schema named = =E2=80=9Cvalerie=E2=80=9D on each server.

The user name is also = =E2=80=9Cvalerie=E2=80=9D.

Postgres version is = 11.1.

Auto = commit is enabled on both servers.

I use pgAdmin4 for the tests but I = have the same issue when using psql or writing applications with = ecpg.

 

On server = A:

1)      = Create the physical = table:

 

Create Table = my_schema.Test (ID integer Not Null Primary key, Name varchar (10) Not = Null);

 

2)      = Create a stored = procedure inserting data into the table:

 

Create or replace = procedure valerie.p_insert() as $$

Declare

   i = =C2=A0=C2=A0=C2=A0=C2=A0integer;

  _first = integer;

Begin

   Select Coalesce (Max(ID), 0) + 1 Into _first =