mirror of
https://github.com/postgres/postgres.git
synced 2025-12-19 17:02:53 +03:00
Add slotsync skip statistics.
This patch adds two new columns to the pg_stat_replication_slots view: slotsync_skip_count - the total number of times a slotsync operation was skipped. slotsync_skip_at - the timestamp of the most recent skip. These additions provide better visibility into replication slot synchronization behavior. A future patch will introduce the slotsync_skip_reason column in pg_replication_slots to capture the reason for skip. Author: Shlok Kyal <shlok.kyal.oss@gmail.com> Reviewed-by: shveta malik <shveta.malik@gmail.com> Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com> Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com> Reviewed-by: Amit Kapila <amit.kapila16@gmail.com> Discussion: https://postgr.es/m/CAE9k0PkhfKrTEAsGz4DjOhEj1nQ+hbQVfvWUxNacD38ibW3a1g@mail.gmail.com
This commit is contained in:
@@ -213,19 +213,75 @@ is( $standby1->safe_psql(
|
||||
##################################################
|
||||
# Test that the synchronized slot will be dropped if the corresponding remote
|
||||
# slot on the primary server has been dropped.
|
||||
#
|
||||
# Note: Both slots need to be dropped for the next test to work
|
||||
##################################################
|
||||
|
||||
$primary->psql('postgres', "SELECT pg_drop_replication_slot('lsub2_slot');");
|
||||
$primary->psql('postgres', "SELECT pg_drop_replication_slot('lsub1_slot');");
|
||||
|
||||
$standby1->safe_psql('postgres', "SELECT pg_sync_replication_slots();");
|
||||
|
||||
is( $standby1->safe_psql(
|
||||
'postgres',
|
||||
q{SELECT count(*) = 0 FROM pg_replication_slots WHERE slot_name = 'lsub2_slot';}
|
||||
q{SELECT count(*) = 0 FROM pg_replication_slots WHERE slot_name IN ('lsub1_slot', 'lsub2_slot');}
|
||||
),
|
||||
"t",
|
||||
'synchronized slot has been dropped');
|
||||
|
||||
##################################################
|
||||
# Verify that slotsync skip statistics are correctly updated when the
|
||||
# slotsync operation is skipped.
|
||||
##################################################
|
||||
|
||||
# Create a logical replication slot and create some DDL on the primary so
|
||||
# that the slot lags behind the standby.
|
||||
$primary->safe_psql(
|
||||
'postgres', qq(
|
||||
SELECT pg_create_logical_replication_slot('lsub1_slot', 'pgoutput', false, false, true);
|
||||
CREATE TABLE wal_push(a int);
|
||||
));
|
||||
$primary->wait_for_replay_catchup($standby1);
|
||||
|
||||
my $log_offset = -s $standby1->logfile;
|
||||
|
||||
# Enable slot sync worker.
|
||||
$standby1->append_conf('postgresql.conf', qq(sync_replication_slots = on));
|
||||
$standby1->reload;
|
||||
|
||||
# Confirm that the slot sync worker is able to start.
|
||||
$standby1->wait_for_log(qr/slot sync worker started/, $log_offset);
|
||||
|
||||
# Confirm that the slot sync is skipped due to the remote slot lagging behind
|
||||
$standby1->wait_for_log(
|
||||
qr/could not synchronize replication slot \"lsub1_slot\"/, $log_offset);
|
||||
|
||||
# Confirm that the slotsync skip statistics is updated
|
||||
$result = $standby1->safe_psql('postgres',
|
||||
"SELECT slotsync_skip_count > 0 FROM pg_stat_replication_slots WHERE slot_name = 'lsub1_slot'"
|
||||
);
|
||||
is($result, 't', "check slot sync skip count increments");
|
||||
|
||||
# Clean the table
|
||||
$primary->safe_psql(
|
||||
'postgres', qq(
|
||||
DROP TABLE wal_push;
|
||||
));
|
||||
$primary->wait_for_replay_catchup($standby1);
|
||||
|
||||
# Re-create the logical replication slot and sync it to standby for further tests
|
||||
$primary->safe_psql(
|
||||
'postgres', qq(
|
||||
SELECT pg_drop_replication_slot('lsub1_slot');
|
||||
SELECT pg_create_logical_replication_slot('lsub1_slot', 'pgoutput', false, false, true);
|
||||
));
|
||||
$standby1->wait_for_log(
|
||||
qr/newly created replication slot \"lsub1_slot\" is sync-ready now/,
|
||||
$log_offset);
|
||||
|
||||
$standby1->append_conf('postgresql.conf', qq(sync_replication_slots = off));
|
||||
$standby1->reload;
|
||||
|
||||
##################################################
|
||||
# Test that if the synchronized slot is invalidated while the remote slot is
|
||||
# still valid, the slot will be dropped and re-created on the standby by
|
||||
@@ -281,7 +337,7 @@ $inactive_since_on_primary =
|
||||
# the failover slots.
|
||||
$primary->wait_for_replay_catchup($standby1);
|
||||
|
||||
my $log_offset = -s $standby1->logfile;
|
||||
$log_offset = -s $standby1->logfile;
|
||||
|
||||
# Synchronize the primary server slots to the standby.
|
||||
$standby1->safe_psql('postgres', "SELECT pg_sync_replication_slots();");
|
||||
|
||||
@@ -2151,9 +2151,11 @@ pg_stat_replication_slots| SELECT s.slot_name,
|
||||
s.mem_exceeded_count,
|
||||
s.total_txns,
|
||||
s.total_bytes,
|
||||
s.slotsync_skip_count,
|
||||
s.slotsync_skip_at,
|
||||
s.stats_reset
|
||||
FROM pg_replication_slots r,
|
||||
LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, stats_reset)
|
||||
LATERAL pg_stat_get_replication_slot((r.slot_name)::text) s(slot_name, spill_txns, spill_count, spill_bytes, stream_txns, stream_count, stream_bytes, mem_exceeded_count, total_txns, total_bytes, slotsync_skip_count, slotsync_skip_at, stats_reset)
|
||||
WHERE (r.datoid IS NOT NULL);
|
||||
pg_stat_slru| SELECT name,
|
||||
blks_zeroed,
|
||||
|
||||
Reference in New Issue
Block a user