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 1vr5KY-0066R1-1q for pgsql-hackers@arkaria.postgresql.org; Sat, 14 Feb 2026 02:24:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vr5JW-00Gshp-1f for pgsql-hackers@arkaria.postgresql.org; Sat, 14 Feb 2026 02:23:18 +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 1vr5JW-00Gshh-02 for pgsql-hackers@lists.postgresql.org; Sat, 14 Feb 2026 02:23:18 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vr5JT-00000000XUZ-0PtS for pgsql-hackers@lists.postgresql.org; Sat, 14 Feb 2026 02:23:16 +0000 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-b885a18f620so202622966b.3 for ; Fri, 13 Feb 2026 18:23:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1771035793; cv=none; d=google.com; s=arc-20240605; b=HH/YvA9LDP0GA/4GehiGYlO0ZUU5lmf/lzMHL5JJCaGrOJDeCfjCeJNwzofQScrVsU sbqcAJxGjBiY5RUmsAC+QohjE15Q+xA9F/14zWtluXWxtAlNzEmaF1NSPAI5ktqrVq0A SOeJE2W9nSYxvqSyMEskzvO0mygk+vqYClQdak69WEwVjaRoKlKP5OYyvoCtCOi627ZD 09MfG8hCG9eYe8dBwS+xoLnpwEb440QeaEJITgpuKm6ttGYsk//LRS450faaYobGD/QC Ga46dnGSbsVJok8yVBFTcHx629IBfUXJlXG+oyewfgfvd/4cNV3LPshXl4flx4mIlSM6 O2dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=PzLq8yqKuxspliP+uNNCA55rPJdpNb4fCJ+4tvk2y2w=; fh=pOSXZcKzRUhYWGYfJU++3EEzGLTygMQyW4ib3GkJPuw=; b=fWDkZTFbLxpm0O+Qv864SmiIZkO67kCM2Hm48C7SH/cMrhfN2y5doeF64aA1kXgr7n e+CzR82wAYVjPQDjANS8BImPJEU0jShXmbIIAEy/xEsT9ruKEARX//ois0m3mL5ducaH GILOWoz8z7AufeK/d2OtckDX0lnBhtoD/EKcqctISPokhgoUdJ7bV5Bof9Idme9rwxnk fhhwcAfgFgU7dyQkLpEsdupXOLjW2NAWwSQRoH13Kbkn8PLYCeFj7JWdQ1lg5nK8maSw jnLWZqy29zpTP0vzxFoZl5OO5yM/2b31S/6Cb3KvIipXGcBUv+hTq2lhh5qgtCcUpOe+ O8MA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771035793; x=1771640593; 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=PzLq8yqKuxspliP+uNNCA55rPJdpNb4fCJ+4tvk2y2w=; b=bwPVuCquL9SOJ+buYkXzvWIwA5f/WVxcxYe+2RHHWLGUBP03szOzh8xVk6GuPJFJ5C GNLROCQwLpK9jTn9p8Pnh/c1GEj5APn6QvJ8DMfPFfn01WQgTLcvnYdvCSnWqt4AjwQZ rJPD1UzIBioN8qgKJ2G0UKnxvn+zt2i9Qtgaw+UI+unvesy5TvUMrLRwNm3rwJ7Bd/qP B4b88f7FZupGhZOIV1hnjbgcT+5wfZuyNuEqV4KoeXiGItWzYoebeBiQIxKcmjC+469M ai7F6zCADsL51rBsPMxYxjHkgqVVrsuQhiZ54QQ8PoVp9bTP08ijao8ZWAouRAW9GBMY wiqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771035793; x=1771640593; 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=PzLq8yqKuxspliP+uNNCA55rPJdpNb4fCJ+4tvk2y2w=; b=n/zyVBB9J3/OdqnxS5Od3W9CtZC6H4aWcMM4L+pFFCsdORrKUAgmBI0h0QTjt3Pv1c cIKAo96Os2kdACXNyBf2Gjc2lHiLpiwbKmM7dz5SZ8jbmE5y1xTK3FpbGGjI72N4QuUo 5qpNlOpSxx809NmUbB6nCHI3SYwW09x0JYCL9w8FHrTk0ZMKNAgH+bvb0R27vC50lToh xoX4BbjZLvglz5JoVLSfDhVI4Fr8+7Gg8nZunH4b3JNzdvMGm+PnKb+3bcZce+yaqsgQ pYho3+ERH5Ro/JDqjqiQD93PiW7nDv2mqq47sgBq48gg6XQQDCfIOZmBUW4/Ya3v6IyC gnEQ== X-Forwarded-Encrypted: i=1; AJvYcCXny18vfZN9OlVGiSycbXihDD968TQKK94AwnoSOF6I0GrfQCO9nqzmL7ddf4w0fEvk5kBhKjKikwVSZrpZ@lists.postgresql.org X-Gm-Message-State: AOJu0Yx3wqmekNgmdcpQU/zSL/qYfQM+wpPUAUUqhOKRt1CzQGP/aR3l tlTQMaMeniAkZLxkyI+PjZ/k362PPq/lnYfLhPBm/vaUA0smXVWPQD/ivBGPaD3Man7kouIrHE2 Zn3His2Wcw09z8ftPmJa4hzeYI+A1EDg= X-Gm-Gg: AZuq6aIgvOy4Rm0zzgyGU+9Fmy4lGJII2JmevHB2mJbp1XqJnOcOwhwFoN4/HRSvZ7p ya/D/FXnd/U/gDTnita+j8DYBQ9l51n7JeneVovfil60sBHMeS3POJP3fyw+B09JgzN5/yX7LKn kwnsQGAuPLUvFrgzcc5Krxp8HKSM5otzXoyTElclOgTF8vOMEGIWpkEQyd0L9Lsl/xvUBdxxeZr cXjn23DTnerfqe2mMi1aUwnH8LpjvN/JNc3QhtaVXqrpEgfvldfT/V9tmTXPNa9LkXpINRs0Pvc CYHxm54= X-Received: by 2002:a17:906:4787:b0:b86:fed0:2b with SMTP id a640c23a62f3a-b8face24ae2mr255609766b.32.1771035792828; Fri, 13 Feb 2026 18:23:12 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Sami Imseih Date: Fri, 13 Feb 2026 20:23:01 -0600 X-Gm-Features: AaiRm517F3MmaOGv9-VGf6W3levUI2A3z6Hyb3rVlU5PFFyH_3cuIbxGT6dO1ZY Message-ID: Subject: Re: Flush some statistics within running transactions To: Bertrand Drouvot Cc: Michael Paquier , Fujii Masao , pgsql-hackers@lists.postgresql.org, Zsolt Parragi Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > PFA attached v6, addressing the reviews comments. Thanks for the patches! v6 is getting closer IMO. Here are some comments I have. v6-0001 looks solid, but some minor comments: 1/ + pgstat_flush_backend(nowait, PGSTAT_BACKEND_FLUSH_WAL, true); let's also use explicit (void) cast here 2/ + * Timeout handler for flushing non-transactional stats. I also noticed in v6-0005, we refer to "anytime" stats as "non-transactional". It's better to just refer to them as "anytime" anywhere instead of "non-transactional:. v6-0002: + if (nowait && !LWLockConditionalAcquire(&stats_shmem->lock, LW_EXCLUSIVE)) + return true; /* failed to flush */ + + LWLockAcquire(&stats_shmem->lock, LW_EXCLUSIVE); Here the LWLock acquisition will deadlock if we are nowait, successfully acquire the lock conditionally, and then we try to acquire it again. The logic here should not try to acquire the lock twice. + -- Force anytime flush (inside transaction!) + select pg_stat_force_anytime_flush(); Not sure why we need pg_stat_force_anytime_flush. A pg_sleep is sufficient, like below. right? ``` select test_custom_stats_fixed_anytime_update() from generate_series(1, 2); select pg_sleep(1.5); select 'anytime:'||numcalls from test_custom_stats_fixed_report(); ``` v6-0003: 1/ Suggested doc changes: - Sets the interval at which statistics that can be updated while a - transaction is still running are made visible. These include, for example, - WAL activity and I/O operations. + Sets the interval at which certain statistics, which can be updated while a + transaction is in progress, are made visible. These include WAL activity + and I/O operations. Such statistics are refreshed at the specified interval and can be observed during active transactions in monitoring views such as - pg_stat_io + pg_stat_wal and - pg_stat_wal. - Other statistics are only made visible at transaction end and are not - affected by this setting. + pg_stat_io. If the value is specified without a unit, milliseconds are assumed. The default is 10 seconds (10s), which is generally the smallest practical value for long-running transactions. - Other statistics are only made visible at transaction end and are not - affected by this setting. I removed this, because it's mentioned in the notes section later on. 2/ I don't see we have tests for other timeout based GUCs, but it would nice to ensure that this woks correctly. Maybe as a custom_stats test where we SET stats_flush_interval inside the transaction and make sure the stats flush only after the new timeout has passed. Maybe? v6-0004: 1/ NIT: +$node_primary->append_conf('postgresql.conf', "stats_flush_interval= '1s'"); +$node_publisher->append_conf('postgresql.conf', "stats_flush_interval= '1s'"); missing space before the equal sign. v6-0005: 1/ /* Partial flush only happens in anytime mode for FLUSH_ANYTIME stats */ is_partial_flush = (anytime_only && kind_info->flush_mode == FLUSH_ANYTIME); Will this be tue at all time? Let's imagine a Kind that flushes all the fields ANYTIME, would we not want to delete the pending entry? + /* if successfull non-partial flush, remove entry */ + if (did_flush && !is_partial_flush) pgstat_delete_pending_entry(entry_ref); 2/ indentation: Some statistics are updated while a transaction is in progress (for example, blks_read, blks_hit, tup_returned and tup_fetched). - Statistics that either do not depend on transactions or require transactional - consistency are updated only when the transaction ends. Statistics that require - transactional consistency include xact_commit, - xact_rollback, tup_inserted, - tup_updated and tup_deleted. + Statistics that either do not depend on transactions or require transactional + consistency are updated only when the transaction ends. Statistics that require + transactional consistency include xact_commit, + xact_rollback, tup_inserted, + tup_updated and tup_deleted. -- Sami Imseih Amazon Web Services (AWS)