mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Flush table's relcache during ALTER TABLE ADD PRIMARY KEY USING INDEX.
Previously, unless we had to add a NOT NULL constraint to the column, this command resulted in updating only the index's relcache entry. That's problematic when replication behavior is being driven off the existence of a primary key: other sessions (and ours too for that matter) failed to recalculate their opinion of whether the table can be replicated. Add a relcache invalidation to fix it. This has been broken since pg_class.relhaspkey was removed in v11. Before that, updating the table's relhaspkey value sufficed to cause a cache flush. Hence, backpatch to v11. Report and patch by Hou Zhijie Discussion: https://postgr.es/m/OS0PR01MB5716EBE01F112C62F8F9B786947B9@OS0PR01MB5716.jpnprd01.prod.outlook.com
This commit is contained in:
@@ -268,6 +268,20 @@ Publications:
|
||||
"testpib_ins_trunct"
|
||||
"testpub_fortbl"
|
||||
|
||||
-- verify relation cache invalidation when a primary key is added using
|
||||
-- an existing index
|
||||
CREATE TABLE pub_test.testpub_addpk (id int not null, data int);
|
||||
ALTER PUBLICATION testpub_default ADD TABLE pub_test.testpub_addpk;
|
||||
INSERT INTO pub_test.testpub_addpk VALUES(1, 11);
|
||||
CREATE UNIQUE INDEX testpub_addpk_id_idx ON pub_test.testpub_addpk(id);
|
||||
-- fail:
|
||||
UPDATE pub_test.testpub_addpk SET id = 2;
|
||||
ERROR: cannot update table "testpub_addpk" because it does not have a replica identity and publishes updates
|
||||
HINT: To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.
|
||||
ALTER TABLE pub_test.testpub_addpk ADD PRIMARY KEY USING INDEX testpub_addpk_id_idx;
|
||||
-- now it should work:
|
||||
UPDATE pub_test.testpub_addpk SET id = 2;
|
||||
DROP TABLE pub_test.testpub_addpk;
|
||||
-- permissions
|
||||
SET ROLE regress_publication_user2;
|
||||
CREATE PUBLICATION testpub2; -- fail
|
||||
|
@@ -149,6 +149,19 @@ ALTER PUBLICATION testpub_default DROP TABLE pub_test.testpub_nopk;
|
||||
|
||||
\d+ testpub_tbl1
|
||||
|
||||
-- verify relation cache invalidation when a primary key is added using
|
||||
-- an existing index
|
||||
CREATE TABLE pub_test.testpub_addpk (id int not null, data int);
|
||||
ALTER PUBLICATION testpub_default ADD TABLE pub_test.testpub_addpk;
|
||||
INSERT INTO pub_test.testpub_addpk VALUES(1, 11);
|
||||
CREATE UNIQUE INDEX testpub_addpk_id_idx ON pub_test.testpub_addpk(id);
|
||||
-- fail:
|
||||
UPDATE pub_test.testpub_addpk SET id = 2;
|
||||
ALTER TABLE pub_test.testpub_addpk ADD PRIMARY KEY USING INDEX testpub_addpk_id_idx;
|
||||
-- now it should work:
|
||||
UPDATE pub_test.testpub_addpk SET id = 2;
|
||||
DROP TABLE pub_test.testpub_addpk;
|
||||
|
||||
-- permissions
|
||||
SET ROLE regress_publication_user2;
|
||||
CREATE PUBLICATION testpub2; -- fail
|
||||
|
Reference in New Issue
Block a user