@@ -22,19 +22,27 @@ SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot_p', 'test
2222 init
2323(1 row)
2424
25+ SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot_t2', 'test_decoding', true);
26+ ?column?
27+ ----------
28+ init
29+ (1 row)
30+
2531-- here we want to start a new session and wait till old one is gone
2632select pg_backend_pid() as oldpid \gset
2733\c -
2834do 'declare c int = 0;
2935begin
30- while (select count(*) from pg_stat_activity where pid = '
36+ while (select count(*) from pg_replication_slots where active_pid = '
3137 :'oldpid'
32- ') > 0 loop c := c + 1; perform pg_stat_clear_snapshot( ); end loop;
38+ ') > 0 loop c := c + 1; perform pg_sleep(0.01 ); end loop;
3339 raise log ''slot test looped % times'', c;
3440end';
35- -- should fail because the temporary slot was dropped automatically
41+ -- should fail because the temporary slots were dropped automatically
3642SELECT pg_drop_replication_slot('regression_slot_t');
3743ERROR: replication slot "regression_slot_t" does not exist
44+ SELECT pg_drop_replication_slot('regression_slot_t2');
45+ ERROR: replication slot "regression_slot_t2" does not exist
3846-- permanent slot has survived
3947SELECT pg_drop_replication_slot('regression_slot_p');
4048 pg_drop_replication_slot
@@ -49,19 +57,44 @@ SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot1', 'test_
4957 init
5058(1 row)
5159
60+ CREATE TABLE replication_example(id SERIAL PRIMARY KEY, somedata int, text varchar(120));
61+ BEGIN;
62+ INSERT INTO replication_example(somedata, text) VALUES (1, 1);
63+ INSERT INTO replication_example(somedata, text) VALUES (1, 2);
64+ COMMIT;
5265SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot2', 'test_decoding', true);
5366 ?column?
5467----------
5568 init
5669(1 row)
5770
58- SELECT * FROM pg_logical_slot_get_changes('regression_slot1', NULL, NULL);
59- location | xid | data
60- ----------+-----+------
61- (0 rows)
71+ INSERT INTO replication_example(somedata, text) VALUES (1, 3);
72+ SELECT data FROM pg_logical_slot_get_changes('regression_slot1', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
73+ data
74+ ---------------------------------------------------------------------------------------------------------
75+ BEGIN
76+ table public.replication_example: INSERT: id[integer]:1 somedata[integer]:1 text[character varying]:'1'
77+ table public.replication_example: INSERT: id[integer]:2 somedata[integer]:1 text[character varying]:'2'
78+ COMMIT
79+ BEGIN
80+ table public.replication_example: INSERT: id[integer]:3 somedata[integer]:1 text[character varying]:'3'
81+ COMMIT
82+ (7 rows)
6283
63- SELECT * FROM pg_logical_slot_get_changes('regression_slot2', NULL, NULL);
64- location | xid | data
65- ----------+-----+------
66- (0 rows)
84+ SELECT data FROM pg_logical_slot_get_changes('regression_slot2', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
85+ data
86+ ---------------------------------------------------------------------------------------------------------
87+ BEGIN
88+ table public.replication_example: INSERT: id[integer]:3 somedata[integer]:1 text[character varying]:'3'
89+ COMMIT
90+ (3 rows)
6791
92+ DROP TABLE replication_example;
93+ -- error
94+ SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot1', 'test_decoding', true);
95+ ERROR: replication slot "regression_slot1" already exists
96+ -- both should error as they should be dropped on error
97+ SELECT pg_drop_replication_slot('regression_slot1');
98+ ERROR: replication slot "regression_slot1" does not exist
99+ SELECT pg_drop_replication_slot('regression_slot2');
100+ ERROR: replication slot "regression_slot2" does not exist
0 commit comments