Re: pgstat: Flush some statistics within running transactions, take 2

From: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
To: Sami Imseih <samimseih(dot)pg(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, Lukas Fittl <lukas(at)fittl(dot)com>
Subject: Re: pgstat: Flush some statistics within running transactions, take 2
Date: 2026-11-12 09:32:17
Message-ID: avWHoZ+kIoq0rKgp@bdtpg
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Wed, Nov 04, 2026 at 07:08:54PM -0600, Sami Imseih wrote:
> PFA a mandatory rebase

Thanks for the updated patch!

+ xact_boundary = !IsTransactionOrTransactionBlock();

I looks like that procedure commits are missed.

For example, in session 1:

CREATE TABLE flush_test (id integer);

CREATE PROCEDURE flush_probe()
LANGUAGE plpgsql AS $$
BEGIN
INSERT INTO flush_test VALUES (1);
PERFORM pg_stat_force_next_flush();
COMMIT;

INSERT INTO flush_test VALUES (2);
PERFORM pg_stat_force_next_flush();
PERFORM pg_sleep(20);
END
$$;

CALL flush_probe();

While it sleeps, session 2 reports one row:

SELECT count(*) FROM flush_test;
count
-------
1

but no inserts:

SELECT n_tup_ins FROM pg_stat_user_tables
WHERE relname = 'flush_test';
n_tup_ins
-----------
0

I would have expected n_tup_ins = 1.

I wonder if the committed transaction’s counters should be flushed before the
procedure starts the next transaction?

Regards,

--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2026-11-12 09:32:44 Re: Add a hook for handling logical decoding messages on subscribers.
Previous Message Tomas Vondra 2026-11-12 09:26:19 Re: reconsider_full_join_clause fails to consider if COALESCE() arguments are NULL-preserving