Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vJxEm-009XfA-0W for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Nov 2025 17:05:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vJxEj-007JB7-2t for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Nov 2025 17:05:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vJxEj-007JAz-1g for pgsql-hackers@lists.postgresql.org; Fri, 14 Nov 2025 17:05:25 +0000 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vJxEh-007kg4-02 for pgsql-hackers@postgresql.org; Fri, 14 Nov 2025 17:05:24 +0000 Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-948e03b096dso92858039f.0 for ; Fri, 14 Nov 2025 09:05:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763139916; x=1763744716; darn=postgresql.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=/g9Bu7UiecOA+NMPby1CDKkzQx2v2sQVp0tf2NlZMvk=; b=Fwj7j5TS0XFYpSfKBFbA/TYk94tyB8aPjih6Ij7f4cQJz3M+/mW/Adl94Tt1C7Sr0q 00DVTPCxZjp9mOCC+ca0FTQdoDtVBSJVRXhxm4Y5JxpZ/xUEF3u49zG+9DzahgEER7Cz MbUoCkB/7AW/HayKTUPxSENRYmVvLlmHIpqGa1lvlsElWkzKONtMZwukiurXqgPev756 g63K6Lrrumvxbxizr6FMAWfQBUZZdreEs8DdC+SFccPNDv3PCWu1J3zHn/2Wf9AhFGwZ gb8xnbxqJjKp6JpBhCllfLSion1ipi+q+1fW1lgn2UspGeKD4aKWDhI/r8AkGXx05Gax PtaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763139916; x=1763744716; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/g9Bu7UiecOA+NMPby1CDKkzQx2v2sQVp0tf2NlZMvk=; b=Y796zVbEDbySFH/2liD4CVNh6SlvNZ07JXZocCiKN1G/iFaC66f72jpGoRmCoJrZ9N GGUEb4hmdnGzfx7Xs2S/9wwK9dPOQezgWcR7f5acgbuTKIqsCzWpM6A7JzgsA3+0uOYI vK/Udehe7hqrpDU5eWsgwyvLMZPOMsRV0mWDe/l/sn9r75HIH8HMxlWS1AdSKmOTeiNG kkqn8RKY6lfd3JuWlQP7RZl9vJvTTYM4f2D7etb/v2ZD669MNKS6iFSB9qxrTG6mQiqh OBs7ulkjDOKeeJ+i1DY+/kCNOT2O6e2bz0/qNEhxfZnm5otI62RHqL3/SPkarb9H7le9 lxkQ== X-Gm-Message-State: AOJu0YxV3l3JBJ2zotPP7FPgPq+3ee05PVH2+RV+2NRAcBpRymjgRprm A2BOy+AX/ZiYB/RmnwIpk7Zj94i3EHvzdOdEDJl6tm5WR0Rr+4DcuXKvhZrjiQ== X-Gm-Gg: ASbGncvfBNj9qY0tODhLfquZGcW1jPmd3fCXoMLVGgHcji1mQfUDq6FDIV40lzBOzmH PTqD/udun+YnQKrKZezQjiXtkLmISBdRxpLcRLj5r0GgdcrKRQ+UDDl1u0c5xslTvtTZ7tKHZb2 m+lKwApByFGljstH1IyL54wRQ2bQn4rlW6kVfhdh/+QiuXPCK+TBh9GvM58ADLxFBrucrJq80ST YO/P/RhEqY8b5Ym0GcrscrY46u7v9qTI2d1+hVQ/mV6EAE9lBnNokN1f5qsRsXPdL9L/0FRr2PO LTisW7hrSHVOhePEsL6TXFYs0yq4IaxiciXLZ6tXIuZ1++VHc0UBuBfoasWU4dG1A8mzhwkeLEL tQFBKLyR2hHs73uWyzrVzaHq85robzNDMVHDCAx8t6SdwoPvZjxD/9KBDCj4vhkTN1T7g3akS9X zq7XqWKVv7CW+HXf++IXbh3ws6vblqZS3DuGM3t2pVV5ej8fIBDJtDgBWaN4hIPFd++A== X-Google-Smtp-Source: AGHT+IEK9w3riz/7P0HArDLGi24eRh1sm43audKth78/qdydveaHD4CqnZW8Hx4LJetMQgnXhpqWfQ== X-Received: by 2002:a05:6e02:1fee:b0:430:c90d:10ae with SMTP id e9e14a558f8ab-4348c955240mr67421315ab.32.1763139915672; Fri, 14 Nov 2025 09:05:15 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-434839cdbe8sm28035145ab.31.2025.11.14.09.05.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Nov 2025 09:05:14 -0800 (PST) Date: Fri, 14 Nov 2025 11:05:13 -0600 From: Nathan Bossart To: pgsql-hackers@postgresql.org Subject: enhance wraparound warnings Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="i7+bPtDlPvAbCgMY" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --i7+bPtDlPvAbCgMY Content-Type: text/plain; charset=us-ascii Content-Disposition: inline varsup.c has the following comment: /* * We'll start complaining loudly when we get within 40M transactions of * data loss. This is kind of arbitrary, but if you let your gas gauge * get down to 2% of full, would you be looking for the next gas station? * We need to be fairly liberal about this number because there are lots * of scenarios where most transactions are done by automatic clients that * won't pay attention to warnings. (No, we're not gonna make this * configurable. If you know enough to configure it, you know enough to * not get in this kind of trouble in the first place.) */ I don't know about you, but I start getting antsy around a quarter tank. In any case, I'm told that even 40M transactions aren't enough time to react these days. Attached are a few patches to enhance the wraparound warnings. * 0001 adds a "percent remaining" detail message to the existing WARNING. The idea is that "1.86% of transaction IDs" is both easier to understand and better indicates urgency than "39985967 transactions". * 0002 bumps the warning limit from 40M to 100M to give folks some more time to react. * 0003 adds an early warning system for when fewer than 500M transactions remain. This system sends a LOG only to the server log every 1M transactions. The hope is that this gets someone's attention sooner without flooding the application and server log. Thoughts? -- nathan --i7+bPtDlPvAbCgMY Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0001-Add-percentage-of-transaction-IDs-that-are-availa.patch From 4fd750a67e98cb7b86970ecca5ff3a26fd1f7690 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 14 Nov 2025 09:59:15 -0600 Subject: [PATCH v1 1/3] Add percentage of transaction IDs that are available to wraparound warnings. --- doc/src/sgml/maintenance.sgml | 1 + src/backend/access/transam/multixact.c | 10 ++++++++++ src/backend/access/transam/varsup.c | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/doc/src/sgml/maintenance.sgml b/doc/src/sgml/maintenance.sgml index 120bac8875f..b89278ef032 100644 --- a/doc/src/sgml/maintenance.sgml +++ b/doc/src/sgml/maintenance.sgml @@ -674,6 +674,7 @@ SELECT datname, age(datfrozenxid) FROM pg_database; WARNING: database "mydb" must be vacuumed within 39985967 transactions +DETAIL: Approximately 1.86% of transactions IDs are available for use. HINT: To avoid XID assignment failures, execute a database-wide VACUUM in that database. diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c index 9d5f130af7e..63eb2548da1 100644 --- a/src/backend/access/transam/multixact.c +++ b/src/backend/access/transam/multixact.c @@ -1118,6 +1118,8 @@ GetNewMultiXactId(int nmembers, MultiXactOffset *offset) multiWrapLimit - result, oldest_datname, multiWrapLimit - result), + errdetail("Approximately %.2f%% of MultiXactIds are available for use.", + (double) (multiWrapLimit - result) / PG_INT32_MAX * 100), errhint("Execute a database-wide VACUUM in that database.\n" "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); else @@ -1127,6 +1129,8 @@ GetNewMultiXactId(int nmembers, MultiXactOffset *offset) multiWrapLimit - result, oldest_datoid, multiWrapLimit - result), + errdetail("Approximately %.2f%% of MultiXactIds are available for use.", + (double) (multiWrapLimit - result) / PG_INT32_MAX * 100), errhint("Execute a database-wide VACUUM in that database.\n" "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); } @@ -1225,6 +1229,8 @@ GetNewMultiXactId(int nmembers, MultiXactOffset *offset) MultiXactState->offsetStopLimit - nextOffset + nmembers, MultiXactState->oldestMultiXactDB, MultiXactState->offsetStopLimit - nextOffset + nmembers), + errdetail("Approximately %.2f%% of multixact members are available for use.", + (double) (MultiXactState->offsetStopLimit - nextOffset + nmembers) / PG_INT32_MAX * 100), errhint("Execute a database-wide VACUUM in that database with reduced \"vacuum_multixact_freeze_min_age\" and \"vacuum_multixact_freeze_table_age\" settings."))); ExtendMultiXactMember(nextOffset, nmembers); @@ -2414,6 +2420,8 @@ SetMultiXactIdLimit(MultiXactId oldest_datminmxid, Oid oldest_datoid, multiWrapLimit - curMulti, oldest_datname, multiWrapLimit - curMulti), + errdetail("Approximately %.2f%% of MultiXactIds are available for use.", + (double) (multiWrapLimit - curMulti) / PG_INT32_MAX * 100), errhint("To avoid MultiXactId assignment failures, execute a database-wide VACUUM in that database.\n" "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); else @@ -2423,6 +2431,8 @@ SetMultiXactIdLimit(MultiXactId oldest_datminmxid, Oid oldest_datoid, multiWrapLimit - curMulti, oldest_datoid, multiWrapLimit - curMulti), + errdetail("Approximately %.2f%% of MultiXactIds are available for use.", + (double) (multiWrapLimit - curMulti) / PG_INT32_MAX * 100), errhint("To avoid MultiXactId assignment failures, execute a database-wide VACUUM in that database.\n" "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); } diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c index f8c4dada7c9..962396bae10 100644 --- a/src/backend/access/transam/varsup.c +++ b/src/backend/access/transam/varsup.c @@ -175,6 +175,8 @@ GetNewTransactionId(bool isSubXact) (errmsg("database \"%s\" must be vacuumed within %u transactions", oldest_datname, xidWrapLimit - xid), + errdetail("Approximately %.2f%% of transaction IDs are available for use.", + (double) (xidWrapLimit - xid) / PG_INT32_MAX * 100), errhint("To avoid transaction ID assignment failures, execute a database-wide VACUUM in that database.\n" "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); else @@ -182,6 +184,8 @@ GetNewTransactionId(bool isSubXact) (errmsg("database with OID %u must be vacuumed within %u transactions", oldest_datoid, xidWrapLimit - xid), + errdetail("Approximately %.2f%% of transaction IDs are available for use.", + (double) (xidWrapLimit - xid) / PG_INT32_MAX * 100), errhint("To avoid XID assignment failures, execute a database-wide VACUUM in that database.\n" "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); } @@ -490,6 +494,8 @@ SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid) (errmsg("database \"%s\" must be vacuumed within %u transactions", oldest_datname, xidWrapLimit - curXid), + errdetail("Approximately %.2f%% of transaction IDs are available for use.", + (double) (xidWrapLimit - curXid) / PG_INT32_MAX * 100), errhint("To avoid XID assignment failures, execute a database-wide VACUUM in that database.\n" "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); else @@ -497,6 +503,8 @@ SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid) (errmsg("database with OID %u must be vacuumed within %u transactions", oldest_datoid, xidWrapLimit - curXid), + errdetail("Approximately %.2f%% of transaction IDs are available for use.", + (double) (xidWrapLimit - curXid) / PG_INT32_MAX * 100), errhint("To avoid XID assignment failures, execute a database-wide VACUUM in that database.\n" "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); } -- 2.39.5 (Apple Git-154) --i7+bPtDlPvAbCgMY Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0002-Bump-transaction-ID-limit-to-warn-at-100M.patch From 6555ccd8910420f365a253f03327e0067bc0ca66 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 14 Nov 2025 10:28:52 -0600 Subject: [PATCH v1 2/3] Bump transaction ID limit to warn at 100M. --- doc/src/sgml/maintenance.sgml | 4 ++-- src/backend/access/transam/multixact.c | 6 +++--- src/backend/access/transam/varsup.c | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/src/sgml/maintenance.sgml b/doc/src/sgml/maintenance.sgml index b89278ef032..8a12bd5f65a 100644 --- a/doc/src/sgml/maintenance.sgml +++ b/doc/src/sgml/maintenance.sgml @@ -670,7 +670,7 @@ SELECT datname, age(datfrozenxid) FROM pg_database; If for some reason autovacuum fails to clear old XIDs from a table, the system will begin to emit warning messages like this when the database's - oldest XIDs reach forty million transactions from the wraparound point: + oldest XIDs reach one hundred million transactions from the wraparound point: WARNING: database "mydb" must be vacuumed within 39985967 transactions @@ -824,7 +824,7 @@ HINT: Execute a database-wide VACUUM in that database. Similar to the XID case, if autovacuum fails to clear old MXIDs from a table, the - system will begin to emit warning messages when the database's oldest MXIDs reach forty + system will begin to emit warning messages when the database's oldest MXIDs reach one hundred million transactions from the wraparound point. And, just as in the XID case, if these warnings are ignored, the system will refuse to generate new MXIDs once there are fewer than three million left until wraparound. diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c index 63eb2548da1..67810ea489a 100644 --- a/src/backend/access/transam/multixact.c +++ b/src/backend/access/transam/multixact.c @@ -2327,16 +2327,16 @@ SetMultiXactIdLimit(MultiXactId oldest_datminmxid, Oid oldest_datoid, multiStopLimit -= FirstMultiXactId; /* - * We'll start complaining loudly when we get within 40M multis of data + * We'll start complaining loudly when we get within 100M multis of data * loss. This is kind of arbitrary, but if you let your gas gauge get - * down to 2% of full, would you be looking for the next gas station? We + * down to 5% of full, would you be looking for the next gas station? We * need to be fairly liberal about this number because there are lots of * scenarios where most transactions are done by automatic clients that * won't pay attention to warnings. (No, we're not gonna make this * configurable. If you know enough to configure it, you know enough to * not get in this kind of trouble in the first place.) */ - multiWarnLimit = multiWrapLimit - 40000000; + multiWarnLimit = multiWrapLimit - 100000000; if (multiWarnLimit < FirstMultiXactId) multiWarnLimit -= FirstMultiXactId; diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c index 962396bae10..5585381bc8c 100644 --- a/src/backend/access/transam/varsup.c +++ b/src/backend/access/transam/varsup.c @@ -411,16 +411,16 @@ SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid) xidStopLimit -= FirstNormalTransactionId; /* - * We'll start complaining loudly when we get within 40M transactions of + * We'll start complaining loudly when we get within 100M transactions of * data loss. This is kind of arbitrary, but if you let your gas gauge - * get down to 2% of full, would you be looking for the next gas station? + * get down to 5% of full, would you be looking for the next gas station? * We need to be fairly liberal about this number because there are lots * of scenarios where most transactions are done by automatic clients that * won't pay attention to warnings. (No, we're not gonna make this * configurable. If you know enough to configure it, you know enough to * not get in this kind of trouble in the first place.) */ - xidWarnLimit = xidWrapLimit - 40000000; + xidWarnLimit = xidWrapLimit - 100000000; if (xidWarnLimit < FirstNormalTransactionId) xidWarnLimit -= FirstNormalTransactionId; -- 2.39.5 (Apple Git-154) --i7+bPtDlPvAbCgMY Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v1-0003-Perodically-emit-server-logs-when-fewer-than-500M.patch From 65c2776462f6023108b1586afc9b9b17927a5bd9 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 14 Nov 2025 10:48:35 -0600 Subject: [PATCH v1 3/3] Perodically emit server logs when fewer than 500M remaining transaction IDs. --- src/backend/access/transam/multixact.c | 40 +++++++++++++++++++++++--- src/backend/access/transam/varsup.c | 40 +++++++++++++++++++++++--- src/include/access/transam.h | 5 ++-- 3 files changed, 75 insertions(+), 10 deletions(-) diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c index 67810ea489a..159ae5efb80 100644 --- a/src/backend/access/transam/multixact.c +++ b/src/backend/access/transam/multixact.c @@ -264,6 +264,7 @@ typedef struct MultiXactStateData /* support for anti-wraparound measures */ MultiXactId multiVacLimit; + MultiXactId multiLogLimit; MultiXactId multiWarnLimit; MultiXactId multiStopLimit; MultiXactId multiWrapLimit; @@ -1048,6 +1049,7 @@ GetNewMultiXactId(int nmembers, MultiXactOffset *offset) * If we're past multiVacLimit or the safe threshold for member storage * space, or we don't know what the safe threshold for member storage is, * start trying to force autovacuum cycles. + * If we're past multiLogLimit, start issuing logs periodically. * If we're past multiWarnLimit, start issuing warnings. * If we're past multiStopLimit, refuse to create new MultiXactIds. * @@ -1063,6 +1065,7 @@ GetNewMultiXactId(int nmembers, MultiXactOffset *offset) * possibility of deadlock while doing get_database_name(). First, * copy all the shared values we'll need in this path. */ + MultiXactId multiLogLimit = MultiXactState->multiLogLimit; MultiXactId multiWarnLimit = MultiXactState->multiWarnLimit; MultiXactId multiStopLimit = MultiXactState->multiStopLimit; MultiXactId multiWrapLimit = MultiXactState->multiWrapLimit; @@ -1106,13 +1109,27 @@ GetNewMultiXactId(int nmembers, MultiXactOffset *offset) if (IsUnderPostmaster && (result % 65536) == 0) SendPostmasterSignal(PMSIGNAL_START_AUTOVAC_LAUNCHER); - if (!MultiXactIdPrecedes(result, multiWarnLimit)) + if (!MultiXactIdPrecedes(result, multiWarnLimit) || + (!MultiXactIdPrecedes(result, multiLogLimit) && + result % 1000000 == 0)) { char *oldest_datname = get_database_name(oldest_datoid); + int elevel; + + /* + * We only send the periodic warnings to the server log in an + * attempt to avoid confusion from clients (since the WARNING will + * disappear for 1M multis at a time). Once the warning limit is + * reached, we emit a proper WARNING every time. + */ + if (!MultiXactIdPrecedes(result, multiWarnLimit)) + elevel = WARNING; + else + elevel = LOG_SERVER_ONLY; /* complain even if that DB has disappeared */ if (oldest_datname) - ereport(WARNING, + ereport(elevel, (errmsg_plural("database \"%s\" must be vacuumed before %u more MultiXactId is used", "database \"%s\" must be vacuumed before %u more MultiXactIds are used", multiWrapLimit - result, @@ -1123,7 +1140,7 @@ GetNewMultiXactId(int nmembers, MultiXactOffset *offset) errhint("Execute a database-wide VACUUM in that database.\n" "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); else - ereport(WARNING, + ereport(elevel, (errmsg_plural("database with OID %u must be vacuumed before %u more MultiXactId is used", "database with OID %u must be vacuumed before %u more MultiXactIds are used", multiWrapLimit - result, @@ -2299,6 +2316,7 @@ SetMultiXactIdLimit(MultiXactId oldest_datminmxid, Oid oldest_datoid, bool is_startup) { MultiXactId multiVacLimit; + MultiXactId multiLogLimit; MultiXactId multiWarnLimit; MultiXactId multiStopLimit; MultiXactId multiWrapLimit; @@ -2340,6 +2358,15 @@ SetMultiXactIdLimit(MultiXactId oldest_datminmxid, Oid oldest_datoid, if (multiWarnLimit < FirstMultiXactId) multiWarnLimit -= FirstMultiXactId; + /* + * We'll start complaining every 1M multis when we get within 500M multis + * of data loss. The idea is to provide an early warning system that is + * less noisy than multiWarnLimit but provides ample time to react. + */ + multiLogLimit = multiWrapLimit - 500000000; + if (multiLogLimit < FirstMultiXactId) + multiLogLimit -= FirstMultiXactId; + /* * We'll start trying to force autovacuums when oldest_datminmxid gets to * be more than autovacuum_multixact_freeze_max_age mxids old. @@ -2357,6 +2384,7 @@ SetMultiXactIdLimit(MultiXactId oldest_datminmxid, Oid oldest_datoid, MultiXactState->oldestMultiXactId = oldest_datminmxid; MultiXactState->oldestMultiXactDB = oldest_datoid; MultiXactState->multiVacLimit = multiVacLimit; + MultiXactState->multiLogLimit = multiLogLimit; MultiXactState->multiWarnLimit = multiWarnLimit; MultiXactState->multiStopLimit = multiStopLimit; MultiXactState->multiWrapLimit = multiWrapLimit; @@ -2394,7 +2422,11 @@ SetMultiXactIdLimit(MultiXactId oldest_datminmxid, Oid oldest_datoid, needs_offset_vacuum) && IsUnderPostmaster) SendPostmasterSignal(PMSIGNAL_START_AUTOVAC_LAUNCHER); - /* Give an immediate warning if past the wrap warn point */ + /* + * Give an immediate warning if past the wrap warn point. We don't bother + * with multiLogLimit here, as it's unlikely to apply. We leave that part + * to GetNewMultiXactId() instead. + */ if (MultiXactIdPrecedes(multiWarnLimit, curMulti)) { char *oldest_datname; diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c index 5585381bc8c..74ba958eb7a 100644 --- a/src/backend/access/transam/varsup.c +++ b/src/backend/access/transam/varsup.c @@ -112,6 +112,7 @@ GetNewTransactionId(bool isSubXact) * catastrophic data loss due to XID wraparound. The basic rules are: * * If we're past xidVacLimit, start trying to force autovacuum cycles. + * If we're past xidLogLimit, start issuing logs periodically. * If we're past xidWarnLimit, start issuing warnings. * If we're past xidStopLimit, refuse to execute transactions, unless * we are running in single-user mode (which gives an escape hatch @@ -129,6 +130,7 @@ GetNewTransactionId(bool isSubXact) * possibility of deadlock while doing get_database_name(). First, * copy all the shared values we'll need in this path. */ + TransactionId xidLogLimit = TransamVariables->xidLogLimit; TransactionId xidWarnLimit = TransamVariables->xidWarnLimit; TransactionId xidStopLimit = TransamVariables->xidStopLimit; TransactionId xidWrapLimit = TransamVariables->xidWrapLimit; @@ -165,13 +167,27 @@ GetNewTransactionId(bool isSubXact) errhint("Execute a database-wide VACUUM in that database.\n" "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); } - else if (TransactionIdFollowsOrEquals(xid, xidWarnLimit)) + else if (TransactionIdFollowsOrEquals(xid, xidWarnLimit) || + (TransactionIdFollowsOrEquals(xid, xidLogLimit) && + xid % 1000000 == 0)) { char *oldest_datname = get_database_name(oldest_datoid); + int elevel; + + /* + * We only send the periodic warnings to the server log in an + * attempt to avoid confusion from clients (since the WARNING will + * disappear for 1M transactions at a time). Once the warning + * limit is reached, we emit a proper WARNING every time. + */ + if (TransactionIdFollowsOrEquals(xid, xidWarnLimit)) + elevel = WARNING; + else + elevel = LOG_SERVER_ONLY; /* complain even if that DB has disappeared */ if (oldest_datname) - ereport(WARNING, + ereport(elevel, (errmsg("database \"%s\" must be vacuumed within %u transactions", oldest_datname, xidWrapLimit - xid), @@ -180,7 +196,7 @@ GetNewTransactionId(bool isSubXact) errhint("To avoid transaction ID assignment failures, execute a database-wide VACUUM in that database.\n" "You might also need to commit or roll back old prepared transactions, or drop stale replication slots."))); else - ereport(WARNING, + ereport(elevel, (errmsg("database with OID %u must be vacuumed within %u transactions", oldest_datoid, xidWrapLimit - xid), @@ -376,6 +392,7 @@ void SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid) { TransactionId xidVacLimit; + TransactionId xidLogLimit; TransactionId xidWarnLimit; TransactionId xidStopLimit; TransactionId xidWrapLimit; @@ -424,6 +441,16 @@ SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid) if (xidWarnLimit < FirstNormalTransactionId) xidWarnLimit -= FirstNormalTransactionId; + /* + * We'll start complaining every 1M transactions when we get within 500M + * transactions of data loss. The idea is to provide an early warning + * system that is less noisy than xidWarnLimit but provides ample time to + * react. + */ + xidLogLimit = xidWrapLimit - 500000000; + if (xidLogLimit < FirstNormalTransactionId) + xidLogLimit -= FirstNormalTransactionId; + /* * We'll start trying to force autovacuums when oldest_datfrozenxid gets * to be more than autovacuum_freeze_max_age transactions old. @@ -447,6 +474,7 @@ SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid) LWLockAcquire(XidGenLock, LW_EXCLUSIVE); TransamVariables->oldestXid = oldest_datfrozenxid; TransamVariables->xidVacLimit = xidVacLimit; + TransamVariables->xidLogLimit = xidLogLimit; TransamVariables->xidWarnLimit = xidWarnLimit; TransamVariables->xidStopLimit = xidStopLimit; TransamVariables->xidWrapLimit = xidWrapLimit; @@ -470,7 +498,11 @@ SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid) IsUnderPostmaster && !InRecovery) SendPostmasterSignal(PMSIGNAL_START_AUTOVAC_LAUNCHER); - /* Give an immediate warning if past the wrap warn point */ + /* + * Give an immediate warning if past the wrap warn point. We don't bother + * with xidLogLimit here, as it's unlikely to apply. We leave that part + * to GetNewTransactionId() instead. + */ if (TransactionIdFollowsOrEquals(curXid, xidWarnLimit) && !InRecovery) { char *oldest_datname; diff --git a/src/include/access/transam.h b/src/include/access/transam.h index c9e20418275..a1bd4259f86 100644 --- a/src/include/access/transam.h +++ b/src/include/access/transam.h @@ -203,8 +203,8 @@ FullTransactionIdAdvance(FullTransactionId *dest) * LWLocks. * * Note: xidWrapLimit and oldestXidDB are not "active" values, but are - * used just to generate useful messages when xidWarnLimit or xidStopLimit - * are exceeded. + * used just to generate useful messages when xidLogLimit, xidWarnLimit, or + * xidStopLimit are exceeded. */ typedef struct TransamVariablesData { @@ -221,6 +221,7 @@ typedef struct TransamVariablesData TransactionId oldestXid; /* cluster-wide minimum datfrozenxid */ TransactionId xidVacLimit; /* start forcing autovacuums here */ + TransactionId xidLogLimit; /* start logging periodically here */ TransactionId xidWarnLimit; /* start complaining here */ TransactionId xidStopLimit; /* refuse to advance nextXid beyond here */ TransactionId xidWrapLimit; /* where the world ends */ -- 2.39.5 (Apple Git-154) --i7+bPtDlPvAbCgMY--