Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc3fe108

Browse files
committed
Rename wal_keep_segments to wal_keep_size.
max_slot_wal_keep_size that was added in v13 and wal_keep_segments arethe GUC parameters to specify how much WAL files to retain forthe standby servers. While max_slot_wal_keep_size accepts the number ofbytes of WAL files, wal_keep_segments accepts the number of WAL files.This difference of setting units between those similar parameters couldbe confusing to users.To alleviate this situation, this commit renames wal_keep_segments towal_keep_size, and make users specify the WAL size in it instead ofthe number of WAL files.There was also the idea to rename max_slot_wal_keep_size tomax_slot_wal_keep_segments, in the discussion. But we have been movingaway from measuring in segments, for example, checkpoint_segments wasreplaced by max_wal_size. So we concluded to rename wal_keep_segmentsto wal_keep_size.Back-patch to v13 where max_slot_wal_keep_size was added.Author: Fujii MasaoReviewed-by: Álvaro Herrera, Kyotaro Horiguchi, David SteeleDiscussion:https://postgr.es/m/574b4ea3-e0f9-b175-ead2-ebea7faea855@oss.nttdata.com
1 parent0bead9a commitc3fe108

File tree

12 files changed

+58
-48
lines changed

12 files changed

+58
-48
lines changed

‎doc/src/sgml/catalogs.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11278,7 +11278,7 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx
1127811278
<para><literal>extended</literal> means
1127911279
that <varname>max_wal_size</varname> is exceeded but the files are
1128011280
still retained, either by the replication slot or
11281-
by <varname>wal_keep_segments</varname>.
11281+
by <varname>wal_keep_size</varname>.
1128211282
</para>
1128311283
</listitem>
1128411284
<listitem>

‎doc/src/sgml/config.sgml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3151,7 +3151,7 @@ include_dir 'conf.d'
31513151
checkpoints. This is a soft limit; WAL size can exceed
31523152
<varname>max_wal_size</varname> under special circumstances, such as
31533153
heavy load, a failing <varname>archive_command</varname>, or a high
3154-
<varname>wal_keep_segments</varname> setting.
3154+
<varname>wal_keep_size</varname> setting.
31553155
If this value is specified without units, it is taken as megabytes.
31563156
The default is 1 GB.
31573157
Increasing this parameter can increase the amount of time needed for
@@ -3778,36 +3778,37 @@ restore_command = 'copy "C:\\server\\archivedir\\%f" "%p"' # Windows
37783778
</listitem>
37793779
</varlistentry>
37803780

3781-
<varlistentry id="guc-wal-keep-segments" xreflabel="wal_keep_segments">
3782-
<term><varname>wal_keep_segments</varname> (<type>integer</type>)
3781+
<varlistentry id="guc-wal-keep-size" xreflabel="wal_keep_size">
3782+
<term><varname>wal_keep_size</varname> (<type>integer</type>)
37833783
<indexterm>
3784-
<primary><varname>wal_keep_segments</varname> configuration parameter</primary>
3784+
<primary><varname>wal_keep_size</varname> configuration parameter</primary>
37853785
</indexterm>
37863786
</term>
37873787
<listitem>
37883788
<para>
3789-
Specifies the minimumnumber of past log file segments kept in the
3789+
Specifies the minimumsize of past log file segments kept in the
37903790
<filename>pg_wal</filename>
37913791
directory, in case a standby server needs to fetch them for streaming
3792-
replication.Each segment is normally 16 megabytes.If a standby
3792+
replication. If a standby
37933793
server connected to the sending server falls behind by more than
3794-
<varname>wal_keep_segments</varname>segments, the sending server might remove
3795-
a WAL segment still needed by the standby, in which case the
3794+
<varname>wal_keep_size</varname>megabytes, the sending server might
3795+
removea WAL segment still needed by the standby, in which case the
37963796
replication connection will be terminated. Downstream connections
37973797
will also eventually fail as a result. (However, the standby
37983798
server can recover by fetching the segment from archive, if WAL
37993799
archiving is in use.)
38003800
</para>
38013801

