Re: Logical replication - schema change not invalidating the relation cache
vignesh C <vignesh21@gmail.com>
From: vignesh C <vignesh21@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Michael Paquier <michael@paquier.xyz>,
Dilip Kumar <dilipbalaut@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2023-01-06T05:17:24Z
Lists: pgsql-hackers
Attachments
- v6-0001-Fix-for-invalidating-logical-replication-relation.patch (text/x-patch) patch v6-0001
On Fri, 6 Jan 2023 at 04:32, Tom Lane <tgl@sss.pgh.pa.us> wrote: > > vignesh C <vignesh21@gmail.com> writes: > > On Thu, 5 Jan 2023 at 03:17, Tom Lane <tgl@sss.pgh.pa.us> wrote: > >> The bigger picture here though is that in examples such as the one > >> you gave at the top of the thread, it's not very clear to me that > >> there's *any* principled behavior. If the connection between publisher > >> and subscriber tables is only the relation name, fine ... but exactly > >> which relation name applies? > > > The connection between publisher and subscriber table is based on > > relation id, During the first change relid, relname and schema name > > from publisher will be sent to the subscriber. Subscriber stores these > > id, relname and schema name in the LogicalRepRelMap hash for which > > relation id is the key. Subsequent data received in the subscriber > > will use the relation id received from the publisher and apply the > > changes in the subscriber. > > Hm. I spent some time cleaning up this patch, and found that there's > still a problem. ISTM that the row with value "3" ought to end up > in the subscriber's sch2.t1 table, but it does not: the attached > test script fails with > > t/100_bugs.pl .. 6/? > # Failed test 'check data in subscriber sch2.t1 after schema rename' > # at t/100_bugs.pl line 361. > # got: '' > # expected: '3' > # Looks like you failed 1 test of 9. > t/100_bugs.pl .. Dubious, test returned 1 (wstat 256, 0x100) > Failed 1/9 subtests > > What's up with that? When the subscription is created, the subscriber will create a subscription relation map of the corresponding relations from the publication. The subscription relation map will only have sch1.t1 entry. As sch2.t1 was not present in the publisher when the subscription was created, subscription will not have this entry in the subscription relation map. So the insert operations performed on the new table sch2.t1 will not be applied by the subscriber. We will have to refresh the publication using 'ALTER SUBSCRIPTION ... REFRESH PUBLICATION' to fetch missing table information from publisher. This will start replication of tables that were added to the subscribed-to publications since CREATE SUBSCRIPTION or the last invocation of REFRESH PUBLICATION. I have modified the test to include 'ALTER SUBSCRIPTION ... REFRESH PUBLICATION' to get the new data. The test should expect 1 & 3 for sch2.t1 as the record with value 1 was already inserted before rename. The updated v6 patch has the changes for the same. Regards, Vignesh
Commits
-
Invalidate pgoutput's replication-decisions cache upon schema rename.
- cd4b2334db49 16.0 landed
-
Add wait_for_subscription_sync for TAP tests.
- 0c20dd33db16 16.0 cited
-
Unify PostgresNode's new() and get_new_node() methods
- 201a76183e20 15.0 cited