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 1la5S3-0006ff-60 for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Apr 2021 23:43:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1la5S0-0005Kw-MM for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Apr 2021 23:43:08 +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 1la5S0-0005Ha-B1 for pgsql-hackers@lists.postgresql.org; Fri, 23 Apr 2021 23:43:08 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1la5Rs-0003ne-KC for pgsql-hackers@postgresql.org; Fri, 23 Apr 2021 23:43:06 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id B1A1C3485; Fri, 23 Apr 2021 19:42:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 23 Apr 2021 19:42:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=+YBymVsKrF053wjkLeHdG47B8/M JpeQDvBtWxu+WArE=; b=I/pAOnVTMlrBwHHS4DnXlxU9QtCT5uh+d2o4O8lzC/h 6DBDB0B1mKx+RAhvpZYLShGfe3heJwcYaGMp/H6gFLcnWwAOpCvJ8IYIO9NQlT19 ZH9U8jFr2kmCA2rlJYjFLlKTkfN2wdC39+Xr39vZOOsPfuJlttNC9Sa47TV2QYth dw+B+3owuoXsA0uyddabGPEsSCg7L8uDUdaSMPFv1eSHv88isMlwgd/eJN1zUwka HoUWuj7w9oWOTnDLBSVTLSgSC4Qt1UxsdTOXS5mdl839ijJw51mmYXXhKwSCOEkF u4ft3UdM+zcKpo1NVgUsEVM8Lq82m6ZWUnWI0IrYdsA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=+YBymV sKrF053wjkLeHdG47B8/MJpeQDvBtWxu+WArE=; b=BlzQMtvJ9uWUmz4ot3htCv QlOj5WsZuUDtA3BmkkwM0Tvw2oXo0THcYVrU5eqvWmNtqRpkyuHKnt+ydnjKPTj3 ni1NIHp1gNVU/3QEJnz+LPZCJJcV/fnYeYscTXENy9QHKuCjNj6U+DsQ8vW+R3Fz d3db9EVbPsmcJzgpnLQX/CVkzUk3m3gQxxSwCFoNMo7lcPNXTlM5U+SRfhOVjbjg EItag22ei2OwM2rsD3yPfPnns8rY+EtrWv9+EHF53EGo0W5A8YMyxLWZw9qMi8wD AtaAv/5VxABFnpasF0U8riPnz4sZ4q+0BplqJZIoNCN2fu3yGAopvOe8fc/A5knA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvddufedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpedukefhkeelueegveetheelffffjeegleeuudelfeefuedtleffueejfffh ueffudenucfkphepuddtjedrudegvddrfeefrddutdefnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomheprghnughrvghssegrnhgrrhgriigvlhdr uggv X-ME-Proxy: Received: from intern.anarazel.de (107-142-33-103.lightspeed.sntcca.sbcglobal.net [107.142.33.103]) by mail.messagingengine.com (Postfix) with ESMTPA id 3587824005C; Fri, 23 Apr 2021 19:42:57 -0400 (EDT) Date: Fri, 23 Apr 2021 16:42:56 -0700 From: Andres Freund To: Noah Misch , Tom Lane , Bruce Momjian Cc: Jason Harvey , Peter Geoghegan , PostgreSQL Hackers Subject: Re: pg_upgrade can result in early wraparound on databases with high transaction load Message-ID: <20210423234256.hwopuftipdmp3okf@alap3.anarazel.de> References: <20190615183759.GB239428@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190615183759.GB239428@rfd.leadboat.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2019-06-15 11:37:59 -0700, Noah Misch wrote: > On Tue, May 21, 2019 at 03:23:00PM -0700, Peter Geoghegan wrote: > > On Mon, May 20, 2019 at 3:10 AM Jason Harvey wrote: > > > This week I upgraded one of my large(2.8TB), high-volume databases from 9 to 11. The upgrade itself went fine. About two days later, we unexpectedly hit transaction ID wraparound. What was perplexing about this was that the age of our oldest `datfrozenxid` was only 1.2 billion - far away from where I'd expect a wraparound. Curiously, the wraparound error referred to a mysterious database of `OID 0`: > > > > > > UPDATE ERROR: database is not accepting commands to avoid wraparound data loss in database with OID 0 > > That's bad. Yea. The code triggering it in pg_resetwal is bogus as far as I can tell. That pg_upgrade triggers it makes this quite bad. I just hit issues related to it when writing a wraparound handling test. Peter remembered this issue (how?)... Especially before 13 (inserts triggering autovacuum) it is quite common to have tables that only ever get vacuumed due to anti-wraparound vacuums. And it's common for larger databases to increase autovacuum_freeze_max_age. Which makes it fairly likely for this to guess an oldestXid value that's *newer* than an accurate one. Since oldestXid is used in a few important-ish places (like triggering vacuums, and in 14 also some snapshot related logic) I think that's bad. The relevant code: if (set_xid != 0) { ControlFile.checkPointCopy.nextXid = FullTransactionIdFromEpochAndXid(EpochFromFullTransactionId(ControlFile.checkPointCopy.nextXid), set_xid); /* * For the moment, just set oldestXid to a value that will force * immediate autovacuum-for-wraparound. It's not clear whether adding * user control of this is useful, so let's just do something that's * reasonably safe. The magic constant here corresponds to the * maximum allowed value of autovacuum_freeze_max_age. */ ControlFile.checkPointCopy.oldestXid = set_xid - 2000000000; if (ControlFile.checkPointCopy.oldestXid < FirstNormalTransactionId) ControlFile.checkPointCopy.oldestXid += FirstNormalTransactionId; ControlFile.checkPointCopy.oldestXidDB = InvalidOid; } Originally from: commit 25ec228ef760eb91c094cc3b6dea7257cc22ffb5 Author: Tom Lane Date: 2009-08-31 02:23:23 +0000 Track the current XID wrap limit (or more accurately, the oldest unfrozen XID) in checkpoint records. This eliminates the need to recompute the value from scratch during database startup, which is one of the two remaining reasons for the flatfile code to exist. It should also simplify life for hot-standby operation. I think we should remove the oldestXid guessing logic, and expose it as an explicit option. I think it's important that pg_upgrade sets an accurate value. Probably not worth caring about oldestXidDB though? Greetings, Andres Freund