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.
|
Allow publishing the tables of schema.
A new option "FOR ALL TABLES IN SCHEMA" in Create/Alter Publication allows
one or more schemas to be specified, whose tables are selected by the
publisher for sending the data to the subscriber.
The new syntax allows specifying both the tables and schemas. For example:
CREATE PUBLICATION pub1 FOR TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
OR
ALTER PUBLICATION pub1 ADD TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
A new system table "pg_publication_namespace" has been added, to maintain
the schemas that the user wants to publish through the publication.
Modified the output plugin (pgoutput) to publish the changes if the
relation is part of schema publication.
Updates pg_dump to identify and dump schema publications. Updates the \d
family of commands to display schema publications and \dRp+ variant will
now display associated schemas if any.
Author: Vignesh C, Hou Zhijie, Amit Kapila
Syntax-Suggested-by: Tom Lane, Alvaro Herrera
Reviewed-by: Greg Nancarrow, Masahiko Sawada, Hou Zhijie, Amit Kapila, Haiying Tang, Ajin Cherian, Rahila Syed, Bharath Rupireddy, Mark Dilger
Tested-by: Haiying Tang
Discussion: https://www.postgresql.org/message-id/CALDaNm0OANxuJ6RXqwZsM1MSY4s19nuH3734j4a72etDwvBETQ@mail.gmail.com
2021-10-27 04:14:52 +02:00
|
|
|
-- fail - can't add schema to 'FOR ALL TABLES' publication
|
|
|
|
ALTER PUBLICATION testpub_foralltables ADD ALL TABLES IN SCHEMA pub_test;
|
|
|
|
ERROR: publication "testpub_foralltables" is defined as FOR ALL TABLES
|
|
|
|
DETAIL: Tables from schema cannot be added to, dropped from, or set on FOR ALL TABLES publications.
|
|
|
|
-- fail - can't drop schema from 'FOR ALL TABLES' publication
|
|
|
|
ALTER PUBLICATION testpub_foralltables DROP ALL TABLES IN SCHEMA pub_test;
|
|
|
|
ERROR: publication "testpub_foralltables" is defined as FOR ALL TABLES
|
|
|
|
DETAIL: Tables from schema cannot be added to, dropped from, or set on FOR ALL TABLES publications.
|
|
|
|
-- fail - can't set schema to 'FOR ALL TABLES' publication
|
|
|
|
ALTER PUBLICATION testpub_foralltables SET ALL TABLES IN SCHEMA pub_test;
|
|
|
|
ERROR: publication "testpub_foralltables" is defined as FOR ALL TABLES
|
|
|
|
DETAIL: Tables from schema cannot be added to, dropped from, or set on FOR ALL TABLES publications.
|
|
|
|
SET client_min_messages = 'ERROR';
|
|
|
|
CREATE PUBLICATION testpub_fortable FOR TABLE testpub_tbl1;
|
|
|
|
RESET client_min_messages;
|
|
|
|
-- should be able to add schema to 'FOR TABLE' publication
|
|
|
|
ALTER PUBLICATION testpub_fortable ADD ALL TABLES IN SCHEMA pub_test;
|
|
|
|
\dRp+ testpub_fortable
|
|
|
|
Publication testpub_fortable
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables:
|
|
|
|
"public.testpub_tbl1"
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test"
|
|
|
|
|
|
|
|
-- should be able to drop schema from 'FOR TABLE' publication
|
|
|
|
ALTER PUBLICATION testpub_fortable DROP ALL TABLES IN SCHEMA pub_test;
|
|
|
|
\dRp+ testpub_fortable
|
|
|
|
Publication testpub_fortable
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables:
|
|
|
|
"public.testpub_tbl1"
|
|
|
|
|
|
|
|
-- should be able to set schema to 'FOR TABLE' publication
|
|
|
|
ALTER PUBLICATION testpub_fortable SET ALL TABLES IN SCHEMA pub_test;
|
|
|
|
\dRp+ testpub_fortable
|
|
|
|
Publication testpub_fortable
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test"
|
|
|
|
|
|
|
|
SET client_min_messages = 'ERROR';
|
|
|
|
CREATE PUBLICATION testpub_forschema FOR ALL TABLES IN SCHEMA pub_test;
|
|
|
|
RESET client_min_messages;
|
|
|
|
-- fail - can't create publication with schema and table of the same schema
|
|
|
|
CREATE PUBLICATION testpub_for_tbl_schema FOR ALL TABLES IN SCHEMA pub_test, TABLE pub_test.testpub_nopk;
|
|
|
|
ERROR: cannot add relation "pub_test.testpub_nopk" to publication
|
|
|
|
DETAIL: Table's schema "pub_test" is already part of the publication or part of the specified schema list.
|
|
|
|
-- fail - can't add a table of the same schema to the schema publication
|
|
|
|
ALTER PUBLICATION testpub_forschema ADD TABLE pub_test.testpub_nopk;
|
|
|
|
ERROR: cannot add relation "pub_test.testpub_nopk" to publication
|
|
|
|
DETAIL: Table's schema "pub_test" is already part of the publication or part of the specified schema list.
|
|
|
|
-- fail - can't drop a table from the schema publication which isn't in the
|
|
|
|
-- publication
|
|
|
|
ALTER PUBLICATION testpub_forschema DROP TABLE pub_test.testpub_nopk;
|
|
|
|
ERROR: relation "testpub_nopk" is not part of the publication
|
|
|
|
-- should be able to set table to schema publication
|
|
|
|
ALTER PUBLICATION testpub_forschema SET TABLE pub_test.testpub_nopk;
|
|
|
|
\dRp+ testpub_forschema
|
|
|
|
Publication testpub_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables:
|
|
|
|
"pub_test.testpub_nopk"
|
|
|
|
|
2017-01-19 18:00:00 +01:00
|
|
|
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;
|
Allow publishing the tables of schema.
A new option "FOR ALL TABLES IN SCHEMA" in Create/Alter Publication allows
one or more schemas to be specified, whose tables are selected by the
publisher for sending the data to the subscriber.
The new syntax allows specifying both the tables and schemas. For example:
CREATE PUBLICATION pub1 FOR TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
OR
ALTER PUBLICATION pub1 ADD TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
A new system table "pg_publication_namespace" has been added, to maintain
the schemas that the user wants to publish through the publication.
Modified the output plugin (pgoutput) to publish the changes if the
relation is part of schema publication.
Updates pg_dump to identify and dump schema publications. Updates the \d
family of commands to display schema publications and \dRp+ variant will
now display associated schemas if any.
Author: Vignesh C, Hou Zhijie, Amit Kapila
Syntax-Suggested-by: Tom Lane, Alvaro Herrera
Reviewed-by: Greg Nancarrow, Masahiko Sawada, Hou Zhijie, Amit Kapila, Haiying Tang, Ajin Cherian, Rahila Syed, Bharath Rupireddy, Mark Dilger
Tested-by: Haiying Tang
Discussion: https://www.postgresql.org/message-id/CALDaNm0OANxuJ6RXqwZsM1MSY4s19nuH3734j4a72etDwvBETQ@mail.gmail.com
2021-10-27 04:14:52 +02:00
|
|
|
DROP PUBLICATION testpub_foralltables, testpub_fortable, testpub_forschema;
|
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);
|
2021-09-22 04:30:54 +02:00
|
|
|
CREATE TABLE testpub_parted2 (LIKE testpub_parted);
|
2020-03-10 08:42:59 +01:00
|
|
|
ALTER PUBLICATION testpub_forparted1 SET (publish='insert');
|
2021-09-22 04:30:54 +02:00
|
|
|
ALTER TABLE testpub_parted ATTACH PARTITION testpub_parted1 FOR VALUES IN (1);
|
|
|
|
ALTER TABLE testpub_parted ATTACH PARTITION testpub_parted2 FOR VALUES IN (2);
|
2020-03-10 08:42:59 +01:00
|
|
|
-- works despite missing REPLICA IDENTITY, because updates are not replicated
|
|
|
|
UPDATE testpub_parted1 SET a = 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"
|
|
|
|
|
2021-09-22 04:30:54 +02:00
|
|
|
-- 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;
|
2020-03-10 08:42:59 +01:00
|
|
|
DROP PUBLICATION testpub_forparted, testpub_forparted1;
|
2021-09-08 08:20:37 +02:00
|
|
|
-- Test cache invalidation FOR ALL TABLES publication
|
|
|
|
SET client_min_messages = 'ERROR';
|
|
|
|
CREATE TABLE testpub_tbl4(a int);
|
|
|
|
INSERT INTO testpub_tbl4 values(1);
|
|
|
|
UPDATE testpub_tbl4 set a = 2;
|
|
|
|
CREATE PUBLICATION testpub_foralltables FOR ALL TABLES;
|
|
|
|
RESET client_min_messages;
|
|
|
|
-- fail missing REPLICA IDENTITY
|
|
|
|
UPDATE testpub_tbl4 set a = 3;
|
|
|
|
ERROR: cannot update table "testpub_tbl4" because it does not have a replica identity and publishes updates
|
|
|
|
HINT: To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.
|
|
|
|
DROP PUBLICATION testpub_foralltables;
|
|
|
|
-- should pass after dropping the publication
|
|
|
|
UPDATE testpub_tbl4 set a = 3;
|
|
|
|
DROP TABLE testpub_tbl4;
|
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.
|
2021-11-17 14:40:38 +01:00
|
|
|
CREATE TEMPORARY TABLE testpub_temptbl(a int);
|
|
|
|
-- fail - temporary table
|
|
|
|
CREATE PUBLICATION testpub_fortemptbl FOR TABLE testpub_temptbl;
|
|
|
|
ERROR: cannot add relation "testpub_temptbl" to publication
|
|
|
|
DETAIL: This operation is not supported for temporary tables.
|
|
|
|
DROP TABLE testpub_temptbl;
|
|
|
|
CREATE UNLOGGED TABLE testpub_unloggedtbl(a int);
|
|
|
|
-- fail - unlogged table
|
|
|
|
CREATE PUBLICATION testpub_forunloggedtbl FOR TABLE testpub_unloggedtbl;
|
|
|
|
ERROR: cannot add relation "testpub_unloggedtbl" to publication
|
|
|
|
DETAIL: This operation is not supported for unlogged tables.
|
|
|
|
DROP TABLE testpub_unloggedtbl;
|
|
|
|
-- fail - system table
|
|
|
|
CREATE PUBLICATION testpub_forsystemtbl FOR TABLE pg_publication;
|
|
|
|
ERROR: cannot add relation "pg_publication" to publication
|
|
|
|
DETAIL: This operation is not supported for system tables.
|
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
|
Allow publishing the tables of schema.
A new option "FOR ALL TABLES IN SCHEMA" in Create/Alter Publication allows
one or more schemas to be specified, whose tables are selected by the
publisher for sending the data to the subscriber.
The new syntax allows specifying both the tables and schemas. For example:
CREATE PUBLICATION pub1 FOR TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
OR
ALTER PUBLICATION pub1 ADD TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
A new system table "pg_publication_namespace" has been added, to maintain
the schemas that the user wants to publish through the publication.
Modified the output plugin (pgoutput) to publish the changes if the
relation is part of schema publication.
Updates pg_dump to identify and dump schema publications. Updates the \d
family of commands to display schema publications and \dRp+ variant will
now display associated schemas if any.
Author: Vignesh C, Hou Zhijie, Amit Kapila
Syntax-Suggested-by: Tom Lane, Alvaro Herrera
Reviewed-by: Greg Nancarrow, Masahiko Sawada, Hou Zhijie, Amit Kapila, Haiying Tang, Ajin Cherian, Rahila Syed, Bharath Rupireddy, Mark Dilger
Tested-by: Haiying Tang
Discussion: https://www.postgresql.org/message-id/CALDaNm0OANxuJ6RXqwZsM1MSY4s19nuH3734j4a72etDwvBETQ@mail.gmail.com
2021-10-27 04:14:52 +02:00
|
|
|
CREATE PUBLICATION testpub3 FOR ALL TABLES IN SCHEMA pub_test; -- fail
|
|
|
|
ERROR: must be superuser to create FOR ALL TABLES IN SCHEMA publication
|
|
|
|
CREATE PUBLICATION testpub3; -- 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
|
Allow publishing the tables of schema.
A new option "FOR ALL TABLES IN SCHEMA" in Create/Alter Publication allows
one or more schemas to be specified, whose tables are selected by the
publisher for sending the data to the subscriber.
The new syntax allows specifying both the tables and schemas. For example:
CREATE PUBLICATION pub1 FOR TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
OR
ALTER PUBLICATION pub1 ADD TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
A new system table "pg_publication_namespace" has been added, to maintain
the schemas that the user wants to publish through the publication.
Modified the output plugin (pgoutput) to publish the changes if the
relation is part of schema publication.
Updates pg_dump to identify and dump schema publications. Updates the \d
family of commands to display schema publications and \dRp+ variant will
now display associated schemas if any.
Author: Vignesh C, Hou Zhijie, Amit Kapila
Syntax-Suggested-by: Tom Lane, Alvaro Herrera
Reviewed-by: Greg Nancarrow, Masahiko Sawada, Hou Zhijie, Amit Kapila, Haiying Tang, Ajin Cherian, Rahila Syed, Bharath Rupireddy, Mark Dilger
Tested-by: Haiying Tang
Discussion: https://www.postgresql.org/message-id/CALDaNm0OANxuJ6RXqwZsM1MSY4s19nuH3734j4a72etDwvBETQ@mail.gmail.com
2021-10-27 04:14:52 +02:00
|
|
|
ALTER PUBLICATION testpub3 ADD ALL TABLES IN SCHEMA pub_test; -- fail
|
|
|
|
ERROR: must be superuser to add or set schemas
|
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;
|
Allow publishing the tables of schema.
A new option "FOR ALL TABLES IN SCHEMA" in Create/Alter Publication allows
one or more schemas to be specified, whose tables are selected by the
publisher for sending the data to the subscriber.
The new syntax allows specifying both the tables and schemas. For example:
CREATE PUBLICATION pub1 FOR TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
OR
ALTER PUBLICATION pub1 ADD TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
A new system table "pg_publication_namespace" has been added, to maintain
the schemas that the user wants to publish through the publication.
Modified the output plugin (pgoutput) to publish the changes if the
relation is part of schema publication.
Updates pg_dump to identify and dump schema publications. Updates the \d
family of commands to display schema publications and \dRp+ variant will
now display associated schemas if any.
Author: Vignesh C, Hou Zhijie, Amit Kapila
Syntax-Suggested-by: Tom Lane, Alvaro Herrera
Reviewed-by: Greg Nancarrow, Masahiko Sawada, Hou Zhijie, Amit Kapila, Haiying Tang, Ajin Cherian, Rahila Syed, Bharath Rupireddy, Mark Dilger
Tested-by: Haiying Tang
Discussion: https://www.postgresql.org/message-id/CALDaNm0OANxuJ6RXqwZsM1MSY4s19nuH3734j4a72etDwvBETQ@mail.gmail.com
2021-10-27 04:14:52 +02:00
|
|
|
DROP PUBLICATION testpub3;
|
2017-03-15 18:52:07 +01:00
|
|
|
SET ROLE regress_publication_user;
|
2021-12-08 07:01:16 +01:00
|
|
|
CREATE ROLE regress_publication_user3;
|
|
|
|
GRANT regress_publication_user2 TO regress_publication_user3;
|
|
|
|
SET client_min_messages = 'ERROR';
|
|
|
|
CREATE PUBLICATION testpub4 FOR ALL TABLES IN SCHEMA pub_test;
|
|
|
|
RESET client_min_messages;
|
|
|
|
ALTER PUBLICATION testpub4 OWNER TO regress_publication_user3;
|
|
|
|
SET ROLE regress_publication_user3;
|
|
|
|
-- fail - new owner must be superuser
|
|
|
|
ALTER PUBLICATION testpub4 owner to regress_publication_user2; -- fail
|
|
|
|
ERROR: permission denied to change owner of publication "testpub4"
|
|
|
|
HINT: The owner of a FOR ALL TABLES IN SCHEMA publication must be a superuser.
|
|
|
|
ALTER PUBLICATION testpub4 owner to regress_publication_user; -- ok
|
|
|
|
SET ROLE regress_publication_user;
|
|
|
|
DROP PUBLICATION testpub4;
|
|
|
|
DROP ROLE regress_publication_user3;
|
2017-03-15 18:52:07 +01:00
|
|
|
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 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)
|
|
|
|
|
Allow publishing the tables of schema.
A new option "FOR ALL TABLES IN SCHEMA" in Create/Alter Publication allows
one or more schemas to be specified, whose tables are selected by the
publisher for sending the data to the subscriber.
The new syntax allows specifying both the tables and schemas. For example:
CREATE PUBLICATION pub1 FOR TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
OR
ALTER PUBLICATION pub1 ADD TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
A new system table "pg_publication_namespace" has been added, to maintain
the schemas that the user wants to publish through the publication.
Modified the output plugin (pgoutput) to publish the changes if the
relation is part of schema publication.
Updates pg_dump to identify and dump schema publications. Updates the \d
family of commands to display schema publications and \dRp+ variant will
now display associated schemas if any.
Author: Vignesh C, Hou Zhijie, Amit Kapila
Syntax-Suggested-by: Tom Lane, Alvaro Herrera
Reviewed-by: Greg Nancarrow, Masahiko Sawada, Hou Zhijie, Amit Kapila, Haiying Tang, Ajin Cherian, Rahila Syed, Bharath Rupireddy, Mark Dilger
Tested-by: Haiying Tang
Discussion: https://www.postgresql.org/message-id/CALDaNm0OANxuJ6RXqwZsM1MSY4s19nuH3734j4a72etDwvBETQ@mail.gmail.com
2021-10-27 04:14:52 +02:00
|
|
|
-- adding schemas and tables
|
|
|
|
CREATE SCHEMA pub_test1;
|
|
|
|
CREATE SCHEMA pub_test2;
|
|
|
|
CREATE SCHEMA pub_test3;
|
|
|
|
CREATE SCHEMA "CURRENT_SCHEMA";
|
|
|
|
CREATE TABLE pub_test1.tbl (id int, data text);
|
|
|
|
CREATE TABLE pub_test1.tbl1 (id serial primary key, data text);
|
|
|
|
CREATE TABLE pub_test2.tbl1 (id serial primary key, data text);
|
|
|
|
CREATE TABLE "CURRENT_SCHEMA"."CURRENT_SCHEMA"(id int);
|
|
|
|
-- suppress warning that depends on wal_level
|
|
|
|
SET client_min_messages = 'ERROR';
|
|
|
|
CREATE PUBLICATION testpub1_forschema FOR ALL TABLES IN SCHEMA pub_test1;
|
|
|
|
\dRp+ testpub1_forschema
|
|
|
|
Publication testpub1_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1"
|
|
|
|
|
|
|
|
CREATE PUBLICATION testpub2_forschema FOR ALL TABLES IN SCHEMA pub_test1, pub_test2, pub_test3;
|
|
|
|
\dRp+ testpub2_forschema
|
|
|
|
Publication testpub2_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1"
|
|
|
|
"pub_test2"
|
|
|
|
"pub_test3"
|
|
|
|
|
|
|
|
-- check create publication on CURRENT_SCHEMA
|
|
|
|
CREATE PUBLICATION testpub3_forschema FOR ALL TABLES IN SCHEMA CURRENT_SCHEMA;
|
|
|
|
CREATE PUBLICATION testpub4_forschema FOR ALL TABLES IN SCHEMA "CURRENT_SCHEMA";
|
|
|
|
CREATE PUBLICATION testpub5_forschema FOR ALL TABLES IN SCHEMA CURRENT_SCHEMA, "CURRENT_SCHEMA";
|
|
|
|
CREATE PUBLICATION testpub6_forschema FOR ALL TABLES IN SCHEMA "CURRENT_SCHEMA", CURRENT_SCHEMA;
|
|
|
|
CREATE PUBLICATION testpub_fortable FOR TABLE "CURRENT_SCHEMA"."CURRENT_SCHEMA";
|
|
|
|
RESET client_min_messages;
|
|
|
|
\dRp+ testpub3_forschema
|
|
|
|
Publication testpub3_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"public"
|
|
|
|
|
|
|
|
\dRp+ testpub4_forschema
|
|
|
|
Publication testpub4_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"CURRENT_SCHEMA"
|
|
|
|
|
|
|
|
\dRp+ testpub5_forschema
|
|
|
|
Publication testpub5_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"CURRENT_SCHEMA"
|
|
|
|
"public"
|
|
|
|
|
|
|
|
\dRp+ testpub6_forschema
|
|
|
|
Publication testpub6_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"CURRENT_SCHEMA"
|
|
|
|
"public"
|
|
|
|
|
|
|
|
\dRp+ testpub_fortable
|
|
|
|
Publication testpub_fortable
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables:
|
|
|
|
"CURRENT_SCHEMA.CURRENT_SCHEMA"
|
|
|
|
|
|
|
|
-- check create publication on CURRENT_SCHEMA where search_path is not set
|
|
|
|
SET SEARCH_PATH='';
|
|
|
|
CREATE PUBLICATION testpub_forschema FOR ALL TABLES IN SCHEMA CURRENT_SCHEMA;
|
|
|
|
ERROR: no schema has been selected for CURRENT_SCHEMA
|
|
|
|
RESET SEARCH_PATH;
|
|
|
|
-- check create publication on CURRENT_SCHEMA where TABLE/ALL TABLES in SCHEMA
|
|
|
|
-- is not specified
|
|
|
|
CREATE PUBLICATION testpub_forschema1 FOR CURRENT_SCHEMA;
|
2021-11-09 04:09:33 +01:00
|
|
|
ERROR: TABLE/ALL TABLES IN SCHEMA should be specified before the table/schema name(s)
|
Allow publishing the tables of schema.
A new option "FOR ALL TABLES IN SCHEMA" in Create/Alter Publication allows
one or more schemas to be specified, whose tables are selected by the
publisher for sending the data to the subscriber.
The new syntax allows specifying both the tables and schemas. For example:
CREATE PUBLICATION pub1 FOR TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
OR
ALTER PUBLICATION pub1 ADD TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
A new system table "pg_publication_namespace" has been added, to maintain
the schemas that the user wants to publish through the publication.
Modified the output plugin (pgoutput) to publish the changes if the
relation is part of schema publication.
Updates pg_dump to identify and dump schema publications. Updates the \d
family of commands to display schema publications and \dRp+ variant will
now display associated schemas if any.
Author: Vignesh C, Hou Zhijie, Amit Kapila
Syntax-Suggested-by: Tom Lane, Alvaro Herrera
Reviewed-by: Greg Nancarrow, Masahiko Sawada, Hou Zhijie, Amit Kapila, Haiying Tang, Ajin Cherian, Rahila Syed, Bharath Rupireddy, Mark Dilger
Tested-by: Haiying Tang
Discussion: https://www.postgresql.org/message-id/CALDaNm0OANxuJ6RXqwZsM1MSY4s19nuH3734j4a72etDwvBETQ@mail.gmail.com
2021-10-27 04:14:52 +02:00
|
|
|
LINE 1: CREATE PUBLICATION testpub_forschema1 FOR CURRENT_SCHEMA;
|
|
|
|
^
|
|
|
|
-- check create publication on CURRENT_SCHEMA along with FOR TABLE
|
|
|
|
CREATE PUBLICATION testpub_forschema1 FOR TABLE CURRENT_SCHEMA;
|
|
|
|
ERROR: syntax error at or near "CURRENT_SCHEMA"
|
|
|
|
LINE 1: CREATE PUBLICATION testpub_forschema1 FOR TABLE CURRENT_SCHE...
|
|
|
|
^
|
|
|
|
-- check create publication on a schema that does not exist
|
|
|
|
CREATE PUBLICATION testpub_forschema FOR ALL TABLES IN SCHEMA non_existent_schema;
|
|
|
|
ERROR: schema "non_existent_schema" does not exist
|
|
|
|
-- check create publication on a system schema
|
|
|
|
CREATE PUBLICATION testpub_forschema FOR ALL TABLES IN SCHEMA pg_catalog;
|
|
|
|
ERROR: cannot add schema "pg_catalog" to publication
|
|
|
|
DETAIL: This operation is not supported for system schemas.
|
|
|
|
-- check create publication on an object which is not schema
|
|
|
|
CREATE PUBLICATION testpub1_forschema1 FOR ALL TABLES IN SCHEMA testpub_view;
|
|
|
|
ERROR: schema "testpub_view" does not exist
|
|
|
|
-- dropping the schema should reflect the change in publication
|
|
|
|
DROP SCHEMA pub_test3;
|
|
|
|
\dRp+ testpub2_forschema
|
|
|
|
Publication testpub2_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1"
|
|
|
|
"pub_test2"
|
|
|
|
|
|
|
|
-- renaming the schema should reflect the change in publication
|
|
|
|
ALTER SCHEMA pub_test1 RENAME to pub_test1_renamed;
|
|
|
|
\dRp+ testpub2_forschema
|
|
|
|
Publication testpub2_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1_renamed"
|
|
|
|
"pub_test2"
|
|
|
|
|
|
|
|
ALTER SCHEMA pub_test1_renamed RENAME to pub_test1;
|
|
|
|
\dRp+ testpub2_forschema
|
|
|
|
Publication testpub2_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1"
|
|
|
|
"pub_test2"
|
|
|
|
|
|
|
|
-- alter publication add schema
|
|
|
|
ALTER PUBLICATION testpub1_forschema ADD ALL TABLES IN SCHEMA pub_test2;
|
|
|
|
\dRp+ testpub1_forschema
|
|
|
|
Publication testpub1_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1"
|
|
|
|
"pub_test2"
|
|
|
|
|
|
|
|
-- add non existent schema
|
|
|
|
ALTER PUBLICATION testpub1_forschema ADD ALL TABLES IN SCHEMA non_existent_schema;
|
|
|
|
ERROR: schema "non_existent_schema" does not exist
|
|
|
|
\dRp+ testpub1_forschema
|
|
|
|
Publication testpub1_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1"
|
|
|
|
"pub_test2"
|
|
|
|
|
|
|
|
-- add a schema which is already added to the publication
|
|
|
|
ALTER PUBLICATION testpub1_forschema ADD ALL TABLES IN SCHEMA pub_test1;
|
|
|
|
ERROR: schema "pub_test1" is already member of publication "testpub1_forschema"
|
|
|
|
\dRp+ testpub1_forschema
|
|
|
|
Publication testpub1_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1"
|
|
|
|
"pub_test2"
|
|
|
|
|
|
|
|
-- alter publication drop schema
|
|
|
|
ALTER PUBLICATION testpub1_forschema DROP ALL TABLES IN SCHEMA pub_test2;
|
|
|
|
\dRp+ testpub1_forschema
|
|
|
|
Publication testpub1_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1"
|
|
|
|
|
|
|
|
-- drop schema that is not present in the publication
|
|
|
|
ALTER PUBLICATION testpub1_forschema DROP ALL TABLES IN SCHEMA pub_test2;
|
|
|
|
ERROR: tables from schema "pub_test2" are not part of the publication
|
|
|
|
\dRp+ testpub1_forschema
|
|
|
|
Publication testpub1_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1"
|
|
|
|
|
|
|
|
-- drop a schema that does not exist in the system
|
|
|
|
ALTER PUBLICATION testpub1_forschema DROP ALL TABLES IN SCHEMA non_existent_schema;
|
|
|
|
ERROR: schema "non_existent_schema" does not exist
|
|
|
|
\dRp+ testpub1_forschema
|
|
|
|
Publication testpub1_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1"
|
|
|
|
|
|
|
|
-- drop all schemas
|
|
|
|
ALTER PUBLICATION testpub1_forschema DROP ALL TABLES IN SCHEMA pub_test1;
|
|
|
|
\dRp+ testpub1_forschema
|
|
|
|
Publication testpub1_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- alter publication set multiple schema
|
|
|
|
ALTER PUBLICATION testpub1_forschema SET ALL TABLES IN SCHEMA pub_test1, pub_test2;
|
|
|
|
\dRp+ testpub1_forschema
|
|
|
|
Publication testpub1_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1"
|
|
|
|
"pub_test2"
|
|
|
|
|
|
|
|
-- alter publication set non-existent schema
|
|
|
|
ALTER PUBLICATION testpub1_forschema SET ALL TABLES IN SCHEMA non_existent_schema;
|
|
|
|
ERROR: schema "non_existent_schema" does not exist
|
|
|
|
\dRp+ testpub1_forschema
|
|
|
|
Publication testpub1_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1"
|
|
|
|
"pub_test2"
|
|
|
|
|
|
|
|
-- alter publication set it duplicate schemas should set the schemas after
|
|
|
|
-- removing the duplicate schemas
|
|
|
|
ALTER PUBLICATION testpub1_forschema SET ALL TABLES IN SCHEMA pub_test1, pub_test1;
|
|
|
|
\dRp+ testpub1_forschema
|
|
|
|
Publication testpub1_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1"
|
|
|
|
|
|
|
|
-- cleanup pub_test1 schema for invalidation tests
|
|
|
|
ALTER PUBLICATION testpub2_forschema DROP ALL TABLES IN SCHEMA pub_test1;
|
|
|
|
DROP PUBLICATION testpub3_forschema, testpub4_forschema, testpub5_forschema, testpub6_forschema, testpub_fortable;
|
|
|
|
DROP SCHEMA "CURRENT_SCHEMA" CASCADE;
|
|
|
|
NOTICE: drop cascades to table "CURRENT_SCHEMA"."CURRENT_SCHEMA"
|
|
|
|
-- verify relation cache invalidations through update statement for the
|
|
|
|
-- default REPLICA IDENTITY on the relation, if schema is part of the
|
|
|
|
-- publication then update will fail because relation's relreplident
|
|
|
|
-- option will be set, if schema is not part of the publication then update
|
|
|
|
-- will be successful.
|
|
|
|
INSERT INTO pub_test1.tbl VALUES(1, 'test');
|
|
|
|
-- fail
|
|
|
|
UPDATE pub_test1.tbl SET id = 2;
|
|
|
|
ERROR: cannot update table "tbl" 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 testpub1_forschema DROP ALL TABLES IN SCHEMA pub_test1;
|
|
|
|
-- success
|
|
|
|
UPDATE pub_test1.tbl SET id = 2;
|
|
|
|
ALTER PUBLICATION testpub1_forschema SET ALL TABLES IN SCHEMA pub_test1;
|
|
|
|
-- fail
|
|
|
|
UPDATE pub_test1.tbl SET id = 2;
|
|
|
|
ERROR: cannot update table "tbl" because it does not have a replica identity and publishes updates
|
|
|
|
HINT: To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.
|
|
|
|
-- verify invalidation of partition table having parent and child tables in
|
|
|
|
-- different schema
|
|
|
|
CREATE SCHEMA pub_testpart1;
|
|
|
|
CREATE SCHEMA pub_testpart2;
|
|
|
|
CREATE TABLE pub_testpart1.parent1 (a int) partition by list (a);
|
|
|
|
CREATE TABLE pub_testpart2.child_parent1 partition of pub_testpart1.parent1 for values in (1);
|
|
|
|
INSERT INTO pub_testpart2.child_parent1 values(1);
|
|
|
|
UPDATE pub_testpart2.child_parent1 set a = 1;
|
|
|
|
SET client_min_messages = 'ERROR';
|
|
|
|
CREATE PUBLICATION testpubpart_forschema FOR ALL TABLES IN SCHEMA pub_testpart1;
|
|
|
|
RESET client_min_messages;
|
|
|
|
-- fail
|
|
|
|
UPDATE pub_testpart1.parent1 set a = 1;
|
|
|
|
ERROR: cannot update table "child_parent1" because it does not have a replica identity and publishes updates
|
|
|
|
HINT: To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.
|
|
|
|
UPDATE pub_testpart2.child_parent1 set a = 1;
|
|
|
|
ERROR: cannot update table "child_parent1" because it does not have a replica identity and publishes updates
|
|
|
|
HINT: To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.
|
|
|
|
DROP PUBLICATION testpubpart_forschema;
|
|
|
|
-- verify invalidation of partition tables for schema publication that has
|
|
|
|
-- parent and child tables of different partition hierarchies
|
|
|
|
CREATE TABLE pub_testpart2.parent2 (a int) partition by list (a);
|
|
|
|
CREATE TABLE pub_testpart1.child_parent2 partition of pub_testpart2.parent2 for values in (1);
|
|
|
|
INSERT INTO pub_testpart1.child_parent2 values(1);
|
|
|
|
UPDATE pub_testpart1.child_parent2 set a = 1;
|
|
|
|
SET client_min_messages = 'ERROR';
|
|
|
|
CREATE PUBLICATION testpubpart_forschema FOR ALL TABLES IN SCHEMA pub_testpart2;
|
|
|
|
RESET client_min_messages;
|
|
|
|
-- fail
|
|
|
|
UPDATE pub_testpart2.child_parent1 set a = 1;
|
|
|
|
ERROR: cannot update table "child_parent1" because it does not have a replica identity and publishes updates
|
|
|
|
HINT: To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.
|
|
|
|
UPDATE pub_testpart2.parent2 set a = 1;
|
|
|
|
ERROR: cannot update table "child_parent2" because it does not have a replica identity and publishes updates
|
|
|
|
HINT: To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.
|
|
|
|
UPDATE pub_testpart1.child_parent2 set a = 1;
|
|
|
|
ERROR: cannot update table "child_parent2" 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 set 'ALL TABLES IN SCHEMA' on an empty publication.
|
|
|
|
SET client_min_messages = 'ERROR';
|
|
|
|
CREATE PUBLICATION testpub3_forschema;
|
|
|
|
RESET client_min_messages;
|
|
|
|
\dRp+ testpub3_forschema
|
|
|
|
Publication testpub3_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
ALTER PUBLICATION testpub3_forschema SET ALL TABLES IN SCHEMA pub_test1;
|
|
|
|
\dRp+ testpub3_forschema
|
|
|
|
Publication testpub3_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1"
|
|
|
|
|
|
|
|
-- create publication including both 'FOR TABLE' and 'FOR ALL TABLES IN SCHEMA'
|
|
|
|
SET client_min_messages = 'ERROR';
|
|
|
|
CREATE PUBLICATION testpub_forschema_fortable FOR ALL TABLES IN SCHEMA pub_test1, TABLE pub_test2.tbl1;
|
|
|
|
CREATE PUBLICATION testpub_fortable_forschema FOR TABLE pub_test2.tbl1, ALL TABLES IN SCHEMA pub_test1;
|
|
|
|
RESET client_min_messages;
|
|
|
|
\dRp+ testpub_forschema_fortable
|
|
|
|
Publication testpub_forschema_fortable
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables:
|
|
|
|
"pub_test2.tbl1"
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1"
|
|
|
|
|
|
|
|
\dRp+ testpub_fortable_forschema
|
|
|
|
Publication testpub_fortable_forschema
|
|
|
|
Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
|
|
|
|
--------------------------+------------+---------+---------+---------+-----------+----------
|
|
|
|
regress_publication_user | f | t | t | t | t | f
|
|
|
|
Tables:
|
|
|
|
"pub_test2.tbl1"
|
|
|
|
Tables from schemas:
|
|
|
|
"pub_test1"
|
|
|
|
|
|
|
|
-- fail specifying table without any of 'FOR ALL TABLES IN SCHEMA' or
|
|
|
|
--'FOR TABLE' or 'FOR ALL TABLES'
|
|
|
|
CREATE PUBLICATION testpub_error FOR pub_test2.tbl1;
|
2021-11-09 04:09:33 +01:00
|
|
|
ERROR: TABLE/ALL TABLES IN SCHEMA should be specified before the table/schema name(s)
|
Allow publishing the tables of schema.
A new option "FOR ALL TABLES IN SCHEMA" in Create/Alter Publication allows
one or more schemas to be specified, whose tables are selected by the
publisher for sending the data to the subscriber.
The new syntax allows specifying both the tables and schemas. For example:
CREATE PUBLICATION pub1 FOR TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
OR
ALTER PUBLICATION pub1 ADD TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
A new system table "pg_publication_namespace" has been added, to maintain
the schemas that the user wants to publish through the publication.
Modified the output plugin (pgoutput) to publish the changes if the
relation is part of schema publication.
Updates pg_dump to identify and dump schema publications. Updates the \d
family of commands to display schema publications and \dRp+ variant will
now display associated schemas if any.
Author: Vignesh C, Hou Zhijie, Amit Kapila
Syntax-Suggested-by: Tom Lane, Alvaro Herrera
Reviewed-by: Greg Nancarrow, Masahiko Sawada, Hou Zhijie, Amit Kapila, Haiying Tang, Ajin Cherian, Rahila Syed, Bharath Rupireddy, Mark Dilger
Tested-by: Haiying Tang
Discussion: https://www.postgresql.org/message-id/CALDaNm0OANxuJ6RXqwZsM1MSY4s19nuH3734j4a72etDwvBETQ@mail.gmail.com
2021-10-27 04:14:52 +02:00
|
|
|
LINE 1: CREATE PUBLICATION testpub_error FOR pub_test2.tbl1;
|
|
|
|
^
|
|
|
|
DROP VIEW testpub_view;
|
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;
|
Allow publishing the tables of schema.
A new option "FOR ALL TABLES IN SCHEMA" in Create/Alter Publication allows
one or more schemas to be specified, whose tables are selected by the
publisher for sending the data to the subscriber.
The new syntax allows specifying both the tables and schemas. For example:
CREATE PUBLICATION pub1 FOR TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
OR
ALTER PUBLICATION pub1 ADD TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
A new system table "pg_publication_namespace" has been added, to maintain
the schemas that the user wants to publish through the publication.
Modified the output plugin (pgoutput) to publish the changes if the
relation is part of schema publication.
Updates pg_dump to identify and dump schema publications. Updates the \d
family of commands to display schema publications and \dRp+ variant will
now display associated schemas if any.
Author: Vignesh C, Hou Zhijie, Amit Kapila
Syntax-Suggested-by: Tom Lane, Alvaro Herrera
Reviewed-by: Greg Nancarrow, Masahiko Sawada, Hou Zhijie, Amit Kapila, Haiying Tang, Ajin Cherian, Rahila Syed, Bharath Rupireddy, Mark Dilger
Tested-by: Haiying Tang
Discussion: https://www.postgresql.org/message-id/CALDaNm0OANxuJ6RXqwZsM1MSY4s19nuH3734j4a72etDwvBETQ@mail.gmail.com
2021-10-27 04:14:52 +02:00
|
|
|
DROP PUBLICATION testpub1_forschema;
|
|
|
|
DROP PUBLICATION testpub2_forschema;
|
|
|
|
DROP PUBLICATION testpub3_forschema;
|
|
|
|
DROP PUBLICATION testpub_forschema_fortable;
|
|
|
|
DROP PUBLICATION testpub_fortable_forschema;
|
|
|
|
DROP PUBLICATION testpubpart_forschema;
|
2017-01-19 18:00:00 +01:00
|
|
|
DROP SCHEMA pub_test CASCADE;
|
|
|
|
NOTICE: drop cascades to table pub_test.testpub_nopk
|
Allow publishing the tables of schema.
A new option "FOR ALL TABLES IN SCHEMA" in Create/Alter Publication allows
one or more schemas to be specified, whose tables are selected by the
publisher for sending the data to the subscriber.
The new syntax allows specifying both the tables and schemas. For example:
CREATE PUBLICATION pub1 FOR TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
OR
ALTER PUBLICATION pub1 ADD TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
A new system table "pg_publication_namespace" has been added, to maintain
the schemas that the user wants to publish through the publication.
Modified the output plugin (pgoutput) to publish the changes if the
relation is part of schema publication.
Updates pg_dump to identify and dump schema publications. Updates the \d
family of commands to display schema publications and \dRp+ variant will
now display associated schemas if any.
Author: Vignesh C, Hou Zhijie, Amit Kapila
Syntax-Suggested-by: Tom Lane, Alvaro Herrera
Reviewed-by: Greg Nancarrow, Masahiko Sawada, Hou Zhijie, Amit Kapila, Haiying Tang, Ajin Cherian, Rahila Syed, Bharath Rupireddy, Mark Dilger
Tested-by: Haiying Tang
Discussion: https://www.postgresql.org/message-id/CALDaNm0OANxuJ6RXqwZsM1MSY4s19nuH3734j4a72etDwvBETQ@mail.gmail.com
2021-10-27 04:14:52 +02:00
|
|
|
DROP SCHEMA pub_test1 CASCADE;
|
|
|
|
NOTICE: drop cascades to 2 other objects
|
|
|
|
DETAIL: drop cascades to table pub_test1.tbl
|
|
|
|
drop cascades to table pub_test1.tbl1
|
|
|
|
DROP SCHEMA pub_test2 CASCADE;
|
|
|
|
NOTICE: drop cascades to table pub_test2.tbl1
|
|
|
|
DROP SCHEMA pub_testpart1 CASCADE;
|
|
|
|
NOTICE: drop cascades to 2 other objects
|
|
|
|
DETAIL: drop cascades to table pub_testpart1.parent1
|
|
|
|
drop cascades to table pub_testpart1.child_parent2
|
|
|
|
DROP SCHEMA pub_testpart2 CASCADE;
|
|
|
|
NOTICE: drop cascades to table pub_testpart2.parent2
|
|
|
|
-- Test the list of partitions published with or without
|
|
|
|
-- 'PUBLISH_VIA_PARTITION_ROOT' parameter
|
|
|
|
SET client_min_messages = 'ERROR';
|
|
|
|
CREATE SCHEMA sch1;
|
|
|
|
CREATE SCHEMA sch2;
|
|
|
|
CREATE TABLE sch1.tbl1 (a int) PARTITION BY RANGE(a);
|
|
|
|
CREATE TABLE sch2.tbl1_part1 PARTITION OF sch1.tbl1 FOR VALUES FROM (1) to (10);
|
|
|
|
-- Schema publication that does not include the schema that has the parent table
|
|
|
|
CREATE PUBLICATION pub FOR ALL TABLES IN SCHEMA sch2 WITH (PUBLISH_VIA_PARTITION_ROOT=1);
|
|
|
|
SELECT * FROM pg_publication_tables;
|
|
|
|
pubname | schemaname | tablename
|
|
|
|
---------+------------+------------
|
|
|
|
pub | sch2 | tbl1_part1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
DROP PUBLICATION pub;
|
|
|
|
-- Table publication that does not include the parent table
|
|
|
|
CREATE PUBLICATION pub FOR TABLE sch2.tbl1_part1 WITH (PUBLISH_VIA_PARTITION_ROOT=1);
|
|
|
|
SELECT * FROM pg_publication_tables;
|
|
|
|
pubname | schemaname | tablename
|
|
|
|
---------+------------+------------
|
|
|
|
pub | sch2 | tbl1_part1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
DROP PUBLICATION pub;
|
|
|
|
-- Schema publication that does not include the schema that has the parent table
|
|
|
|
CREATE PUBLICATION pub FOR ALL TABLES IN SCHEMA sch2 WITH (PUBLISH_VIA_PARTITION_ROOT=0);
|
|
|
|
SELECT * FROM pg_publication_tables;
|
|
|
|
pubname | schemaname | tablename
|
|
|
|
---------+------------+------------
|
|
|
|
pub | sch2 | tbl1_part1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
DROP PUBLICATION pub;
|
|
|
|
-- Table publication that does not include the parent table
|
|
|
|
CREATE PUBLICATION pub FOR TABLE sch2.tbl1_part1 WITH (PUBLISH_VIA_PARTITION_ROOT=0);
|
|
|
|
SELECT * FROM pg_publication_tables;
|
|
|
|
pubname | schemaname | tablename
|
2021-12-08 06:45:25 +01:00
|
|
|
---------+------------+------------
|
|
|
|
pub | sch2 | tbl1_part1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- Table publication that includes both the parent table and the child table
|
|
|
|
ALTER PUBLICATION pub ADD TABLE sch1.tbl1;
|
|
|
|
SELECT * FROM pg_publication_tables;
|
|
|
|
pubname | schemaname | tablename
|
Allow publishing the tables of schema.
A new option "FOR ALL TABLES IN SCHEMA" in Create/Alter Publication allows
one or more schemas to be specified, whose tables are selected by the
publisher for sending the data to the subscriber.
The new syntax allows specifying both the tables and schemas. For example:
CREATE PUBLICATION pub1 FOR TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
OR
ALTER PUBLICATION pub1 ADD TABLE t1,t2,t3, ALL TABLES IN SCHEMA s1,s2;
A new system table "pg_publication_namespace" has been added, to maintain
the schemas that the user wants to publish through the publication.
Modified the output plugin (pgoutput) to publish the changes if the
relation is part of schema publication.
Updates pg_dump to identify and dump schema publications. Updates the \d
family of commands to display schema publications and \dRp+ variant will
now display associated schemas if any.
Author: Vignesh C, Hou Zhijie, Amit Kapila
Syntax-Suggested-by: Tom Lane, Alvaro Herrera
Reviewed-by: Greg Nancarrow, Masahiko Sawada, Hou Zhijie, Amit Kapila, Haiying Tang, Ajin Cherian, Rahila Syed, Bharath Rupireddy, Mark Dilger
Tested-by: Haiying Tang
Discussion: https://www.postgresql.org/message-id/CALDaNm0OANxuJ6RXqwZsM1MSY4s19nuH3734j4a72etDwvBETQ@mail.gmail.com
2021-10-27 04:14:52 +02:00
|
|
|
---------+------------+------------
|
|
|
|
pub | sch2 | tbl1_part1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
DROP PUBLICATION pub;
|
|
|
|
DROP TABLE sch2.tbl1_part1;
|
|
|
|
DROP TABLE sch1.tbl1;
|
|
|
|
CREATE TABLE sch1.tbl1 (a int) PARTITION BY RANGE(a);
|
|
|
|
CREATE TABLE sch1.tbl1_part1 PARTITION OF sch1.tbl1 FOR VALUES FROM (1) to (10);
|
|
|
|
CREATE TABLE sch1.tbl1_part2 PARTITION OF sch1.tbl1 FOR VALUES FROM (10) to (20);
|
|
|
|
CREATE TABLE sch1.tbl1_part3 (a int) PARTITION BY RANGE(a);
|
|
|
|
ALTER TABLE sch1.tbl1 ATTACH PARTITION sch1.tbl1_part3 FOR VALUES FROM (20) to (30);
|
|
|
|
CREATE PUBLICATION pub FOR ALL TABLES IN SCHEMA sch1 WITH (PUBLISH_VIA_PARTITION_ROOT=1);
|
|
|
|
SELECT * FROM pg_publication_tables;
|
|
|
|
pubname | schemaname | tablename
|
|
|
|
---------+------------+-----------
|
|
|
|
pub | sch1 | tbl1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
RESET client_min_messages;
|
|
|
|
DROP PUBLICATION pub;
|
|
|
|
DROP TABLE sch1.tbl1;
|
|
|
|
DROP SCHEMA sch1 cascade;
|
|
|
|
DROP SCHEMA sch2 cascade;
|
2017-01-19 18:00:00 +01:00
|
|
|
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;
|