| 1 |
-- predictability |
| 2 |
SET synchronous_commit = on; |
| 3 |
|
| 4 |
-- setup |
| 5 |
CREATE ROLE regress_lr_normal; |
| 6 |
CREATE ROLE regress_lr_superuser SUPERUSER; |
| 7 |
CREATE ROLE regress_lr_replication REPLICATION; |
| 8 |
CREATE TABLE lr_test(data text); |
| 9 |
|
| 10 |
-- superuser can control replication |
| 11 |
SET ROLE regress_lr_superuser; |
| 12 |
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); |
| 13 |
INSERT INTO lr_test VALUES('lr_superuser_init'); |
| 14 |
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); |
| 15 |
SELECT pg_drop_replication_slot('regression_slot'); |
| 16 |
RESET ROLE; |
| 17 |
|
| 18 |
-- no users can load an untrusted plugin |
| 19 |
SET output_plugin_libraries = pgoutput; |
| 20 |
SET ROLE regress_lr_replication; |
| 21 |
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); |
| 22 |
RESET ROLE; |
| 23 |
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); |
| 24 |
RESET output_plugin_libraries; |
| 25 |
|
| 26 |
-- replication user can control replication |
| 27 |
SET ROLE regress_lr_replication; |
| 28 |
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); |
| 29 |
INSERT INTO lr_test VALUES('lr_superuser_init'); |
| 30 |
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); |
| 31 |
SELECT pg_drop_replication_slot('regression_slot'); |
| 32 |
RESET ROLE; |
| 33 |
|
| 34 |
-- plain user *can't* can control replication |
| 35 |
SET ROLE regress_lr_normal; |
| 36 |
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); |
| 37 |
INSERT INTO lr_test VALUES('lr_superuser_init'); |
| 38 |
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); |
| 39 |
SELECT pg_drop_replication_slot('regression_slot'); |
| 40 |
SELECT pg_sync_replication_slots(); |
| 41 |
RESET ROLE; |
| 42 |
|
| 43 |
-- replication users can drop superuser created slots |
| 44 |
SET ROLE regress_lr_superuser; |
| 45 |
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); |
| 46 |
RESET ROLE; |
| 47 |
SET ROLE regress_lr_replication; |
| 48 |
SELECT pg_drop_replication_slot('regression_slot'); |
| 49 |
RESET ROLE; |
| 50 |
|
| 51 |
-- normal users can't drop existing slots |
| 52 |
SET ROLE regress_lr_superuser; |
| 53 |
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); |
| 54 |
RESET ROLE; |
| 55 |
SET ROLE regress_lr_normal; |
| 56 |
SELECT pg_drop_replication_slot('regression_slot'); |
| 57 |
RESET ROLE; |
| 58 |
|
| 59 |
-- all users can see existing slots |
| 60 |
SET ROLE regress_lr_superuser; |
| 61 |
SELECT slot_name, plugin FROM pg_replication_slots; |
| 62 |
RESET ROLE; |
| 63 |
|
| 64 |
SET ROLE regress_lr_replication; |
| 65 |
SELECT slot_name, plugin FROM pg_replication_slots; |
| 66 |
RESET ROLE; |
| 67 |
|
| 68 |
SET ROLE regress_lr_normal; |
| 69 |
SELECT slot_name, plugin FROM pg_replication_slots; |
| 70 |
RESET ROLE; |
| 71 |
|
| 72 |
-- cleanup |
| 73 |
SELECT pg_drop_replication_slot('regression_slot'); |
| 74 |
|
| 75 |
DROP ROLE regress_lr_normal; |
| 76 |
DROP ROLE regress_lr_superuser; |
| 77 |
DROP ROLE regress_lr_replication; |
| 78 |
DROP TABLE lr_test; |