mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
Invalidate all partitions for a partitioned table in publication.
Updates/Deletes on a partition were allowed even without replica identity after the parent table was added to a publication. This would later lead to an error on subscribers. The reason was that we were not invalidating the partition's relcache and the publication information for partitions was not getting rebuilt. Similarly, we were not invalidating the partitions' relcache after dropping a partitioned table from a publication which will prohibit Updates/Deletes on its partition without replica identity even without any publication. Reported-by: Haiying Tang Author: Hou Zhijie and Vignesh C Reviewed-by: Vignesh C and Amit Kapila Backpatch-through: 13 Discussion: https://postgr.es/m/OS0PR01MB6113D77F583C922F1CEAA1C3FBD29@OS0PR01MB6113.jpnprd01.prod.outlook.com
This commit is contained in:
@@ -124,10 +124,12 @@ CREATE PUBLICATION testpub_forparted;
|
||||
CREATE PUBLICATION testpub_forparted1;
|
||||
RESET client_min_messages;
|
||||
CREATE TABLE testpub_parted1 (LIKE testpub_parted);
|
||||
CREATE TABLE testpub_parted2 (LIKE testpub_parted);
|
||||
ALTER PUBLICATION testpub_forparted1 SET (publish='insert');
|
||||
ALTER TABLE testpub_parted ATTACH PARTITION testpub_parted1 FOR VALUES IN (1);
|
||||
ALTER TABLE testpub_parted ATTACH PARTITION testpub_parted2 FOR VALUES IN (2);
|
||||
-- works despite missing REPLICA IDENTITY, because updates are not replicated
|
||||
UPDATE testpub_parted1 SET a = 1;
|
||||
ALTER TABLE testpub_parted ATTACH PARTITION testpub_parted1 FOR VALUES IN (1);
|
||||
-- only parent is listed as being in publication, not the partition
|
||||
ALTER PUBLICATION testpub_forparted ADD TABLE testpub_parted;
|
||||
\dRp+ testpub_forparted
|
||||
@@ -154,7 +156,14 @@ ALTER PUBLICATION testpub_forparted SET (publish_via_partition_root = true);
|
||||
Tables:
|
||||
"public.testpub_parted"
|
||||
|
||||
DROP TABLE testpub_parted1;
|
||||
-- still fail, because parent's publication replicates updates
|
||||
UPDATE testpub_parted2 SET a = 2;
|
||||
ERROR: cannot update table "testpub_parted2" because it does not have a replica identity and publishes updates
|
||||
HINT: To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.
|
||||
ALTER PUBLICATION testpub_forparted DROP TABLE testpub_parted;
|
||||
-- works again, because update is no longer replicated
|
||||
UPDATE testpub_parted2 SET a = 2;
|
||||
DROP TABLE testpub_parted1, testpub_parted2;
|
||||
DROP PUBLICATION testpub_forparted, testpub_forparted1;
|
||||
-- Test cache invalidation FOR ALL TABLES publication
|
||||
SET client_min_messages = 'ERROR';
|
||||
|
@@ -76,10 +76,12 @@ CREATE PUBLICATION testpub_forparted;
|
||||
CREATE PUBLICATION testpub_forparted1;
|
||||
RESET client_min_messages;
|
||||
CREATE TABLE testpub_parted1 (LIKE testpub_parted);
|
||||
CREATE TABLE testpub_parted2 (LIKE testpub_parted);
|
||||
ALTER PUBLICATION testpub_forparted1 SET (publish='insert');
|
||||
ALTER TABLE testpub_parted ATTACH PARTITION testpub_parted1 FOR VALUES IN (1);
|
||||
ALTER TABLE testpub_parted ATTACH PARTITION testpub_parted2 FOR VALUES IN (2);
|
||||
-- works despite missing REPLICA IDENTITY, because updates are not replicated
|
||||
UPDATE testpub_parted1 SET a = 1;
|
||||
ALTER TABLE testpub_parted ATTACH PARTITION testpub_parted1 FOR VALUES IN (1);
|
||||
-- only parent is listed as being in publication, not the partition
|
||||
ALTER PUBLICATION testpub_forparted ADD TABLE testpub_parted;
|
||||
\dRp+ testpub_forparted
|
||||
@@ -90,7 +92,12 @@ ALTER TABLE testpub_parted DETACH PARTITION testpub_parted1;
|
||||
UPDATE testpub_parted1 SET a = 1;
|
||||
ALTER PUBLICATION testpub_forparted SET (publish_via_partition_root = true);
|
||||
\dRp+ testpub_forparted
|
||||
DROP TABLE testpub_parted1;
|
||||
-- still fail, because parent's publication replicates updates
|
||||
UPDATE testpub_parted2 SET a = 2;
|
||||
ALTER PUBLICATION testpub_forparted DROP TABLE testpub_parted;
|
||||
-- works again, because update is no longer replicated
|
||||
UPDATE testpub_parted2 SET a = 2;
|
||||
DROP TABLE testpub_parted1, testpub_parted2;
|
||||
DROP PUBLICATION testpub_forparted, testpub_forparted1;
|
||||
|
||||
-- Test cache invalidation FOR ALL TABLES publication
|
||||
|
Reference in New Issue
Block a user