# Copyright (c) 2021-2025, PostgreSQL Global Development Group
# Tests that standbys: # - drop stats for objects when the those records are replayed # - persist stats across graceful restarts # - discard stats after immediate / crash restarts
use strict;
use warnings FATAL => 'all';
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More;
# Test that the stats were cleaned up on standby # Note that this connects to 'postgres' but provides the dboid of dropped db # 'test' which we acquired previously
test_standby_func_tab_stats_status('postgres',
$dboid, $tableoid, $funcoid, 'f');
sub populate_standby_stats
{
my ($connect_db, $schema) = @_;
# create objects on primary
$node_primary->safe_psql($connect_db, "CREATE TABLE $schema.drop_tab_test1 AS SELECT generate_series(1,100) AS a"
);
$node_primary->safe_psql($connect_db, "CREATE FUNCTION $schema.drop_func_test1() RETURNS VOID AS 'select 2;' LANGUAGE SQL IMMUTABLE"
);
$node_primary->wait_for_replay_catchup($node_standby);
# collect object oids
my $dboid = $node_standby->safe_psql($connect_db, "SELECT oid FROM pg_database WHERE datname = '$connect_db'");
my $tableoid = $node_standby->safe_psql($connect_db, "SELECT '$schema.drop_tab_test1'::regclass::oid");
my $funcoid = $node_standby->safe_psql($connect_db, "SELECT '$schema.drop_func_test1()'::regprocedure::oid");
# generate stats on standby
$node_standby->safe_psql($connect_db, "SELECT * FROM $schema.drop_tab_test1");
$node_standby->safe_psql($connect_db, "SELECT $schema.drop_func_test1()");
return ($dboid, $tableoid, $funcoid);
}
sub drop_function_by_oid
{
my ($connect_db, $funcoid) = @_;
# Get function name from returned oid
my $func_name = $node_primary->safe_psql($connect_db, "SELECT '$funcoid'::regprocedure");
$node_primary->safe_psql($connect_db, "DROP FUNCTION $func_name");
}
sub drop_table_by_oid
{
my ($connect_db, $tableoid) = @_;
# Get table name from returned oid
my $table_name =
$node_primary->safe_psql($connect_db, "SELECT '$tableoid'::regclass");
$node_primary->safe_psql($connect_db, "DROP TABLE $table_name");
}
sub test_standby_func_tab_stats_status
{
local $Test::Builder::Level = $Test::Builder::Level + 1;
my ($connect_db, $dboid, $tableoid, $funcoid, $present) = @_;
my %expected = (rel => $present, func => $present);
my %stats;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.