38023802
<para>
3803-
This sets only the minimumnumber of segments retained in
3803+
This sets only the minimumsize of segments retained in
38043804
<filename>pg_wal</filename>; the system might need to retain more segments
38053805
for WAL archival or to recover from a checkpoint. If
3806-
<varname>wal_keep_segments</varname> is zero (the default), the system
3806+
<varname>wal_keep_size</varname> is zero (the default), the system
38073807
doesn't keep any extra segments for standby purposes, so the number
38083808
of old WAL segments available to standby servers is a function of
38093809
the location of the previous checkpoint and status of WAL
38103810
archiving.
3811+
If this value is specified without units, it is taken as megabytes.
38113812
This parameter can only be set in the
38123813
<filename>postgresql.conf</filename> file or on the server command line.
38133814
</para>

‎doc/src/sgml/high-availability.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ archive_cleanup_command = 'pg_archivecleanup /path/to/archive %r'
785785
archiving, the server might recycle old WAL segments before the standby
786786
has received them. If this occurs, the standby will need to be
787787
reinitialized from a new base backup. You can avoid this by setting
788-
<varname>wal_keep_segments</varname> to a value large enough to ensure that
788+
<varname>wal_keep_size</varname> to a value large enough to ensure that
789789
WAL segments are not recycled too early, or by configuring a replication
790790
slot for the standby. If you set up a WAL archive that's accessible from
791791
the standby, these solutions are not required, since the standby can
@@ -929,7 +929,7 @@ primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
929929
</para>
930930
<para>
931931
In lieu of using replication slots, it is possible to prevent the removal
932-
of old WAL segments using <xref linkend="guc-wal-keep-segments"/>, or by
932+
of old WAL segments using <xref linkend="guc-wal-keep-size"/>, or by
933933
storing the segments in an archive using
934934
<xref linkend="guc-archive-command"/>.
935935
However, these methods often result in retaining more WAL segments than

‎doc/src/sgml/ref/pg_basebackup.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ PostgreSQL documentation
305305
<para>
306306
The write-ahead log files are collected at the end of the backup.
307307
Therefore, it is necessary for the
308-
<xref linkend="guc-wal-keep-segments"/> parameter to be set high
308+
<xref linkend="guc-wal-keep-size"/> parameter to be set high
309309
enough that the log is not removed before the end of the backup.
310310
If the log has been rotated when it's time to transfer it, the
311311
backup will fail and be unusable.

‎doc/src/sgml/wal.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,8 @@
578578

579579
<para>
580580
Independently of <varname>max_wal_size</varname>,
581-
<xref linkend="guc-wal-keep-segments"/> + 1 most recent WAL files are
581+
the most recent <xref linkend="guc-wal-keep-size"/> megabytes of
582+
WAL files plus one additional WAL file are
582583
kept at all times. Also, if WAL archiving is used, old segments can not be
583584
removed or recycled until they are archived. If WAL archiving cannot keep up
584585
with the pace that WAL is generated, or if <varname>archive_command</varname>

‎src/backend/access/transam/xlog.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ extern uint32 bootstrap_data_checksum_version;
8888
/* User-settable parameters */
8989
intmax_wal_size_mb=1024;/* 1 GB */
9090
intmin_wal_size_mb=80;/* 80 MB */
91-
intwal_keep_segments=0;
91+
intwal_keep_size_mb=0;
9292
intXLOGbuffers=-1;
9393
intXLogArchiveTimeout=0;
9494
intXLogArchiveMode=ARCHIVE_MODE_OFF;
@@ -9525,7 +9525,7 @@ GetWALAvailability(XLogRecPtr targetLSN)
95259525

95269526
/*
95279527
* Calculate the oldest segment currently reserved by all slots,
9528-
* consideringwal_keep_segments and max_slot_wal_keep_size. Initialize
9528+
* consideringwal_keep_size and max_slot_wal_keep_size. Initialize
95299529
* oldestSlotSeg to the current segment.
95309530
*/
95319531
currpos=GetXLogWriteRecPtr();
@@ -9576,9 +9576,9 @@ GetWALAvailability(XLogRecPtr targetLSN)
95769576

