Skip to content

Commit 37c76ae

Browse files
committed
Change unit of idle_replication_slot_timeout to seconds.
Previously, the idle_replication_slot_timeout parameter used minutes as its unit, based on the assumption that values would typically exceed one minute in production environments. However, this caused unexpected behavior: specifying a value below 30 seconds would round down to 0, effectively disabling the timeout. This could be surprising to users. To allow finer-grained control and avoid such confusion, this commit changes the unit of idle_replication_slot_timeout to seconds. Larger values can still be specified easily using standard time suffixes, for example, '24h' for 24 hours. Back-patch to v18 where idle_replication_slot_timeout was added. Reported-by: Gunnar Morling <gunnar.morling@googlemail.com> Author: Fujii Masao <masao.fujii@gmail.com> Reviewed-by: Laurenz Albe <laurenz.albe@cybertec.at> Reviewed-by: David G. Johnston <david.g.johnston@gmail.com> Reviewed-by: Amit Kapila <amit.kapila16@gmail.com> Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/CADGJaX_0+FTguWpNSpgVWYQP_7MhoO0D8=cp4XozSQgaZ40Odw@mail.gmail.com Backpatch-through: 18
1 parent 39f0108 commit 37c76ae

File tree

5 files changed

+15
-18
lines changed

5 files changed

+15
-18
lines changed

doc/src/sgml/config.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4620,7 +4620,7 @@ restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows
46204620
<para>
46214621
Invalidate replication slots that have remained idle longer than this
46224622
duration. If this value is specified without units, it is taken as
4623-
minutes. A value of zero (the default) disables the idle timeout
4623+
seconds. A value of zero (the default) disables the idle timeout
46244624
invalidation mechanism. This parameter can only be set in the
46254625
<filename>postgresql.conf</filename> file or on the server command
46264626
line.

src/backend/replication/slot.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ int max_replication_slots = 10; /* the maximum number of replication
154154
* Invalidate replication slots that have remained idle longer than this
155155
* duration; '0' disables it.
156156
*/
157-
int idle_replication_slot_timeout_mins = 0;
157+
int idle_replication_slot_timeout_secs = 0;
158158

159159
/*
160160
* This GUC lists streaming replication standby server slot names that
@@ -1612,13 +1612,10 @@ ReportSlotInvalidation(ReplicationSlotInvalidationCause cause,
16121612

16131613
case RS_INVAL_IDLE_TIMEOUT:
16141614
{
1615-
int minutes = slot_idle_seconds / SECS_PER_MINUTE;
1616-
int secs = slot_idle_seconds % SECS_PER_MINUTE;
1617-
16181615
/* translator: %s is a GUC variable name */
1619-
appendStringInfo(&err_detail, _("The slot's idle time of %dmin %02ds exceeds the configured \"%s\" duration of %dmin."),
1620-
minutes, secs, "idle_replication_slot_timeout",
1621-
idle_replication_slot_timeout_mins);
1616+
appendStringInfo(&err_detail, _("The slot's idle time of %lds exceeds the configured \"%s\" duration of %ds."),
1617+
slot_idle_seconds, "idle_replication_slot_timeout",
1618+
idle_replication_slot_timeout_secs);
16221619
/* translator: %s is a GUC variable name */
16231620
appendStringInfo(&err_hint, _("You might need to increase \"%s\"."),
16241621
"idle_replication_slot_timeout");
@@ -1656,7 +1653,7 @@ ReportSlotInvalidation(ReplicationSlotInvalidationCause cause,
16561653
static inline bool
16571654
CanInvalidateIdleSlot(ReplicationSlot *s)
16581655
{
1659-
return (idle_replication_slot_timeout_mins != 0 &&
1656+
return (idle_replication_slot_timeout_secs != 0 &&
16601657
!XLogRecPtrIsInvalid(s->data.restart_lsn) &&
16611658
s->inactive_since > 0 &&
16621659
!(RecoveryInProgress() && s->data.synced));
@@ -1717,9 +1714,9 @@ DetermineSlotInvalidationCause(uint32 possible_causes, ReplicationSlot *s,
17171714
if (CanInvalidateIdleSlot(s))
17181715
{
17191716
/*
1720-
* We simulate the invalidation due to idle_timeout as the minimum
1721-
* time idle time is one minute which makes tests take a long
1722-
* time.
1717+
* Simulate the invalidation due to idle_timeout to test the
1718+
* timeout behavior promptly, without waiting for it to trigger
1719+
* naturally.
17231720
*/
17241721
#ifdef USE_INJECTION_POINTS
17251722
if (IS_INJECTION_POINT_ATTACHED("slot-timeout-inval"))
@@ -1734,7 +1731,7 @@ DetermineSlotInvalidationCause(uint32 possible_causes, ReplicationSlot *s,
17341731
* idle_replication_slot_timeout GUC.
17351732
*/
17361733
if (TimestampDifferenceExceedsSeconds(s->inactive_since, now,
1737-
idle_replication_slot_timeout_mins * SECS_PER_MINUTE))
1734+
idle_replication_slot_timeout_secs))
17381735
{
17391736
*inactive_since = s->inactive_since;
17401737
return RS_INVAL_IDLE_TIMEOUT;

src/backend/utils/misc/guc_tables.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3100,10 +3100,10 @@ struct config_int ConfigureNamesInt[] =
31003100
gettext_noop("Sets the duration a replication slot can remain idle before "
31013101
"it is invalidated."),
31023102
NULL,
3103-
GUC_UNIT_MIN
3103+
GUC_UNIT_S
31043104
},
3105-
&idle_replication_slot_timeout_mins,
3106-
0, 0, INT_MAX / SECS_PER_MINUTE,
3105+
&idle_replication_slot_timeout_secs,
3106+
0, 0, INT_MAX,
31073107
check_idle_replication_slot_timeout, NULL, NULL
31083108
},
31093109

src/backend/utils/misc/postgresql.conf.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@
342342
# (change requires restart)
343343
#wal_keep_size = 0 # in megabytes; 0 disables
344344
#max_slot_wal_keep_size = -1 # in megabytes; -1 disables
345-
#idle_replication_slot_timeout = 0 # in minutes; 0 disables
345+
#idle_replication_slot_timeout = 0 # in seconds; 0 disables
346346
#wal_sender_timeout = 60s # in milliseconds; 0 disables
347347
#track_commit_timestamp = off # collect timestamp of transaction commit
348348
# (change requires restart)

src/include/replication/slot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ extern PGDLLIMPORT ReplicationSlot *MyReplicationSlot;
266266
/* GUCs */
267267
extern PGDLLIMPORT int max_replication_slots;
268268
extern PGDLLIMPORT char *synchronized_standby_slots;
269-
extern PGDLLIMPORT int idle_replication_slot_timeout_mins;
269+
extern PGDLLIMPORT int idle_replication_slot_timeout_secs;
270270

271271
/* shmem initialization functions */
272272
extern Size ReplicationSlotsShmemSize(void);

0 commit comments

Comments
 (0)