Debian Codegraph @

contrib/pg_visibility/t/001_concurrent_transaction.pl

raw
1
2 # Copyright (c) 2021-2025, PostgreSQL Global Development Group
3
4 # Check that a concurrent transaction doesn't cause false negatives in
5 # pg_check_visible() function
6 use strict;
7 use warnings FATAL => 'all';
8 use PostgreSQL::Test::Cluster;
9 use PostgreSQL::Test::Utils;
10 use Test::More;
11
12
13 # Initialize the primary node
14 my $node = PostgreSQL::Test::Cluster->new('main');
15 $node->init(allows_streaming => 1);
16 $node->start;
17
18 # Initialize the streaming standby
19 my $backup_name = 'my_backup';
20 $node->backup($backup_name);
21 my $standby = PostgreSQL::Test::Cluster->new('standby');
22 $standby->init_from_backup($node, $backup_name, has_streaming => 1);
23 $standby->start;
24
25 # Setup another database
26 $node->safe_psql("postgres", "CREATE DATABASE other_database;\n");
27 my $bsession = $node->background_psql('other_database');
28
29 # Run a concurrent transaction
30 $bsession->query_safe(
31 qq[
32 BEGIN;
33 SELECT txid_current();
34 ]);
35
36 # Create a sample table and run vacuum
37 $node->safe_psql("postgres",
38 "CREATE EXTENSION pg_visibility;\n"
39 . "CREATE TABLE vacuum_test AS SELECT 42 i;\n"
40 . "VACUUM (disable_page_skipping) vacuum_test;");
41
42 # Run pg_check_visible()
43 my $result = $node->safe_psql("postgres",
44 "SELECT * FROM pg_check_visible('vacuum_test');");
45
46 # There should be no false negatives
47 ok($result eq "", "pg_check_visible() detects no errors");
48
49 # Run pg_check_visible() on standby
50 $node->wait_for_catchup($standby);
51 $result = $standby->safe_psql("postgres",
52 "SELECT * FROM pg_check_visible('vacuum_test');");
53
54 # There should be no false negatives either
55 ok($result eq "", "pg_check_visible() detects no errors");
56
57 # Shutdown
58 $bsession->query_safe("COMMIT;");
59 $bsession->quit;
60 $node->stop;
61 $standby->stop;
62
63 done_testing();