Skip to content

Commit 6d49c8d

Browse files
author
Amit Kapila
committed
Change last_inactive_time to inactive_since in pg_replication_slots.
Commit a11f330 added last_inactive_time to show the last time the slot was inactive. But, it tells the last time that a currently-inactive slot previously *WAS* active. This could be unclear, so we changed the name to inactive_since. Reported-by: Robert Haas Author: Bharath Rupireddy Reviewed-by: Bertrand Drouvot, Shveta Malik, Amit Kapila Discussion: https://postgr.es/m/CA+Tgmob_Ta-t2ty8QrKHBGnNLrf4ZYcwhGHGFsuUoFrAEDw4sA@mail.gmail.com Discussion: https://postgr.es/m/CALj2ACUXS0SfbHzsX8bqo+7CZhocsV52Kiu7OWGb5HVPAmJqnA@mail.gmail.com
1 parent bb952c8 commit 6d49c8d

File tree

9 files changed

+52
-49
lines changed

9 files changed

+52
-49
lines changed

doc/src/sgml/system-views.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,10 +2525,10 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx
25252525

25262526
<row>
25272527
<entry role="catalog_table_entry"><para role="column_definition">
2528-
<structfield>last_inactive_time</structfield> <type>timestamptz</type>
2528+
<structfield>inactive_since</structfield> <type>timestamptz</type>
25292529
</para>
25302530
<para>
2531-
The time at which the slot became inactive.
2531+
The time since the slot has become inactive.
25322532
<literal>NULL</literal> if the slot is currently being used.
25332533
</para></entry>
25342534
</row>

src/backend/catalog/system_views.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ CREATE VIEW pg_replication_slots AS
10231023
L.wal_status,
10241024
L.safe_wal_size,
10251025
L.two_phase,
1026-
L.last_inactive_time,
1026+
L.inactive_since,
10271027
L.conflicting,
10281028
L.invalidation_reason,
10291029
L.failover,

src/backend/replication/slot.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ ReplicationSlotCreate(const char *name, bool db_specific,
409409
slot->candidate_restart_valid = InvalidXLogRecPtr;
410410
slot->candidate_restart_lsn = InvalidXLogRecPtr;
411411
slot->last_saved_confirmed_flush = InvalidXLogRecPtr;
412-
slot->last_inactive_time = 0;
412+
slot->inactive_since = 0;
413413

414414
/*
415415
* Create the slot on disk. We haven't actually marked the slot allocated
@@ -623,9 +623,12 @@ ReplicationSlotAcquire(const char *name, bool nowait)
623623
if (SlotIsLogical(s))
624624
pgstat_acquire_replslot(s);
625625

626-
/* Reset the last inactive time as the slot is active now. */
626+
/*
627+
* Reset the time since the slot has become inactive as the slot is active
628+
* now.
629+
*/
627630
SpinLockAcquire(&s->mutex);
628-
s->last_inactive_time = 0;
631+
s->inactive_since = 0;
629632
SpinLockRelease(&s->mutex);
630633

631634
if (am_walsender)
@@ -703,14 +706,14 @@ ReplicationSlotRelease(void)
703706
*/
704707
SpinLockAcquire(&slot->mutex);
705708
slot->active_pid = 0;
706-
slot->last_inactive_time = now;
709+
slot->inactive_since = now;
707710
SpinLockRelease(&slot->mutex);
708711
ConditionVariableBroadcast(&slot->active_cv);
709712
}
710713
else
711714
{
712715
SpinLockAcquire(&slot->mutex);
713-
slot->last_inactive_time = now;
716+
slot->inactive_since = now;
714717
SpinLockRelease(&slot->mutex);
715718
}
716719

@@ -2373,9 +2376,9 @@ RestoreSlotFromDisk(const char *name)
23732376
* inactive as decoding is not allowed on those.
23742377
*/
23752378
if (!(RecoveryInProgress() && slot->data.synced))
2376-
slot->last_inactive_time = GetCurrentTimestamp();
2379+
slot->inactive_since = GetCurrentTimestamp();
23772380
else
2378-
slot->last_inactive_time = 0;
2381+
slot->inactive_since = 0;
23792382

23802383
restored = true;
23812384
break;

src/backend/replication/slotfuncs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,8 @@ pg_get_replication_slots(PG_FUNCTION_ARGS)
410410

411411
values[i++] = BoolGetDatum(slot_contents.data.two_phase);
412412

413-
if (slot_contents.last_inactive_time > 0)
414-
values[i++] = TimestampTzGetDatum(slot_contents.last_inactive_time);
413+
if (slot_contents.inactive_since > 0)
414+
values[i++] = TimestampTzGetDatum(slot_contents.inactive_since);
415415
else
416416
nulls[i++] = true;
417417

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/* yyyymmddN */
60-
#define CATALOG_VERSION_NO 202403251
60+
#define CATALOG_VERSION_NO 202403271
6161

6262
#endif

