This commit adds a new property called last_inactive_time for slots. It is
set to 0 whenever a slot is made active/acquired and set to the current
timestamp whenever the slot is inactive/released or restored from the disk.
Note that we don't set the last_inactive_time for the slots currently being
synced from the primary to the standby because such slots are typically
inactive as decoding is not allowed on those.
The 'last_inactive_time' will be useful on production servers to debug and
analyze inactive replication slots. It will also help to know the lifetime
of a replication slot - one can know how long a streaming standby, logical
subscriber, or replication slot consumer is down.
The 'last_inactive_time' will also be useful to implement inactive
timeout-based replication slot invalidation in a future commit.
Author: Bharath Rupireddy
Reviewed-by: Bertrand Drouvot, Amit Kapila, Shveta Malik
Discussion: https://www.postgresql.org/message-id/CALj2ACW4aUe-_uFQOjdWCEN-xXoLGhmvRFnL8SNw_TZ5nJe+aw@mail.gmail.com
# Now the slot is active so last_inactive_time value must be NULL
is($primary4->safe_psql(
'postgres',
qq[SELECT last_inactive_time IS NULL FROM pg_replication_slots WHERE slot_name = '$sb4_slot';]
),
't',
'last inactive time for an active physical slot is NULL');
# Stop the standby to check its last_inactive_time value is updated
$standby4->stop;
# Let's restart the primary so that the last_inactive_time is set upon
# loading the slot from the disk.
$primary4->restart;
is($primary4->safe_psql(
'postgres',
qq[SELECT last_inactive_time > '$last_inactive_time'::timestamptz FROM pg_replication_slots WHERE slot_name = '$sb4_slot' AND last_inactive_time IS NOT NULL;]
),
't',
'last inactive time for an inactive physical slot is updated correctly');
$standby4->stop;
# Testcase end: Check last_inactive_time property of the streaming standby's slot
# Now the slot is active so last_inactive_time value must be NULL
is($publisher4->safe_psql(
'postgres',
qq[SELECT last_inactive_time IS NULL FROM pg_replication_slots WHERE slot_name = '$lsub4_slot';]
),
't',
'last inactive time for an active logical slot is NULL');
# Stop the subscriber to check its last_inactive_time value is updated
$subscriber4->stop;
# Let's restart the publisher so that the last_inactive_time is set upon
# loading the slot from the disk.
$publisher4->restart;
is($publisher4->safe_psql(
'postgres',
qq[SELECT last_inactive_time > '$last_inactive_time'::timestamptz FROM pg_replication_slots WHERE slot_name = '$lsub4_slot' AND last_inactive_time IS NOT NULL;]
),
't',
'last inactive time for an inactive logical slot is updated correctly');
# Testcase end: Check last_inactive_time property of the logical subscriber's slot