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 1jmvRn-0002KK-6u for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Jun 2020 08:35:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jmvRk-0004yK-Ru for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Jun 2020 08:35:24 +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 1jmvRk-0004yB-BA for pgsql-hackers@lists.postgresql.org; Sun, 21 Jun 2020 08:35:24 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jmvRh-0001ho-4g for pgsql-hackers@postgresql.org; Sun, 21 Jun 2020 08:35:23 +0000 Received: by mail-pl1-x643.google.com with SMTP id k1so6135282pls.2 for ; Sun, 21 Jun 2020 01:35:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=XdPZ9IsFbkknd9zp/wsqy9uLWeVWdJ5TtHcb8Y8XbAk=; b=ZsGYJB5B4kP3wlhz8eWIcX7hV/gKGYfZNNahxdSeoN/ybUlLoDVdvqlf2W4XnSzyXC IXO8pRNA11ZLQvwsMEWEhfo16Gq6DsxzjbQZKDz81Opx+m+SJObwssDD3IhkEGav9777 JFLOYMlCoMtCHQXJ8riksshuSmFJIWX6V7XAY= 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:mime-version :content-disposition:user-agent; bh=XdPZ9IsFbkknd9zp/wsqy9uLWeVWdJ5TtHcb8Y8XbAk=; b=ACTNCtbuAsR9C22YfRL6cx1aEsuZ01PLvfMvQErzITpegkYscdpCmiaVHhNmwX/qke dqxZm5NEdMxoTXi5U1TcETcaZkBzDG2WNuO5Ec8QEDn2yCd0YKc4/bAA1aZe9SueDtBh U+WgG9lAXuB2/MEmRT48qCrvGtyUX7X43Ru7z94VX2Sspb77j+MBaxzanQMiE6xA3WEa CymJ26JRYWbykN428QncTPx3xUAajED1pZ0gleRnCQ9nSwR98pyRbWT9YQo3cFmTbjof Agr3xkEjBr8jRaO1jDxAQJYGVB6FRDnUrUyYoMmU925QxDglZQqQWcxxnqNN1FcOH2Qb OdFg== X-Gm-Message-State: AOAM533dzw4fNxEJuTT4RA/QtL6MwDVX6EWB0sseOpeokNGDnT4Ad/ws fNj64FnpD6hRrkAql6eGBLAaDLp34c4= X-Google-Smtp-Source: ABdhPJzI7M4KGExpuLqilPHgrypUkyct30dI8nz3gEu0efDd0MPwxDKiBasjd28Zn2nLxgTGVMo39g== X-Received: by 2002:a17:90b:1013:: with SMTP id gm19mr12428796pjb.231.1592728517502; Sun, 21 Jun 2020 01:35:17 -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 x18sm10527917pfr.106.2020.06.21.01.35.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Jun 2020 01:35:16 -0700 (PDT) Date: Sun, 21 Jun 2020 01:35:13 -0700 From: Noah Misch To: pgsql-hackers@postgresql.org Subject: Raising stop and warn limits Message-ID: <20200621083513.GA3074645@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="T4sUOijqQbZv57TR" Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --T4sUOijqQbZv57TR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In brief, I'm proposing to raise xidWrapLimit-xidStopLimit to 3M and xidWrapLimit-xidWarnLimit to 40M. Likewise for mxact counterparts. PostgreSQL has three "stop limit" values beyond which only single-user mode will assign new values of a certain counter: - xidStopLimit protects pg_xact, pg_commit_ts, pg_subtrans, and pg_serial. SetTransactionIdLimit() withholds a million XIDs, and warnings start ten million before that. - multiStopLimit protects pg_multixact/offsets. SetMultiXactIdLimit() withholds 100 mxacts, and warnings start at ten million. - offsetStopLimit protects pg_multixact/members. SetOffsetVacuumLimit() withholds [1,2) SLRU segments thereof (50k-100k member XIDs). No warning phase for this one. Reasons to like a larger stop limit: 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. I think a DBA can suppress VACUUM's mxact consumption by stopping all transactions older than vacuum_freeze_min_age, including prepared transactions. 2. We currently have edge-case bugs when assigning values in the last few dozen pages before the wrap limit (https://postgr.es/m/20190214072623.GA1139206@rfd.leadboat.com and https://postgr.es/m/20200525070033.GA1591335@rfd.leadboat.com). A higher stop limit could make this class of bug unreachable outside of single-user mode. That's valuable against undiscovered bugs of this class. 3. Any bug in stop limit enforcement is less likely to have user impact. For a live example, see the XXX comment that https://postgr.es/m/attachment/111084/slru-truncate-modulo-v3.patch adds to CheckPointPredicate(). Raising a stop limit prompts an examination of warn limits, which represent the time separating the initial torrent of warnings from the service outage. The current limits appeared in 2005; transaction rates have grown, while human reaction times have not. I like warnings starting when an SLRU is 98% consumed (40M XIDs or mxacts remaining). That doesn't change things enough to make folks reconfigure VACUUM, and it buys back some of the grace period DBAs had in 2005. I considered 95-97%, but the max_val of autovacuum_freeze_max_age would then start the warnings before the autovacuum. While that wouldn't rule out a value lower than 98%, 98% felt fine anyhow. For the new stop limits, I propose allowing 99.85% SLRU fullness (stop with 3M XIDs or mxacts remaining). If stopping this early will bother users, an alternative is 3M for XIDs and 0.2M for others. Either way leaves at least two completely-idle segments for each SLRU, which I expect to mitigate present and future edge-case bugs. Changing this does threaten clusters that experience pg_upgrade when close to a limit. pg_upgrade can fail or, worse, yield a cluster that spews warnings shortly after the upgrade. I could implement countermeasures, but they would take effect only when one upgrades a cluster having a 98%-full SLRU. I propose not to change pg_upgrade; some sites may find cause to do a whole-cluster VACUUM before pg_upgrade. Do you agree or disagree with that choice? I am attaching a patch (not for commit) that demonstrates the pg_upgrade behavior that nearly-full-SLRU clusters would see. Thanks, nm --T4sUOijqQbZv57TR Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="demo-upgrade-wrap-v0.patch" diff --git a/src/backend/access/transam/clog.c b/src/backend/access/transam/clog.c index f3da40a..c43ebbf 100644 --- a/src/backend/access/transam/clog.c +++ b/src/backend/access/transam/clog.c @@ -795,6 +795,10 @@ TrimCLOG(void) int slotno; char *byteptr; + /* hack for pg_resetwal moving us to the middle of a page */ + if (!SimpleLruDoesPhysicalPageExist(XactCtl, pageno)) + SimpleLruZeroPage(XactCtl, pageno); + slotno = SimpleLruReadPage(XactCtl, pageno, false, xid); byteptr = XactCtl->shared->page_buffer[slotno] + byteno; diff --git a/src/backend/access/transam/multixact.c b/src/backend/access/transam/multixact.c index ce84dac..ed47ce0 100644 --- a/src/backend/access/transam/multixact.c +++ b/src/backend/access/transam/multixact.c @@ -2042,6 +2042,10 @@ TrimMultiXact(void) int slotno; MultiXactOffset *offptr; + /* hack for pg_resetwal moving us to the middle of a page */ + if (!SimpleLruDoesPhysicalPageExist(MultiXactOffsetCtl, pageno)) + SimpleLruZeroPage(MultiXactOffsetCtl, pageno); + slotno = SimpleLruReadPage(MultiXactOffsetCtl, pageno, true, nextMXact); offptr = (MultiXactOffset *) MultiXactOffsetCtl->shared->page_buffer[slotno]; offptr += entryno; diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c index 2334418..454ff8b 100644 --- a/src/bin/pg_resetwal/pg_resetwal.c +++ b/src/bin/pg_resetwal/pg_resetwal.c @@ -434,6 +434,8 @@ main(int argc, char *argv[]) FullTransactionIdFromEpochAndXid(EpochFromFullTransactionId(ControlFile.checkPointCopy.nextFullXid), set_xid); + /* ruins testing of cases close to wraparound */ +#if 0 /* * For the moment, just set oldestXid to a value that will force * immediate autovacuum-for-wraparound. It's not clear whether adding @@ -445,6 +447,7 @@ main(int argc, char *argv[]) if (ControlFile.checkPointCopy.oldestXid < FirstNormalTransactionId) ControlFile.checkPointCopy.oldestXid += FirstNormalTransactionId; ControlFile.checkPointCopy.oldestXidDB = InvalidOid; +#endif } if (set_oldest_commit_ts_xid != 0) diff --git a/src/bin/pg_upgrade/test.sh b/src/bin/pg_upgrade/test.sh index 7ff06de..befa5bb 100644 --- a/src/bin/pg_upgrade/test.sh +++ b/src/bin/pg_upgrade/test.sh @@ -28,6 +28,7 @@ standard_initdb() { then cat "$TEMP_CONFIG" >> "$PGDATA/postgresql.conf" fi + echo "backtrace_functions = 'SlruReportIOError'" >> "$PGDATA/postgresql.conf" ../../test/regress/pg_regress --config-auth "$PGDATA" } @@ -202,7 +203,39 @@ if "$MAKE" -C "$oldsrc" installcheck-parallel; then else make_installcheck_status=$? fi + +# multixact alone between stop limit and wrap limit: no error +reset_args_sql=" +select format('--multixact-ids=%s,%s', + oldest_multi_xid::text::bigint + (1::bigint << 31) - 50, + oldest_multi_xid) +from pg_control_checkpoint(); +" +# xid and multixact between warn limit and stop limit, noisy but successful: +reset_args_sql=" +select format('--next-transaction-id=%s --multixact-ids=%s,%s', + oldest_xid::text::bigint + (1::bigint << 31) - 5e6, + oldest_multi_xid::text::bigint + (1::bigint << 31) - 5e6, + oldest_multi_xid) +from pg_control_checkpoint(); +" +# xid and multixact between stop limit and wrap limit will fail: +# Setting frozenxid and minmxid counters in new cluster SQL command failed +# UPDATE pg_catalog.pg_database SET datfrozenxid = '2147484095' +# ERROR: database is not accepting commands to avoid wraparound data loss in database "template0" +reset_args_sql=" +select format('--next-transaction-id=%s --multixact-ids=%s,%s', + oldest_xid::text::bigint + (1::bigint << 31) - 50, + oldest_multi_xid::text::bigint + (1::bigint << 31) - 50, + oldest_multi_xid) +from pg_control_checkpoint(); +" +reset_args=`psql -X -A -t -d template1 -c "$reset_args_sql"` "$oldbindir"/pg_ctl -m fast stop +"$oldbindir"/pg_controldata | tee "$logdir"/before | grep 'Next.*X' +"$oldbindir"/pg_resetwal $reset_args $PGDATA +"$oldbindir"/pg_controldata | tee "$logdir"/after | grep 'Next.*X' + if [ -n "$createdb_status" ]; then exit 1 fi --T4sUOijqQbZv57TR--