| 1 |
-- predictability |
| 2 |
SET synchronous_commit = on; |
| 3 |
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); |
| 4 |
?column? |
| 5 |
---------- |
| 6 |
init |
| 7 |
(1 row) |
| 8 |
|
| 9 |
CREATE TABLE test_prepared1(id int); |
| 10 |
CREATE TABLE test_prepared2(id int); |
| 11 |
-- test simple successful use of a prepared xact |
| 12 |
BEGIN; |
| 13 |
INSERT INTO test_prepared1 VALUES (1); |
| 14 |
PREPARE TRANSACTION 'test_prepared#1'; |
| 15 |
COMMIT PREPARED 'test_prepared#1'; |
| 16 |
INSERT INTO test_prepared1 VALUES (2); |
| 17 |
-- test abort of a prepared xact |
| 18 |
BEGIN; |
| 19 |
INSERT INTO test_prepared1 VALUES (3); |
| 20 |
PREPARE TRANSACTION 'test_prepared#2'; |
| 21 |
ROLLBACK PREPARED 'test_prepared#2'; |
| 22 |
INSERT INTO test_prepared1 VALUES (4); |
| 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 |
-- test that we decode correctly while an uncommitted prepared xact |
| 30 |
-- with ddl exists. |
| 31 |
-- separate table because of the lock from the ALTER |
| 32 |
-- this will come before the '5' row above, as this commits before it. |
| 33 |
INSERT INTO test_prepared2 VALUES (7); |
| 34 |
COMMIT PREPARED 'test_prepared#3'; |
| 35 |
-- make sure stuff still works |
| 36 |
INSERT INTO test_prepared1 VALUES (8); |
| 37 |
INSERT INTO test_prepared2 VALUES (9); |
| 38 |
-- cleanup |
| 39 |
DROP TABLE test_prepared1; |
| 40 |
DROP TABLE test_prepared2; |
| 41 |
-- show results |
| 42 |
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); |
| 43 |
data |
| 44 |
------------------------------------------------------------------------- |
| 45 |
BEGIN |
| 46 |
table public.test_prepared1: INSERT: id[integer]:1 |
| 47 |
COMMIT |
| 48 |
BEGIN |
| 49 |
table public.test_prepared1: INSERT: id[integer]:2 |
| 50 |
COMMIT |
| 51 |
BEGIN |
| 52 |
table public.test_prepared1: INSERT: id[integer]:4 |
| 53 |
COMMIT |
| 54 |
BEGIN |
| 55 |
table public.test_prepared2: INSERT: id[integer]:7 |
| 56 |
COMMIT |
| 57 |
BEGIN |
| 58 |
table public.test_prepared1: INSERT: id[integer]:5 |
| 59 |
table public.test_prepared1: INSERT: id[integer]:6 data[text]:'frakbar' |
| 60 |
COMMIT |
| 61 |
BEGIN |
| 62 |
table public.test_prepared1: INSERT: id[integer]:8 data[text]:null |
| 63 |
COMMIT |
| 64 |
BEGIN |
| 65 |
table public.test_prepared2: INSERT: id[integer]:9 |
| 66 |
COMMIT |
| 67 |
(22 rows) |
| 68 |
|
| 69 |
SELECT pg_drop_replication_slot('regression_slot'); |
| 70 |
pg_drop_replication_slot |
| 71 |
-------------------------- |
| 72 |
|
| 73 |
(1 row) |
| 74 |
|