mirror of
https://github.com/postgres/postgres.git
synced 2025-05-03 22:24:49 +03:00
Currently, pg_visibility computes its xid horizon using the GetOldestNonRemovableTransactionId(). The problem is that this horizon can sometimes go backward. That can lead to reporting false errors. In order to fix that, this commit implements a new function GetStrictOldestNonRemovableTransactionId(). This function computes the xid horizon, which would be guaranteed to be newer or equal to any xid horizon computed before. We have to do the following to achieve this. 1. Ignore processes xmin's, because they consider connection to other databases that were ignored before. 2. Ignore KnownAssignedXids, because they are not database-aware. At the same time, the primary could compute its horizons database-aware. 3. Ignore walsender xmin, because it could go backward if some replication connections don't use replication slots. As a result, we're using only currently running xids to compute the horizon. Surely these would significantly sacrifice accuracy. But we have to do so to avoid reporting false errors. Inspired by earlier patch by Daniel Shelepanov and the following discussion with Robert Haas and Tom Lane. Discussion: https://postgr.es/m/1649062270.289865713%40f403.i.mail.ru Reviewed-by: Alexander Lakhin, Dmitry Koval
48 lines
1.1 KiB
Perl
48 lines
1.1 KiB
Perl
|
|
# 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();
|