Commit b31fbe85 authored by Thomas Munro's avatar Thomas Munro

Warn if wal_level is too low when creating a publication.

Provide a hint to users that they need to increase wal_level before
subscriptions can work.

Author: Lucas Viecelli, with some adjustments by Thomas Munro
Reviewed-by: Tom Lane
Discussion: https://postgr.es/m/CAPjy-57rn5Y9g4e5u--eSOP-7P4QrE9uOZmT2ZcUebF8qxsYhg%40mail.gmail.com
parent d3751adc
...@@ -232,6 +232,14 @@ CreatePublication(CreatePublicationStmt *stmt) ...@@ -232,6 +232,14 @@ CreatePublication(CreatePublicationStmt *stmt)
InvokeObjectPostCreateHook(PublicationRelationId, puboid, 0); InvokeObjectPostCreateHook(PublicationRelationId, puboid, 0);
if (wal_level != WAL_LEVEL_LOGICAL)
{
ereport(WARNING,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("wal_level is insufficient to publish logical changes"),
errhint("Set wal_level to logical before creating subscriptions.")));
}
return myself; return myself;
} }
......
...@@ -42,7 +42,10 @@ ALTER DEFAULT PRIVILEGES FOR ROLE regress_addr_user REVOKE DELETE ON TABLES FROM ...@@ -42,7 +42,10 @@ ALTER DEFAULT PRIVILEGES FOR ROLE regress_addr_user REVOKE DELETE ON TABLES FROM
CREATE TRANSFORM FOR int LANGUAGE SQL ( CREATE TRANSFORM FOR int LANGUAGE SQL (
FROM SQL WITH FUNCTION prsd_lextype(internal), FROM SQL WITH FUNCTION prsd_lextype(internal),
TO SQL WITH FUNCTION int4recv(internal)); TO SQL WITH FUNCTION int4recv(internal));
-- suppress warning that depends on wal_level
SET client_min_messages = 'ERROR';
CREATE PUBLICATION addr_pub FOR TABLE addr_nsp.gentable; CREATE PUBLICATION addr_pub FOR TABLE addr_nsp.gentable;
RESET client_min_messages;
CREATE SUBSCRIPTION regress_addr_sub CONNECTION '' PUBLICATION bar WITH (connect = false, slot_name = NONE); CREATE SUBSCRIPTION regress_addr_sub CONNECTION '' PUBLICATION bar WITH (connect = false, slot_name = NONE);
WARNING: tables were not subscribed, you will have to run ALTER SUBSCRIPTION ... REFRESH PUBLICATION to subscribe the tables WARNING: tables were not subscribed, you will have to run ALTER SUBSCRIPTION ... REFRESH PUBLICATION to subscribe the tables
CREATE STATISTICS addr_nsp.gentable_stat ON a, b FROM addr_nsp.gentable; CREATE STATISTICS addr_nsp.gentable_stat ON a, b FROM addr_nsp.gentable;
......
...@@ -5,7 +5,10 @@ CREATE ROLE regress_publication_user LOGIN SUPERUSER; ...@@ -5,7 +5,10 @@ CREATE ROLE regress_publication_user LOGIN SUPERUSER;
CREATE ROLE regress_publication_user2; CREATE ROLE regress_publication_user2;
CREATE ROLE regress_publication_user_dummy LOGIN NOSUPERUSER; CREATE ROLE regress_publication_user_dummy LOGIN NOSUPERUSER;
SET SESSION AUTHORIZATION 'regress_publication_user'; SET SESSION AUTHORIZATION 'regress_publication_user';
-- suppress warning that depends on wal_level
SET client_min_messages = 'ERROR';
CREATE PUBLICATION testpub_default; CREATE PUBLICATION testpub_default;
RESET client_min_messages;
COMMENT ON PUBLICATION testpub_default IS 'test publication'; COMMENT ON PUBLICATION testpub_default IS 'test publication';
SELECT obj_description(p.oid, 'pg_publication') FROM pg_publication p; SELECT obj_description(p.oid, 'pg_publication') FROM pg_publication p;
obj_description obj_description
...@@ -13,7 +16,9 @@ SELECT obj_description(p.oid, 'pg_publication') FROM pg_publication p; ...@@ -13,7 +16,9 @@ SELECT obj_description(p.oid, 'pg_publication') FROM pg_publication p;
test publication test publication
(1 row) (1 row)
SET client_min_messages = 'ERROR';
CREATE PUBLICATION testpib_ins_trunct WITH (publish = insert); CREATE PUBLICATION testpib_ins_trunct WITH (publish = insert);
RESET client_min_messages;
ALTER PUBLICATION testpub_default SET (publish = update); ALTER PUBLICATION testpub_default SET (publish = update);
-- error cases -- error cases
CREATE PUBLICATION testpub_xxx WITH (foo); CREATE PUBLICATION testpub_xxx WITH (foo);
...@@ -43,7 +48,9 @@ CREATE TABLE testpub_tbl1 (id serial primary key, data text); ...@@ -43,7 +48,9 @@ CREATE TABLE testpub_tbl1 (id serial primary key, data text);
CREATE TABLE pub_test.testpub_nopk (foo int, bar int); CREATE TABLE pub_test.testpub_nopk (foo int, bar int);
CREATE VIEW testpub_view AS SELECT 1; CREATE VIEW testpub_view AS SELECT 1;
CREATE TABLE testpub_parted (a int) PARTITION BY LIST (a); CREATE TABLE testpub_parted (a int) PARTITION BY LIST (a);
SET client_min_messages = 'ERROR';
CREATE PUBLICATION testpub_foralltables FOR ALL TABLES WITH (publish = 'insert'); CREATE PUBLICATION testpub_foralltables FOR ALL TABLES WITH (publish = 'insert');
RESET client_min_messages;
ALTER PUBLICATION testpub_foralltables SET (publish = 'insert, update'); ALTER PUBLICATION testpub_foralltables SET (publish = 'insert, update');
CREATE TABLE testpub_tbl2 (id serial primary key, data text); CREATE TABLE testpub_tbl2 (id serial primary key, data text);
-- fail - can't add to for all tables publication -- fail - can't add to for all tables publication
...@@ -86,8 +93,10 @@ DROP TABLE testpub_tbl2; ...@@ -86,8 +93,10 @@ DROP TABLE testpub_tbl2;
DROP PUBLICATION testpub_foralltables; DROP PUBLICATION testpub_foralltables;
CREATE TABLE testpub_tbl3 (a int); CREATE TABLE testpub_tbl3 (a int);
CREATE TABLE testpub_tbl3a (b text) INHERITS (testpub_tbl3); CREATE TABLE testpub_tbl3a (b text) INHERITS (testpub_tbl3);
SET client_min_messages = 'ERROR';
CREATE PUBLICATION testpub3 FOR TABLE testpub_tbl3; CREATE PUBLICATION testpub3 FOR TABLE testpub_tbl3;
CREATE PUBLICATION testpub4 FOR TABLE ONLY testpub_tbl3; CREATE PUBLICATION testpub4 FOR TABLE ONLY testpub_tbl3;
RESET client_min_messages;
\dRp+ testpub3 \dRp+ testpub3
Publication testpub3 Publication testpub3
Owner | All tables | Inserts | Updates | Deletes | Truncates Owner | All tables | Inserts | Updates | Deletes | Truncates
...@@ -111,7 +120,9 @@ DROP PUBLICATION testpub3, testpub4; ...@@ -111,7 +120,9 @@ DROP PUBLICATION testpub3, testpub4;
CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_view; CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_view;
ERROR: "testpub_view" is not a table ERROR: "testpub_view" is not a table
DETAIL: Only tables can be added to publications. DETAIL: Only tables can be added to publications.
SET client_min_messages = 'ERROR';
CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1, pub_test.testpub_nopk; CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1, pub_test.testpub_nopk;
RESET client_min_messages;
-- fail - already added -- fail - already added
ALTER PUBLICATION testpub_fortbl ADD TABLE testpub_tbl1; ALTER PUBLICATION testpub_fortbl ADD TABLE testpub_tbl1;
ERROR: relation "testpub_tbl1" is already member of publication "testpub_fortbl" ERROR: relation "testpub_tbl1" is already member of publication "testpub_fortbl"
...@@ -196,7 +207,9 @@ ERROR: permission denied for database regression ...@@ -196,7 +207,9 @@ ERROR: permission denied for database regression
SET ROLE regress_publication_user; SET ROLE regress_publication_user;
GRANT CREATE ON DATABASE regression TO regress_publication_user2; GRANT CREATE ON DATABASE regression TO regress_publication_user2;
SET ROLE regress_publication_user2; SET ROLE regress_publication_user2;
SET client_min_messages = 'ERROR';
CREATE PUBLICATION testpub2; -- ok CREATE PUBLICATION testpub2; -- ok
RESET client_min_messages;
ALTER PUBLICATION testpub2 ADD TABLE testpub_tbl1; -- fail ALTER PUBLICATION testpub2 ADD TABLE testpub_tbl1; -- fail
ERROR: must be owner of table testpub_tbl1 ERROR: must be owner of table testpub_tbl1
SET ROLE regress_publication_user; SET ROLE regress_publication_user;
......
...@@ -45,7 +45,10 @@ ALTER DEFAULT PRIVILEGES FOR ROLE regress_addr_user REVOKE DELETE ON TABLES FROM ...@@ -45,7 +45,10 @@ ALTER DEFAULT PRIVILEGES FOR ROLE regress_addr_user REVOKE DELETE ON TABLES FROM
CREATE TRANSFORM FOR int LANGUAGE SQL ( CREATE TRANSFORM FOR int LANGUAGE SQL (
FROM SQL WITH FUNCTION prsd_lextype(internal), FROM SQL WITH FUNCTION prsd_lextype(internal),
TO SQL WITH FUNCTION int4recv(internal)); TO SQL WITH FUNCTION int4recv(internal));
-- suppress warning that depends on wal_level
SET client_min_messages = 'ERROR';
CREATE PUBLICATION addr_pub FOR TABLE addr_nsp.gentable; CREATE PUBLICATION addr_pub FOR TABLE addr_nsp.gentable;
RESET client_min_messages;
CREATE SUBSCRIPTION regress_addr_sub CONNECTION '' PUBLICATION bar WITH (connect = false, slot_name = NONE); CREATE SUBSCRIPTION regress_addr_sub CONNECTION '' PUBLICATION bar WITH (connect = false, slot_name = NONE);
CREATE STATISTICS addr_nsp.gentable_stat ON a, b FROM addr_nsp.gentable; CREATE STATISTICS addr_nsp.gentable_stat ON a, b FROM addr_nsp.gentable;
......
...@@ -6,12 +6,17 @@ CREATE ROLE regress_publication_user2; ...@@ -6,12 +6,17 @@ CREATE ROLE regress_publication_user2;
CREATE ROLE regress_publication_user_dummy LOGIN NOSUPERUSER; CREATE ROLE regress_publication_user_dummy LOGIN NOSUPERUSER;
SET SESSION AUTHORIZATION 'regress_publication_user'; SET SESSION AUTHORIZATION 'regress_publication_user';
-- suppress warning that depends on wal_level
SET client_min_messages = 'ERROR';
CREATE PUBLICATION testpub_default; CREATE PUBLICATION testpub_default;
RESET client_min_messages;
COMMENT ON PUBLICATION testpub_default IS 'test publication'; COMMENT ON PUBLICATION testpub_default IS 'test publication';
SELECT obj_description(p.oid, 'pg_publication') FROM pg_publication p; SELECT obj_description(p.oid, 'pg_publication') FROM pg_publication p;
SET client_min_messages = 'ERROR';
CREATE PUBLICATION testpib_ins_trunct WITH (publish = insert); CREATE PUBLICATION testpib_ins_trunct WITH (publish = insert);
RESET client_min_messages;
ALTER PUBLICATION testpub_default SET (publish = update); ALTER PUBLICATION testpub_default SET (publish = update);
...@@ -32,7 +37,9 @@ CREATE TABLE pub_test.testpub_nopk (foo int, bar int); ...@@ -32,7 +37,9 @@ CREATE TABLE pub_test.testpub_nopk (foo int, bar int);
CREATE VIEW testpub_view AS SELECT 1; CREATE VIEW testpub_view AS SELECT 1;
CREATE TABLE testpub_parted (a int) PARTITION BY LIST (a); CREATE TABLE testpub_parted (a int) PARTITION BY LIST (a);
SET client_min_messages = 'ERROR';
CREATE PUBLICATION testpub_foralltables FOR ALL TABLES WITH (publish = 'insert'); CREATE PUBLICATION testpub_foralltables FOR ALL TABLES WITH (publish = 'insert');
RESET client_min_messages;
ALTER PUBLICATION testpub_foralltables SET (publish = 'insert, update'); ALTER PUBLICATION testpub_foralltables SET (publish = 'insert, update');
CREATE TABLE testpub_tbl2 (id serial primary key, data text); CREATE TABLE testpub_tbl2 (id serial primary key, data text);
...@@ -52,8 +59,10 @@ DROP PUBLICATION testpub_foralltables; ...@@ -52,8 +59,10 @@ DROP PUBLICATION testpub_foralltables;
CREATE TABLE testpub_tbl3 (a int); CREATE TABLE testpub_tbl3 (a int);
CREATE TABLE testpub_tbl3a (b text) INHERITS (testpub_tbl3); CREATE TABLE testpub_tbl3a (b text) INHERITS (testpub_tbl3);
SET client_min_messages = 'ERROR';
CREATE PUBLICATION testpub3 FOR TABLE testpub_tbl3; CREATE PUBLICATION testpub3 FOR TABLE testpub_tbl3;
CREATE PUBLICATION testpub4 FOR TABLE ONLY testpub_tbl3; CREATE PUBLICATION testpub4 FOR TABLE ONLY testpub_tbl3;
RESET client_min_messages;
\dRp+ testpub3 \dRp+ testpub3
\dRp+ testpub4 \dRp+ testpub4
...@@ -62,7 +71,9 @@ DROP PUBLICATION testpub3, testpub4; ...@@ -62,7 +71,9 @@ DROP PUBLICATION testpub3, testpub4;
-- fail - view -- fail - view
CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_view; CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_view;
SET client_min_messages = 'ERROR';
CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1, pub_test.testpub_nopk; CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1, pub_test.testpub_nopk;
RESET client_min_messages;
-- fail - already added -- fail - already added
ALTER PUBLICATION testpub_fortbl ADD TABLE testpub_tbl1; ALTER PUBLICATION testpub_fortbl ADD TABLE testpub_tbl1;
-- fail - already added -- fail - already added
...@@ -98,7 +109,9 @@ CREATE PUBLICATION testpub2; -- fail ...@@ -98,7 +109,9 @@ CREATE PUBLICATION testpub2; -- fail
SET ROLE regress_publication_user; SET ROLE regress_publication_user;
GRANT CREATE ON DATABASE regression TO regress_publication_user2; GRANT CREATE ON DATABASE regression TO regress_publication_user2;
SET ROLE regress_publication_user2; SET ROLE regress_publication_user2;
SET client_min_messages = 'ERROR';
CREATE PUBLICATION testpub2; -- ok CREATE PUBLICATION testpub2; -- ok
RESET client_min_messages;
ALTER PUBLICATION testpub2 ADD TABLE testpub_tbl1; -- fail ALTER PUBLICATION testpub2 ADD TABLE testpub_tbl1; -- fail
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment