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 1la69z-0007tV-WD for pgsql-hackers@arkaria.postgresql.org; Sat, 24 Apr 2021 00:28:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1la69y-0002Wz-Od for pgsql-hackers@arkaria.postgresql.org; Sat, 24 Apr 2021 00:28:34 +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 1la69y-0002Ws-Cw for pgsql-hackers@lists.postgresql.org; Sat, 24 Apr 2021 00:28:34 +0000 Received: from mail-il1-x131.google.com ([2607:f8b0:4864:20::131]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1la69v-00030d-22 for pgsql-hackers@postgresql.org; Sat, 24 Apr 2021 00:28:33 +0000 Received: by mail-il1-x131.google.com with SMTP id b17so42111737ilh.6 for ; Fri, 23 Apr 2021 17:28:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=TJbWg+0lJrKyQNAChU185bkYFcEEFAFejbK8x7mg4H0=; b=ALVhW9k8gHKOmrFbS0nJrhvsrs+Pii2d+gLL38iC1peQEKyKeMrW7v+tyCGgGJMDXJ zIth8kg+3ZBwE1U0D2hV0QKuV2UJtuw/bMyqWLIeJnAhb9Az3qSoxgZ69QT7DVC2iRkC ZDlyLiuJqe7lPPMEzK+ZUcXNFof8HUliTvk6a6OBZ2v+qOi9MAQGdlfs9a96ivrsj5Y+ xlo/JF7XVAexJn5DzxMuY4x5Ym7Gj1eZtRw3u1kr12D+oLHlVwn5loh1Fm7D1iwUMASA 8lDHbYLrXOenCCeSc7QPXbQccLACBuL7nkbgPiyd61HeyY/C/aYV5amtGSUMDzbYtYKq uDMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=TJbWg+0lJrKyQNAChU185bkYFcEEFAFejbK8x7mg4H0=; b=aLQVYN/htyRbANL6kYjzIxYVBkFoz9LmUPosAZnG0c1qr+rbP0ePKJiWhsTWK+2x0Z Ld5LHxDj0XQ1M2Jt50SSSDBIHXCfNCp/Gyi4Hc+CBS2wJbhnKhAEQvbXp28OxOH9V5Ue SjxtVleBDBsQNW3n8Q4xwMZEPJDqJxuKYFmyoFvLlo+9yBUHfH/0ixtfqlzZHzMsH3m7 F3MNWfqfqgJBKZJYn3OY2BC9rfpiTmMv3/TRiArW29ftjDNP624xI35GLIE10lh3PVmD tlG/h7tGzcOo+zXD0qCTwxYJ0IVFsdtJ+drpNmuZpwGkvS9ihz6PaExqwyjI1RhPmPcM 43Gw== X-Gm-Message-State: AOAM531p4r1cjBUWRiw80iY+EoTbDAZc8Kj0wBwW8ulAVio3FncNkFwU XseTL+1OoW8KZOq0oLNbYdRHFQ== X-Google-Smtp-Source: ABdhPJw4e0MYhoRYqRlDS7Q7JtXZ94QWtQSxFu47gDmipBe3cTg8CeRaBVN+/Xz7cNiE7jM/v64LCg== X-Received: by 2002:a05:6e02:1bc3:: with SMTP id x3mr4923847ilv.47.1619224109228; Fri, 23 Apr 2021 17:28:29 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id b8sm3491273iob.30.2021.04.23.17.28.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Apr 2021 17:28:28 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 8CCCF801553; Fri, 23 Apr 2021 19:28:27 -0500 (CDT) Date: Fri, 23 Apr 2021 19:28:27 -0500 From: Justin Pryzby To: Andres Freund Cc: Noah Misch , Tom Lane , Bruce Momjian , Jason Harvey , Peter Geoghegan , "Tharakan, Robins" , pgsql-hackers@postgresql.org Subject: Re: pg_upgrade can result in early wraparound on databases with high transaction load Message-ID: <20210424002827.GO7256@telsasoft.com> References: <20190615183759.GB239428@rfd.leadboat.com> <20210423234256.hwopuftipdmp3okf@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210423234256.hwopuftipdmp3okf@alap3.anarazel.de> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Apr 23, 2021 at 04:42:56PM -0700, Andres Freund wrote: > 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? This (combination of) thread(s) seems relevant. Subject: pg_upgrade failing for 200+ million Large Objects https://www.postgresql.org/message-id/flat/12601596dbbc4c01b86b4ac4d2bd4d48%40EX13D05UWC001.ant.amazon.com https://www.postgresql.org/message-id/flat/a9f9376f1c3343a6bb319dce294e20ac%40EX13D05UWC001.ant.amazon.com https://www.postgresql.org/message-id/flat/cc089cc3-fc43-9904-fdba-d830d8222145%40enterprisedb.com#3eec85391c6076a4913e96a86fece75e > Allows the user to provide a constant via pg_upgrade command-line, that >overrides the 2 billion constant in pg_resetxlog [1] thereby increasing the >(window of) Transaction IDs available for pg_upgrade to complete. -- Justin