Debian Codegraph @

contrib/test_decoding/sql/prepared.sql

raw
1 -- predictability
2 SET synchronous_commit = on;
3 SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
4
5 CREATE TABLE test_prepared1(id int);
6 CREATE TABLE test_prepared2(id int);
7
8 -- test simple successful use of a prepared xact
9 BEGIN;
10 INSERT INTO test_prepared1 VALUES (1);
11 PREPARE TRANSACTION 'test_prepared#1';
12 COMMIT PREPARED 'test_prepared#1';
13 INSERT INTO test_prepared1 VALUES (2);
14
15 -- test abort of a prepared xact
16 BEGIN;
17 INSERT INTO test_prepared1 VALUES (3);
18 PREPARE TRANSACTION 'test_prepared#2';
19 ROLLBACK PREPARED 'test_prepared#2';
20
21 INSERT INTO test_prepared1 VALUES (4);
22
23 -- test prepared xact containing ddl
24 BEGIN;
25 INSERT INTO test_prepared1 VALUES (5);
26 ALTER TABLE test_prepared1 ADD COLUMN data text;
27 INSERT INTO test_prepared1 VALUES (6, 'frakbar');
28 PREPARE TRANSACTION 'test_prepared#3';
29
30 -- test that we decode correctly while an uncommitted prepared xact
31 -- with ddl exists.
32
33 -- separate table because of the lock from the ALTER
34 -- this will come before the '5' row above, as this commits before it.
35 INSERT INTO test_prepared2 VALUES (7);
36
37 COMMIT PREPARED 'test_prepared#3';
38
39 -- make sure stuff still works
40 INSERT INTO test_prepared1 VALUES (8);
41 INSERT INTO test_prepared2 VALUES (9);
42
43 -- cleanup
44 DROP TABLE test_prepared1;
45 DROP TABLE test_prepared2;
46
47 -- show results
48 SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
49
50 SELECT pg_drop_replication_slot('regression_slot');