mirror of https://github.com/postgres/postgres
If your connection to the database server is lost while a COMMIT is in progress, it may be difficult to figure out whether the COMMIT was successful or not. This function will tell you, provided that you don't wait too long to ask. It may be useful in other situations, too. Craig Ringer, reviewed by Simon Riggs and by me Discussion: http://postgr.es/m/CAMsr+YHQiWNEi0daCTboS40T+V5s_+dst3PYv_8v2wNVH+Xx4g@mail.gmail.compull/3/merge
parent
42b4b0b241
commit
857ee8e391
@ -0,0 +1,46 @@ |
||||
# |
||||
# Tests relating to PostgreSQL crash recovery and redo |
||||
# |
||||
use strict; |
||||
use warnings; |
||||
use PostgresNode; |
||||
use TestLib; |
||||
use Test::More tests => 3; |
||||
|
||||
my $node = get_new_node('master'); |
||||
$node->init(allows_streaming => 1); |
||||
$node->start; |
||||
|
||||
my ($stdin, $stdout, $stderr) = ('', '', ''); |
||||
|
||||
# Ensure that txid_status reports 'aborted' for xacts |
||||
# that were in-progress during crash. To do that, we need |
||||
# an xact to be in-progress when we crash and we need to know |
||||
# its xid. |
||||
my $tx = IPC::Run::start( |
||||
['psql', '-qAt', '-v', 'ON_ERROR_STOP=1', '-f', '-', '-d', $node->connstr('postgres')], |
||||
'<', \$stdin, '>', \$stdout, '2>', \$stderr); |
||||
$stdin .= q[ |
||||
BEGIN; |
||||
CREATE TABLE mine(x integer); |
||||
SELECT txid_current(); |
||||
]; |
||||
$tx->pump until $stdout =~ /[[:digit:]]+[\r\n]$/; |
||||
|
||||
# Status should be in-progress |
||||
my $xid = $stdout; |
||||
chomp($xid); |
||||
|
||||
is($node->safe_psql('postgres', qq[SELECT txid_status('$xid');]), 'in progress', 'own xid is in-progres'); |
||||
|
||||
# Crash and restart the postmaster |
||||
$node->stop('immediate'); |
||||
$node->start; |
||||
|
||||
# Make sure we really got a new xid |
||||
cmp_ok($node->safe_psql('postgres', 'SELECT txid_current()'), '>', $xid, |
||||
'new xid after restart is greater'); |
||||
# and make sure we show the in-progress xact as aborted |
||||
is($node->safe_psql('postgres', qq[SELECT txid_status('$xid');]), 'aborted', 'xid is aborted after crash'); |
||||
|
||||
$tx->kill_kill; |
Loading…
Reference in new issue