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 1vkGZZ-00CsuQ-25 for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Jan 2026 06:59:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vkGZW-006Zfx-1r for pgsql-hackers@arkaria.postgresql.org; Mon, 26 Jan 2026 06:59:38 +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 1vkGZW-006Zfp-0f for pgsql-hackers@lists.postgresql.org; Mon, 26 Jan 2026 06:59:38 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vkGZT-00000000V1i-33Sl for pgsql-hackers@lists.postgresql.org; Mon, 26 Jan 2026 06:59:37 +0000 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-42fbc305552so3598850f8f.0 for ; Sun, 25 Jan 2026 22:59:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769410770; x=1770015570; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=E7VHxdSlgA9dHQ1SBBwysHAs/YlaW/aUe1GOkAp76X4=; b=Vo8fZuU+F8ocKMU5+IDlNwvZtQI4qUjcRLquHVCKVHhcqvI10XA44D5h4nKV0LHjxS TF6ewy1K0Z1B6FAKr42Va1f81/n5qJRyhXO0pqtioLSSVbOhgvHPisyIqxCBCAv9GjZk gGKLJvO5k+Bw8r6AGA6QovQfxWVDuyJl60OTek4PF30xzo8EISxOkGs2UfrkU0wBSskr /N8aGbdJcFamn97lW0uex6mrEhkRHDpJnXpDcY9uDpGBwlgHPBuEQH4LgovMmAdkTOTf BAIbIBZPd7ltyN0QvkvaWSQeLY9tEIMNCCm/ztV2Va3Z0feNScJSrqgSWAF2RrgGQFke bVTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769410770; x=1770015570; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E7VHxdSlgA9dHQ1SBBwysHAs/YlaW/aUe1GOkAp76X4=; b=dtu18N416uQtbcf3Mlp8eBRsOpe2i5AZBuTpWiI0gHBoYGC/FNgGcmBKuaKXP1YI7h MVYuthkowyQogyusnbNwt136TnNdshnAg4lGkKLuFBKmR8GneO19R4K0Pd2QZ+Rt+7HN nnozzhfKLYkHZBKwBpcS3mOto4+wBQc4crTupzXuQ1fJj7DT6za9XVNCq5xwfbARHctB 01KP5tQXqJfnTk+Euh8uVCEYR/llIHLnckzbiZcmXIal+arGLJwBEaVrBayyUcyzev0k V01CQXfpR9SnoG8QrWum3unpt3rbKSZlSUY0bZm+3Bgb3TbF169QQHmU4v4XjTeUMMTU cyeQ== X-Forwarded-Encrypted: i=1; AJvYcCXJPGFf/yXyD6nM9SUg85lq1lI8fT/W+tV4kqz7iqVMjfEd4milhCs3g9766UTNHMvUjvRQx9ARB4oJge/A@lists.postgresql.org X-Gm-Message-State: AOJu0Yzrbw5NWfgqP38xxE8q7zad9vQnWx3sGIl6vi0v3ZZUksYyJp/8 fIz+2KpQ8QJAb6bvQpHp8omwSNChJnoVJx4ZzSlGVE0Wf385+Z6TeR/Z X-Gm-Gg: AZuq6aKBN93xMKPaohsQ64QwlsPVVxY1/WXlEuaCwcRQHeJb0MFvWrdQLF++SpERCZh 0VU2PlSdz9CCzTXPsMaPsWYoRrK+mycR1uFdB5MnxKXfGcwafSNtmjJF4UUdFRN8wBZT3MHncDd ovYEz/GB1ep07gzynjSW2cyw/bTtM89gJCQ3Fku6is7s4dB2s81bFhGmi/LCNN3URMHpoyXLynH CrYrJZ2kV70FQXqeRbBPvPm7li8zIxYGYiNbT2x4X311+WgeQrU1yAjih0Vn0AJ3flsOexnBOR0 evsTTY3+/XQdGBmPdSYmYuEOM0gfzk+y6EwTNQKy4rXl8Fu66EzvsG+yZQc2QJgYj2F2SHI5+Wu bYgY5ftSICwcnO7VlfHMkZjtM7tzBpX1JggXvjGYPZyHn7mUZoxDZepJwUv/pjQCFbehL1EZkIh DUfLk9e9KmwmZLlVoT0ycIDvnMPTaALKzPK8rlk3KI+LvjIRJ2kF0i21K/6UzRCCoWUwmz2S64r PaMS+yWGFPAwNE+Q5e1oZlld+QAH35V37SI6rqjYMoTMQ== X-Received: by 2002:a05:6000:4212:b0:435:a0ca:bdc9 with SMTP id ffacd0b85a97d-435ca39aa2emr6298266f8f.44.1769410769895; Sun, 25 Jan 2026 22:59:29 -0800 (PST) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-435b1c0179bsm27570666f8f.1.2026.01.25.22.59.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Jan 2026 22:59:29 -0800 (PST) Date: Mon, 26 Jan 2026 06:59:28 +0000 From: Bertrand Drouvot To: Fujii Masao Cc: Sami Imseih , Michael Paquier , pgsql-hackers@lists.postgresql.org, Zsolt Parragi Subject: Re: Flush some statistics within running transactions Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8uxM0EZUDIpqMe6c" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --8uxM0EZUDIpqMe6c Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On Thu, Jan 22, 2026 at 04:45:31PM +0000, Bertrand Drouvot wrote: > On Thu, Jan 22, 2026 at 09:12:18PM +0900, Fujii Masao wrote: > > > > With this setup, the following messages were logged once per second: > > > > LOG: process 72199 still waiting for ShareLock on transaction 771 > > after 63034.119 ms > > DETAIL: Process holding the lock: 72190. Wait queue: 72199. > > > > Thanks! > > I see, the WaitLatch() in ProcSleep() is "woken up" every 1s due to the > enable_timeout_after(ANYTIME_STATS_UPDATE_TIMEOUT,...) being set unconditionally > in ProcessInterrupts(). We need to be more restrictive as to when to enable the > timeout, I'll fix in the next version. The attached, to apply on top of 0001, fix the issue. However it handles only the WaitLatch in ProcSleep() case and I start to have concern about the others WaitLatch() that would/could be "woken up" every 1s. Using disable_timeout() and enable_timeout_after() in WaitEventSetWait() does not look like a great answer to this concern, so I wonder if we should use a larger flush frequency instead (as proposed up-thread), thoughts? Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com --8uxM0EZUDIpqMe6c Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="fix_ProcSleep.txt" diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 063826ae576..7376dd1f316 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -1322,6 +1322,7 @@ ProcSleep(LOCALLOCK *locallock) bool allow_autovacuum_cancel = true; bool logged_recovery_conflict = false; ProcWaitStatus myWaitStatus; + bool anytime_timeout_was_active = false; /* The caller must've armed the on-error cleanup mechanism */ Assert(GetAwaitedLock() == locallock); @@ -1398,6 +1399,10 @@ ProcSleep(LOCALLOCK *locallock) standbyWaitStart = GetCurrentTimestamp(); } + anytime_timeout_was_active = get_timeout_active(ANYTIME_STATS_UPDATE_TIMEOUT); + if (anytime_timeout_was_active) + disable_timeout(ANYTIME_STATS_UPDATE_TIMEOUT, false); + /* * If somebody wakes us between LWLockRelease and WaitLatch, the latch * will not wait. But a set latch does not necessarily mean that the lock @@ -1661,6 +1666,9 @@ ProcSleep(LOCALLOCK *locallock) } } while (myWaitStatus == PROC_WAIT_STATUS_WAITING); + if (anytime_timeout_was_active) + enable_timeout_after(ANYTIME_STATS_UPDATE_TIMEOUT, PGSTAT_MIN_INTERVAL); + /* * Disable the timers, if they are still running. As in LockErrorCleanup, * we must preserve the LOCK_TIMEOUT indicator flag: if a lock timeout has --8uxM0EZUDIpqMe6c--