Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x11Bh-004w5L-2F for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Aug 2026 12:32:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x11Bg-0006UK-1m for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Aug 2026 12:32:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x11Bg-0006UC-0m for pgsql-hackers@lists.postgresql.org; Mon, 31 Aug 2026 12:32:32 +0000 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x11Bd-00000002BoQ-0bvO for pgsql-hackers@lists.postgresql.org; Mon, 31 Aug 2026 12:32:31 +0000 Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-c25420fe973so42993566b.0 for ; Mon, 31 Aug 2026 05:32:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1788179547; x=1788784347; darn=lists.postgresql.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=VRa6CWYPC1DTEJ25RYzUsr8SzEQ3bGu/bsX2RFWElWo=; b=ZOx+f4BVevrSo6WqMLRJ7QtKGx21gl0NH8pXIS2IMZD7LbepMZ7ZrCP10U1Wwe6Gza SU1zF5DfWshSWCgCEkLVIK3gO7N9DXznIhYQM87nkl+ctCiRR4f5LL5gPiDx+z8iXAdc I5WRf49vs8dEnfIt88LfrV1aEosxIuTbh6GFCBIkzxsN9Yd+7OXMqNdVyIweEoGabK9q ilUXwJVeZyKs2mJa3VBoy5K5J23QdRD5GREntokQ6S26K6CoW9k3GI1EL8imUKJah9yo FCU1SkDD2epXBpUkoer9F+PCu2k8F0N6hj3i2/8PdUzFnLRYxZFqp/S40kyj0QMjLILL poCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788179547; x=1788784347; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=VRa6CWYPC1DTEJ25RYzUsr8SzEQ3bGu/bsX2RFWElWo=; b=k2t/2Mcw1cE0S/DtiMzLeA6gTum1bdZekEi2G7W0kyL98bbaVhDQ9FcidS8UWsRN22 zH463HMn6s99XQuoZ1SZUaUiEnlKQ3FRDLmHVxL96paGzW3budI0uT/iT/QzwumRprHL lnBKawlk5/uNUfOC5VshYmVT+scIguJdeeeS/4w1EzjV624Xntgk0020q/jwFF5dN9xP n+wbLfBCRafYJAOLdig1meNKfR+HI4+26UioSQu1KOK9EnAuNsPj2pKPuEIdMk0KQoZu QfosYjJf+GcqDk3zS6oRnvjBrlB2xivSTZ8ZgIPQYFNU3YmWvMmR7r+meyiGThEsMm3P GCoQ== X-Forwarded-Encrypted: i=1; AHgh+RrOLyznRieGbDmUcd71zQ8gV1y7PAesY4TdOE0BzjcR17jaXkrqMUJwMBdyAuPiDAGg+tfYXRhT6DIh/gv0@lists.postgresql.org X-Gm-Message-State: AFuF++lsWEbB4yly0X91vPpPf3NN2ppocSUP/96M97e6nAfR04ARA7Y+ oxqq2KMrbJ+mvNiFVOMHEPccsU36cSU76D1C4VySSlfPUJ1KYbvojddpYlun+HNZqA== X-Gm-Gg: AR+sD10vtxWmJCLxHFHJzWeOv1WJLb+8Ex08lywo9WsO/kNgabO51anMf+L2m5wm4h+ 1LUyrDqDiVuefjbyflRGJ+8uYuBlHz4/lnBDMcCSST3peBKtOEhoEdYctZLjcnk0GrhLzYrzEVp FDB98yuFVqv19GTDQvz3awLKFwbcacQo0UM44Roo7wqbJT2cD93fYm3QYW1gqL/8KxK3H9vB4y0 IlqSeKKRyyIZlGINlKQ/A5/fafjMZHLiC1vdPB56Ns0sugwGzB6BS5jdhc3Fkg2Ro6+Nfo+vLx7 L0FuOYs/L/RvGOJZR3bZiMLD7Jnklqwh0iEx91JBhAkMTpiw8zSVtmnPws1nDAE98rXTKwveH0c Bj22xRJQB+sOJAD6zOCpc79kKH+aih1i8OHgONIXwKXsCrcGprg8mjQ+PZUog4vzFtZJ7qiI1OE TsnUePGxm4uJh6h4rtqGpYYh5Y2Xvz1I6G1EJAkE8GslJDCE8A0HESI88RQOd72XFfJslS0S7pK fiupcipAgJvaLiI4pMAyHriOnm5gRBdsquLyD9urNkskzIznCZZkqw+VPtVqNSpP00MOswIF2ho WWpM X-Received: by 2002:a17:907:6d0f:b0:c25:3c0a:99fa with SMTP id a640c23a62f3a-c255742f419mr1596782866b.13.1788179547173; Mon, 31 Aug 2026 05:32:27 -0700 (PDT) Received: from [192.168.88.235] ([163.116.177.178]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c25878ba94csm243625466b.47.2026.08.31.05.32.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 31 Aug 2026 05:32:26 -0700 (PDT) Message-ID: <999caa0e-d015-42da-9b79-001087e719b8@enterprisedb.com> Date: Mon, 31 Aug 2026 13:32:25 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Possible race condition in pg_basebackup To: Andrey Borodin Cc: =?UTF-8?Q?=C3=81lvaro_Herrera?= , pgsql-hackers mailing list References: <5516902D-65A5-4C61-8568-E32F111C89EF@yandex-team.ru> <99DF8255-F6B8-4B10-85A2-B6984B3DD16C@yandex-team.ru> Content-Language: en-US From: Nick Ivanov In-Reply-To: <99DF8255-F6B8-4B10-85A2-B6984B3DD16C@yandex-team.ru> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello Andrey, Thank you for your comments, they are very helpful. On 29/08/2026 15:18, Andrey Borodin wrote: > RegisterBackupStartpoint() is called after the starting checkpoint has > selected the startpoint. Another checkpoint can remove WAL between reading > ControlFile and registering that LSN. The test stops later, after > registration, so it does not exercise this window. > ... > Avoiding this requires registering a conservative current insert or replay > position before requesting the starting checkpoint. If the selected > startpoint is older, as can happen on a standby, the horizon then has to be > lowered. Alternatively, selection and registration need an interlock with > WAL removal. I did consider this gap, but thought it wasn't wide enough to be of great risk. However, you're right in that, when fixing a race condition we should close the gap completely and not resort to a half-measure. I will update the test and see where it takes me. > For a backpatch, I think a new postmaster GUC is a non-starter. It adds a > user-visible limit and shared-memory sizing decisions to a minor-version bug > fix, while concurrent BASE_BACKUP sessions are already bounded by > max_wal_senders. Unconditionally registering in do_pg_backup_start() also > changes SQL-level pg_backup_start(). I didn't like introducing a new GUC myself, but I thought recycling max_wal_senders (or max_replication_slots or whatever) would be confusing. I believe this race condition can affect `pg_basebackup --wal-method=fetch` as well as `--wal-method=stream`, so tying this to replication seemed wrong to me. On the other hand, I didn't fully consider back-porting the patch, so this needs more thought obviously. > I suggested server-owned retention upthread, but after reading the patch I > think your original client-side proposal deserves another look. Creating > the requested slot before sending BASE_BACKUP directly fixes the reported > --create-slot case, is much smaller to backpatch, and also works when a new > pg_basebackup connects to an older server. Existing slots with a NULL > restart_lsn, idle_replication_slot_timeout, and server-fetched WAL can be > treated as separate server-side problems. WDYT? I suspect this won't address the `--wal-method=fetch` situation, which I think is subject to the same WAL removal/recycling risk. > The September Commitfest is open for registration until September 1. I > suggest registering the patch now so that further versions and discussion do > not fall between CommitFests. Thanks for the advice, will do. Cheers Nick