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 1w5wjh-003n2r-2S for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Mar 2026 02:15:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5wjg-00766v-0v for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Mar 2026 02:15:44 +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 1w5wjg-00766m-06 for pgsql-bugs@lists.postgresql.org; Fri, 27 Mar 2026 02:15:44 +0000 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w5wje-00000001F23-1mtR for pgsql-bugs@lists.postgresql.org; Fri, 27 Mar 2026 02:15:43 +0000 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-b982d56dac4so256617666b.3 for ; Thu, 26 Mar 2026 19:15:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774577740; cv=none; d=google.com; s=arc-20240605; b=V3jIa7e1G3go4t4HR1JC2kKnrFFsGDnB7wZf96lVYZ/clYdQkuo3LzgZ3OLCj7gp0I YPT1RHY0+uWpMxkDVjEoiTrHtjda75dw/QbLiznlFYAjbAk7N8xktD0MWCS/KrI/pxX8 BrdzqZGFErYhkrgMrhU9AcXJtD8+Wm2riNKqp0zsD9jokhk1CkpxzxCJqBaM8sQnsTh9 YIzlPmyBZ3fv1vJya4Bkk7lcqWq0/BBOwDGaYi5K1mNURU0jFyYxxJjAVWtgX/5xhEBP /lZ8lVQdC9t6g9DBSlg7HbjSJIEHG3+hjzHDOlKxE6gND9dsbjtRQqBLHWpBpQFBd82j Lqdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=uTNSmRqBioMtNTLu+tEIIaE73+K4pu9s/zDBl1GYr5o=; fh=UD+rd7quVnaQxQJsFs1mTL4KE4yTmCSFV+juK7ZsRZQ=; b=LoqOlftnG1yytvrFJAZ+zAsVTajcG8YwWpflSXMucHEi2FqPLNsnPjab1h7woLENIf oq2WgPLQnrhW66se/mcvkhTtimTcIwMzm3TyQk69OpkH8bbDsMFexwYR7/LP6zLhTWyC PLNGGCbHwXSo/mThJXL9TBN2pIkTOR829nVk2feVw7cmjpmzVpzP5OyZvJuVw19g3rzu 9KH/nfyenRcQToMXRcuwv/QTat92tVy7hBw0qJOLyftedZBvUJ/haw9LybYwcx5DRqQJ sSQKESTL29hKkCEqUcPIo6FTq74bGhEZb9fsVhAhjGdCraFgx3SVyUXE6bPaPXPFyMaV cdsw==; 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=20251104; t=1774577739; x=1775182539; darn=lists.postgresql.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=uTNSmRqBioMtNTLu+tEIIaE73+K4pu9s/zDBl1GYr5o=; b=V9MFnVwM8vj8DVHhJGmMPKShxxOxIDwS0Jy1W3uX9fA6hvzMYpLOj3qRbm9DXu+dzc PHuAN/8vSsw1vDZ+2El7qHkdYlZbadUXIUTDVAdJq5ajjj+TExeVdGN07DFvG2c6DMLr Pf0/XuMpQWHVpRBihSv4qHZBlGXN5A2HFS5eWpHrScntxHCOKvcuCK3IfAXJKc9TAYNV 7D4p6yIq7dDa+CcjaIlavuBX1VZuyJbDPQnuS1sLe26hx3OImjWZ3+GBP/9Gs+XkkEVH ZYCR9sy6weYj7OsS+Nh7D7FRBGybrf6+pp/QWy1IoAZZg3b1JyGXqELFw4+HQURLGbSE XtJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774577739; x=1775182539; h=content-transfer-encoding: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=uTNSmRqBioMtNTLu+tEIIaE73+K4pu9s/zDBl1GYr5o=; b=X+cflNJddYgsveVNRUxN7BLttQPi9u8qkq3bNb7i/TqyeH63LIwQlEe/t8gfRHsGk8 oKPwKUYeRMpBWSoE2WwxPnrvKu6zg6rMiBqZFfXTmQvJOFL/qva+tCElm1vUR1Oy8E73 pHoM1/yR0smgVUKlP2/Zr9VRcBlARY9Gt2srN1iBmDUiucwGnhNhBIf490RQgQXY7eF8 UhH52BmMmUW24oHIEA1pwu4zh/T+6dWyTlMKIgVUNZKHvAVOYhPsk1/cPfIgcsY9KvzH aMCf6zgtrXU6220Zrax8ATFSv7Q9v3peRVSg33MmtMm129wTYRcHCuhGvckVfYE+A5ie stag== X-Forwarded-Encrypted: i=1; AJvYcCUME3fHUJ/XQEqk88uoITG44i1jVzkZD9lZ56mWyeAzBXoEGn2kcfXc30/CNALbHWBvH8IjEoFCgeH/@lists.postgresql.org X-Gm-Message-State: AOJu0Yzi7vZsUQPECBgobdshiHC2w3bXdT0OhtPwa6xUrXb17nYdNBbP QBB85wjo2n5RaV8bmeiErKpLIgtH+I86/HvZI/ztHIgwxEjBkXZVvhpErkHfoUnezgHqGh0qgB+ o9b9ou/GQhE5TFhcIYXWBP2VMUNKOpNY= X-Gm-Gg: ATEYQzwnAd4sRtOpjPzf6igvlOSxG1K7nQvt6xa9KZqvZL2M4l5ErN48RdOwfob/IhZ IpeRGIx8IpHxDP6pHplqs1Q5/5dHcQenc43lOG51+Cqer/SrIQRiMD2Cj8A+jj1ZJ3Qa2m8Ne4B LEcO9j2wOCoXd9J1NtT7q/d/xOARQP4XlAn55npbRCS1spmT8OlP+OyJhv+3wL/PeZ97K76B6X7 A7LmU9wWOcGasImgE/WQM55P252e6N3J2xVEBu2uOKoUfKSqub7k8HXkLDwE3ymcrxwJUmloD7d xl4lZ4Oy7dP9h8J9tKNjXZAThJo6oCMi45/U7ayAwkqWfzKgW9mYdK9deD8Qf9iXJuAnkljMyrw EHaqE36d70DKRgVUQy2c= X-Received: by 2002:a17:906:ef08:b0:b98:549d:8367 with SMTP id a640c23a62f3a-b9b5033e19cmr37350066b.17.1774577739368; Thu, 26 Mar 2026 19:15:39 -0700 (PDT) MIME-Version: 1.0 References: <19439-8f02018f9fc3a240@postgresql.org> In-Reply-To: <19439-8f02018f9fc3a240@postgresql.org> From: Xuneng Zhou Date: Fri, 27 Mar 2026 10:15:27 +0800 X-Gm-Features: AQROBzBRY6g_7GJKyhSuGO06t2-y5s7nC58Dx_u1XWY5--yQGbeNsVd_Ixnxi4k Message-ID: Subject: Re: BUG #19439: pg_stat_xact_user_tables stat not currect during the transaction To: klemen.kobau@gmail.com, pgsql-bugs@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi klemen, Thanks for the report. On Fri, Mar 27, 2026 at 5:36=E2=80=AFAM PG Bug reporting form wrote: > > 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: > > 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 tex= t); > 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 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 t= he > 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 =E2=80=9Cthroughout the transaction.=E2=80=9D 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