4 CREATE ROLE regress_publication_user LOGIN SUPERUSER;
5 CREATE ROLE regress_publication_user2;
6 CREATE ROLE regress_publication_user_dummy LOGIN NOSUPERUSER;
7 SET SESSION AUTHORIZATION 'regress_publication_user';
8 -- suppress warning that depends on wal_level
9 SET client_min_messages = 'ERROR';
10 CREATE PUBLICATION testpub_default;
11 RESET client_min_messages;
12 COMMENT ON PUBLICATION testpub_default IS 'test publication';
13 SELECT obj_description(p.oid, 'pg_publication') FROM pg_publication p;
19 SET client_min_messages = 'ERROR';
20 CREATE PUBLICATION testpib_ins_trunct WITH (publish = insert);
21 RESET client_min_messages;
22 ALTER PUBLICATION testpub_default SET (publish = update);
24 CREATE PUBLICATION testpub_xxx WITH (foo);
25 ERROR: unrecognized publication parameter: "foo"
26 CREATE PUBLICATION testpub_xxx WITH (publish = 'cluster, vacuum');
27 ERROR: unrecognized "publish" value: "cluster"
28 CREATE PUBLICATION testpub_xxx WITH (publish_via_partition_root = 'true', publish_via_partition_root = '0');
29 ERROR: conflicting or redundant options
30 LINE 1: ...ub_xxx WITH (publish_via_partition_root = 'true', publish_vi...
34 Name | Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
35 --------------------+--------------------------+------------+---------+---------+---------+-----------+----------
36 testpib_ins_trunct | regress_publication_user | f | t | f | f | f | f
37 testpub_default | regress_publication_user | f | f | t | f | f | f
40 ALTER PUBLICATION testpub_default SET (publish = 'insert, update, delete');
43 Name | Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
44 --------------------+--------------------------+------------+---------+---------+---------+-----------+----------
45 testpib_ins_trunct | regress_publication_user | f | t | f | f | f | f
46 testpub_default | regress_publication_user | f | t | t | t | f | f
50 CREATE SCHEMA pub_test;
51 CREATE TABLE testpub_tbl1 (id serial primary key, data text);
52 CREATE TABLE pub_test.testpub_nopk (foo int, bar int);
53 CREATE VIEW testpub_view AS SELECT 1;
54 CREATE TABLE testpub_parted (a int) PARTITION BY LIST (a);
55 SET client_min_messages = 'ERROR';
56 CREATE PUBLICATION testpub_foralltables FOR ALL TABLES WITH (publish = 'insert');
57 RESET client_min_messages;
58 ALTER PUBLICATION testpub_foralltables SET (publish = 'insert, update');
59 CREATE TABLE testpub_tbl2 (id serial primary key, data text);
60 -- fail - can't add to for all tables publication
61 ALTER PUBLICATION testpub_foralltables ADD TABLE testpub_tbl2;
62 ERROR: publication "testpub_foralltables" is defined as FOR ALL TABLES
63 DETAIL: Tables cannot be added to or dropped from FOR ALL TABLES publications.
64 -- fail - can't drop from all tables publication
65 ALTER PUBLICATION testpub_foralltables DROP TABLE testpub_tbl2;
66 ERROR: publication "testpub_foralltables" is defined as FOR ALL TABLES
67 DETAIL: Tables cannot be added to or dropped from FOR ALL TABLES publications.
68 -- fail - can't add to for all tables publication
69 ALTER PUBLICATION testpub_foralltables SET TABLE pub_test.testpub_nopk;
70 ERROR: publication "testpub_foralltables" is defined as FOR ALL TABLES
71 DETAIL: Tables cannot be added to or dropped from FOR ALL TABLES publications.
72 SELECT pubname, puballtables FROM pg_publication WHERE pubname = 'testpub_foralltables';
73 pubname | puballtables
74 ----------------------+--------------
75 testpub_foralltables | t
79 Table "public.testpub_tbl2"
80 Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
81 --------+---------+-----------+----------+------------------------------------------+----------+--------------+-------------
82 id | integer | | not null | nextval('testpub_tbl2_id_seq'::regclass) | plain | |
83 data | text | | | | extended | |
85 "testpub_tbl2_pkey" PRIMARY KEY, btree (id)
87 "testpub_foralltables"
89 \dRp+ testpub_foralltables
90 Publication testpub_foralltables
91 Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
92 --------------------------+------------+---------+---------+---------+-----------+----------
93 regress_publication_user | t | t | t | f | f | f
96 DROP TABLE testpub_tbl2;
97 DROP PUBLICATION testpub_foralltables;
98 CREATE TABLE testpub_tbl3 (a int);
99 CREATE TABLE testpub_tbl3a (b text) INHERITS (testpub_tbl3);
100 SET client_min_messages = 'ERROR';
101 CREATE PUBLICATION testpub3 FOR TABLE testpub_tbl3;
102 CREATE PUBLICATION testpub4 FOR TABLE ONLY testpub_tbl3;
103 RESET client_min_messages;
106 Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
107 --------------------------+------------+---------+---------+---------+-----------+----------
108 regress_publication_user | f | t | t | t | t | f
110 "public.testpub_tbl3"
111 "public.testpub_tbl3a"
115 Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
116 --------------------------+------------+---------+---------+---------+-----------+----------
117 regress_publication_user | f | t | t | t | t | f
119 "public.testpub_tbl3"
121 DROP TABLE testpub_tbl3, testpub_tbl3a;
122 DROP PUBLICATION testpub3, testpub4;
123 -- Tests for partitioned tables
124 SET client_min_messages = 'ERROR';
125 CREATE PUBLICATION testpub_forparted;
126 CREATE PUBLICATION testpub_forparted1;
127 RESET client_min_messages;
128 CREATE TABLE testpub_parted1 (LIKE testpub_parted);
129 ALTER PUBLICATION testpub_forparted1 SET (publish='insert');
130 -- works despite missing REPLICA IDENTITY, because updates are not replicated
131 UPDATE testpub_parted1 SET a = 1;
132 ALTER TABLE testpub_parted ATTACH PARTITION testpub_parted1 FOR VALUES IN (1);
133 -- only parent is listed as being in publication, not the partition
134 ALTER PUBLICATION testpub_forparted ADD TABLE testpub_parted;
135 \dRp+ testpub_forparted
136 Publication testpub_forparted
137 Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
138 --------------------------+------------+---------+---------+---------+-----------+----------
139 regress_publication_user | f | t | t | t | t | f
141 "public.testpub_parted"
143 -- should now fail, because parent's publication replicates updates
144 UPDATE testpub_parted1 SET a = 1;
145 ERROR: cannot update table "testpub_parted1" because it does not have a replica identity and publishes updates
146 HINT: To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.
147 ALTER TABLE testpub_parted DETACH PARTITION testpub_parted1;
148 -- works again, because parent's publication is no longer considered
149 UPDATE testpub_parted1 SET a = 1;
150 ALTER PUBLICATION testpub_forparted SET (publish_via_partition_root = true);
151 \dRp+ testpub_forparted
152 Publication testpub_forparted
153 Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
154 --------------------------+------------+---------+---------+---------+-----------+----------
155 regress_publication_user | f | t | t | t | t | t
157 "public.testpub_parted"
159 DROP TABLE testpub_parted1;
160 DROP PUBLICATION testpub_forparted, testpub_forparted1;
161 -- Test cache invalidation FOR ALL TABLES publication
162 SET client_min_messages = 'ERROR';
163 CREATE TABLE testpub_tbl4(a int);
164 INSERT INTO testpub_tbl4 values(1);
165 UPDATE testpub_tbl4 set a = 2;
166 CREATE PUBLICATION testpub_foralltables FOR ALL TABLES;
167 RESET client_min_messages;
168 -- fail missing REPLICA IDENTITY
169 UPDATE testpub_tbl4 set a = 3;
170 ERROR: cannot update table "testpub_tbl4" because it does not have a replica identity and publishes updates
171 HINT: To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.
172 DROP PUBLICATION testpub_foralltables;
173 -- should pass after dropping the publication
174 UPDATE testpub_tbl4 set a = 3;
175 DROP TABLE testpub_tbl4;
177 CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_view;
178 ERROR: cannot add relation "testpub_view" to publication
179 DETAIL: This operation is not supported for views.
180 SET client_min_messages = 'ERROR';
181 CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1, pub_test.testpub_nopk;
182 RESET client_min_messages;
183 -- fail - already added
184 ALTER PUBLICATION testpub_fortbl ADD TABLE testpub_tbl1;
185 ERROR: relation "testpub_tbl1" is already member of publication "testpub_fortbl"
186 -- fail - already added
187 CREATE PUBLICATION testpub_fortbl FOR TABLE testpub_tbl1;
188 ERROR: publication "testpub_fortbl" already exists
190 Publication testpub_fortbl
191 Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
192 --------------------------+------------+---------+---------+---------+-----------+----------
193 regress_publication_user | f | t | t | t | t | f
195 "pub_test.testpub_nopk"
196 "public.testpub_tbl1"
199 ALTER PUBLICATION testpub_default ADD TABLE testpub_view;
200 ERROR: cannot add relation "testpub_view" to publication
201 DETAIL: This operation is not supported for views.
202 ALTER PUBLICATION testpub_default ADD TABLE testpub_tbl1;
203 ALTER PUBLICATION testpub_default SET TABLE testpub_tbl1;
204 ALTER PUBLICATION testpub_default ADD TABLE pub_test.testpub_nopk;
205 ALTER PUBLICATION testpib_ins_trunct ADD TABLE pub_test.testpub_nopk, testpub_tbl1;
206 \d+ pub_test.testpub_nopk
207 Table "pub_test.testpub_nopk"
208 Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
209 --------+---------+-----------+----------+---------+---------+--------------+-------------
210 foo | integer | | | | plain | |
211 bar | integer | | | | plain | |
218 Table "public.testpub_tbl1"
219 Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
220 --------+---------+-----------+----------+------------------------------------------+----------+--------------+-------------
221 id | integer | | not null | nextval('testpub_tbl1_id_seq'::regclass) | plain | |
222 data | text | | | | extended | |
224 "testpub_tbl1_pkey" PRIMARY KEY, btree (id)
230 \dRp+ testpub_default
231 Publication testpub_default
232 Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
233 --------------------------+------------+---------+---------+---------+-----------+----------
234 regress_publication_user | f | t | t | t | f | f
236 "pub_test.testpub_nopk"
237 "public.testpub_tbl1"
239 ALTER PUBLICATION testpub_default DROP TABLE testpub_tbl1, pub_test.testpub_nopk;
240 -- fail - nonexistent
241 ALTER PUBLICATION testpub_default DROP TABLE pub_test.testpub_nopk;
242 ERROR: relation "testpub_nopk" is not part of the publication
244 Table "public.testpub_tbl1"
245 Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
246 --------+---------+-----------+----------+------------------------------------------+----------+--------------+-------------
247 id | integer | | not null | nextval('testpub_tbl1_id_seq'::regclass) | plain | |
248 data | text | | | | extended | |
250 "testpub_tbl1_pkey" PRIMARY KEY, btree (id)
256 SET ROLE regress_publication_user2;
257 CREATE PUBLICATION testpub2; -- fail
258 ERROR: permission denied for database regression
259 SET ROLE regress_publication_user;
260 GRANT CREATE ON DATABASE regression TO regress_publication_user2;
261 SET ROLE regress_publication_user2;
262 SET client_min_messages = 'ERROR';
263 CREATE PUBLICATION testpub2; -- ok
264 RESET client_min_messages;
265 ALTER PUBLICATION testpub2 ADD TABLE testpub_tbl1; -- fail
266 ERROR: must be owner of table testpub_tbl1
267 SET ROLE regress_publication_user;
268 GRANT regress_publication_user TO regress_publication_user2;
269 SET ROLE regress_publication_user2;
270 ALTER PUBLICATION testpub2 ADD TABLE testpub_tbl1; -- ok
271 DROP PUBLICATION testpub2;
272 SET ROLE regress_publication_user;
273 REVOKE CREATE ON DATABASE regression FROM regress_publication_user2;
274 DROP TABLE testpub_parted;
275 DROP VIEW testpub_view;
276 DROP TABLE testpub_tbl1;
277 \dRp+ testpub_default
278 Publication testpub_default
279 Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
280 --------------------------+------------+---------+---------+---------+-----------+----------
281 regress_publication_user | f | t | t | t | f | f
284 -- fail - must be owner of publication
285 SET ROLE regress_publication_user_dummy;
286 ALTER PUBLICATION testpub_default RENAME TO testpub_dummy;
287 ERROR: must be owner of publication testpub_default
289 ALTER PUBLICATION testpub_default RENAME TO testpub_foo;
292 Name | Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
293 -------------+--------------------------+------------+---------+---------+---------+-----------+----------
294 testpub_foo | regress_publication_user | f | t | t | t | f | f
297 -- rename back to keep the rest simple
298 ALTER PUBLICATION testpub_foo RENAME TO testpub_default;
299 ALTER PUBLICATION testpub_default OWNER TO regress_publication_user2;
302 Name | Owner | All tables | Inserts | Updates | Deletes | Truncates | Via root
303 -----------------+---------------------------+------------+---------+---------+---------+-----------+----------
304 testpub_default | regress_publication_user2 | f | t | t | t | f | f
307 DROP PUBLICATION testpub_default;
308 DROP PUBLICATION testpib_ins_trunct;
309 DROP PUBLICATION testpub_fortbl;
310 DROP SCHEMA pub_test CASCADE;
311 NOTICE: drop cascades to table pub_test.testpub_nopk
312 RESET SESSION AUTHORIZATION;
313 DROP ROLE regress_publication_user, regress_publication_user2;
314 DROP ROLE regress_publication_user_dummy;