public inbox for [email protected]  
help / color / mirror / Atom feed
From: Xuneng Zhou <[email protected]>
To: [email protected]
To: [email protected]
Subject: Re: BUG #19439: pg_stat_xact_user_tables stat not currect during the transaction
Date: Fri, 27 Mar 2026 10:15:27 +0800
Message-ID: <CABPTF7Wx=WTHa67PJUnH8VaJf-svrcFjt1ZgOVrqWzfgwDuMCA@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

Hi klemen,

Thanks for the report.

On Fri, Mar 27, 2026 at 5:36 AM PG Bug reporting form
<[email protected]> wrote:
>
> The following bug has been logged on the website:
>
> Bug reference:      19439
> Logged by:          klemen kobau
> Email address:      [email protected]
> PostgreSQL version: 18.0
> Operating system:   Linux (EndeavorOS)
> Description:
>
> I am running postgres:18.0 in a docker container, the configuration is as
> follows:
>
>   postgres:
>     image: postgres:18.0
>     command: [
>       "postgres",
>       "-N", "200",
>       "-c", "max_prepared_transactions=100",
>       "-c", "wal_level=logical",
>       "-c", "max_wal_senders=10",
>       "-c", "max_replication_slots=20",
>       "-c", "wal_keep_size=10",
>       "-c", "max_slot_wal_keep_size=1024"
>     ]
>     environment:
>       POSTGRES_USER: postgres
>       POSTGRES_PASSWORD: postgres
>       POSTGRES_DB: postgres
>       TZ: UTC
>       PGTZ: UTC
>     ports:
>       - 5432:5432
>     volumes:
>       - postgres_data:/var/lib/postgresql
>
> I use psql version 18.3.
>
> I run the following:
>
> psql -h localhost -p 5432 -U postgres -d postgres -c "
> -- Transaction 1: insert 1 row, check stats, commit
> BEGIN;
> CREATE TABLE IF NOT EXISTS temp.xact_test (id serial PRIMARY KEY, val text);
> INSERT INTO temp.xact_test (val) VALUES ('a');
> SELECT relname, n_tup_ins FROM pg_stat_xact_user_tables WHERE relname =
> 'xact_test';
> COMMIT;
>
> -- Transaction 2: insert 1 row, check stats
> BEGIN;
> INSERT INTO temp.xact_test (val) VALUES ('b');
> SELECT relname, n_tup_ins FROM pg_stat_xact_user_tables WHERE relname =
> 'xact_test';
> ROLLBACK;
>
> -- Cleanup
> DROP TABLE temp.xact_test;
> "
>
> And the output is
>
> BEGIN
> CREATE TABLE
> INSERT 0 1
>   relname  | n_tup_ins
> -----------+-----------
>  xact_test |         1
> (1 row)
>
> COMMIT
> BEGIN
> INSERT 0 1
>   relname  | n_tup_ins
> -----------+-----------
>  xact_test |         2
> (1 row)
>
> ROLLBACK
> DROP TABLE

I can also reproduce this behavior on HEAD.

> This is not what I would expect from reading
> https://www.postgresql.org/docs/current/monitoring-stats.html#MONITORING-STATS-VIEWS,
> where it states
>
> > A transaction can also see its own statistics (not yet flushed out to the
> shared memory statistics) in the views pg_stat_xact_all_tables,
> pg_stat_xact_sys_tables, pg_stat_xact_user_tables, and
> pg_stat_xact_user_functions. These numbers do not act as stated above;
> instead they update continuously throughout the transaction.
>
> based on this, I would expect that the numbers are updated each time an
> insert happens and that they are isolated per transaction.
>

This snippet of the doc feels somewhat ambiguous. The current behavior
does not seem fully consistent with wording such as “throughout the
transaction.” It also seems more appropriate for these table views to
reflect stats within their own scopes, rather than cumulative values
spanning txn boundaries.


--
Best,
Xuneng






reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: BUG #19439: pg_stat_xact_user_tables stat not currect during the transaction
  In-Reply-To: <CABPTF7Wx=WTHa67PJUnH8VaJf-svrcFjt1ZgOVrqWzfgwDuMCA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox