Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
# Copyright (c) 2026, PostgreSQL Global Development Group
 
# Backend exit must finish temp-schema cleanup even when the session default
# is SERIALIZABLE READ ONLY DEFERRABLE and a prepared serializable transaction
# is still around.
 
use strict;
use warnings FATAL => 'all';
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More;
 
my $node = PostgreSQL::Test::Cluster->new('deferrable_temp_exit');
$node->init;
$node->append_conf('postgresql.conf', 'max_prepared_transactions = 1');
$node->start;
 
my $psql1 = $node->background_psql('postgres');
 
$psql1->query_safe(
    q{
CREATE TEMPORARY TABLE tt (i int);
SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY DEFERRABLE;
});
 
my $pid = $psql1->query_safe(q{SELECT pg_backend_pid();});
chomp $pid;
like($pid, qr/^\d+$/, "backend pid $pid");
 
# Overlapping read/write serializable xact that outlives session 1.
$node->safe_psql(
    'postgres',
    q{
CREATE TABLE t (i int);
BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE;
INSERT INTO t VALUES (1);
PREPARE TRANSACTION 'pt';
});
 
# Disconnect: RemoveTempRelationsCallback runs during backend exit.
$psql1->quit;
 
ok( $node->poll_query_until(
        'postgres',
        "SELECT count(*) = 0 FROM pg_stat_activity WHERE pid = $pid"),
    'backend exited despite prepared serializable xact');
 
is( $node->safe_psql(
        'postgres',
        q{SELECT count(*) FROM pg_class WHERE relname = 'tt' AND relpersistence = 't'}
    ),
    '0',
    'temporary table cleaned up on exit');
 
$node->safe_psql('postgres', q{ROLLBACK PREPARED 'pt';});
$node->safe_psql('postgres', q{DROP TABLE t;});
 
done_testing();