Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jfhH6-0007Xz-Rx for pgsql-admin@arkaria.postgresql.org; Mon, 01 Jun 2020 10:02:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jfhH5-0001dd-Ph for pgsql-admin@arkaria.postgresql.org; Mon, 01 Jun 2020 10:02:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jfhH5-0001dW-Hs for pgsql-admin@lists.postgresql.org; Mon, 01 Jun 2020 10:02:31 +0000 Received: from hermes.gatewaynet.com ([193.92.121.98]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jfhH2-00026D-LW for pgsql-admin@lists.postgresql.org; Mon, 01 Jun 2020 10:02:30 +0000 Received: from smadev.internal.net (pc131.internal.net [10.9.200.131]) by hermes.gatewaynet.com (8.15.2/8.15.2/Debian-8) with ESMTPS id 051A2Jgq012120 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 1 Jun 2020 13:02:24 +0300 Received: from smadev.internal.net (smadev [10.9.200.131]) by smadev.internal.net (8.15.2/8.15.2) with ESMTP id 051A2Jup016394 for ; Mon, 1 Jun 2020 13:02:19 +0300 (EEST) (envelope-from achill@matrix.gatewaynet.com) To: pgsql-admin@lists.postgresql.org From: Achilleas Mantzios Subject: pg_stat_database.xact_commit + pg_stat_database.xact_rollback as a reliable metric for xid consumption ? Message-ID: <51fa222b-374e-39da-eb8c-66d667426bae@matrix.gatewaynet.com> Date: Mon, 1 Jun 2020 13:02:19 +0300 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:60.0) Gecko/20100101 Thunderbird/60.3.2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Virus-Scanned: clamav-milter 0.101.4 at hermes X-Virus-Status: Clean X-Spam-Status: No, score=-27.5 required=5.0 tests=ALL_TRUSTED,DYN_HAM_COORD, DYN_HAM_IT,DYN_HAM_NAUTICAL,DYN_HAM_SHORT_BODY,DYN_SPAM_SUBJ autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on hermes.gatewaynet.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello I attended two interesting online courses by 2ndQuadrant recently, about MVCC and Freezing , and I started to seriously dig into this for the first time in our almost 20-yrs postgersql installation (running 10.x currently). I thought of using the info from the statistics collector : pg_stat_database xact_commit and pg_stat_database.xact_rollback but to my surprise this gave very high numbers, almost 20 times up , so I wrote a cron to insert every morning into an archive/historic table : pgstat_database_arc which is basically the schema of pgstat_database plus a timestamp col. And I got two instances of it one yesterday and one this morning : dynacom=# select xmin,datname,xact_commit+xact_rollback as num_of_xacts,ts from pgstat_database_arc WHERE datname='dynacom';    xmin    | datname | num_of_xacts | ts -----------+---------+--------------+-------------------------------  813560437 | dynacom |   7734784237 | 2020-05-31 18:37:08.950399+03  813889272 | dynacom |   7740424341 | 2020-06-01 08:00:01.912157+03 (2 rows) But the reported increase in the total number of xacts is 7740424341 - 7734784237 = 5640104 , while the actual xid consumption (using xmin, this table only does inserts) is : 813889272 - 813560437 = 328835. The xid difference (via xmin) is compatible with another system that I maintain (for our custom replication solution), so I am wondering why this almost 20-fold difference between actual xid consumption and pg_stat_database metrics. -- Achilleas Mantzios IT DEV Lead IT DEPT Dynacom Tankers Mgmt