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 1wVK69-001seq-2p for pgsql-bugs@arkaria.postgresql.org; Fri, 05 Jun 2026 02:15:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wVK58-009Zyn-2M for pgsql-bugs@arkaria.postgresql.org; Fri, 05 Jun 2026 02:14:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wVK53-009ZyM-0P for pgsql-bugs@lists.postgresql.org; Fri, 05 Jun 2026 02:14:46 +0000 Received: from fout-b2-smtp.messagingengine.com ([202.12.124.145]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wVK51-00000001AFf-0kaf for pgsql-bugs@lists.postgresql.org; Fri, 05 Jun 2026 02:14:40 +0000 Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfout.stl.internal (Postfix) with ESMTP id 177081D00037; Thu, 4 Jun 2026 22:14:38 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Thu, 04 Jun 2026 22:14:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1780625677; x=1780712077; bh=ECk16ZBQmk OyxC3a673WOCIxtaV++sAftGiWaXKQy5s=; b=SMM5AiNiUyJR47AVQbEN18Qr+g ETEiHF4vHv0AtpjMPdNpRRuMy3T1nVrbBTTZuEeZMT2DNC/0Fpt3WdfSQ5U3F++6 41v713fQAm5nCfBTnb6xRK9cCBjUy0RVFLe3kT7uIVhVsQwVHhia5hKnz7EnKbia 7xIdsN7RLrVdJgzpo1q2aRTpaivec23ZZx6eZWIEGJ5sHTaP2HPIzpHOhl8K4Bof vswcben0qbPE0Np3m1slMziT84ln4pTnmC9qRDFMmVT00mUq6AZq4aI77oBTGIwQ TPUXa0PrTjBiSc1s4dtZY8B+e3hPMdE5tS84LVUwQuXxfpIhtRW3fBn1Iy8A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1780625677; x=1780712077; bh=ECk16ZBQmkOyxC3a673WOCIxtaV++sAftGi WaXKQy5s=; b=AF3iZ2O4hPoGWLB6Nl4YWbCw0K0Ro5tVSnx9PleehJvvMOG7Dj0 u8t086yoNMZg34h6ccUo1BUr1clMc8eWph+Te16N5RNua6vEX0yVvPXWd0xRpp7o uqVOZ1UU+KgnHK5VXzUrmRMc2OTG/7feMHHfnF0LuMEIxYiCLy/9T2IleFat/aJ2 6qPiDOIY0Q498z8wXxeGeAtRFfZlOibUoB0zxTEwcZnf00uNo7yr7i2IeXXEj6kC ysXuJz3DpYidFa9kuHoNlF1bg4/AUeTgS4rSnja3ihuCA2HaIZeaH8SFzOVWPk0S 1dksL4suO/vo58l7voYad8M3ZL5p+fPiHVA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTGLG74DT9IT1eI1NErfG0OZu7UZDZ+a6a70EUjfiZZ/yugxirTExzh87Xq+jpw442 XincgqrWAB9daJwWHxNZuy+W+ELlZWCxraoahUufex50tQRPQaYYgGfryGS4HpQfyDUszw ddIjjpgistBnIJP/lFo6aG8ouHChXx8qV+9v2L1jXotJM7kOgAoNogT6L8Xojnv60JOe2x C6sO21A18I2g36vn9gRGlqD3UikACduGLp+GMWU6tWHt1CcDFJtx7+NKsDt6Zbkn59zZTY uOi3VgA5fC8fxFUgRXv4msJJ0s7hr9isXZ69rCrk3cBpfKPAU5bRScZSoBIYKOFSZdhjVf PKp0H/IzDeJStBHcX/s7YNsMmmK6y1ro2WW1eFlT0P1KLq79g0vAJaQtvk3z9mIa2uWsh4 nRagOZ/rtzswEFrKEWf/OSIBtHZVPrUufzRyFcv1sD2+ikNTGHnD4KAHRvfhtGr4JuIayY WBFXZ4Oc2A5Usw9MkP3ekVZDlH5kxGxrPEfdvk3OoAIrhKTT9uhLUHiADAKuLZ51hgUT9O ZL8HLRnjE4ce57vkKdavgkpLBdx2VA/p+N8Hd1ZGJvIBpGpSi6Xfk+g3s2wbbdPgFlh/y0 O+mgENzPGskikHWK/KgPkgs6utj/A6Q1hkyw8+k2P0ch9PyQogfJ0Ua0q9Ow X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 4 Jun 2026 22:14:36 -0400 (EDT) Date: Fri, 5 Jun 2026 11:14:31 +0900 From: Michael Paquier To: Xuneng Zhou Cc: Alexander Lakhin , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18158: Assert in pgstat_report_stat() fails when a backend shutting down with stats pending Message-ID: References: <18158-88f667028dbc7e7b@postgresql.org> <58b5d6bf-7dca-41e5-8000-e12981205ada@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="f1dkMevmLII8QzUu" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --f1dkMevmLII8QzUu Content-Type: multipart/mixed; boundary="TwV5nfSZvOa/8eah" Content-Disposition: inline --TwV5nfSZvOa/8eah Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, May 14, 2026 at 03:19:34PM +0800, Xuneng Zhou wrote: > I agree that applying the change wholesale could be too invasive. If > we decide not to address the ordering issue, removing this assertion > seems reasonable, since the non-assert path does not actually provide > the required guarantee. Attached is a patch for 15~17 that is able to achieve this goal: - Lift the assertion on shutdown for WAL senders, but keep it everywhere else. - Secondary trick in pgstat_shutdown_hook to cope with the fact that some stats make still be around at shutdown for a WAL sender. I cannot reproduce the failure re-using the trick sent by Alexander at the top of the thread. Thoughts or objections? -- Michael --TwV5nfSZvOa/8eah Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=0001-Lift-shutdown-assertion-in-pgstats-for-WAL-senders.patch Content-Transfer-Encoding: quoted-printable =46rom 62bae7f32ea095e0130af762bdf6ef39a7c5d388 Mon Sep 17 00:00:00 2001 =46rom: Michael Paquier Date: Fri, 5 Jun 2026 10:42:47 +0900 Subject: [PATCH] Lift shutdown assertion in pgstats for WAL senders Backpatch-through: 15-17 --- src/backend/utils/activity/pgstat.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activi= ty/pgstat.c index 33025cf4aad3..b7cf6fa88ff4 100644 --- a/src/backend/utils/activity/pgstat.c +++ b/src/backend/utils/activity/pgstat.c @@ -97,6 +97,7 @@ #include "lib/dshash.h" #include "pgstat.h" #include "port/atomics.h" +#include "replication/walsender.h" #include "storage/fd.h" #include "storage/ipc.h" #include "storage/lwlock.h" @@ -516,8 +517,12 @@ pgstat_shutdown_hook(int code, Datum arg) =20 pgstat_report_stat(true); =20 - /* there shouldn't be any pending changes left */ - Assert(dlist_is_empty(&pgStatPending)); + /* + * There shouldn't be any pending changes left, unless this is a WAL + * sender that would shut down after the checkpointer has flushed the + * stats. + */ + Assert(dlist_is_empty(&pgStatPending) || am_walsender); dlist_init(&pgStatPending); =20 pgstat_detach_shmem(); @@ -608,7 +613,13 @@ pgstat_report_stat(bool force) * assert that before the checks above, as there is an unconditional * pgstat_report_stat() call in pgstat_shutdown_hook() - which at least * the process that ran pgstat_before_server_shutdown() will still call. + * + * WAL senders would be shut down after the checkpointer and may still + * have stats. Skip them. */ + if (pgStatLocal.shmem->is_shutdown && am_walsender) + return 0; + Assert(!pgStatLocal.shmem->is_shutdown); =20 if (force) --=20 2.54.0 --TwV5nfSZvOa/8eah-- --f1dkMevmLII8QzUu Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmoiMQcACgkQnvQgOdby QH0etg/+OwRN7rYPRw0prwsdHSzrLu1lqGGr7k2uYlOpggPzP8OSBWWi4AYqleu9 DbYsMm8HxQD48xoGbN7PemrkfsqNaKhBn7P+14MWWoG6JtLiRbRFuVvfiwOdLSFz YWpKHqZorowoGwnyYXNWtAzDGMQxeP3G/JkQkzehZ56NxkuxVBZu9scrrULHSmll 0scqdmtzVveJR93c/+4xAP6mmJNNX/bWPCmGvoNM3hik2TqpeY3VQxnev8NLSsM9 2J1Lj2VLOJCdRtB2wtVHyv7c/EX56blt1+ScNZ8pvuHj7kWHzCpMQItbdlMp4CWH M/kd9anHGxcOaykdBd8FyU9wGTAKkAEDiuIboo+rjlEeuUYGktPE2NrJMsjuAoY4 bZPlY65mp7kC8gSdn0GI98WNH6u0dKdQiLOM0u3jBdMWphxxspwjND4VJ0d9tyJY 4rL4zYJB9N+fqSuEaLgGN+yX8CFDV0ovusq0sFLddu0F8H7HxqfsERDLiVjNegqQ O8povyXfuNlGZuBi1iv8GwhHqN0WauYffVykgsG7C84RPX0mhBEmOrigXF25dWHP 6CT7vJQPWdrke81pI7gHdRFudqqRbh9i5soVsEFdJ1iNp1WPwnUweVuA/4F5uhNS ks3y8+MkDSaX5xelQ389grYCULcNMz+5qS9Ab8SFCOLnJtfypGY= =ZR5C -----END PGP SIGNATURE----- --f1dkMevmLII8QzUu--