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 1wVMfA-001uMG-0A for pgsql-bugs@arkaria.postgresql.org; Fri, 05 Jun 2026 05:00:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wVMf8-00ACgB-1y for pgsql-bugs@arkaria.postgresql.org; Fri, 05 Jun 2026 05:00:06 +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 1wVMf8-00ACg2-19 for pgsql-bugs@lists.postgresql.org; Fri, 05 Jun 2026 05:00:06 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wVMf6-00000001BNX-2aHv for pgsql-bugs@lists.postgresql.org; Fri, 05 Jun 2026 05:00:05 +0000 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-490b4a8e28bso12070445e9.1 for ; Thu, 04 Jun 2026 22:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780635603; x=1781240403; darn=lists.postgresql.org; h=content-transfer-encoding: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; bh=LFz2qH5looZ2mHYsQZMR0/O+XyaQKQHH64o6+IxVob0=; b=kr/9K8RxebWp9IWy5SfxFf4V5XxwZqdcnwFHamOGW5TlkagdYELG+WUH/QawSxLtyN bTK4sHFYxqOrArhehD/G8KuwI5rx7BRaYpF8yQkV6e2DCqU9YqzwLj877vHuz7QsRspT R4VkLj3TyPLWX6w91ut1fTClFETT+U7tCaei6l9MxaiEO7cn7D9D+JPG+TlojwJ19dXP s6B6Og4uxJWxXgUi+0UehBnWzGAkDGmcBQ25Z88Sj3EVIGC7An9i2uO9K7ECt/LSRoWl ou6V036O4RZFu2sibgKQtr4qTSSfrdg9WEWN1w3OYwll9wretIqglMebloMQq6P77ojM QGsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780635603; x=1781240403; h=content-transfer-encoding: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; bh=LFz2qH5looZ2mHYsQZMR0/O+XyaQKQHH64o6+IxVob0=; b=H71sz34DAFZrDKx0yQmE+K82RyjY3U9vOZRaKcCRWwIaURvz/HbUZ0vObomP+cTK1l ipH95xuyjY0Gu4dI3kkOevD2DtnzxM57cOgu83rxYsBeF3eR73VW6aDgvl6gXePUodVe Pfaz8qAs9R02yFzYYtuMycapygHKAZDuuxv3iRnWVvfT3J59jB+OxZWbR0+4oapxhWi+ zBAeFmQh/vG39ma5ilOddUZHMpE+8UDwKGwAbpEumMB8XEZghFnbFQFoYa64lP3aLUmM Loyv+xqjuqwnJq0g9RYiCRe8F4RjJdAu3bdE2yjO92jEWum4HYpifzmZebQRft2mtQ2I LWfg== X-Gm-Message-State: AOJu0YzC3CdaSQgwupgKkevRtZu3Pson6D0lLMgO5HdHhQR+mioKcUEj Czs12/gGFjfDyc5tNptHwH6NLfx6Egn67sQdY/UyKUSfSGhxyGOfzDcr X-Gm-Gg: Acq92OFGzU/Hjb5nw8Wds4C3l9Tw3r8QYmkUXD5LZNd7mnac4Zs4vmdtzBmiG0ojPvw xdiC79cnNwDeMNBUq+5z026tQ+mhMiF2SgqAmDI5wEJDz00HH3O3a/v2KE6EPe/AQXhMEquVrtj P4Drd+e7/rEuwKvxqtOuptQB4E8/LPBJcc/divOJsipEiJGc1ZnhZxG83dvD1XishirvEwZR3EQ 3Ie7Yb0BkoRx5fY7GzWJ11FwAFFU0Pil3tgtPxp09bKODgL5ErgAQI0e2BZX9MhuyC8S5Orqrcz wXHe6YW/p0DuD6VgArgS4QTW+uR8pol6LFd2hVHjttbEhf4dJrMzUQu3M4azN6HsAc8XH3n+SLn rXsX7OgySWWVHiJII/+EXqI7+iRf57k0O9m1BXkhio5PQn+YitB+CrnN0FzSO34FHQ6lDpjey+2 ciVOA0MDcUT4NOEn4aqFcbYy7wgzWm2aMfAZyAnGwh1INWYQ== X-Received: by 2002:a05:600c:19d3:b0:490:48df:2793 with SMTP id 5b1f17b1804b1-490c25fa410mr23257855e9.26.1780635602274; Thu, 04 Jun 2026 22:00:02 -0700 (PDT) Received: from [192.168.0.50] ([89.149.68.143]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490c2c9ea37sm29880535e9.0.2026.06.04.22.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Jun 2026 22:00:01 -0700 (PDT) Message-ID: <5edd4f4a-0d79-465d-a250-8b4735f780ca@gmail.com> Date: Fri, 5 Jun 2026 08:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18158: Assert in pgstat_report_stat() fails when a backend shutting down with stats pending To: Michael Paquier , Xuneng Zhou Cc: pgsql-bugs@lists.postgresql.org References: <18158-88f667028dbc7e7b@postgresql.org> <58b5d6bf-7dca-41e5-8000-e12981205ada@gmail.com> Content-Language: en-US From: Alexander Lakhin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello Michael, 05.06.2026 05:14, Michael Paquier wrote: > 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. Please try the following: --- a/src/backend/utils/activity/pgstat.c +++ b/src/backend/utils/activity/pgstat.c @@ -107,2 +107,3 @@ +#include "common/pg_prng.h" @@ -1212,3 +1213,8 @@ pgstat_flush_pending_entries(bool nowait)          /* flush the stats, if possible */ +if (nowait && (pg_prng_double(&pg_global_prng_state) < 0.1)) +        did_flush = false; +else +{          did_flush = kind_info->flush_pending_cb(entry_ref, nowait); +} As far as I can see, that rand() gives the same sequence on macOS each run, while on Linux I see different sequences. The patch works for me test-wise. Thank you for the fix! Best regards, Alexander