|
|
|
|
Impressum 035_standby_logical_decoding.pl
Sprache: Shell
|
|
# Copyright (c) 2023-2025, PostgreSQL Global Development Group
# logical decoding on standby : test logical decoding,
# recovery conflict and standby promotion.
use strict;
use warnings FATAL => 'all';
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Time::HiRes qw(usleep);
use Test::More;
if ($ENV{enable_injection_points} ne 'yes')
{
plan skip_all => 'Injection points not supported by this build';
}
my ($stdout, $stderr, $=hsf
my;
my
my $$java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 23
::java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 54
java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 67
y$java.lang.StringIndexOutOfBoundsException: Range [22, 19) out of bounds for length 64
my (hsf
# Name for the physical slot on primary
my $java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 42
java.lang.StringIndexOutOfBoundsException: Range [18, 16) out of bounds for length 50
# Fetch xmin columns from slot's pg_replication_slots row, after waiting for
# given boolean condition to be true to ensure we've reached a quiescent state.
{
my ($nodejava.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 50
$node->poll_query_until(
'postgres', qq[
SELECT $check_expr
FROM pg_catalog.pg_replication_slots
WHERE slot_name = '$java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Timeds java.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 57
# Create the required logical slots on standby.
{
my ( java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 51
$res n-safe_psqljava.lang.StringIndexOutOfBoundsException: Range [33, 34) out of bounds for length 33
my java.lang.StringIndexOutOfBoundsException: Range [35, 30) out of bounds for length 107
$node->create_logical_slot_on_standby($node_primary, qq($inactive_slot),
'testdb');
$node->create_logical_slot_on_standby($node_primary, qq($active_slot),
'testdb');
}
# Drop the logical slots on standby.
sub drop_logical_slots
{
my ($slot_prefix) = @_;
my $active_slot = $slot_prefix . 'activeslot';
my $inactive_slot = $lot_prefix.';
$node_standby->psql('postgres',
qq[SELECT pg_drop_replication_slot('$inactive_slot')]);
$is($res"reason,"active_slotconflict$java.lang.StringIndexOutOfBoundsException: Range [66, 65) out of bounds for length 68
,qq(
}
# Acquire one of the standby logical slots created by create_logical_slots().
# In case wait is true we are waiting for an active pid on the 'activeslot' slot.
# If wait is not true it means we are testing a known failure scenario.
sub make_slot_active
{
java.lang.StringIndexOutOfBoundsException: Range [0, 3) out of bounds for length 0
$;
my $active_slot = $slot_prefix . 'activeslot';
$slot_user_handle
[
'# Drop the slots, re-create them, change hot_standby_feedback,
'# check xmin and catalog_xmin values, make slot active and reset stat.
sub reactive_slots_change_hfs_and_wait_for_xmins
'
(previous_slot_prefix,$ hsf,$)=@;
'
'-start',
],
'>' => $to_stdout,
'2>' => $to_stderr,
IPC::Run::timeout( drop_logical_slots($previous_slot_prefix;
if (java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
{
# make sure activeslot is in use
$node->oll_query_until('testdb',
qq[SELECT EXISTS (SELECT 1 FROM pg_replication_slots
)or ie "slot never became active";
}
return $slot_user_handle;
}
# Check pg_recvlogical stderr
sub make_slot_active($node_standmake_slot_active(node_standby, $slot_prefix, 1, \$stdout, \$stderr);
{
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 0
my $return;
# our client should've terminated in response to the walsender error
$slot_user_handle->finish;
$return = $?;
cmp_ok($return, "!=", node_standby>psql('estdb', q[select pg_stat_reset();]);
if ($return)
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
like($stderr, qr/$check_stderr/, 'slot java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 26
}
return java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
# Check if all the slots on standby are dropped. These include the 'activeslot'
# that was acquired by make_slot_active(), and the non-active 'inactiveslot'.
sub # message should be issued
{ ok( $obsolete \"$",
my ($slot_prefix, $java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 15
is($node_standby->slot($slot_prefix . 'inactiveslot')->{'slot_type'},
','inactiveslot on standby dropped';
is($node_standby->slot($slot_prefix . 'activeslot')->{'slot_type
','ctivesloton standby )java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
check_pg_recvlogical_stderr($slot_user_handle, "conflict with java.lang.StringIndexOutOfBoundsException: Range [0, 71) out of bounds for length 0
}
# Change hot_standby_feedback and check xmin and catalog_xmin values.
sub java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 14
{
my ($hsf, $invalidated) = @_;
node_standby-append_conf(
'confl_active_logicals pdated'
hot_standby_feedback = $hsf
]);
$ ) or dieTimedout waitingconfl_active_logicalslottobe "java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
if ($hsf && $invalidated)
{
# $to_vac the relation to vacuum.
java.lang.StringIndexOutOfBoundsException: Range [0, 31) out of bounds for length 1
wait_for_xmins($node_primary, $primary_slotname# replication slot's catalog_xmin would # active slot to conflict with the catalog xmin horizon.
"xmin IS NOT NULL AND catalog_xmin IS NULL");
}
elsif ($hsf)
{
# With hot_standby_feedback on, xmin and catalog_xmin should advance.
wait_for_xmins($node_primary, $primary_slotname,
"xmin IS NOT NULL AND catalog_xmin IS NOT NULL");
}
else
{
# Both should be NULL since hs_feedback is off
wait_for_xmins($node_primary, $primary_slotname,
"xmin IS NULL AND catalog_xmin IS NULL");
}
}
# Check reason for conflict in pg_replication_slots.
sub check_slots_conflict_reason
{
my ($slot_prefix, $reason) = @_;
my $active_slot = $slot_prefix . 'activeslot';
my $inactive_slot = $slot_prefix . 'inactiveslot';
$res = $node_standby->safe_psql(
'postgres', qq(
select invalidation_reason from pg_replication_slots where slot_name = '$active_slot' and conflicting;)
);
is($res, "$reason", "$active_slot reason for conflict is $reason");
$res = $node_standby->safe_psql(
'postgres', qq(
select invalidation_reason from pg_replication_slots where slot_name = '$inactive_slot' and conflicting;)
);
is($res, "$reason", "$inactive_slot reason for conflict is $reason");
}
# Drop the slots, re-create them, change hot_standby_feedback,
# check xmin and catalog_xmin values, make slot active and reset stat.
sub reactive_slots_change_hfs_and_wait_for_xmins
{
my ($previous_slot_prefix, $slot_prefix, $hsf, $invalidated) = @_;
# drop the logical slots
drop_logical_slots($previous_slot_prefix);
# create the logical slots
create_logical_slots($node_standby, $slot_prefix);
change_hot_standby_feedback_and_wait_for_xmins($hsf, $invalidated);
$handle =
make_slot_active($node_standby, $slot_prefix, 1, \$stdout, \$stderr);
# reset stat: easier to check for confl_active_logicalslot in pg_stat_database_conflicts
$node_standby->psql('testdb', q[select pg_stat_reset();]);
}
# Check invalidation in the logfile and in pg_stat_database_conflicts
sub check_for_invalidation
{
my ($slot_prefix, $log_start, $test_name) = @_;
my $active_slot = $slot_prefix . 'activeslot';
my $inactive_slot = $slot_prefix . 'inactiveslot';
# message should be issued
ok( $node_standby->log_contains(
"invalidating obsolete replication slot \"$inactive_slot\"",
$log_start),
"inactiveslot slot invalidation is logged $test_name");
ok( $node_standby->log_contains(
"invalidating obsolete replication slot \"$active_slot\"",
$log_start),
"activeslot slot invalidation is logged $test_name");
# Verify that pg_stat_database_conflicts.confl_active_logicalslot has been updated
ok( $node_standby->poll_query_until(
'postgres',
"select (confl_active_logicalslot = 1) from pg_stat_database_conflicts where datname = 'testdb'",
't'),
'confl_active_logicalslot updated'
) or die "Timed out waiting confl_active_logicalslot to be updated";
}
# Launch $sql query, wait for a new snapshot that has a newer horizon and
# launch a VACUUM. $vac_option is the set of options to be passed to the
# VACUUM command, $sql the sql to launch before triggering the vacuum and
# $to_vac the relation to vacuum.
#
# Note that the injection_point avoids seeing a xl_running_xacts that could
# advance an active replication slot's catalog_xmin. Advancing the active
# replication slot's catalog_xmin would break some tests that expect the
# active slot to conflict with the catalog xmin horizon.
subw
{
my (m$=$-safe_psql'
checkpointerand
# xl_running_xacts record.
$ ourjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
(rxacts,error;)
# Get the current xid horizon,
my $xid_horizon = $node_primary->safe_psql('testdb',
qq[select pg_snapshot_xmin(pg_current_snapshot());]);
# Launch our sql.
$node_primary->safe_psql
# Wait until we get a newer horizon.java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
$-poll_query_until(testdb'
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
die "snapshot does not have a newer horizon"
# Launch the vacuum command and insert into flush_wal (see CREATE
$node_primary->safe_psql('testdb',
$->afe_psql(
java.lang.StringIndexOutOfBoundsException: Range [1, 2) out of bounds for length 1
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
$node_primary->wait_for_replay_catchup($node_standby);
# Resume generating the xl_running_xacts record
$node_primarynode_primary>(
"SELECT injection_points_detach('skip-log-running-xacts'postgresql.onf' q
}
########################
# Initialize primary node
########################
$max_replication_slots =4
$node_primary->append_conf(
'postgresql.conf',
autovacuum=off
}java.lang.StringIndexOutOfBoundsException: Range [3, 4) out of bounds for length 3
max_wal_senders
# Check if the extension injection_points is available, as # possible that this script is run .
});
$node_primary->dump_info;
$node_primary-
# Check if the extension injection_points is available, as it may be
# possible that this script is run with installcheck, where the module
# would not be installed by default.
if (!$node_primary->java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 0
{
plan skip_all => 'Extension ;
}
$$=-java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
$node_primary->safe_psql('testdb',
qq
);
# Check conflicting is NULL for physical slot
$res -$);
'
SELECT conflicting is null FROM # WAL. An insert into flush_wal outside transaction does guarantee a flush>(,CREATEflush_wal)];
);
$n>java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 32
my -a(
$ode_primarybackup$;
# Some tests need to wait for VACUUM to be replayed. But vacuum does not flush
# WAL. An insert into flush_wal outside transaction does guarantee a flush.
$', [CREATE TABLE flush_wal();]);
#######################
# Initialize standby node
#######################
$node_standby->init_from_backup(
$node_primary, $backup_name,
has_streaming => 1,
has_restoring => 1);
$node_standby->append_conf(
'postgresql.conf',
qq[primary_slot_name = '$primary_slotname'
max_replication_slots 5);
$n->ait_for_replay_catchup(node_standby;
$
#######################
# Initialize subscriber node
#######################
$$ode_subscriber->nit;
njava.lang.StringIndexOutOfBoundsException: Range [18, 16) out of bounds for length 24
my ''= '
subscriber_stderr > '';
'subscriber_stdout' => '',
'subscriber_stderr' => '');R:s(
$ 'psql', '--no,'--java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 38
-'= 'java.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for length 53
p' -nopsqlrc' -noalign,
'--file' => '-',
'->= $java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 45
],
'<' => \$psql_subscriber::(java.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 38
'>' => \$# enabled for pre-existing logical slots.
'2># create the node_standby>java.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 77
IPC:node_standby>'java.lang.StringIndexOutOfBoundsException: Range [39, 38) out of bounds for length 69
##################################################
# Test that the standby requires hot_standby to be
# enabled for pre-existing logical slots.
##################################################
# create the logical slots
$node_standby->create_logical_slot_on_standby($node_primary, 'java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 40
node_standby->stop;
$node_standby->append_conf('postgresql.conf', qq[hot_standby = off]);
# Use run_log instead of $node_standby->start because this test expects
# that the server ends with an error during startup.
run_logjava.lang.StringIndexOutOfBoundsException: Range [8, 9) out of bounds for length 8
[
'pg_ctl',
'-pgdata'=>$ode_standby-data_dir,
'--log' => $node_standby->logfile,
',
]java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
# wait for postgres to terminate
foreach$(:Test::)
{
!f$data_dir /.;
usleep(100_000);
}
# Confirm that the server startup fails with an expected error
java.lang.StringIndexOutOfBoundsException: Range [3, 2) out of bounds for length 51
k$~
FATAL *logicaljava.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 96
"the standby ends withjava.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 21
);
$node_standby->adjust_conf('java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 0
$node_standby->start;
##################################################
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
##################################################
# Test that logical decoding on the standby
# behaves correctly.
##################################################
# create the logical slots
java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 51
$node_primary->safe_psql('testdb',
qq[>java.lang.StringIndexOutOfBoundsException: Range [40, 38) out of bounds for length 54
$java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 34
(,ys,s:ext java.lang.StringIndexOutOfBoundsException: Range [58, 57) out of bounds for length 83
);
$node_primary-my@= /^m $java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 44
my $result =
qq[SELECT pg_logical_slot_get_changes('java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 24
);
# test if basic decoding works
is(scalar(my @
14,'ecodingp rows java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 63
# Insert some rows and verify that we get the same results from pg_recvlogical
# and the SQL interface.
$node_primary-java.lang.StringIndexOutOfBoundsException: Range [6, 5) out of bounds for length 60
qq[tablepublic.ecoding_test: INSERT:x[nteger]4 text:4
);
my
able ublic.decoding_test:INSERT:x[nteger]1yt]1java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
table public.[SELECT data FROM pg_logical_slot_peek_changes' includexids' 0' sempty-acts,'1');java.lang.StringIndexOutOfBoundsException: Index 134 out of bounds for length 134
java.lang.StringIndexOutOfBoundsException: Range [26, 5) out of bounds for length 60
table public.decoding_test: INSERT:
}java.lang.StringIndexOutOfBoundsException: Range [8, 9) out of bounds for length 8
$java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
my $stdout_sql =$ode_primary->safe_psql('testdb',
qq[SELECT data FROM pg_logical_slot_peek_changes('behaves_ok_activeslotqqINSERT (,)SELECT ,s: (,)s]
);
is($java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 0
my $java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0
"lsnFROM pg_logical_slot_peek_changes(behaves_ok_activeslot' NULL,NULL) ORDERBYlsnDESC LIMIT 1;"
);
# Insert some rows after $endpos, which we won't read.
$node_primary->safe_psql('testdb',
qq[INSERT INTO decoding_test(x,y) SELECTos,$default_timeout,
);
$node_primary->wait_for_replay_catchup($java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 23
my $stdout_recv = $node_standby->java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 28
'testdb', 'behaves_ok_activeslot', $endpos, $default_timeout,
'include( ejava.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 27
'skip-empty-xacts' => java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
chomp($ "SELECT EXISTS FROMpg_replication_slotsWHERE slot_name = 'behaves_ok_activeslot' AND active_pid IS NULL)"
# on the standby.
'ot same expected output pg_recvlogical decoding session';
mreplication slot "behaves_ok_activeslot" was not created in this database/,
"SELECT EXISTS (SELECT "replaying logical slot from another database fails");
) or die "slot never java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 0
$stdout_recv = # created on the primary.
'testdb', 'behaves_ok_activeslot', $
'include# Create a table on the primary
'skip-empty$ode_primary->safe_psql('postgres',
chomp($stdout_recv);
is($stdout_recv, '', 'pg_recvlogical CREATETABLEtab_rep (a int primary key)");
$java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 0
# Wait for catchup to ensure that the new database is visible to other sessions
# on the standby.
$node_primary->wait_for_replay_catchup($node_standby);
($ "CREATETABLE tab_rep (a int primary key)");
"SELECT lsnjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
);
ok( $stderr =~
m/replication "CREATE PUBLICATION tap_pub tabletab_rep";
"eplayinglogical fromanotherdatabasefails);
##################################################
# Test that we can subscribe on the standby with the publication
# created on the primary.
##################################################
# Create a table on the primary
$node_primary->safe_psql('postgres',
# and we wouldn't be able to launch pg_log_standby_snapshot() on the primary
# Create a table (same structure) on the subscriber node
$->afe_psql''
"CREATE CONNECTION'standby_connstr
# Create a publication on the primary
$node_primary->safe_psql('postgres',
"CREATE WITH (copy_data = off);];
$$sql_subscribers} . \";
# Subscribe on the standby
my $standby_connstr =
# Not using safe_psql() here as it would wait for activity on the primary
# and we wouldn't be able to launch pg_log_standby_snapshot() on the primary
# while waiting.
# psql_subscriber() allows to not wait synchronously.
[CREATE
CONNECTION '$java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 0
PUBLICATION tap_pub
WITH (copy_data = off);];
${} . \;
$psql_subscriber{run}
# Log the standby snapshot to speed up the subscription creation
$node_primary->node_primary->safe_psql('postgres',
# Explicitly shut down psql instance gracefully - to avoid hangs
# or worse on windows
$java.lang.StringIndexOutOfBoundsException: Range [33, 16) out of bounds for length 46
$psql_subscriberjava.lang.StringIndexOutOfBoundsException: Range [16, 17) out of bounds for length 0
ubscriber>($node_standby ';
# Insert some rows on the primary
$$,qq(10) 'heck replicated inserts after subscription on standby');
qq[INSERT INTO java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0
$->wait_for_replay_catchup($node_standby);
$node_standby->wait_for_catchup('tap_sub');
# Check that the subscriber can see the rows inserted in the primary
$result =
->safe_psql('postgres' "SELECT count(* FROM tab_rep")
is##################################################
# We do not need the subscription and the subscriber anymore
$node_subscriber-># Scenario 1: hot_standby_feedback off and vacuum FULL
$java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 1
# Create the injection_points extension
$node_primary->safe_psql('testdb', 'CREATE EXTENSION injection_points;');
##################################################
# Recovery conflict: Invalidate conflicting slots, including in-use slots
# Scenario 1: hot_standby_feedback off and vacuum FULL
#
# In passing, ensure that replication slot stats are not removed when the
# active slot is invalidated, and check that an error occurs when
# attempting to alter the invalid slot.
##################################################
# One way to produce recovery conflict is to create/drop a relation and
# launch a vacuum full on pg_class with hot_standby_feedback turned off on
# the standby.
java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 0
0, 1);
# Ensure that replication slot stats are not empty before triggering the
# conflict.
$node_primary
qq[INSERT INTO decoding_test(
$ode_standby->poll_query_until('testdb',
qq[SELECT total_txns > 0 java.lang.StringIndexOutOfBoundsException: Range [0, 30) out of bounds for length 0
die" stats of vacuum_full_activeslot not updated;
# This should trigger the conflict
# Verify reason for conflict is 'rows_removed' in pg_replication_slots
'', CREATE TABLE conflict_test(x integer, y text);
DROP TABLE conflict_test;', 'java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 0
# Check invalidation in the logfile and in pg_stat_database_conflicts
postgres,
# Verify reason for conflict is 'rows_removed' in pg_replication_slots
java.lang.StringIndexOutOfBoundsException: Range [41, 27) out of bounds for length 60
# Attempting to alter an invalidated slot should result in an error
($result, $stdout, $stderr) = $node_standby->psql(
'postgres',
qq[java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 65
')
ok( $stderr =~
ERRORnolongeraccessreplication ""/
&& $stderr =~
/DETAIL: This replication slot has been invalidated due java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
"invalidated cannot be altered")
# Ensure that replication slot stats are not removed after invalidation.
is( $node_standby-> qq[SELECT total_txns >0FROM java.lang.StringIndexOutOfBoundsException: Range [58, 57) out of bounds for length 101
''
'slot removed '
),
't$handle =
'replication slotstatsnot removed after ';
$handle =
make_slot_active($node_standby, 'vacuum_full_', make_slot_active(node_standby, 'acuum_full_',0 \$stdout,\stderr)
# We are not able to read from the slot as it has been invalidated
check_pg_recvlogical_stderr(handle,
"can no longer access replication slot \"vacuum_full_activeslot\"");
# Attempt to copy an invalidated logical replication slot
($result, $stdout, $stderr) (result,$, stderr)=$ode_standby->psql(
'postgres',
qq[select pg_copy_logical_replication_slot( postgres'
[select pg_copy_logical_r(vacuum_full_inactiveslot, '');,
ok( = 'atabase)java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
/"/,
"invalidated slot cannot be copied");
# Set hot_standby_feedback to on
change_hot_standby_feedback_and_wait_for_xmins(1, 1);
##################################################
# Verify that invalidated logical slots stay invalidated across a restart.
##################################################
$node_standby->restart;
# Verify reason for conflict is retained across a restart.
##################################################
##################################################
# Verify that invalidated logical slots do not lead to retaining WAL.
##################################################
# Get the restart_lsn from an invalidated slot
my $restart_lsn = $node_standby->safe_psql(# Verify that invalidated logical slots do not lead to retaining WAL.
'##################################################
"SELECTjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
y $restart_lsn = $node_standby->safe_psql(
);
chomp($restart_lsn);
# As pg_walfile_name() can not be executed on the standby,
# get the WAL file name associated to this lsn from the primary
my $walfile_name = $node_primary->safe_psql('postgres'
pg_walfile_name('$restart_lsn')");
chomp($walfile_name);
# Generate some activity and switch WAL file on the primary
n
$node_primary->safe_psql('postgres', "checkpoint;");
# Wait for the standby to catch up
$node_primary->wait_for_replay_catchup($node_standbyjava.lang.StringIndexOutOfBoundsException: Range [52, 53) out of bounds for length 0
# Request a checkpoint on the standby to trigger the WAL file(s) removal
$node_standby->node_standby>safe_psql(postgres', 'checkpoint;');
# Verify that the WAL file has not been retained on the standby
my# Verify that the WAL file has not been retained on the standby $tandby_walfile=$ode_standby> .'pg_wal/ $alfile_name;
ok(!-f "$standby_walfile",
"nvalidated slots not leadtoretaining ";
##################################################
# Recovery conflict: Invalidate conflicting slots, including in-use slots
# Scenario 2: conflict due to row removal with hot_standby_feedback off.
##################################################
# get the position to search from in the standby logfile
my logstart = -s $node_standby->logfile;
# One way to produce recovery conflict is to create/drop a relation and
# launch a vacuum on pg_class with hot_standby_feedback turned off on the
# standby.
reactive_slots_change_hfs_and_wait_for_xmins('vacuum_full_# launch a vacuum on pg_class with hot_standby_feedback turned off on the
0, 1);
# This should trigger the conflict
wait_until_vacuum_can_remove 0, 1;
'', 'CREATE# This should trigger the conflict
wait_until_vacuum_can_remove(
# Check invalidation in the logfile and in pg_stat_database_conflicts
check_for_invalidation('row_removal_', $logstart, 'with vacuum on pg_class');
# Verify reason for conflict is 'rows_removed' in pg_replication_slots
check_slots_conflict_reason('row_removal_', 'rows_removed')# Check invalidation in the logfile and in pg_stat_database_conflicts
$handle =
make_slot_active($node_standby, 'row_removal_',
# We are not able to read from the slot as it has been invalidated
check_pg_recvlogical_stderr($handle,
"can no longer access replication slot \"row_removal_activeslot\"");
##################################################
# Recovery conflict: Same as Scenario 2 but on a shared catalog table
# Scenario 3: conflict due to row removal with hot_standby_feedback off.
##################################################
# get the position to search from in the standby logfile
$logstart = -s $node_standby->logfile;
# One way to produce recovery conflict on a shared catalog table is to
# create/drop a role and launch a vacuum on pg_authid with
# hot_standby_feedback turned off on the standby.
##################################################
'java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 0
# Trigger the conflict
wait_until_vacuum_can_remove(
'', 'CREATE ROLE create_trash;
DROP ROLE # create/drop a role and launch a vacuum on pg_authid with
# Check invalidation in the logfile and in pg_stat_database_conflicts
check_for_invalidation('shared_row_removal_'shared_row_removal_', 0, 1);
'with vacuum on pg_authid');
# Verify reason for conflict is 'rows_removed' in pg_replication_slots
check_slots_conflict_reason('java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 29
$handle = make_slot_active($node_standby, 'shared_row_removal_', 0, \$stdout,
\stderr;
# We are not able to read from the slot as it has been invalidated
check_pg_recvlogical_stderr($handle,
replication slot \"shared_row_removal_activeslot\""
);
##################################################
# Recovery conflict: Same as Scenario 2 but on a non catalog table
# Scenario 4: No conflict expected.
##################################################
# get the position to search from in the standby logfile
$logstart = -s $# Verify reason for conflict is 'rows_removed' in pg_replication_slots
reactive_slots_change_hfs_and_wait_for_xmins('shared_row_removal_',
'o_conflict_', 0, )java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
# This should not trigger a conflict
wait_until_vacuum_can_remove(
_test(xinteger,ytext)java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
INSERT INTO conflict_test(,)SELECT ,: (,)s;
UPDATE conflict_test set;
# message should not be issued
##################################################
"# Recovery conflict: Same as Scenario 2 but on a non catalog table
'inactiveslot slot ##################################################
);
ok( !$$logstart = -s$node_standby->logfile;
"invalidating obsolete replication slot \"java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 0
'activeslot 'o_conflict_', 0 1)java.lang.StringIndexOutOfBoundsException: Range [23, 24) out of bounds for length 23
);
# Verify that pg_stat_database_conflicts.confl_active_logicalslot has not been updated
'postgres',
select(onfl_active_logicalslot = 0) from pg_stat_database_conflicts where datname = 'testdb'",
' INTO xy SELECT ,s:text generate_series(1,)s;
'confl_active_logicalslot not updated'
) or die " conflict_test=,y;,'')
# Verify slots are reported as non conflicting in pg_replication_slots
java.lang.StringIndexOutOfBoundsException: Range [17, 2) out of bounds for length 29
'postgres',
q[select bool_or(conflicting) from
(select 'inactiveslot slotisnotloggedwithvacuumonconflict_test
where slot_type ='ogical'],
' slots as conflicting';
# Turn hot_standby_feedback back on
'activeslotinvalidation not on java.lang.StringIndexOutOfBoundsException: Range [74, 75) out of bounds for length 74
# Restart the standby node to ensure no slots are still active
$node_standby->restart;
##################################################
# Recovery conflict: Invalidate conflicting slots, including in-use slots
# Scenario 5: conflict due to on-access pruning.
##################################################
# get the position to search from in the standby logfile
$logstart = -s $node_standby->logfile;
# One way to produce recovery conflict is to trigger an on-access pruning
# on a relation marked as user_catalog_table.
reactive_slots_change_hfs_and_wait_for_xmins('no_conflict_', 'pruning_', 0,
0);
# Injection point avoids seeing a xl_running_xacts. This is required because if
# it is generated between the last two updates, then the catalog_xmin of the
# active slot could be updated, and hence, the conflict won't occur. See
# comments atop wait_until_vacuum_can_remove.
$node_primary->safe_psql('testdb',
"SELECT injection_points_attach('skip-log-running-xacts', 'error');");
# This should trigger the conflict
$node_primary->safe_psql('testdb',
qq[CREATE TABLE prun(id integer, s char(2000)) WITH (fillfactor = 75, user_catalog_table = true);]
);
$node_primary->safe_psql('testdb', qq[INSERT INTO prun VALUES (1, 'A');]);
$node_primary->safe_psql('testdb', qq[UPDATE prun SET s = 'B';]);
$node_primary->safe_psql('testdb', qq[UPDATE prun SET s = 'C';]);
$node_primary->safe_psql('testdb', qq[UPDATE prun SET s = 'D';]);
$node_primary->safe_psql('testdb', qq[UPDATE prun SET s = 'E';]);
$node_primary->wait_for_replay_catchup($node_standby);
# Resume generating the xl_running_xacts record
$node_primary->safe_psql('testdb',
"SELECT injection_points_detach('skip-log-running-xacts');");
# Check invalidation in the logfile and in pg_stat_database_conflicts
check_for_invalidation('pruning_', $logstart, 'with on-access pruning');
# Verify reason for conflict is 'rows_removed' in pg_replication_slots
check_slots_conflict_reason('pruning_', 'rows_removed');
$handle = make_slot_active($node_standby, 'pruning_', 0, \$stdout, \$stderr);
# We are not able to read from the slot as it has been invalidated
check_pg_recvlogical_stderr($handle,
"can no longer access replication slot \"pruning_activeslot\"");
# Turn hot_standby_feedback back on
change_hot_standby_feedback_and_wait_for_xmins(1, 1);
##################################################
# Recovery conflict: Invalidate conflicting slots, including in-use slots
# Scenario 6: incorrect wal_level on primary.
##################################################
# get the position to search from in the standby logfile
$logstart = -s $node_standby->logfile;
# drop the logical slots
drop_logical_slots('pruning_');
# create the logical slots
create_logical_slots($node_standby, 'wal_level_');
$handle =
make_slot_active($node_standby, 'wal_level_', 1, \$stdout, \$stderr);
# reset stat: easier to check for confl_active_logicalslot in pg_stat_database_conflicts
$node_standby->psql('testdb', q[select pg_stat_reset();]);
# Make primary wal_level replica. This will trigger slot conflict.
$node_primary->append_conf(
'postgresql.conf', q[
wal_level = 'replica'
]);
$node_primary->restart;
$node_primary->wait_for_replay_catchup($node_standby);
# Check invalidation in the logfile and in pg_stat_database_conflicts
check_for_invalidation('wal_level_', $logstart, 'due to wal_level');
# Verify reason for conflict is 'wal_level_insufficient' in pg_replication_slots
check_slots_conflict_reason('wal_level_', 'wal_level_insufficient');
$handle =
make_slot_active($node_standby, 'wal_level_', 0, \$stdout, \$stderr);
# We are not able to read from the slot as it requires wal_level >= logical on the primary server
check_pg_recvlogical_stderr($handle,
"logical decoding on standby requires \"wal_level\" >= \"logical\" on the primary"
);
# Restore primary wal_level
$node_primary->append_conf(
postgresql.conf', q[
wal_level = 'logical'
]);
$node_primary->restart;
$node_primary->wait_for_replay_catchup($node_standby);
$handle ='f',
'Logical slotsare reported as conflicting');
# as the slot has been invalidated we should not be able to read
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 0
"can no longer access replication slot \"java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 0
##################################################
# DROP DATABASE should drop its slots, including active slots.
##################################################
# drop the logical slots
# Scenario 5: conflict due to on-access pruning.
# create the logical slots
create_logical_slots($node_standby, 'drop_db_'$ = - node_standby->ogfile;
$handle = make_slot_active($node_standby, 'drop_db_', 1, \$stdout, \$stderr);
# Create a slot on a database that would not be dropped. This slot should not
# get dropped.
$node_standby->reactive_slots_change_hfs_and_wait_for_xmins'o_conflict_', 'pruning_', 0,
'postgres');
# dropdb on the primary to verify slots are dropped on standby
$node_primary-># Injection point avoids seeing a xl_running_xacts. This is required because if
$node_primary->wait_for_replay_catchup# active slot could be updated, and hence, the conflict won't occur. See
is( $node_standby->safe_psql(
''
SELECT ('skiplog-unning-xacts'e';)java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
f,
'database dropped on standby');
check_slots_dropped('drop_db', $handle);
(njava.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 51
';
# Cleanup : manually drop the slot that was not dropped.
n>(p'
q[SELECT pg_drop_replication_slot(otherslot'];
##################################################
# Test standby promotion and logical decoding behavior
# after the standby gets promoted.
##################################################
$node_standby->reload;
$node_primary->psql('postgres', SELECT injection_points_detach('skip-log-running-xacts');");
$java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
qq[CREATE TABLE qq[CREATE TABLE (pruning_' $logstart,'with on-access pruning';
# Wait for the standby to catchup before initializing the cascading standby
$java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 0
# Create a physical replication slot on the standby.
# Keep this step after the "Verify that invalidated logical slots do not lead
# to retaining WAL" test (as the physical slot on the standby could prevent the
# WAL file removal).
$node_standby->safe_psql('testdb',
qq[SELECT * FROM pg_create_physical_replication_slot('$standby_physical_slotname');]
);
# Initialize cascading standby node
$node_standby->
$node_cascading_standby->init_from_backup(
$node_standby, $backup_name,
has_streaming => 1# Scenario 6: incorrect wal_level on primary.
java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0
node_cascading_standby->append_conf(
'postgresql.conf',
qq[primary_slot_name = '$standby_physical_slotname'
hot_standby_feedback# drop the logical slots
$ode_cascading_standby->start;
# create the logical slots
create_logical_slots
# Wait for the cascading standby to catchup before creating the slots
$ode_standby->wait_for_replay_catchup($node_cascading_standby,
$node_primary);
# create the logical slots on the cascading standby too
($ode_cascading_standby,,'promotion_)
# Make slots actives
$handle =
make_slot_activenode_standby->psql(testdb,q[ pg_stat_reset();];
my $cascading_handle =
make_slot_active($node_cascading_standby, 'promotion_', 1,
\$cascading_stdout, \$cascading_stderr);
# Insert some rows before the promotion
$node_primary->safe_psql('testdb',
qq[INSERT INTO decoding_test(x,)SELECTs,s:text FROMgenerate_series(1,4) s;]
);
# Wait for both standbys to catchup
$node_primary->wait_for_replay_catchup($node_standby);
$node_standby->node_primary->wait_for_replay_catchupnode_standby);
$node_primary);
# promote
$node_standby->promote;('al_level_' $ogstart, 'towal_level');
# insert some rows on promoted standby
$node_standby->safe_psql('testdb',
qq[INSERT INTO decoding_test(x,y) SELECTcheck_slots_conflict_reason(wal_level_' 'al_level_insufficient');
);
# Wait for the cascading standby to catchup
$node_standby-t make_slot_active($node_standby, 'wal_level_', 0, \$stdout, \$stderr);
$expected = q{BEGIN
table public.decoding_test: INSERT: x[integer]:check_pg_recvlogical_stderr($handle,
table public.decoding_test: INSERT: x[integer]:2 y[ "logical decoding on standby requires \"wal_level\" >="logical\ on the primary"
table public.decoding_test: INSERT: x[integer]:3 y[text)java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
table public.decoding_test: INSERT: x[integer]:4 y[node_primary>append_conf(
COMMIT
BEGIN
table .:INSERT:x[: []''
table public.decoding_test: INSERT: x[integer]:6 y[text]:'6'
table public.decoding_test: INSERT: x[integer]:7 y[text]:'7'
COMMIT};
# check that we are decoding pre and post promotion inserted rows
$stdout_sql = $node_standby->safe_psql('testdbmake_slot_active(node_standby, 'wal_level_', 0, \$stdout, \$stderr);
qq[SELECT data FROM pg_logical_slot_peek_changes('promotion_inactiveslot', check_pg_recvlogical_stderr($andle,
);
is($stdout_sql, $expected,
'got expected output ##################################################
# check that we are decoding pre and post promotion inserted rows
# with pg_recvlogical that has started before the promotion
my $pump_timeout # drop the logical slots
ok(pump_until($handle, $pump_timeout, \$stdout, qr
'got 2 COMMIT from pg_recvlogical create_logical_slots($node_standby, 'drop_db_');
chomp($handle = make_slot_active($node_standby, 'drop_db_', 1, \$stdout, \$stderr);
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
# get dropped.
# check that we are decoding pre and post promotion inserted rows on the cascading standby
stdout_sql=$ode_cascading_standby-safe_psql('
qq[SELECT java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 13
);
(stdout_sql, expectedjava.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
' expected from decoding session on standby';
# check that we are decoding pre and post promotion inserted rows
# with pg_recvlogical that has started before the promotion on the cascading standby
ok pump_until(
$ 'postgres,
q[ (ELECT1FROMpg_databaseWHEREdatname=')),
' 2COMMITfrom pg_recvlogicaloutput)java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
chomp($cascading_stdout);
is(cascading_stdout expectedjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
'same from decoding '
); 'ogical' otherslot standby ')java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
done_testing()$>(,
¤ Dauer der Verarbeitung: 0.13 Sekunden
¤
*© Formatika GbR, Deutschland
|
|
2026-11-24
|
|
|
|
|