forked from postgres/postgres
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path0000_precommit.pl
73 lines (57 loc) · 1.8 KB
/
0000_precommit.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use strict;
use warnings;
use PostgresNode;
use TestLib;
use Test::More tests => 2;
my $psql_out = '';
my $psql_rc = '';
my $node = get_new_node("london");
$node->init(allows_streaming => 1);
$node->append_conf(
'postgresql.conf', qq(
max_prepared_transactions = 10
log_checkpoints = true
));
$node->start;
# Create table we'll use in the test transactions
$node->psql('postgres', "CREATE TABLE t_precommit_tbl (id int, msg text)");
###############################################################################
# Check ordinary restart
###############################################################################
$node->psql(
'postgres', "
BEGIN;
INSERT INTO t_precommit_tbl VALUES (1, 'x');
PREPARE TRANSACTION 'xact_prepared';
BEGIN;
INSERT INTO t_precommit_tbl VALUES (2, 'x');
PREPARE TRANSACTION 'xact_precommited';
SELECT pg_precommit_prepared('xact_precommited', 'precommited');");
$node->stop;
$node->start;
$node->psql(
'postgres',
"SELECT count(*) FROM pg_prepared_xacts WHERE state3pc = 'precommited'",
stdout => \$psql_out);
is($psql_out, '1',
"Check that state3pc preserved during reboot");
###############################################################################
# Check crash/recover
###############################################################################
$node->psql(
'postgres', "
BEGIN;
INSERT INTO t_precommit_tbl VALUES (3, 'x');
PREPARE TRANSACTION 'xact_prepared_2';
BEGIN;
INSERT INTO t_precommit_tbl VALUES (4, 'x');
PREPARE TRANSACTION 'xact_precommited_2';
SELECT pg_precommit_prepared('xact_precommited_2', 'precommited');");
$node->stop("immediate");
$node->start;
$node->psql(
'postgres',
"SELECT count(*) FROM pg_prepared_xacts WHERE state3pc = 'precommited'",
stdout => \$psql_out);
is($psql_out, '2',
"Check that state3pc preserved during reboot");