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';
|
|
|
|
|
|
|
|
-- fail - no connection
|
|
|
|
CREATE SUBSCRIPTION testsub PUBLICATION foo;
|
|
|
|
|
2017-03-04 05:25:34 +01:00
|
|
|
-- fail - cannot do CREATE SUBSCRIPTION CREATE SLOT inside transaction block
|
|
|
|
BEGIN;
|
2017-05-12 14:57:01 +02:00
|
|
|
CREATE SUBSCRIPTION testsub CONNECTION 'testconn' PUBLICATION testpub WITH (create_slot);
|
2017-03-04 05:25:34 +01:00
|
|
|
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;
|
|
|
|
|
2017-03-25 02:48:05 +01:00
|
|
|
-- fail - duplicate publications
|
2017-05-12 14:57:01 +02:00
|
|
|
CREATE SUBSCRIPTION testsub CONNECTION 'dbname=doesnotexist' PUBLICATION foo, testpub, foo WITH (connect = false);
|
2017-03-25 02:48:05 +01:00
|
|
|
|
|
|
|
-- ok
|
2017-05-12 14:57:01 +02:00
|
|
|
CREATE SUBSCRIPTION testsub CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false);
|
2017-03-25 02:48:05 +01:00
|
|
|
|
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;
|
|
|
|
|
2017-03-25 02:48:05 +01:00
|
|
|
-- fail - name already exists
|
2017-05-12 14:57:01 +02:00
|
|
|
CREATE SUBSCRIPTION testsub CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false);
|
2017-01-19 18:00:00 +01:00
|
|
|
|
2017-03-25 02:48:05 +01:00
|
|
|
-- fail - must be superuser
|
|
|
|
SET SESSION AUTHORIZATION 'regress_subscription_user2';
|
2017-05-12 14:57:01 +02:00
|
|
|
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION foo WITH (connect = false);
|
2017-03-25 02:48:05 +01:00
|
|
|
SET SESSION AUTHORIZATION 'regress_subscription_user';
|
|
|
|
|
2017-05-17 18:22:56 +02:00
|
|
|
-- fail - invalid option combinations
|
|
|
|
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, copy_data = true);
|
|
|
|
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, enabled = true);
|
|
|
|
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, create_slot = true);
|
|
|
|
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, enabled = true);
|
|
|
|
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, create_slot = true);
|
2017-05-18 02:47:37 +02:00
|
|
|
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE);
|
|
|
|
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, enabled = false);
|
|
|
|
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, create_slot = false);
|
2017-05-17 18:22:56 +02:00
|
|
|
|
|
|
|
-- ok - with slot_name = NONE
|
|
|
|
CREATE SUBSCRIPTION testsub3 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, connect = false);
|
|
|
|
-- fail
|
|
|
|
ALTER SUBSCRIPTION testsub3 ENABLE;
|
|
|
|
ALTER SUBSCRIPTION testsub3 REFRESH PUBLICATION;
|
|
|
|
|
|
|
|
DROP SUBSCRIPTION testsub3;
|
|
|
|
|
2017-05-08 20:01:00 +02:00
|
|
|
-- fail - invalid connection string
|
|
|
|
ALTER SUBSCRIPTION testsub CONNECTION 'foobar';
|
|
|
|
|
2017-03-23 13:36:36 +01:00
|
|
|
\dRs+
|
2017-01-19 18:00:00 +01:00
|
|
|
|
2017-06-06 03:37:00 +02:00
|
|
|
ALTER SUBSCRIPTION testsub SET PUBLICATION testpub2, testpub3 WITH (refresh = false);
|
2017-01-19 18:00:00 +01:00
|
|
|
ALTER SUBSCRIPTION testsub CONNECTION 'dbname=doesnotexist2';
|
2017-05-12 14:57:01 +02:00
|
|
|
ALTER SUBSCRIPTION testsub SET (slot_name = 'newname');
|
2017-03-25 02:48:05 +01:00
|
|
|
|
|
|
|
-- fail
|
|
|
|
ALTER SUBSCRIPTION doesnotexist CONNECTION 'dbname=doesnotexist2';
|
2017-05-18 02:47:37 +02:00
|
|
|
ALTER SUBSCRIPTION testsub SET (create_slot = false);
|
2017-01-19 18:00:00 +01:00
|
|
|
|
|
|
|
\dRs+
|
|
|
|
|
|
|
|
BEGIN;
|
|
|
|
ALTER SUBSCRIPTION testsub ENABLE;
|
|
|
|
|
|
|
|
\dRs
|
|
|
|
|
|
|
|
ALTER SUBSCRIPTION testsub DISABLE;
|
|
|
|
|
|
|
|
\dRs
|
|
|
|
|
|
|
|
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;
|
|
|
|
RESET ROLE;
|
|
|
|
|
2017-03-03 16:47:04 +01:00
|
|
|
ALTER SUBSCRIPTION testsub RENAME TO testsub_foo;
|
2017-05-12 14:57:01 +02:00
|
|
|
ALTER SUBSCRIPTION testsub_foo SET (synchronous_commit = local);
|
|
|
|
ALTER SUBSCRIPTION testsub_foo SET (synchronous_commit = foobar);
|
2017-03-03 16:47:04 +01:00
|
|
|
|
2017-04-14 19:58:46 +02:00
|
|
|
\dRs+
|
2017-03-03 16:47:04 +01:00
|
|
|
|
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;
|
|
|
|
ALTER ROLE regress_subscription_user2 SUPERUSER;
|
|
|
|
-- now it works
|
|
|
|
ALTER SUBSCRIPTION testsub OWNER TO regress_subscription_user2;
|
|
|
|
|
2017-05-09 16:20:42 +02:00
|
|
|
-- fail - cannot do DROP SUBSCRIPTION inside transaction block with slot name
|
2017-03-04 05:25:34 +01:00
|
|
|
BEGIN;
|
2017-05-09 16:20:42 +02:00
|
|
|
DROP SUBSCRIPTION testsub;
|
2017-03-04 05:25:34 +01:00
|
|
|
COMMIT;
|
|
|
|
|
2017-05-12 14:57:01 +02:00
|
|
|
ALTER SUBSCRIPTION testsub SET (slot_name = NONE);
|
2017-05-09 16:20:42 +02:00
|
|
|
|
|
|
|
-- now it works
|
2017-03-04 05:25:34 +01:00
|
|
|
BEGIN;
|
2017-05-09 16:20:42 +02:00
|
|
|
DROP SUBSCRIPTION testsub;
|
2017-03-04 05:25:34 +01:00
|
|
|
COMMIT;
|
2017-01-19 18:00:00 +01:00
|
|
|
|
2017-05-09 16:20:42 +02:00
|
|
|
DROP SUBSCRIPTION IF EXISTS testsub;
|
|
|
|
DROP SUBSCRIPTION testsub; -- fail
|
2017-03-25 02:48:05 +01:00
|
|
|
|
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;
|