95779577
/*
95789578
* Retreat *logSegNo to the last segment that we need to retain because of
9579-
* eitherwal_keep_segments or replication slots.
9579+
* eitherwal_keep_size or replication slots.
95809580
*
9581-
* This is calculated by subtractingwal_keep_segments from the given xlog
9581+
* This is calculated by subtractingwal_keep_size from the given xlog
95829582
* location, recptr and by making sure that that result is below the
95839583
* requirement of replication slots. For the latter criterion we do consider
95849584
* the effects of max_slot_wal_keep_size: reserve at most that much space back
@@ -9616,14 +9616,20 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo)
96169616
}
96179617
}
96189618

9619-
/* but, keep at leastwal_keep_segments if that's set */
9620-
if (wal_keep_segments>0&&currSegNo-segno<wal_keep_segments)
9619+
/* but, keep at leastwal_keep_size if that's set */
9620+
if (wal_keep_size_mb>0)
96219621
{
9622-
/* avoid underflow, don't go below 1 */
9623-
if (currSegNo <=wal_keep_segments)
9624-
segno=1;
9625-
else
9626-
segno=currSegNo-wal_keep_segments;
9622+
uint64keep_segs;
9623+
9624+
keep_segs=ConvertToXSegs(wal_keep_size_mb,wal_segment_size);
9625+
if (currSegNo-segno<keep_segs)
9626+
{
9627+
/* avoid underflow, don't go below 1 */
9628+
if (currSegNo <=keep_segs)
9629+
segno=1;
9630+
else
9631+
segno=currSegNo-keep_segs;
9632+
}
96279633
}
96289634

96299635
/* don't delete WAL segments newer than the calculated segment */
@@ -11328,7 +11334,7 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p)
1132811334
* If archiving is enabled, wait for all the required WAL files to be
1132911335
* archived before returning. If archiving isn't enabled, the required WAL
1133011336
* needs to be transported via streaming replication (hopefully with
11331-
*wal_keep_segments set high enough), or some more exotic mechanism like
11337+
*wal_keep_size set high enough), or some more exotic mechanism like
1133211338
* polling and copying files from pg_wal with script. We have no knowledge
1133311339
* of those mechanisms, so it's up to the user to ensure that he gets all
1133411340
* the required WAL.

‎src/backend/replication/slotfuncs.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,19 +413,20 @@ pg_get_replication_slots(PG_FUNCTION_ARGS)
413413
else
414414
{
415415
XLogSegNotargetSeg;
416-
XLogSegNokeepSegs;
416+
uint64slotKeepSegs;
417+
uint64keepSegs;
417418
XLogSegNofailSeg;
418419
XLogRecPtrfailLSN;
419420

420421
XLByteToSeg(slot_contents.data.restart_lsn,targetSeg,wal_segment_size);
421422

422-
/* determine how many segments slots can be kept by slots...*/
423-
keepSegs=XLogMBVarToSegs(max_slot_wal_keep_size_mb,wal_segment_size);
424-
/*... and override by wal_keep_segments as needed */
425-
keepSegs=Max(keepSegs,wal_keep_segments);
423+
/* determine how many segments slots can be kept by slots */
424+
slotKeepSegs=XLogMBVarToSegs(max_slot_wal_keep_size_mb,wal_segment_size);
425+
/*ditto for wal_keep_size */
426+
keepSegs=XLogMBVarToSegs(wal_keep_size_mb,wal_segment_size);
426427

427428
/* if currpos reaches failLSN, we lose our segment */
428-
failSeg=targetSeg+keepSegs+1;
429+
failSeg=targetSeg+Max(slotKeepSegs,keepSegs)+1;
429430
XLogSegNoOffsetToRecPtr(failSeg,0,wal_segment_size,failLSN);
430431

431432
values[i++]=Int64GetDatum(failLSN-currlsn);

‎src/backend/utils/misc/guc.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,12 +2636,13 @@ static struct config_int ConfigureNamesInt[] =
26362636
},
26372637