src/include/catalog/pg_proc.dat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11135,7 +11135,7 @@
1113511135
proargtypes => '',
1113611136
proallargtypes => '{name,name,text,oid,bool,bool,int4,xid,xid,pg_lsn,pg_lsn,text,int8,bool,timestamptz,bool,text,bool,bool}',
1113711137
proargmodes => '{o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o,o}',
11138-
proargnames => '{slot_name,plugin,slot_type,datoid,temporary,active,active_pid,xmin,catalog_xmin,restart_lsn,confirmed_flush_lsn,wal_status,safe_wal_size,two_phase,last_inactive_time,conflicting,invalidation_reason,failover,synced}',
11138+
proargnames => '{slot_name,plugin,slot_type,datoid,temporary,active,active_pid,xmin,catalog_xmin,restart_lsn,confirmed_flush_lsn,wal_status,safe_wal_size,two_phase,inactive_since,conflicting,invalidation_reason,failover,synced}',
1113911139
prosrc => 'pg_get_replication_slots' },
1114011140
{ oid => '3786', descr => 'set up a logical replication slot',
1114111141
proname => 'pg_create_logical_replication_slot', provolatile => 'v',

src/include/replication/slot.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ typedef struct ReplicationSlot
202202
*/
203203
XLogRecPtr last_saved_confirmed_flush;
204204

205-
/* The time at which this slot becomes inactive */
206-
TimestampTz last_inactive_time;
205+
/* The time since the slot has become inactive */
206+
TimestampTz inactive_since;
207207
} ReplicationSlot;
208208

209209
#define SlotIsPhysical(slot) ((slot)->data.database == InvalidOid)

src/test/recovery/t/019_replslot_limit.pl

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@
411411
$node_standby3->stop;
412412

413413
# =============================================================================
414-
# Testcase start: Check last_inactive_time property of the streaming standby's slot
414+
# Testcase start: Check inactive_since property of the streaming standby's slot
415415
#
416416

417417
# Initialize primary node
@@ -440,45 +440,45 @@
440440
SELECT pg_create_physical_replication_slot(slot_name := '$sb4_slot');
441441
]);
442442

443-
# Get last_inactive_time value after the slot's creation. Note that the slot
444-
# is still inactive till it's used by the standby below.
445-
my $last_inactive_time =
446-
capture_and_validate_slot_last_inactive_time($primary4, $sb4_slot, $slot_creation_time);
443+
# Get inactive_since value after the slot's creation. Note that the slot is
444+
# still inactive till it's used by the standby below.
445+
my $inactive_since =
446+
capture_and_validate_slot_inactive_since($primary4, $sb4_slot, $slot_creation_time);
447447

448448
$standby4->start;
449449

450450
# Wait until standby has replayed enough data
451451
$primary4->wait_for_catchup($standby4);
452452

453-
# Now the slot is active so last_inactive_time value must be NULL
453+
# Now the slot is active so inactive_since value must be NULL
454454
is( $primary4->safe_psql(
455455
'postgres',
456-
qq[SELECT last_inactive_time IS NULL FROM pg_replication_slots WHERE slot_name = '$sb4_slot';]
456+
qq[SELECT inactive_since IS NULL FROM pg_replication_slots WHERE slot_name = '$sb4_slot';]
457457
),
458458
't',
459459
'last inactive time for an active physical slot is NULL');
460460

461-
# Stop the standby to check its last_inactive_time value is updated
461+
# Stop the standby to check its inactive_since value is updated
462462
$standby4->stop;
463463

464-
# Let's restart the primary so that the last_inactive_time is set upon
465-
# loading the slot from the disk.
464+
# Let's restart the primary so that the inactive_since is set upon loading the
465+
# slot from the disk.
466466
$primary4->restart;
467467

468468
is( $primary4->safe_psql(
469469
'postgres',
470-
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;]
470+
qq[SELECT inactive_since > '$inactive_since'::timestamptz FROM pg_replication_slots WHERE slot_name = '$sb4_slot' AND inactive_since IS NOT NULL;]
471471
),
472472
't',
473473
'last inactive time for an inactive physical slot is updated correctly');
474474

475475
$standby4->stop;
476476

477-
# Testcase end: Check last_inactive_time property of the streaming standby's slot
477+
# Testcase end: Check inactive_since property of the streaming standby's slot
478478
# =============================================================================
479479

480480
# =============================================================================
481-
# Testcase start: Check last_inactive_time property of the logical subscriber's slot
481+
# Testcase start: Check inactive_since property of the logical subscriber's slot
482482
my $publisher4 = $primary4;
483483

484484
# Create subscriber node
@@ -499,10 +499,10 @@
499499
"SELECT pg_create_logical_replication_slot(slot_name := '$lsub4_slot', plugin := 'pgoutput');"
500500
);
501501

