Search Postgresql Archives

Is it safe to create foreign keys beforehand when logical replication is used?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I'm trying to figure out whether the following is safe or not on all conditions with logical replication:


-- on the source (localhost:5432), create the tables which have foreign keys among them
-- load some data and create publication

CREATE TABLE rep_test (a int PRIMARY KEY);
CREATE TABLE rep_test_2 (a int REFERENCES rep_test);
INSERT INTO rep_test SELECT i FROM generate_series(0, 100000) i;
INSERT INTO rep_test_2 SELECT i FROM generate_series(0, 100000) i;
CREATE PUBLICATION pubtest FOR TABLE rep_test, rep_test_2;


-- on the target (localhost:9700) are the following stepscorrect?
-- create the foreign keys before the initial data load

CREATE TABLE rep_test (a int PRIMARY KEY);
CREATE TABLE rep_test_2 (a int REFERENCES rep_test);

-- later, create the subscription
CREATE SUBSCRIPTION testsub CONNECTION 'host=localhost port=5432 user=onderkalaci dbname=postgres' PUBLICATION pubtest;


According to my tests, I've never hit into any issues. But, I'm curious if that's theoretically correct. Is there any case where the table which references to another table's initial data load finishes earlier and the referential integrity is broken? 


Thanks,
Onder

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux