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 1jpQfm-0006GG-FB for pgsql-hackers@arkaria.postgresql.org; Sun, 28 Jun 2020 06:20:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jpQfl-0004Qx-CR for pgsql-hackers@arkaria.postgresql.org; Sun, 28 Jun 2020 06:20:13 +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 1jpQfk-0004Qe-QL for pgsql-hackers@lists.postgresql.org; Sun, 28 Jun 2020 06:20:13 +0000 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jpQfh-0001Wc-W6 for pgsql-hackers@postgresql.org; Sun, 28 Jun 2020 06:20:11 +0000 Received: by mail-pj1-x1041.google.com with SMTP id gc9so199756pjb.2 for ; Sat, 27 Jun 2020 23:20:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=SVkvqUqj2Pc9776ldm/+3N7V+VmwBbMeJF/SasVEqvQ=; b=CggS1Z55wUVZp4t8WXnWfpk3kIjFIC/FyM1JVoBaV9pdu00qdenuKM9D/675suORRw fBcJyW1Ergj+WRkEyJnwYc316T2iipT7XZhTJKz+VnmufBMqI4koypAzd4//cyCeHvrD IpUJdiCR1WIZ8c3J8oRl714fTw84hf6ywQePc= 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:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=SVkvqUqj2Pc9776ldm/+3N7V+VmwBbMeJF/SasVEqvQ=; b=Xv7JE8o83bJ+zFSrAP/jrdVdPM+EsAgf2cazWjZqsmBPseXgXgjFDGUzdilHe1rSZv 3ukXws+UNHDjsU+/sHFrRd7cghKPGIt3EuAu2kwP++PmwXaUnodu8LdHbUMXyZ+4uDgA vKqNOT9pto4Ik8RcsGmUSLo7v3yDYHZ9I4TjC5ATP7g8OC0eq8YQRpm3fWFLfb403mbH y0uyHKpTePXmbXh0/seEsSHjAAv6J9SWswRBDhOR+2+lEcThoWOU0iEmQcgt06t7QY4M bY2589vBcmYfT5l+56n2QVUoB4R7b4C0DcP3mTZwzj5enSz478kZ9G0lzDsws2YeQc5U p+ng== X-Gm-Message-State: AOAM532f6cGwwINNkeJamb02X9s+RA8Su6yCMQi/1DHqdYJWOBUlV5f8 6Jalma6E+SPhWFrkJB8cCr+gM6T9Nog= X-Google-Smtp-Source: ABdhPJyLnWaM419yB3hM2JWE17QvWG3oygIbstfZoPntKfE6Nremla5O3rfNGE0Hqzs/DXOHeDspYQ== X-Received: by 2002:a17:90a:65c5:: with SMTP id i5mr11485338pjs.155.1593325207831; Sat, 27 Jun 2020 23:20:07 -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 m92sm13528981pje.13.2020.06.27.23.20.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Jun 2020 23:20:06 -0700 (PDT) Date: Sat, 27 Jun 2020 23:20:04 -0700 From: Noah Misch To: pgsql-hackers@postgresql.org Subject: Re: Raising stop and warn limits Message-ID: <20200628062004.GA3366199@rfd.leadboat.com> References: <20200621083513.GA3074645@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="TB36FDmn/VVEgNH/" Content-Disposition: inline In-Reply-To: <20200621083513.GA3074645@rfd.leadboat.com> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sun, Jun 21, 2020 at 01:35:13AM -0700, Noah Misch wrote: > In brief, I'm proposing to raise xidWrapLimit-xidStopLimit to 3M and > xidWrapLimit-xidWarnLimit to 40M. Likewise for mxact counterparts. Here's the patch for it. > 1. VACUUM, to advance a limit, may assign IDs subject to one of the limits. > VACUUM formerly consumed XIDs, not mxacts. It now consumes mxacts, not > XIDs. Correction: a lazy_truncate_heap() at wal_level!=minimal does assign an XID, so XID consumption is impossible with "VACUUM (TRUNCATE false)" but possible otherwise. "VACUUM (ANALYZE)", which a DBA might do by reflex, also assigns XIDs. (These corrections do not affect $SUBJECT.) --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="stop-limits-v1.patch" Author: Noah Misch Commit: Noah Misch Change XID and mxact limits to warn at 40M and stop at 3M. We have edge-case bugs when assigning values in the last few dozen pages before the wrap limit. We may introduce similar bugs in the future. At default BLCKSZ, this makes such bugs unreachable outside of single-user mode. Also, when VACUUM began to consume mxacts, multiStopLimit did not change to compensate. pg_upgrade may fail on a cluster that was already printing "must be vacuumed" warnings. Follow the warning's instructions to clear the warning, then run pg_upgrade again. One can still, peacefully consume 98% of XIDs or mxacts, so DBAs need not change routine VACUUM settings. Reviewed by FIXME. Discussion: https://postgr.es/m/20200621083513.GA3074645@rfd.leadboat.com diff --git a/doc/src/sgml/maintenance.sgml b/doc/src/sgml/maintenance.sgml index 612e4cb..a28ea56 100644 --- a/doc/src/sgml/maintenance.sgml +++ b/doc/src/sgml/maintenance.sgml @@ -608,10 +608,10 @@ 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 eleven million transactions from the wraparound point: + oldest XIDs reach forty million transactions from the wraparound point: -WARNING: database "mydb" must be vacuumed within 10985967 transactions +WARNING: database "mydb" must be vacuumed within 39985967 transactions HINT: To avoid a database shutdown, execute a database-wide VACUUM in that database. @@ -621,7 +621,7 @@ HINT: To avoid a database shutdown, execute a database-wide VACUUM in that data be able to advance the database's datfrozenxid.) If these warnings are ignored, the system will shut down and refuse to start any new - transactions once there are fewer than 1 million transactions left + transactions once there are fewer than three million transactions left until wraparound: @@ -629,7 +629,7 @@ ERROR: database is not accepting commands to avoid wraparound data loss in data HINT: Stop the postmaster and vacuum that database in single-user mode. - The 1-million-transaction safety margin exists to let the + The three-million-transaction safety margin exists to let the administrator recover without data loss, by manually executing the required VACUUM commands. However, since the system will not execute commands once it has gone into the safety shutdown mode, diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c index ce84dac..475f5ed 100644 --- a/src/backend/access/transam/multixact.c +++ b/src/backend/access/transam/multixact.c @@ -2217,28 +2217,24 @@ SetMultiXactIdLimit(MultiXactId oldest_datminmxid, Oid oldest_datoid, multiWrapLimit += FirstMultiXactId; /* - * We'll refuse to continue assigning MultiXactIds once we get within 100 - * multi of data loss. - * - * Note: This differs from the magic number used in - * SetTransactionIdLimit() since vacuum itself will never generate new - * multis. XXX actually it does, if it needs to freeze old multis. + * We'll refuse to continue assigning MultiXactIds once we get within 3M + * multi of data loss. See SetTransactionIdLimit. */ - multiStopLimit = multiWrapLimit - 100; + multiStopLimit = multiWrapLimit - 3000000; if (multiStopLimit < FirstMultiXactId) multiStopLimit -= FirstMultiXactId; /* - * We'll start complaining loudly when we get within 10M multis of the - * stop point. This is kind of arbitrary, but if you let your gas gauge - * get down to 1% 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 + * We'll start complaining loudly when we get within 40M 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 + * 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 = multiStopLimit - 10000000; + multiWarnLimit = multiWrapLimit - 40000000; if (multiWarnLimit < FirstMultiXactId) multiWarnLimit -= FirstMultiXactId; diff --git a/src/backend/access/transam/varsup.c b/src/backend/access/transam/varsup.c index e14b53b..0142bc7 100644 --- a/src/backend/access/transam/varsup.c +++ b/src/backend/access/transam/varsup.c @@ -350,27 +350,30 @@ SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid) /* * We'll refuse to continue assigning XIDs in interactive mode once we get - * within 1M transactions of data loss. This leaves lots of room for the + * within 3M transactions of data loss. This leaves lots of room for the * DBA to fool around fixing things in a standalone backend, while not * being significant compared to total XID space. (Note that since * vacuuming requires one transaction per table cleaned, we had better be - * sure there's lots of XIDs left...) + * sure there's lots of XIDs left...) Also, at default BLCKSZ, this + * leaves two completely-idle segments. In the event of edge-case bugs + * involving page or segment arithmetic, idle segments render the bugs + * unreachable outside of single-user mode. */ - xidStopLimit = xidWrapLimit - 1000000; + xidStopLimit = xidWrapLimit - 3000000; if (xidStopLimit < FirstNormalTransactionId) xidStopLimit -= FirstNormalTransactionId; /* - * We'll start complaining loudly when we get within 10M transactions of - * the stop point. This is kind of arbitrary, but if you let your gas - * gauge get down to 1% 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.) + * 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.) */ - xidWarnLimit = xidStopLimit - 10000000; + xidWarnLimit = xidWrapLimit - 40000000; if (xidWarnLimit < FirstNormalTransactionId) xidWarnLimit -= FirstNormalTransactionId; --TB36FDmn/VVEgNH/--