502-
# Get last_inactive_time value after the slot's creation. Note that the slot
503-
# is still inactive till it's used by the subscriber below.
504-
$last_inactive_time =
505-
capture_and_validate_slot_last_inactive_time($publisher4, $lsub4_slot, $slot_creation_time);
502+
# Get inactive_since value after the slot's creation. Note that the slot is
503+
# still inactive till it's used by the subscriber below.
504+
$inactive_since =
505+
capture_and_validate_slot_inactive_since($publisher4, $lsub4_slot, $slot_creation_time);
506506

507507
$subscriber4->start;
508508
$subscriber4->safe_psql('postgres',
@@ -512,54 +512,54 @@
512512
# Wait until subscriber has caught up
513513
$subscriber4->wait_for_subscription_sync($publisher4, 'sub');
514514

515-
# Now the slot is active so last_inactive_time value must be NULL
515+
# Now the slot is active so inactive_since value must be NULL
516516
is( $publisher4->safe_psql(
517517
'postgres',
518-
qq[SELECT last_inactive_time IS NULL FROM pg_replication_slots WHERE slot_name = '$lsub4_slot';]
518+
qq[SELECT inactive_since IS NULL FROM pg_replication_slots WHERE slot_name = '$lsub4_slot';]
519519
),
520520
't',
521521
'last inactive time for an active logical slot is NULL');
522522

523-
# Stop the subscriber to check its last_inactive_time value is updated
523+
# Stop the subscriber to check its inactive_since value is updated
524524
$subscriber4->stop;
525525

526-
# Let's restart the publisher so that the last_inactive_time is set upon
526+
# Let's restart the publisher so that the inactive_since is set upon
527527
# loading the slot from the disk.
528528
$publisher4->restart;
529529

530530
is( $publisher4->safe_psql(
531531
'postgres',
532-
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;]
532+
qq[SELECT inactive_since > '$inactive_since'::timestamptz FROM pg_replication_slots WHERE slot_name = '$lsub4_slot' AND inactive_since IS NOT NULL;]
533533
),
534534
't',
535535
'last inactive time for an inactive logical slot is updated correctly');
536536

537-
# Testcase end: Check last_inactive_time property of the logical subscriber's slot
537+
# Testcase end: Check inactive_since property of the logical subscriber's slot
538538
# =============================================================================
539539

540540
$publisher4->stop;
541541
$subscriber4->stop;
542542

543-
# Capture and validate last_inactive_time of a given slot.
544-
sub capture_and_validate_slot_last_inactive_time
543+
# Capture and validate inactive_since of a given slot.
544+
sub capture_and_validate_slot_inactive_since
545545
{
546546
my ($node, $slot_name, $slot_creation_time) = @_;
547547

548-
my $last_inactive_time = $node->safe_psql('postgres',
549-
qq(SELECT last_inactive_time FROM pg_replication_slots
550-
WHERE slot_name = '$slot_name' AND last_inactive_time IS NOT NULL;)
548+
my $inactive_since = $node->safe_psql('postgres',
549+
qq(SELECT inactive_since FROM pg_replication_slots
550+
WHERE slot_name = '$slot_name' AND inactive_since IS NOT NULL;)
551551
);
552552

553553
# Check that the captured time is sane
554554
is( $node->safe_psql(
555555
'postgres',
556-
qq[SELECT '$last_inactive_time'::timestamptz > to_timestamp(0) AND
557-
'$last_inactive_time'::timestamptz >= '$slot_creation_time'::timestamptz;]
556+
qq[SELECT '$inactive_since'::timestamptz > to_timestamp(0) AND
557+
'$inactive_since'::timestamptz >= '$slot_creation_time'::timestamptz;]
558558
),
559559
't',
560560
"last inactive time for an active slot $slot_name is sane");
561561

562-
return $last_inactive_time;
562+
return $inactive_since;
563563
}
564564

565565
done_testing();

src/test/regress/expected/rules.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,12 +1473,12 @@ pg_replication_slots| SELECT l.slot_name,
14731473
l.wal_status,
14741474
l.safe_wal_size,
14751475
l.two_phase,
1476-
l.last_inactive_time,
1476+
l.inactive_since,
14771477
l.conflicting,
14781478
l.invalidation_reason,
14791479
l.failover,
14801480
l.synced
1481-
FROM (pg_get_replication_slots() l(slot_name, plugin, slot_type, datoid, temporary, active, active_pid, xmin, catalog_xmin, restart_lsn, confirmed_flush_lsn, wal_status, safe_wal_size, two_phase, last_inactive_time, conflicting, invalidation_reason, failover, synced)
1481+
FROM (pg_get_replication_slots() l(slot_name, plugin, slot_type, datoid, temporary, active, active_pid, xmin, catalog_xmin, restart_lsn, confirmed_flush_lsn, wal_status, safe_wal_size, two_phase, inactive_since, conflicting, invalidation_reason, failover, synced)
14821482
LEFT JOIN pg_database d ON ((l.datoid = d.oid)));
14831483
pg_roles| SELECT pg_authid.rolname,
14841484
pg_authid.rolsuper,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy