File: 001_concurrent_transaction.pl

package info (click to toggle)
postgresql-17 17.6-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 150,868 kB
  • sloc: ansic: 945,304; sql: 118,799; perl: 51,715; xml: 30,905; yacc: 20,742; lex: 8,812; makefile: 6,624; sh: 4,972; cpp: 1,021; python: 414; asm: 40; sed: 3
file content (47 lines) | stat: -rw-r--r-- 1,130 bytes parent folder | download | duplicates (2)
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

# Copyright (c) 2021-2024, PostgreSQL Global Development Group

# Check that a concurrent transaction doesn't cause false negatives in
# pg_check_visible() function
use strict;
use warnings FATAL => 'all';
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More;


my $node = PostgreSQL::Test::Cluster->new('main');

$node->init;
$node->start;

# Setup another database
$node->safe_psql("postgres", "CREATE DATABASE other_database;\n");
my $bsession = $node->background_psql('other_database');

# Run a concurrent transaction
$bsession->query_safe(
	qq[
	BEGIN;
	SELECT txid_current();
]);

# Create a sample table and run vacuum
$node->safe_psql("postgres",
		"CREATE EXTENSION pg_visibility;\n"
	  . "CREATE TABLE vacuum_test AS SELECT 42 i;\n"
	  . "VACUUM (disable_page_skipping) vacuum_test;");

# Run pg_check_visible()
my $result = $node->safe_psql("postgres",
	"SELECT * FROM pg_check_visible('vacuum_test');");

# There should be no false negatives
ok($result eq "", "pg_check_visible() detects no errors");

# Shutdown
$bsession->query_safe("COMMIT;");
$bsession->quit;
$node->stop;

done_testing();