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 1i5g9L-000485-0d for pgsql-bugs@arkaria.postgresql.org; Thu, 05 Sep 2019 01:01:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i5g9H-0007HV-Uh for pgsql-bugs@arkaria.postgresql.org; Thu, 05 Sep 2019 01:01:19 +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 1i5g9H-00078b-If; Thu, 05 Sep 2019 01:01:19 +0000 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i5g9E-0002c2-1l; Thu, 05 Sep 2019 01:01:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1567645276; x=1599181276; h=subject:to:references:from:cc:message-id:date: mime-version:in-reply-to; bh=lJtlLfCgfDaTTA3Fyt44Y/OKZWMHGVseDZeMfQCAjnM=; b=lzbSo2JwGK940fe7oKI7WMUFxE4yqBCBFnwdoG/mdmbjPrsynxV80evH kBc4N1x6EIBPJoL/BZLfxluV8cCweSPfp7yNp3oRZVw10UhRAx8zSfTxc hYfKgZNfDWuAK/WH5eQR1gyDeDX11O8nSVgH6bJrnf/uhqBclBa3OVIb3 k=; X-Amazon-filename: fix_multixact_limit_v2.patch X-IronPort-AV: E=Sophos;i="5.64,468,1559520000"; d="scan'208,217";a="827504222" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-2a-e7be2041.us-west-2.amazon.com) ([10.47.22.34]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 05 Sep 2019 01:01:07 +0000 Received: from EX13MTAUWA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-e7be2041.us-west-2.amazon.com (Postfix) with ESMTPS id AE0E1A255E; Thu, 5 Sep 2019 01:01:06 +0000 (UTC) Received: from EX13D18UWA002.ant.amazon.com (10.43.160.199) by EX13MTAUWA001.ant.amazon.com (10.43.160.118) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 5 Sep 2019 01:01:06 +0000 Received: from 186590ce269b.ant.amazon.com (10.43.161.82) by EX13D18UWA002.ant.amazon.com (10.43.160.199) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 5 Sep 2019 01:01:06 +0000 Subject: Re: ERROR: multixact X from before cutoff Y found to be still running To: "pgsql-bugs@postgresql.org" , PostgreSQL-development References: From: Jeremy Schneider CC: "Bossart, Nathan" , "Nasby, Jim" Message-ID: Date: Wed, 4 Sep 2019 18:01:05 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------C3E0BEF037202CC57E7D4DCC" Content-Language: en-US X-Originating-IP: [10.43.161.82] X-ClientProxiedBy: EX13P01UWA004.ant.amazon.com (10.43.160.127) To EX13D18UWA002.ant.amazon.com (10.43.160.199) Precedence: Bulk List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --------------C3E0BEF037202CC57E7D4DCC Content-Type: multipart/alternative; boundary="------------7C1B62C7D08B7F60DD54EB2D" --------------7C1B62C7D08B7F60DD54EB2D Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit On 9/4/19 17:37, Nathan Bossart wrote: > Hi, > > Currently, if you hold a multixact open long enough to generate an > "oldest multixact is far in the past" message during VACUUM, you may > see the following ERROR: > > WARNING: oldest multixact is far in the past > HINT: Close open transactions with multixacts soon to avoid wraparound problems. > ERROR: multixact X from before cutoff Y found to be still running > > Upon further inspection, I found that this is because the multixact > limit used in this case is the threshold for which we emit the "oldest > multixact" message. Instead, I think the multixact limit should be > set to the result of GetOldestMultiXactId(), effectively forcing a > minimum freeze age of zero. The ERROR itself is emitted by > FreezeMultiXactId() and appears to be a safeguard against problems > like this. > > I've attached a patch to set the limit to the oldest multixact instead > of the "safeMxactLimit" in this case. I'd like to credit Jeremy > Schneider as the original reporter. This was fun (sortof) - and a good part of the afternoon for Nathan, Nasby and myself today.  A rather large PostgreSQL database with default autovacuum settings had a large table that started getting behind on Sunday.  The server has a fairly large number of CPUs and a respectable workload.  We realized today that with their XID generation they would go read-only to prevent wraparound tomorrow.  (And perfectly healthy XID age on Sunday - that's wraparound in four days! Did I mention that I'm excited for the default limit GUC change in pg12?)  To make matters more interesting, whenever we attempted to run a VACUUM command we encountered the ERROR message that Nate quoted on every single attempt!  There was a momentary mild panic based on the "ERRCODE_DATA_CORRUPTED" message parameter in heapam.c FreezeMultiXactId() ... but as we looked closer we're now thinking there might just be an obscure bug in the code that sets vacuum limits. Nathan and Nasby and myself have been chatting about this for quite awhile but the vacuum code isn't exactly the simplest thing in the world to reason about.  :)  Anyway, it looks to me like MultiXactMemberFreezeThreshold() is intended to progressively reduce the vacuum multixact limits across multiple vacuum runs on the same table, as pressure on the members space increases.  I'm thinking there was just a small oversight in writing the formula where under the most aggressive circumstances, vacuum could actually be instructed to delete multixacts that are still in use by active transactions and trigger the failure we observed. Nate put together an initial patch (attached to the previous email, which was sent only to the bugs list). We couldn't quite come to a consensus and on the best approach, but we decided that he'd kick of the thread and I'd throw out an alternative version of the patch that might be worth discussion.  [Attached to this email.]  Curious what others think! -Jeremy -- Jeremy Schneider Database Engineer Amazon Web Services --------------7C1B62C7D08B7F60DD54EB2D Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: 8bit
On 9/4/19 17:37, Nathan Bossart wrote:
Hi,

Currently, if you hold a multixact open long enough to generate an
"oldest multixact is far in the past" message during VACUUM, you may
see the following ERROR:

        WARNING:  oldest multixact is far in the past
        HINT:  Close open transactions with multixacts soon to avoid wraparound problems.
        ERROR:  multixact X from before cutoff Y found to be still running

Upon further inspection, I found that this is because the multixact
limit used in this case is the threshold for which we emit the "oldest
multixact" message.  Instead, I think the multixact limit should be
set to the result of GetOldestMultiXactId(), effectively forcing a
minimum freeze age of zero.  The ERROR itself is emitted by
FreezeMultiXactId() and appears to be a safeguard against problems
like this.

I've attached a patch to set the limit to the oldest multixact instead
of the "safeMxactLimit" in this case.  I'd like to credit Jeremy
Schneider as the original reporter.


This was fun (sortof) - and a good part of the afternoon for Nathan, Nasby and myself today.  A rather large PostgreSQL database with default autovacuum settings had a large table that started getting behind on Sunday.  The server has a fairly large number of CPUs and a respectable workload.  We realized today that with their XID generation they would go read-only to prevent wraparound tomorrow.  (And perfectly healthy XID age on Sunday - that's wraparound in four days! Did I mention that I'm excited for the default limit GUC change in pg12?)  To make matters more interesting, whenever we attempted to run a VACUUM command we encountered the ERROR message that Nate quoted on every single attempt!  There was a momentary mild panic based on the "ERRCODE_DATA_CORRUPTED" message parameter in heapam.c FreezeMultiXactId() ... but as we looked closer we're now thinking there might just be an obscure bug in the code that sets vacuum limits.

Nathan and Nasby and myself have been chatting about this for quite awhile but the vacuum code isn't exactly the simplest thing in the world to reason about.  :)  Anyway, it looks to me like MultiXactMemberFreezeThreshold() is intended to progressively reduce the vacuum multixact limits across multiple vacuum runs on the same table, as pressure on the members space increases.  I'm thinking there was just a small oversight in writing the formula where under the most aggressive circumstances, vacuum could actually be instructed to delete multixacts that are still in use by active transactions and trigger the failure we observed.

Nate put together an initial patch (attached to the previous email, which was sent only to the bugs list). We couldn't quite come to a consensus and on the best approach, but we decided that he'd kick of the thread and I'd throw out an alternative version of the patch that might be worth discussion.  [Attached to this email.]  Curious what others think!

-Jeremy

-- 
Jeremy Schneider
Database Engineer
Amazon Web Services
--------------7C1B62C7D08B7F60DD54EB2D-- --------------C3E0BEF037202CC57E7D4DCC Content-Type: text/plain; charset="UTF-8"; x-mac-type=0; x-mac-creator=0; name="fix_multixact_limit_v2.patch" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="fix_multixact_limit_v2.patch" ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL2NvbW1hbmRzL3ZhY3V1bS5jIGIvc3JjL2JhY2tl bmQvY29tbWFuZHMvdmFjdXVtLmMKaW5kZXggZTE1NDUwN2VjZC4uZjA5OTEyNzUxMCAxMDA2 NDQKLS0tIGEvc3JjL2JhY2tlbmQvY29tbWFuZHMvdmFjdXVtLmMKKysrIGIvc3JjL2JhY2tl bmQvY29tbWFuZHMvdmFjdXVtLmMKQEAgLTg5Myw2ICs4OTMsNyBAQCB2YWN1dW1fc2V0X3hp ZF9saW1pdHMoUmVsYXRpb24gcmVsLAogCWludAkJCWVmZmVjdGl2ZV9tdWx0aXhhY3RfZnJl ZXplX21heF9hZ2U7CiAJVHJhbnNhY3Rpb25JZCBsaW1pdDsKIAlUcmFuc2FjdGlvbklkIHNh ZmVMaW1pdDsKKwlNdWx0aVhhY3RJZCBvbGRlc3RNeGFjdDsKIAlNdWx0aVhhY3RJZCBteGFj dExpbWl0OwogCU11bHRpWGFjdElkIHNhZmVNeGFjdExpbWl0OwogCkBAIC05NzAsNyArOTcx LDggQEAgdmFjdXVtX3NldF94aWRfbGltaXRzKFJlbGF0aW9uIHJlbCwKIAlBc3NlcnQobXhp ZF9mcmVlemVtaW4gPj0gMCk7CiAKIAkvKiBjb21wdXRlIHRoZSBjdXRvZmYgbXVsdGksIGJl aW5nIGNhcmVmdWwgdG8gZ2VuZXJhdGUgYSB2YWxpZCB2YWx1ZSAqLwotCW14YWN0TGltaXQg PSBHZXRPbGRlc3RNdWx0aVhhY3RJZCgpIC0gbXhpZF9mcmVlemVtaW47CisJb2xkZXN0TXhh Y3QgPSBHZXRPbGRlc3RNdWx0aVhh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