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 1w5sOJ-003iTG-22 for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Mar 2026 21:37:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5sOI-005hId-0c for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Mar 2026 21:37:22 +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 1w5Ot1-00EGiL-1t for pgsql-bugs@lists.postgresql.org; Wed, 25 Mar 2026 14:07:08 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w5Osy-000000014ql-2oxs for pgsql-bugs@lists.postgresql.org; Wed, 25 Mar 2026 14:07:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=Oy5J5Dq44ega/tQHtCFavx4Dh/NBjzMK98hkZ06/fME=; b=FnsRAadxuza+P3UYM9J+tKeaU1 78jFO3nr0uuF97bxe9VuhjlqVH9o/6Uxah0Ueebe875fzaN9Ifh5m2UKlhLDCfz0K5dKhJTd3MI8n 5oA+v2P5hMDDhPdTm3zP69w1WsefMM1CYhCDPd+B3yxeRS6PQ6SVSZw6PqAn7DI45QxW+nZL1Cg+w MWtdZviGv4Jft5yNRB3spJASV5u4bfS/ZXn6km7s/tdokqkT63INRAiT5URU4j5eK5Ub1K6eIxeZJ 1KHhzP+HiZjlzHv4vaPn98z8eO4/zw1ctE/UNoTL8wthjqvGJmQ9IY5tOgXmRKrFkIhFHAPR4cJHD ADMkdl/g==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w5Osx-004Nr9-2d for pgsql-bugs@lists.postgresql.org; Wed, 25 Mar 2026 14:07:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5Osv-005vZB-2g for pgsql-bugs@lists.postgresql.org; Wed, 25 Mar 2026 14:07:02 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19439: pg_stat_xact_user_tables stat not currect during the transaction To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: klemen.kobau@gmail.com Reply-To: klemen.kobau@gmail.com, pgsql-bugs@lists.postgresql.org Date: Wed, 25 Mar 2026 14:06:37 +0000 Message-ID: <19439-8f02018f9fc3a240@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19439 Logged by: klemen kobau Email address: klemen.kobau@gmail.com PostgreSQL version: 18.0 Operating system: Linux (EndeavorOS) Description: =20 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=3D100", "-c", "wal_level=3Dlogical", "-c", "max_wal_senders=3D10", "-c", "max_replication_slots=3D20", "-c", "wal_keep_size=3D10", "-c", "max_slot_wal_keep_size=3D1024" ] 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 =3D '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 =3D '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 This is not what I would expect from reading https://www.postgresql.org/docs/current/monitoring-stats.html#MONITORING-ST= ATS-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. Kind regards Klemen Kobau