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 1jfozT-0000Fn-4W for pgsql-admin@arkaria.postgresql.org; Mon, 01 Jun 2020 18:16:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jfozS-0003gh-1c for pgsql-admin@arkaria.postgresql.org; Mon, 01 Jun 2020 18:16:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jfozR-0003gT-Qh for pgsql-admin@lists.postgresql.org; Mon, 01 Jun 2020 18:16:49 +0000 Received: from hermes.gatewaynet.com ([193.92.121.98]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jfozP-0001Iw-1A for pgsql-admin@lists.postgresql.org; Mon, 01 Jun 2020 18:16:48 +0000 Received: from hercules.internal.net (hercules.internal.net [10.9.200.8]) by hermes.gatewaynet.com (8.15.2/8.15.2/Debian-8) with ESMTP id 051IGjuQ014785 for ; Mon, 1 Jun 2020 21:16:45 +0300 Received: from [10.9.251.249] (dcmchgw.internal.net [10.9.0.1]) by hercules.internal.net (Postfix) with ESMTPS id 214A91350B7E for ; Mon, 1 Jun 2020 21:16:44 +0300 (EEST) Subject: Re: pg_stat_database.xact_commit + pg_stat_database.xact_rollback as a reliable metric for xid consumption ? To: pgsql-admin@lists.postgresql.org References: <51fa222b-374e-39da-eb8c-66d667426bae@matrix.gatewaynet.com> <36dd7ae2-7c6f-86af-430b-dd9a0f7774b3@matrix.gatewaynet.com> <3B1EF77A-B9DC-4F0A-AD1E-30876F65E2D5@crazybean.net> From: Achilleas Mantzios Message-ID: <2dde66f6-3842-f3a6-ab1a-b01590789ea8@matrix.gatewaynet.com> Date: Mon, 1 Jun 2020 21:16:43 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <3B1EF77A-B9DC-4F0A-AD1E-30876F65E2D5@crazybean.net> 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=-24.0 required=5.0 tests=ALL_TRUSTED,DYN_HAM_IT, DYN_HAM_IT_PARTNERS,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 On 1/6/20 6:58 μ.μ., Rui DeSousa wrote: > >> On Jun 1, 2020, at 7:03 AM, Julien Rouhaud wrote: >> >> On Mon, Jun 1, 2020 at 12:48 PM Achilleas Mantzios >> wrote: >>> On 1/6/20 1:36 μ.μ., Julien Rouhaud wrote: >>>> On Mon, Jun 1, 2020 at 12:02 PM Achilleas Mantzios >>>> wrote: >>>> Because read only transaction usually don't consume an xid. So yes >>>> pg_stat_database gives a more reasonable approximation of the real >>>> number of transactions happening on the server. >>> Thank you, so what would be the official way to monitor txid consumption (from a MVCC / Freezing admin POV)? >> I'm not sure what you're really looking for. If it's the txid >> consumption rate, you can use txid_current() at regular interval to >> compute it (note that this function will consume a txid). For object >> freeeze, you can use age(datfrozenxid) from pg_database, or >> age(relfrozenxid) from pg_class. >> >> > > I also record the stats tables every minute by either inserting into a table hist_ table or exporting the data out to be inserted into another table. When exporting the pg_stat_database table I added the following to record the information without the need to call txid_current(): > > coalesce(txid_current_if_assigned(), txid_snapshot_xmax(txid_current_snapshot())) as xact_txid, … if this is in the same system, and this _hist table only gets inserts, selects/delets, why not just use xmin ? Also since you are inserting how can you have null  txid_current_if_assigned()? > > >