2017-01-19 18:00:00 +01:00
|
|
|
--
|
|
|
|
-- SUBSCRIPTION
|
|
|
|
--
|
|
|
|
CREATE ROLE regress_subscription_user LOGIN SUPERUSER;
|
2017-03-25 02:48:05 +01:00
|
|
|
CREATE ROLE regress_subscription_user2;
|
2017-03-08 04:44:59 +01:00
|
|
|
CREATE ROLE regress_subscription_user_dummy LOGIN NOSUPERUSER;
|
2017-01-19 18:00:00 +01:00
|
|
|
SET SESSION AUTHORIZATION 'regress_subscription_user';
|
|
|
|
-- fail - no publications
|
|
|
|
CREATE SUBSCRIPTION testsub CONNECTION 'foo';
|
|
|
|
ERROR: syntax error at or near ";"
|
|
|
|
LINE 1: CREATE SUBSCRIPTION testsub CONNECTION 'foo';
|
|
|
|
^
|
|
|
|
-- fail - no connection
|
|
|
|
CREATE SUBSCRIPTION testsub PUBLICATION foo;
|
|
|
|
ERROR: syntax error at or near "PUBLICATION"
|
|
|
|
LINE 1: CREATE SUBSCRIPTION testsub PUBLICATION foo;
|
|
|
|
^
|
2017-03-04 05:25:34 +01:00
|
|
|
-- fail - cannot do CREATE SUBSCRIPTION CREATE SLOT inside transaction block
|
|
|
|
BEGIN;
|
|
|
|
CREATE SUBSCRIPTION testsub CONNECTION 'testconn' PUBLICATION testpub WITH (CREATE SLOT);
|
|
|
|
ERROR: CREATE SUBSCRIPTION ... CREATE SLOT cannot run inside a transaction block
|
|
|
|
COMMIT;
|
2017-03-25 02:48:05 +01:00
|
|
|
-- fail - invalid connection string
|
2017-01-19 18:00:00 +01:00
|
|
|
CREATE SUBSCRIPTION testsub CONNECTION 'testconn' PUBLICATION testpub;
|
|
|
|
ERROR: invalid connection string syntax: missing "=" after "testconn" in connection info string
|
|
|
|
|
2017-03-25 02:48:05 +01:00
|
|
|
-- fail - duplicate publications
|
|
|
|
CREATE SUBSCRIPTION testsub CONNECTION 'dbname=doesnotexist' PUBLICATION foo, testpub, foo WITH (NOCONNECT);
|
|
|
|
ERROR: publication name "foo" used more than once
|
|
|
|
-- ok
|
2017-03-23 13:36:36 +01:00
|
|
|
CREATE SUBSCRIPTION testsub CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (NOCONNECT);
|
|
|
|
WARNING: tables were not subscribed, you will have to run ALTER SUBSCRIPTION ... REFRESH PUBLICATION to subscribe the tables
|
2017-03-25 04:25:24 +01:00
|
|
|
COMMENT ON SUBSCRIPTION testsub IS 'test subscription';
|
|
|
|
SELECT obj_description(s.oid, 'pg_subscription') FROM pg_subscription s;
|
|
|
|
obj_description
|
|
|
|
-------------------
|
|
|
|
test subscription
|
|
|
|
(1 row)
|
|
|
|
|
2017-03-25 02:48:05 +01:00
|
|
|
-- fail - name already exists
|
|
|
|
CREATE SUBSCRIPTION testsub CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (NOCONNECT);
|
|
|
|
ERROR: subscription "testsub" already exists
|
|
|
|
-- fail - must be superuser
|
|
|
|
SET SESSION AUTHORIZATION 'regress_subscription_user2';
|
|
|
|
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION foo WITH (NOCONNECT);
|
|
|
|
ERROR: must be superuser to create subscriptions
|
|
|
|
SET SESSION AUTHORIZATION 'regress_subscription_user';
|
2017-05-08 20:01:00 +02:00
|
|
|
-- fail - invalid connection string
|
|
|
|
ALTER SUBSCRIPTION testsub CONNECTION 'foobar';
|
|
|
|
ERROR: invalid connection string syntax: missing "=" after "foobar" in connection info string
|
|
|
|
|
2017-01-19 18:00:00 +01:00
|
|
|
\dRs+
|
2017-04-14 19:58:46 +02:00
|
|
|
List of subscriptions
|
|
|
|
Name | Owner | Enabled | Publication | Synchronous commit | Conninfo
|
|
|
|
---------+---------------------------+---------+-------------+--------------------+---------------------
|
|
|
|
testsub | regress_subscription_user | f | {testpub} | off | dbname=doesnotexist
|
2017-01-19 18:00:00 +01:00
|
|
|
(1 row)
|
|
|
|
|
2017-03-23 13:36:36 +01:00
|
|
|
ALTER SUBSCRIPTION testsub SET PUBLICATION testpub2, testpub3 NOREFRESH;
|
2017-01-19 18:00:00 +01:00
|
|
|
ALTER SUBSCRIPTION testsub CONNECTION 'dbname=doesnotexist2';
|
2017-03-25 02:48:05 +01:00
|
|
|
ALTER SUBSCRIPTION testsub WITH (SLOT NAME = 'newname');
|
|
|
|
-- fail
|
|
|
|
ALTER SUBSCRIPTION doesnotexist CONNECTION 'dbname=doesnotexist2';
|
|
|
|
ERROR: subscription "doesnotexist" does not exist
|
2017-01-19 18:00:00 +01:00
|
|
|
\dRs+
|
2017-04-14 19:58:46 +02:00
|
|
|
List of subscriptions
|
|
|
|
Name | Owner | Enabled | Publication | Synchronous commit | Conninfo
|
|
|
|
---------+---------------------------+---------+---------------------+--------------------+----------------------
|
|
|
|
testsub | regress_subscription_user | f | {testpub2,testpub3} | off | dbname=doesnotexist2
|
2017-01-19 18:00:00 +01:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
BEGIN;
|
|
|
|
ALTER SUBSCRIPTION testsub ENABLE;
|
|
|
|
\dRs
|
2017-03-23 13:36:36 +01:00
|
|
|
List of subscriptions
|
|
|
|
Name | Owner | Enabled | Publication
|
|
|
|
---------+---------------------------+---------+---------------------
|
|
|
|
testsub | regress_subscription_user | t | {testpub2,testpub3}
|
2017-01-19 18:00:00 +01:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
ALTER SUBSCRIPTION testsub DISABLE;
|
|
|
|
\dRs
|
2017-03-23 13:36:36 +01:00
|
|
|
List of subscriptions
|
|
|
|
Name | Owner | Enabled | Publication
|
|
|
|
---------+---------------------------+---------+---------------------
|
|
|
|
testsub | regress_subscription_user | f | {testpub2,testpub3}
|
2017-01-19 18:00:00 +01:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
COMMIT;
|
2017-03-08 04:44:59 +01:00
|
|
|
-- fail - must be owner of subscription
|
|
|
|
SET ROLE regress_subscription_user_dummy;
|
|
|
|
ALTER SUBSCRIPTION testsub RENAME TO testsub_dummy;
|
|
|
|
ERROR: must be owner of subscription testsub
|
|
|
|
RESET ROLE;
|
2017-03-03 16:47:04 +01:00
|
|
|
ALTER SUBSCRIPTION testsub RENAME TO testsub_foo;
|
2017-04-14 19:58:46 +02:00
|
|
|
ALTER SUBSCRIPTION testsub_foo WITH (SYNCHRONOUS_COMMIT = local);
|
|
|
|
ALTER SUBSCRIPTION testsub_foo WITH (SYNCHRONOUS_COMMIT = foobar);
|
|
|
|
ERROR: invalid value for parameter "synchronous_commit": "foobar"
|
|
|
|
HINT: Available values: local, remote_write, remote_apply, on, off.
|
|
|
|
\dRs+
|
|
|
|
List of subscriptions
|
|
|
|
Name | Owner | Enabled | Publication | Synchronous commit | Conninfo
|
|
|
|
-------------+---------------------------+---------+---------------------+--------------------+----------------------
|
|
|
|
testsub_foo | regress_subscription_user | f | {testpub2,testpub3} | local | dbname=doesnotexist2
|
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 SUBSCRIPTION testsub_foo RENAME TO testsub;
|
2017-03-25 02:48:05 +01:00
|
|
|
-- fail - new owner must be superuser
|
|
|
|
ALTER SUBSCRIPTION testsub OWNER TO regress_subscription_user2;
|
|
|
|
ERROR: permission denied to change owner of subscription "testsub"
|
2017-04-17 20:19:39 +02:00
|
|
|
HINT: The owner of a subscription must be a superuser.
|
2017-03-25 02:48:05 +01:00
|
|
|
ALTER ROLE regress_subscription_user2 SUPERUSER;
|
|
|
|
-- now it works
|
|
|
|
ALTER SUBSCRIPTION testsub OWNER TO regress_subscription_user2;
|
2017-03-04 05:25:34 +01:00
|
|
|
-- fail - cannot do DROP SUBSCRIPTION DROP SLOT inside transaction block
|
|
|
|
BEGIN;
|
|
|
|
DROP SUBSCRIPTION testsub DROP SLOT;
|
|
|
|
ERROR: DROP SUBSCRIPTION ... DROP SLOT cannot run inside a transaction block
|
|
|
|
COMMIT;
|
|
|
|
BEGIN;
|
2017-03-15 21:52:12 +01:00
|
|
|
DROP SUBSCRIPTION testsub NODROP SLOT;
|
2017-03-04 05:25:34 +01:00
|
|
|
COMMIT;
|
2017-03-25 02:48:05 +01:00
|
|
|
DROP SUBSCRIPTION IF EXISTS testsub NODROP SLOT;
|
|
|
|
NOTICE: subscription "testsub" does not exist, skipping
|
|
|
|
DROP SUBSCRIPTION testsub NODROP SLOT; -- fail
|
|
|
|
ERROR: subscription "testsub" does not exist
|
2017-01-19 18:00:00 +01:00
|
|
|
RESET SESSION AUTHORIZATION;
|
|
|
|
DROP ROLE regress_subscription_user;
|
2017-03-25 22:25:28 +01:00
|
|
|
DROP ROLE regress_subscription_user2;
|
2017-03-08 04:44:59 +01:00
|
|
|
DROP ROLE regress_subscription_user_dummy;
|