26382638
{
2639-
{"wal_keep_segments",PGC_SIGHUP,REPLICATION_SENDING,
2640-
gettext_noop("Sets the number of WAL files held for standby servers."),
2641-
NULL
2639+
{"wal_keep_size",PGC_SIGHUP,REPLICATION_SENDING,
2640+
gettext_noop("Sets the size of WAL files held for standby servers."),
2641+
NULL,
2642+
GUC_UNIT_MB
26422643
},
2643-
&wal_keep_segments,
2644-
0,0,INT_MAX,
2644+
&wal_keep_size_mb,
2645+
0,0,MAX_KILOBYTES,
26452646
NULL,NULL,NULL
26462647
},
26472648

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@
290290

291291
#max_wal_senders = 10# max number of walsender processes
292292
# (change requires restart)
293-
#wal_keep_segments = 0# inlogfile segments; 0 disables
293+
#wal_keep_size = 0# inmegabytes; 0 disables
294294
#max_slot_wal_keep_size = -1# in megabytes; -1 disables
295295
#wal_sender_timeout = 60s# in milliseconds; 0 disables
296296

‎src/bin/pg_rewind/t/RewindTest.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ sub setup_cluster
135135
extra=>$extra,
136136
auth_extra=> ['--create-role','rewind_user' ]);
137137

138-
# Setwal_keep_segments to prevent WAL segment recycling after enforced
138+
# Setwal_keep_size to prevent WAL segment recycling after enforced
139139
# checkpoints in the tests.
140140
$node_primary->append_conf(
141141
'postgresql.conf',qq(
142-
wal_keep_segments =20
142+
wal_keep_size =320MB
143143
));
144144
return;
145145
}

‎src/include/access/xlog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ extern bool reachedConsistency;
107107
externintwal_segment_size;
108108
externintmin_wal_size_mb;
109109
externintmax_wal_size_mb;
110-
externintwal_keep_segments;
110+
externintwal_keep_size_mb;
111111
externintmax_slot_wal_keep_size_mb;
112112
externintXLOGbuffers;
113113
externintXLogArchiveTimeout;
@@ -273,7 +273,7 @@ typedef enum WALAvailability
273273
WALAVAIL_INVALID_LSN,/* parameter error */
274274
WALAVAIL_RESERVED,/* WAL segment is within max_wal_size */
275275
WALAVAIL_EXTENDED,/* WAL segment is reserved by a slot or
276-
*wal_keep_segments */
276+
*wal_keep_size */
277277
WALAVAIL_UNRESERVED,/* no longer reserved, but not removed yet */
278278
WALAVAIL_REMOVED/* WAL segment has been removed */
279279
}WALAvailability;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,19 @@
116116
$node_primary->wait_for_catchup($node_standby,'replay',$start_lsn);
117117
$node_standby->stop;
118118

119-
#wal_keep_segments overrides max_slot_wal_keep_size
119+
#wal_keep_size overrides max_slot_wal_keep_size
120120
$result =$node_primary->safe_psql('postgres',
121-
"ALTER SYSTEM SETwal_keep_segments to8; SELECT pg_reload_conf();");
121+
"ALTER SYSTEM SETwal_keep_size to'8MB'; SELECT pg_reload_conf();");
122122
# Advance WAL again then checkpoint, reducing remain by 6 MB.
123123
advance_wal($node_primary, 6);
124124
$result =$node_primary->safe_psql('postgres',
125125
"SELECT wal_status as remain FROM pg_replication_slots WHERE slot_name = 'rep1'"
126126
);
127127
is($result,"extended",
128-
'check thatwal_keep_segments overrides max_slot_wal_keep_size');
129-
# restorewal_keep_segments
128+
'check thatwal_keep_size overrides max_slot_wal_keep_size');
129+
# restorewal_keep_size
130130
$result =$node_primary->safe_psql('postgres',
131-
"ALTER SYSTEM SETwal_keep_segments to 0; SELECT pg_reload_conf();");
131+
"ALTER SYSTEM SETwal_keep_size to 0; SELECT pg_reload_conf();");
132132

133133
# The standby can reconnect to primary
134134
$node_standby->start;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp