2017-01-19 18:00:00 +01:00
|
|
|
--
|
|
|
|
-- PUBLICATION
|
|
|
|
--
|
|
|
|
CREATE ROLE regress_publication_user LOGIN SUPERUSER;
|
2017-03-15 18:52:07 +01:00
|
|
|
CREATE ROLE regress_publication_user2;
|
2017-03-08 04:44:59 +01:00
|
|
|
CREATE ROLE regress_publication_user_dummy LOGIN NOSUPERUSER;
|
2017-01-19 18:00:00 +01:00
|
|
|
SET SESSION AUTHORIZATION 'regress_publication_user';
|
2019-07-13 00:35:34 +02:00
|
|
|
-- suppress warning that depends on wal_level
|
|
|
|
SET client_min_messages = 'ERROR';
|
2017-01-19 18:00:00 +01:00
|
|
|
CREATE PUBLICATION testpub_default;
|
2019-07-13 00:35:34 +02:00
|
|
|
RESET client_min_messages;
|
2017-03-25 04:25:24 +01:00
|
|
|
COMMENT ON PUBLICATION testpub_default IS 'test publication';
|
|
|
|
SELECT obj_description(p.oid, 'pg_publication') FROM pg_publication p;
|
|
|
|
obj_description
|
|
|
|
------------------
|
|
|
|
test publication
|
|
|
|
(1 row)
|
|
|
|
|
2019-07-13 00:35:34 +02:00
|
|
|
SET client_min_messages = 'ERROR';
|
2017-05-12 14:57:01 +02:00
|
|
|
CREATE PUBLICATION testpib_ins_trunct WITH (publish = insert);
|
2019-07-13 00:35:34 +02:00
|
|
|
RESET client_min_messages;
|
2017-05-12 14:57:01 +02:00
|
|
|
ALTER PUBLICATION testpub_default SET (publish = update);
|
|
|
|
-- error cases
|
|
|
|
CREATE PUBLICATION testpub_xxx WITH (foo);
|
2019-05-17 02:40:02 +02:00
|
|
|
ERROR: unrecognized publication parameter: "foo"
|
2017-05-12 14:57:01 +02:00
|
|
|
CREATE PUBLICATION testpub_xxx WITH (publish = 'cluster, vacuum');
|
|
|
|
ERROR: unrecognized "publish" value: "cluster"
|
2020-04-08 09:59:27 +02:00
|
|
|
CREATE PUBLICATION testpub_xxx WITH (publish_via_partition_root = 'true', publish_via_partition_root = '0');
|
|
|
|
ERROR: conflicting or redundant options
|
Improve reporting of "conflicting or redundant options" errors.
When reporting "conflicting or redundant options" errors, try to
ensure that errposition() is used, to help the user identify the
offending option.
Formerly, errposition() was invoked in less than 60% of cases. This
patch raises that to over 90%, but there remain a few places where the
ParseState is not readily available. Using errdetail() might improve
the error in such cases, but that is left as a task for the future.
Additionally, since this error is thrown from over 100 places in the
codebase, introduce a dedicated function to throw it, reducing code
duplication.
Extracted from a slightly larger patch by Vignesh C. Reviewed by
Bharath Rupireddy, Alvaro Herrera, Dilip Kumar, Hou Zhijie, Peter
Smith, Daniel Gustafsson, Julien Rouhaud and me.
Discussion: https://postgr.es/m/CALDaNm33FFSS5tVyvmkoK2cCMuDVxcui=gFrjti9ROfynqSAGA@mail.gmail.com
2021-07-15 09:49:45 +02:00
|
|
|
LINE 1: ...ub_xxx WITH (publish_via_partition_root = 'true', publish_vi...
|
|
|
|
^
|
2017-01-19 18:00:00 +01:00
|
|
|
\dRp
|
2020-04-08 09:59:27 +02:00
|
|
|
List of publications
|
|
|
|
Name | Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------+--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
testpib_ins_trunct | regress_publication_user | f | t | f | f | f | f
|
|
|
|
testpub_default | regress_publication_user | f | f | t | f | f | f
|
2017-01-19 18:00:00 +01:00
|
|
|
(2 rows)
|
|
|
|
|
2017-05-12 14:57:01 +02:00
|
|
|
ALTER PUBLICATION testpub_default SET (publish = 'insert, update, delete');
|
2017-01-19 18:00:00 +01:00
|
|
|
\dRp
|
2020-04-08 09:59:27 +02:00
|
|
|
List of publications
|
|
|
|
Name | Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------+--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
testpib_ins_trunct | regress_publication_user | f | t | f | f | f | f
|
|
|
|
testpub_default | regress_publication_user | f | t | t | t | f | f
|
2017-01-19 18:00:00 +01:00
|
|
|
(2 rows)
|
|
|
|
|
|
|
|
--- adding tables
|
|
|
|
CREATE SCHEMA pub_test;
|
|
|
|
CREATE TABLE testpub_tbl1 (id serial primary key, data text);
|
|
|
|
CREATE TABLE pub_test.testpub_nopk (foo int, bar int);
|
|
|
|
CREATE VIEW testpub_view AS SELECT 1;
|
2017-04-20 20:18:33 +02:00
|
|
|
CREATE TABLE testpub_parted (a int) PARTITION BY LIST (a);
|
2019-07-13 00:35:34 +02:00
|
|
|
SET client_min_messages = 'ERROR';
|
2017-05-12 14:57:01 +02:00
|
|
|
CREATE PUBLICATION testpub_foralltables FOR ALL TABLES WITH (publish = 'insert');
|
2019-07-13 00:35:34 +02:00
|
|
|
RESET client_min_messages;
|
2017-05-12 14:57:01 +02:00
|
|
|
ALTER PUBLICATION testpub_foralltables SET (publish = 'insert, update');
|
2017-01-19 18:00:00 +01:00
|
|
|
CREATE TABLE testpub_tbl2 (id serial primary key, data text);
|
|
|
|
-- fail - can't add to for all tables publication
|
|
|
|
ALTER PUBLICATION testpub_foralltables ADD TABLE testpub_tbl2;
|
|
|
|
ERROR: publication "testpub_foralltables" is defined as FOR ALL TABLES
|
|
|
|
DETAIL: Tables cannot be added to or dropped from FOR ALL TABLES publications.
|
|
|
|
-- fail - can't drop from all tables publication
|
|
|
|
ALTER PUBLICATION testpub_foralltables DROP TABLE testpub_tbl2;
|
|
|
|
ERROR: publication "testpub_foralltables" is defined as FOR ALL TABLES
|
|
|
|
DETAIL: Tables cannot be added to or dropped from FOR ALL TABLES publications.
|
|
|
|
-- fail - can't add to for all tables publication
|
|
|
|
ALTER PUBLICATION testpub_foralltables SET TABLE pub_test.testpub_nopk;
|
|
|
|
ERROR: publication "testpub_foralltables" is defined as FOR ALL TABLES
|
|
|
|
DETAIL: Tables cannot be added to or dropped from FOR ALL TABLES publications.
|
|
|
|
SELECT pubname, puballtables FROM pg_publication WHERE pubname = 'testpub_foralltables';
|
|
|
|
pubname | puballtables
|
|
|
|
----------------------+--------------
|
|
|
|
testpub_foralltables | t
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
\d+ testpub_tbl2
|
|
|
|
Table "public.testpub_tbl2"
|
|
|
|
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
|
|
|
|
--------+---------+-----------+----------+------------------------------------------+----------+--------------+-------------
|
|
|
|
id | integer | | not null | nextval('testpub_tbl2_id_seq'::regclass) | plain | |
|
|
|
|
data | text | | | | extended | |
|
|
|
|
Indexes:
|
|
|
|
"testpub_tbl2_pkey" PRIMARY KEY, btree (id)
|
|
|
|
Publications:
|
|
|
|
"testpub_foralltables"
|
|
|
|
|
2017-06-15 16:46:41 +02:00
|
|
|
\dRp+ testpub_foralltables
|
2020-04-08 09:59:27 +02:00
|
|
|
Publication testpub_foralltables
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | t | t | t | f | f | f
|
2017-06-15 16:46:41 +02:00
|
|
|
(1 row)
|
|
|
|
|
2017-01-19 18:00:00 +01:00
|
|
|
DROP TABLE testpub_tbl2;
|
|
|
|
DROP PUBLICATION testpub_foralltables;
|
2017-04-17 15:14:22 +02:00
|
|
|
CREATE TABLE testpub_tbl3 (a int);
|
|
|
|
CREATE TABLE testpub_tbl3a (b text) INHERITS (testpub_tbl3);
|
2019-07-13 00:35:34 +02:00
|
|
|
SET client_min_messages = 'ERROR';
|
2017-04-17 15:14:22 +02:00
|
|
|
CREATE PUBLICATION testpub3 FOR TABLE testpub_tbl3;
|
|
|
|
CREATE PUBLICATION testpub4 FOR TABLE ONLY testpub_tbl3;
|
2019-07-13 00:35:34 +02:00
|
|
|
RESET client_min_messages;
|
2017-04-17 15:14:22 +02:00
|
|
|
\dRp+ testpub3
|
2020-04-08 09:59:27 +02:00
|
|
|
Publication testpub3
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
2017-04-17 15:14:22 +02:00
|
|
|
Tables:
|
|
|
|
"public.testpub_tbl3"
|
|
|
|
"public.testpub_tbl3a"
|
|
|
|
|
|
|
|
\dRp+ testpub4
|
2020-04-08 09:59:27 +02:00
|
|
|
Publication testpub4
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
2017-04-17 15:14:22 +02:00
|
|
|
Tables:
|
|
|
|
"public.testpub_tbl3"
|
|
|
|
|
|
|
|
DROP TABLE testpub_tbl3, testpub_tbl3a;
|
|
|
|
DROP PUBLICATION testpub3, testpub4;
|
2020-03-10 08:42:59 +01:00
|
|
|
-- Tests for partitioned tables
|
|
|
|
SET client_min_messages = 'ERROR';
|
|
|
|
CREATE PUBLICATION testpub_forparted;
|
|
|
|
CREATE PUBLICATION testpub_forparted1;
|
|
|
|
RESET client_min_messages;
|
|
|
|
CREATE TABLE testpub_parted1 (LIKE testpub_parted);
|
|
|
|
ALTER PUBLICATION testpub_forparted1 SET (publish='insert');
|
|
|
|
-- 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
|
2020-04-08 09:59:27 +02:00
|
|
|
Publication testpub_forparted
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
2020-03-10 08:42:59 +01:00
|
|
|
Tables:
|
|
|
|
"public.testpub_parted"
|
|
|
|
|
|
|
|
-- should now fail, because parent's publication replicates updates
|
|
|
|
UPDATE testpub_parted1 SET a = 1;
|
|
|
|
ERROR: cannot update table "testpub_parted1" 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 testpub_parted DETACH PARTITION testpub_parted1;
|
|
|
|
-- works again, because parent's publication is no longer considered
|
|
|
|
UPDATE testpub_parted1 SET a = 1;
|
2020-04-08 09:59:27 +02:00
|
|
|
ALTER PUBLICATION testpub_forparted SET (publish_via_partition_root = true);
|
|
|
|
\dRp+ testpub_forparted
|
|
|
|
Publication testpub_forparted
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | t
|
|
|
|
Tables:
|
|
|
|
"public.testpub_parted"
|
|
|
|
|
2020-03-10 08:42:59 +01:00
|
|
|
DROP TABLE testpub_parted1;
|
|
|
|
DROP PUBLICATION testpub_forparted, testpub_forparted1;
|
2017-01-19 18:00:00 +01:00
|
|
|
-- fail - view
|
|
|
|
CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_view;
|
2021-07-21 07:40:05 +02:00
|
|
|
ERROR: cannot add relation "testpub_view" to publication
|
|
|
|
DETAIL: This operation is not supported for views.
|
2019-07-13 00:35:34 +02:00
|
|
|
SET client_min_messages = 'ERROR';
|
2017-01-19 18:00:00 +01:00
|
|
|
CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1, pub_test.testpub_nopk;
|
2019-07-13 00:35:34 +02:00
|
|
|
RESET client_min_messages;
|
2017-01-19 18:00:00 +01:00
|
|
|
-- fail - already added
|
|
|
|
ALTER PUBLICATION testpub_fortbl ADD TABLE testpub_tbl1;
|
|
|
|
ERROR: relation "testpub_tbl1" is already member of publication "testpub_fortbl"
|
|
|
|
-- fail - already added
|
|
|
|
CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1;
|
|
|
|
ERROR: publication "testpub_fortbl" already exists
|
|
|
|
\dRp+ testpub_fortbl
|
2020-04-08 09:59:27 +02:00
|
|
|
Publication testpub_fortbl
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
2017-01-19 18:00:00 +01:00
|
|
|
Tables:
|
|
|
|
"pub_test.testpub_nopk"
|
|
|
|
"public.testpub_tbl1"
|
|
|
|
|
|
|
|
-- fail - view
|
|
|
|
ALTER PUBLICATION testpub_default ADD TABLE testpub_view;
|
2021-07-21 07:40:05 +02:00
|
|
|
ERROR: cannot add relation "testpub_view" to publication
|
|
|
|
DETAIL: This operation is not supported for views.
|
2017-01-19 18:00:00 +01:00
|
|
|
ALTER PUBLICATION testpub_default ADD TABLE testpub_tbl1;
|
|
|
|
ALTER PUBLICATION testpub_default SET TABLE testpub_tbl1;
|
|
|
|
ALTER PUBLICATION testpub_default ADD TABLE pub_test.testpub_nopk;
|
|
|
|
ALTER PUBLICATION testpib_ins_trunct ADD TABLE pub_test.testpub_nopk, testpub_tbl1;
|
|
|
|
\d+ pub_test.testpub_nopk
|
|
|
|
Table "pub_test.testpub_nopk"
|
|
|
|
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
|
|
|
|
--------+---------+-----------+----------+---------+---------+--------------+-------------
|
|
|
|
foo | integer | | | | plain | |
|
|
|
|
bar | integer | | | | plain | |
|
|
|
|
Publications:
|
|
|
|
"testpib_ins_trunct"
|
|
|
|
"testpub_default"
|
|
|
|
"testpub_fortbl"
|
|
|
|
|
|
|
|
\d+ testpub_tbl1
|
|
|
|
Table "public.testpub_tbl1"
|
|
|
|
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
|
|
|
|
--------+---------+-----------+----------+------------------------------------------+----------+--------------+-------------
|
|
|
|
id | integer | | not null | nextval('testpub_tbl1_id_seq'::regclass) | plain | |
|
|
|
|
data | text | | | | extended | |
|
|
|
|
Indexes:
|
|
|
|
"testpub_tbl1_pkey" PRIMARY KEY, btree (id)
|
|
|
|
Publications:
|
|
|
|
"testpib_ins_trunct"
|
|
|
|
"testpub_default"
|
|
|
|
"testpub_fortbl"
|
|
|
|
|
|
|
|
\dRp+ testpub_default
|
2020-04-08 09:59:27 +02:00
|
|
|
Publication testpub_default
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | f | f
|
2017-01-19 18:00:00 +01:00
|
|
|
Tables:
|
|
|
|
"pub_test.testpub_nopk"
|
|
|
|
"public.testpub_tbl1"
|
|
|
|
|
|
|
|
ALTER PUBLICATION testpub_default DROP TABLE testpub_tbl1, pub_test.testpub_nopk;
|
|
|
|
-- fail - nonexistent
|
|
|
|
ALTER PUBLICATION testpub_default DROP TABLE pub_test.testpub_nopk;
|
|
|
|
ERROR: relation "testpub_nopk" is not part of the publication
|
|
|
|
\d+ testpub_tbl1
|
|
|
|
Table "public.testpub_tbl1"
|
|
|
|
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
|
|
|
|
--------+---------+-----------+----------+------------------------------------------+----------+--------------+-------------
|
|
|
|
id | integer | | not null | nextval('testpub_tbl1_id_seq'::regclass) | plain | |
|
|
|
|
data | text | | | | extended | |
|
|
|
|
Indexes:
|
|
|
|
"testpub_tbl1_pkey" PRIMARY KEY, btree (id)
|
|
|
|
Publications:
|
|
|
|
"testpib_ins_trunct"
|
|
|
|
"testpub_fortbl"
|
|
|
|
|
2017-03-15 18:52:07 +01:00
|
|
|
-- permissions
|
|
|
|
SET ROLE regress_publication_user2;
|
|
|
|
CREATE PUBLICATION testpub2; -- fail
|
|
|
|
ERROR: permission denied for database regression
|
|
|
|
SET ROLE regress_publication_user;
|
|
|
|
GRANT CREATE ON DATABASE regression TO regress_publication_user2;
|
|
|
|
SET ROLE regress_publication_user2;
|
2019-07-13 00:35:34 +02:00
|
|
|
SET client_min_messages = 'ERROR';
|
2017-03-15 18:52:07 +01:00
|
|
|
CREATE PUBLICATION testpub2; -- ok
|
2019-07-13 00:35:34 +02:00
|
|
|
RESET client_min_messages;
|
2017-03-15 18:52:07 +01:00
|
|
|
ALTER PUBLICATION testpub2 ADD TABLE testpub_tbl1; -- fail
|
2017-12-02 15:26:34 +01:00
|
|
|
ERROR: must be owner of table testpub_tbl1
|
2017-03-15 18:52:07 +01:00
|
|
|
SET ROLE regress_publication_user;
|
|
|
|
GRANT regress_publication_user TO regress_publication_user2;
|
|
|
|
SET ROLE regress_publication_user2;
|
|
|
|
ALTER PUBLICATION testpub2 ADD TABLE testpub_tbl1; -- ok
|
|
|
|
DROP PUBLICATION testpub2;
|
|
|
|
SET ROLE regress_publication_user;
|
|
|
|
REVOKE CREATE ON DATABASE regression FROM regress_publication_user2;
|
2017-04-20 20:18:33 +02:00
|
|
|
DROP TABLE testpub_parted;
|
2017-01-19 18:00:00 +01:00
|
|
|
DROP VIEW testpub_view;
|
|
|
|
DROP TABLE testpub_tbl1;
|
|
|
|
\dRp+ testpub_default
|
2020-04-08 09:59:27 +02:00
|
|
|
Publication testpub_default
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | f | f
|
2017-01-19 18:00:00 +01:00
|
|
|
(1 row)
|
|
|
|
|
2017-03-15 21:27:07 +01:00
|
|
|
-- fail - must be owner of publication
|
2017-03-08 04:44:59 +01:00
|
|
|
SET ROLE regress_publication_user_dummy;
|
|
|
|
ALTER PUBLICATION testpub_default RENAME TO testpub_dummy;
|
|
|
|
ERROR: must be owner of publication testpub_default
|
|
|
|
RESET ROLE;
|
2017-03-03 16:47:04 +01:00
|
|
|
ALTER PUBLICATION testpub_default RENAME TO testpub_foo;
|
|
|
|
\dRp testpub_foo
|
2020-04-08 09:59:27 +02:00
|
|
|
List of publications
|
|
|
|
Name | Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
-------------+--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
testpub_foo | regress_publication_user | f | t | t | t | f | f
|
2017-03-03 16:47:04 +01:00
|
|
|
(1 row)
|
|
|
|
|
2017-03-15 21:52:12 +01:00
|
|
|
-- rename back to keep the rest simple
|
|
|
|
ALTER PUBLICATION testpub_foo RENAME TO testpub_default;
|
2017-02-13 14:57:45 +01:00
|
|
|
ALTER PUBLICATION testpub_default OWNER TO regress_publication_user2;
|
|
|
|
\dRp testpub_default
|
2020-04-08 09:59:27 +02:00
|
|
|
List of publications
|
|
|
|
Name | Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
-----------------+---------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
testpub_default | regress_publication_user2 | f | t | t | t | f | f
|
2017-02-13 14:57:45 +01:00
|
|
|
(1 row)
|
|
|
|
|
2017-03-15 21:52:12 +01:00
|
|
|
DROP PUBLICATION testpub_default;
|
2017-01-19 18:00:00 +01:00
|
|
|
DROP PUBLICATION testpib_ins_trunct;
|
2017-01-20 18:00:00 +01:00
|
|
|
DROP PUBLICATION testpub_fortbl;
|
2017-01-19 18:00:00 +01:00
|
|
|
DROP SCHEMA pub_test CASCADE;
|
|
|
|
NOTICE: drop cascades to table pub_test.testpub_nopk
|
|
|
|
RESET SESSION AUTHORIZATION;
|
2017-03-15 18:52:07 +01:00
|
|
|
DROP ROLE regress_publication_user, regress_publication_user2;
|
2017-03-08 04:44:59 +01:00
|
|
|
DROP ROLE regress_publication_user_dummy;
|