1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-24 00:23:06 +03:00

Allow synced slots to have their inactive_since.

This commit does two things:
1) Maintains inactive_since for sync slots whenever the slot is released
just like any other regular slot.

2) Ensures the value is set to the current timestamp during the promotion
of standby to help correctly interpret the time after promotion. We don't
want the slots to appear inactive for a long time after promotion if they
haven't been synchronized recently. This would also avoid the invalidation
of such slots immediately after promotion if tomorrow we have a feature
that invalidates slots based on their inactivity time. Whoever acquires
the slot i.e. makes the slot active will reset it to NULL.

Author: Bharath Rupireddy
Reviewed-by: Bertrand Drouvot, Amit Kapila, Shveta Malik, Masahiko Sawada
Discussion: https://postgr.es/m/CAA4eK1KrPGwfZV9LYGidjxHeW+rxJ=E2ThjXvwRGLO=iLNuo=Q@mail.gmail.com
Discussion: https://postgr.es/m/CALj2ACW4aUe-_uFQOjdWCEN-xXoLGhmvRFnL8SNw_TZ5nJe+aw@mail.gmail.com
Discussion: https://postgr.es/m/CA+Tgmob_Ta-t2ty8QrKHBGnNLrf4ZYcwhGHGFsuUoFrAEDw4sA@mail.gmail.com
This commit is contained in:
Amit Kapila
2024-04-05 09:48:49 +05:30
parent f98dbdeb51
commit 6f132ed693
6 changed files with 160 additions and 39 deletions

View File

@@ -3276,6 +3276,37 @@ sub create_logical_slot_on_standby
=pod
=item $node->validate_slot_inactive_since(self, slot_name, reference_time)
Validate inactive_since value of a given replication slot against the reference
time and return it.
=cut
sub validate_slot_inactive_since
{
my ($self, $slot_name, $reference_time) = @_;
my $name = $self->name;
my $inactive_since = $self->safe_psql('postgres',
qq(SELECT inactive_since FROM pg_replication_slots
WHERE slot_name = '$slot_name' AND inactive_since IS NOT NULL;)
);
# Check that the inactive_since is sane
is($self->safe_psql('postgres',
qq[SELECT '$inactive_since'::timestamptz > to_timestamp(0) AND
'$inactive_since'::timestamptz > '$reference_time'::timestamptz;]
),
't',
"last inactive time for slot $slot_name is valid on node $name")
or die "could not validate captured inactive_since for slot $slot_name";
return $inactive_since;
}
=pod
=item $node->advance_wal(num)
Advance WAL of node by given number of segments.