Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hcDa5-0000RL-NF for pgsql-hackers@arkaria.postgresql.org; Sat, 15 Jun 2019 18:39:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hcDZ4-0004WS-Ri for pgsql-hackers@arkaria.postgresql.org; Sat, 15 Jun 2019 18:38:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hcDZ4-0004WK-It for pgsql-hackers@lists.postgresql.org; Sat, 15 Jun 2019 18:38:10 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hcDYy-0005uD-3I for pgsql-hackers@postgresql.org; Sat, 15 Jun 2019 18:38:09 +0000 Received: by mail-pg1-x543.google.com with SMTP id v9so3428113pgr.13 for ; Sat, 15 Jun 2019 11:38:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=z0HOTDkFu9IlwSNt2bkxUU6RAgmwH4/fA2fKpmDtQAs=; b=T0XTBr9RMv75Xpm5AC2f+OT0soxrkhuFSq0Ya746FWvVwA6i7kd24Tpj6NMzfzZ+5K LEnQsSO8a4vrdDFYJ0HMO6ujvc1SdtoynvOQtXFL8YeFqkU5V1jgo1Iu/pad4t4W9hk2 2NAoDNzDLLnuCXtFQxCuK79grwhXdyRTu2FJg= 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=z0HOTDkFu9IlwSNt2bkxUU6RAgmwH4/fA2fKpmDtQAs=; b=KKOoKHlepqQzRkmt1jcySBXTQpbD/dQIZ9w7BmyCkUji/QOqf4XgH2CrqdZEopHFJp zfLuDxz0thZhn9wwwr18Gabe4QHdDRDiuuMFzQter96KZTj0igeVXWaAUlGh73uFE+uB goUWYICxvoTrqEM/4EP1Y9+uqKICIrRDQeXFQGFLk8Cny+2ycSmSiTO75mPBbDfCpO8v CXzlhRT1NyY6xC76n5YX7JK5RDx5Y12Xaz+FXmDpNinljV9V+0oXSKsKJdWOBoMVzCMk hu7QMHF3hSNtOr2KnDEFRPipY09YQMWRKYAL4OJiX+3b04+6XghHEzqREyWSaQxCwKnE hPhA== X-Gm-Message-State: APjAAAXOkG6Lrf2x7Pa+9AMLSgJ0sLHp8A0YnKob2Y6CQ5aM69CXZqhp CKsyomPMXU6ZUB3F3OsjIv85Cg== X-Google-Smtp-Source: APXvYqzkQ0oBeDOychp3q5G2M6OQtpl2+FC+RAHJCayjow7hCBNhSgXKBrx+rrja9FWlQhmOntTIJQ== X-Received: by 2002:a65:62c6:: with SMTP id m6mr42052202pgv.306.1560623881594; Sat, 15 Jun 2019 11:38:01 -0700 (PDT) Received: from rfd.leadboat.com (108-233-125-46.lightspeed.sntcca.sbcglobal.net. [108.233.125.46]) by smtp.gmail.com with ESMTPSA id l1sm6259179pgi.91.2019.06.15.11.38.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Jun 2019 11:38:01 -0700 (PDT) Date: Sat, 15 Jun 2019 11:37:59 -0700 From: Noah Misch To: Jason Harvey , Peter Geoghegan Cc: PostgreSQL Hackers Subject: Re: pg_upgrade can result in early wraparound on databases with high transaction load Message-ID: <20190615183759.GB239428@rfd.leadboat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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. > > We were able to recover after a few hours by greatly speeding up our vacuum on our largest table. For what it's worth, a quicker workaround is to VACUUM FREEZE any database, however small. That forces a vac_truncate_clog(), which recomputes the wrap point from pg_database.datfrozenxid values. This demonstrates the workaround: --- a/src/bin/pg_upgrade/test.sh +++ b/src/bin/pg_upgrade/test.sh @@ -248,7 +248,10 @@ case $testhost in esac pg_dumpall --no-sync -f "$temp_root"/dump2.sql || pg_dumpall2_status=$? +pg_controldata "${PGDATA}" +vacuumdb -F template1 pg_ctl -m fast stop +pg_controldata "${PGDATA}" if [ -n "$pg_dumpall2_status" ]; then echo "pg_dumpall of post-upgrade database cluster failed" > > In a followup investigation I uncovered the reason we hit the wraparound so early, and also the cause of the mysterious OID 0 message. When pg_upgrade executes, it calls pg_resetwal to set the next transaction ID. Within pg_resetwal is the following code: https://github.com/postgres/postgres/blob/6cd404b344f7e27f4d64555bb133f18a758fe851/src/bin/pg_resetwal/pg_resetwal.c#L440-L450 pg_upgrade should set oldestXID to the same value as the source cluster or set it like vac_truncate_clog() would set it. Today's scheme is usually too pessimistic, but it can be too optimistic if the source cluster was on the bring of wrap. Thanks for the report.