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 1vgmwc-003peX-1x for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Jan 2026 16:45:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vgmwa-004Gbk-0o for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Jan 2026 16:45:04 +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 1vgmwZ-004GbZ-2j for pgsql-hackers@lists.postgresql.org; Fri, 16 Jan 2026 16:45:04 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vgmwY-000qmT-0f for pgsql-hackers@lists.postgresql.org; Fri, 16 Jan 2026 16:45:03 +0000 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-64b92abe63aso4508361a12.0 for ; Fri, 16 Jan 2026 08:45:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768581901; x=1769186701; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=5OsLS/CBhA0VwmyqY0gYsvjXhDi/UwW5vEbRAJX+Meg=; b=bQosXfayLrIRU9UCYWUf4otrEj8m6tDuQUYA9gk2cIQYh3KLRefc5vZzPtuw5j7Tut ASjE/iF6JtHyppzs8iGogcaUKhYMWiKGw0bY+nvU4sfwwiz+F3NJHe3O1pNmE2kZ3Jc1 IkdIbC3jD6hc4rNj8SPz7dLa+xd3GWHT6jFQeQDtPp34OVyAtei9WIlIAzo2we5RTb9R Pl/A37ChQPWg7Ll7CbfFPAh700of5Qj0NCF4CK9Ik81bMDQ/0SL94V73Py/lsKqaok/x faQHUael/GlbSfLz1kVjq9fhg+0oV6ye8vfDlqsTC0lf9Q4qNCtH8pevGbQjE0U/AGaP zAkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768581901; x=1769186701; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=5OsLS/CBhA0VwmyqY0gYsvjXhDi/UwW5vEbRAJX+Meg=; b=XnYGNP7m5U17GlNHF0elnK3I5K9sC7ILynxEpVVqbKbXJL7/UXE6Uo7ZuaPTyoUSwv j+JlKg45yWDm563vBA8ssV0U/JDaRnx/FTBAp9dWosdz2lnyWqBIulx6SG0u7OGPDM7X ayVqbFPNmK2jAvSZF7xI+BDJ1Ie24kS08Z8SqXmfTrDTPAANompOls39aK+nxChLxZtX zRG9YD9LoHNcAOYUSAxR4OkHwySHvLdbfjCSAEcEcWfB2ujK3Sg07yqmOicNigTl33ml fyV6pyxnqcUlVwnXibmX3uBo3L3TlCFfa7QZYy+mv7wCNN6eW4ZFCXbvJxBA1j06BH4u gouw== X-Gm-Message-State: AOJu0YwypJN+g9uhFb3XC353nfrTdzTMswcYwtJ18Xq37FKcLDTQCf1R AjHcCWq26LpKwSVXGKFW4bS42GmY0l5P2wdWz9YERAX66CLNQl0dwevA5coKfF2883XjNDJXUpK ensAM0bV5lhexYrShyEFPKQHaXHxa1OwCgorX1mg= X-Gm-Gg: AY/fxX4VZPDifR6bdwZZ9EJbA0D0x2e75jNoEqLcTnDk5sTa2qz39LXj767u2j4ISs3 qGwUxZrFQcX6FUaEh1nCA7N01FW57J/Lspcl0wGTK49IdW7ihauLIeucBcmxAPndW0DCHbPGi4I 65llQzSKzAjbI1PpfKt86U08HzNm+3m/teJGEeIdTcSs9r4xk9AlIcTskR2lv30+TYXPJyxuOGL fQnqnJaNFy6IGEMvu5GO3UoiAvEBqPR4qKEkqTht3jgGu0HJU78iNowh83SbNPtUA== X-Received: by 2002:a17:907:9814:b0:b7d:1cf:52ad with SMTP id a640c23a62f3a-b87932b8cc8mr349625866b.58.1768581901009; Fri, 16 Jan 2026 08:45:01 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Sami Imseih Date: Fri, 16 Jan 2026 10:44:48 -0600 X-Gm-Features: AZwV_Qhup8bdNRtvWZnHLmeVThC4nBQe49PXzD_-YhfZWjPx5sd4znuINtcemis Message-ID: Subject: Re: Flush some statistics within running transactions To: Bertrand Drouvot Cc: pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I took a look at 0001 in depth. > I don't think this feature could add a noticeable performance impact, so the tests > have been that simple. Do you think we should worry more? One observation is there's no coordination between ANYTIME and TXN_BOUNDARY flushes. While PGSTAT_MIN_INTERVAL prevents a backend from flushing more than once per second, a backend can still perform both an ANYTIME flush and a TXN_BOUNDARY flush within the same 1-second window. Not saying this will be a real problem in the real-world, but we definitely took measures in the current implementation to avoid this scenario. A few other comments on 0001 + /* Skip if completely idle */ + if (!DoingCommandRead || IsTransactionOrTransactionBlock()) + pgstat_report_anytime_stat(false); Does this need to be conditional? worst case, we return right away with an empty list. Best case, is we are consistently flushing. + /* + * When in anytime_only mode, the list may not be empty because + * FLUSH_AT_TXN_BOUNDARY entries were skipped. + */ + Assert(!anytime_only || dlist_is_empty(&pgStatPending) == !have_pending); Checking for !anytime_only is unnecessary here. "list_is_empty(&pgStatPending) == !have_pending" should be true regardless of ANYTIME or TXN_BOUNDARY, right? Below are a couple of edits for comments I felt would improve readability of the code. 1/ /* - * Flush non-transactional stats - * - * This is safe to call even inside a transaction. It only flushes stats - * kinds marked as FLUSH_ANYTIME. - * - * This allows long running transactions to report activity without waiting - * for transaction to finish. + * Flushes only FLUSH_ANYTIME stats using non-blocking locks. Transactional + * stats (FLUSH_AT_TXN_BOUNDARY) remain pending until transaction boundary. + * Safe to call inside transactions. */ 2/ typedef enum PgStat_FlushBehavior { - FLUSH_ANYTIME, /* All fields can flush anytime */ - FLUSH_AT_TXN_BOUNDARY, /* All fields need transaction boundary */ + FLUSH_ANYTIME, /* All fields can be flushed anytime, + * including within transactions */ + FLUSH_AT_TXN_BOUNDARY, /* All fields can only be flushed at + * transaction boundary */ } PgStat_FlushBehavior; I will start looking at the remaining patches next. -- Sami Imseih Amazon Web Services (AWS)