From: Nathan Bossart <nbossart@postgresql.org>
Subject: [PATCH v3 1/1] Prevent underflow in KeepLogSeg().
Date: Mon, 24 Apr 2023 11:29:56 -0700
When determining the oldest segment that must be kept for
replication slots, KeepLogSeg() might calculate a segment number
ahead of the one for the LSN given to the function. This causes
underflow in subsequent calculations, which could result in
unexpected behavior when removing or recycling WAL files. This was
introduced with max_slot_wal_keep_size in c655077. To fix, cap the
aforementioned value as needed.
Reported-by: Xu Xingwang
Author: Kyotaro Horiguchi
Reviewed-by: Junwang Zhao
Discussion: https://postgr.es/m/17903-4288d439dee856c6%40postgresql.org
Backpatch-through: 13
---
src/backend/access/transam/xlog.c | 9 +++++++++
1 file changed, 9 insertions(+)
inline patch 1: src/backend/access/transam/xlog.c (+9/-0 lines) download inline-1.patchdiff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.cindex 63481d826f..66ea6ee204 100644--- a/src/backend/access/transam/xlog.c+++ b/src/backend/access/transam/xlog.c@@ -7463,6 +7463,15 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo)
{
XLByteToSeg(keep, segno, wal_segment_size);
+ /*+ * It's possible for the slot minimum LSN to be greater than the recptr+ * given to the function. This means that the segno we just calculated+ * might be greater than currSegno, which would cause some subsequent+ * calculations to underflow. To avoid this, cap segno at currSegNo.+ */+ if (segno > currSegNo)+ segno = currSegNo;+
/* Cap by max_slot_wal_keep_size ... */
if (max_slot_wal_keep_size_mb >= 0)
{
--
2.25.1
--tThc/1wpZn/ma/RB--
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: nbossart@postgresql.org
Subject: Re: [PATCH v3 1/1] Prevent underflow in KeepLogSeg().
In-Reply-To: <no-message-id-27281@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox