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 1lTnua-0005E4-3w for pgsql-general@arkaria.postgresql.org; Tue, 06 Apr 2021 15:46:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lTnuZ-0006re-2B for pgsql-general@arkaria.postgresql.org; Tue, 06 Apr 2021 15:46:39 +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 1lTnuY-0006rX-OG for pgsql-general@lists.postgresql.org; Tue, 06 Apr 2021 15:46:38 +0000 Received: from mail1.dalibo.net ([212.83.143.11] helo=mail.dalibo.com) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lTnuW-0000Ah-3E for pgsql-general@lists.postgresql.org; Tue, 06 Apr 2021 15:46:37 +0000 Received: from firost (larco.ioguix.net [78.202.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id 73DCF203DC; Tue, 6 Apr 2021 17:46:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1617723993; bh=0FA1gA4HJ+2NACP61+PZFMvWYH93//Yskn2ciMMptLE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=MgwryoPwEyyRCRjiHJL5E9g3Ca553bUy5mSToVDriRGbvBisnLE4Yx8tjrc62Iub3 BiOB6fQ3k6yIT017qVGK8qL5BFiosbj5Os0xkD9TbfR0ikcmJ8+JAVO6xbxQmBgJRb 7J8wrhOFvs4Tb1uFVW5tDghv0r3p+ACS6bol376A= Date: Tue, 6 Apr 2021 17:46:32 +0200 From: Jehan-Guillaume de Rorthais To: Luca Ferrari Cc: Laurenz Albe , pgsql-general Subject: Re: questions about wraparound Message-ID: <20210406174632.11661a54@firost> In-Reply-To: References: <20210402102900.7ae6e665@firost> Organization: Dalibo MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 06 Apr 2021 10:46:08 +0200 Laurenz Albe wrote: > On Sat, 2021-04-03 at 15:22 +0200, Luca Ferrari wrote: > > why having a TransactionId that is 32 bits > > in depth while it is exposed (thru txid_current()) as a 64 bits value? > > I mean, having 64 bits would reduce the need for anti-wrap arpund > > vacuum. I suspect the usage of 32 bits is both for compatibility and > > tuple header size, but I'm just guessing. > > Because there are two of these transaction IDs stored on each tuple > (xmin and xmax) to determine its visibility. The overhead of 8 bytes > per tuples for visibility is already pretty high. > > Another downside is that changing this would prevent the use of > pg_upgrade for upgrading, as the on-disk format changes. Indeed. Compatibility and size. About the txid_current() format. It is showing the 64bit format used internally. It is split in two parts: * lower part is classical XID on 32 bits, stored in tuples header * higher part is the "epoch" of the xid space, ie. the number of time the XID looped. This is not stored in tuples Look for macros EpochFromFullTransactionId and XidFromFullTransactionId in "include/access/transam.h". Given txid_current() returning eg. 10000000000: =# select txid_current(); txid_current -------------- 10000000000 The epoch would be 2: $ echo $((10000000000 >> 32)) 2 The 32bits XID stored in tuples header would be 1410065408: $ echo $((10000000000 % 2**32)) 1410065408 When looking at the NextXID in the controldata file, you would find: $ pg_controldata $PGDATA|grep NextXID Latest checkpoint's NextXID: 2:1410065408 Regards,