Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd900e19

Browse files
committed
Add test case for logical decoding of prepared transactions.
Andres Freund
1 parentafd0fcb commitd900e19

File tree

3 files changed

+133
-1
lines changed

3 files changed

+133
-1
lines changed

‎contrib/test_decoding/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ submake-isolation:
3737
submake-test_decoding:
3838
$(MAKE) -C$(top_builddir)/contrib/test_decoding
3939

40-
REGRESSCHECKS=ddl rewrite toast permissions decoding_in_xact binary
40+
REGRESSCHECKS=ddl rewrite toast permissions decoding_in_xact binary prepared
4141

4242
regresscheck: all | submake-regress submake-test_decoding
4343
$(MKDIR_P) regression_output
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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');
43+
data
44+
-------------------------------------------------------------------------
45+
BEGIN
46+
COMMIT
47+
BEGIN
48+
COMMIT
49+
BEGIN
50+
table public.test_prepared1: INSERT: id[integer]:1
51+
COMMIT
52+
BEGIN
53+
table public.test_prepared1: INSERT: id[integer]:2
54+
COMMIT
55+
BEGIN
56+
table public.test_prepared1: INSERT: id[integer]:4
57+
COMMIT
58+
BEGIN
59+
table public.test_prepared2: INSERT: id[integer]:7
60+
COMMIT
61+
BEGIN
62+
table public.test_prepared1: INSERT: id[integer]:5
63+
table public.test_prepared1: INSERT: id[integer]:6 data[text]:'frakbar'
64+
COMMIT
65+
BEGIN
66+
table public.test_prepared1: INSERT: id[integer]:8 data[text]:null
67+
COMMIT
68+
BEGIN
69+
table public.test_prepared2: INSERT: id[integer]:9
70+
COMMIT
71+
BEGIN
72+
COMMIT
73+
BEGIN
74+
COMMIT
75+
(30 rows)
76+
77+
SELECT pg_drop_replication_slot('regression_slot');
78+
pg_drop_replication_slot
79+
--------------------------
80+
81+
(1 row)
82+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
-- predictability
2+
SET synchronous_commit=on;
3+
SELECT'init'FROM pg_create_logical_replication_slot('regression_slot','test_decoding');
4+
5+
CREATETABLEtest_prepared1(idint);
6+
CREATETABLEtest_prepared2(idint);
7+
8+
-- test simple successful use of a prepared xact
9+
BEGIN;
10+
INSERT INTO test_prepared1VALUES (1);
11+
PREPARE TRANSACTION'test_prepared#1';
12+
COMMIT PREPARED'test_prepared#1';
13+
INSERT INTO test_prepared1VALUES (2);
14+
15+
-- test abort of a prepared xact
16+
BEGIN;
17+
INSERT INTO test_prepared1VALUES (3);
18+
PREPARE TRANSACTION'test_prepared#2';
19+
ROLLBACK PREPARED'test_prepared#2';
20+
21+
INSERT INTO test_prepared1VALUES (4);
22+
23+
-- test prepared xact containing ddl
24+
BEGIN;
25+
INSERT INTO test_prepared1VALUES (5);
26+
ALTERTABLE test_prepared1 ADD COLUMN datatext;
27+
INSERT INTO test_prepared1VALUES (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_prepared2VALUES (7);
36+
37+
COMMIT PREPARED'test_prepared#3';
38+
39+
-- make sure stuff still works
40+
INSERT INTO test_prepared1VALUES (8);
41+
INSERT INTO test_prepared2VALUES (9);
42+
43+
-- cleanup
44+
DROPTABLE test_prepared1;
45+
DROPTABLE test_prepared2;
46+
47+
-- show results
48+
SELECT dataFROM pg_logical_slot_get_changes('regression_slot',NULL,NULL,'include-xids','0');
49+
50+
SELECT pg_drop_replication_slot('regression_slot');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp