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.94.2) (envelope-from ) id 1vDqqr-00HW5b-Bo for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Oct 2025 21:03:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vDqqq-00F6gu-8t for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Oct 2025 21:03:31 +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.94.2) (envelope-from ) id 1vDqqp-00F6gm-T3 for pgsql-hackers@lists.postgresql.org; Tue, 28 Oct 2025 21:03:30 +0000 Received: from mail-il1-x129.google.com ([2607:f8b0:4864:20::129]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vDqqm-004lP7-1v for pgsql-hackers@postgresql.org; Tue, 28 Oct 2025 21:03:30 +0000 Received: by mail-il1-x129.google.com with SMTP id e9e14a558f8ab-430ab5ee3afso62407235ab.2 for ; Tue, 28 Oct 2025 14:03:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761685406; x=1762290206; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=SnxAZHlmaUrvM9iMc5nD/G5MIBXyY+oWdoNxPj1JtXw=; b=hNbWppIYcljVhgvu0FteeyfyTroIQZKsHluWTR/khjhqfZK29/zGtnNuq9gCE5XQA+ jzRX4hfaTct6SDgMJ5TuTluJT9UWnk+SJD7X8nMF/ztxCeAOjxR5aD3NlncwOlKtJmTA 8LmtLs/gvtfZDSW/Un58xtFLajP5kOzW6EVbldxxulUJUbV4ZbskPloiDP2Dyl55M/pk C+z/G2xAf1CwkV2CgukCVtPDQzclyz93rsI6dvlN+15NLpmMm3EHEsnod3pNa97AW4yV k3Uri3kMItK30fvLWX3OS/20uqw5V2do9HLeeAJkqQAQ5GJLUNjx4+/8UTb4/y/epfUK YtsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761685406; x=1762290206; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=SnxAZHlmaUrvM9iMc5nD/G5MIBXyY+oWdoNxPj1JtXw=; b=Hajb1TWvS4J5IB3CGu/yZckMd29nXfSxuxUU+dpdGcvqTdi5iCMgzoDBvX73jtn28c 0Gs7asuA+8RXijG8ODm1yrLSA0bpgIfB7bW2a1nl3bQvNkrgFu6+G4oSlUCbWm2LLL6L RUTkvgaR/ClWfGiycKm1DG0zMQTeuJKLcIx6d04LTrbuG2tTzz9hh+RyBHU/RAJzNF4g 1Q6EsluhQch6JYE81B3kXW90AipFY78nGBhd5ug/VPNO2a2sL9XkCYaVvja1UwiYM1d3 I3nNNh+Tal0uCouqe73YUEV/A1OvnaB8QT3RntA7sT2vykUlVlxcbKUzrW/UDQAc0opu locQ== X-Forwarded-Encrypted: i=1; AJvYcCUeSns3Nko6gavMI4yjwirErtOEkmoPmHHfwiWQZg4VF+sMOI/MDWP+KqHJC7/ow2lTGJRGEWLmEPDj1d4C@postgresql.org X-Gm-Message-State: AOJu0Ywp+L46EwdZFcnG/SbtYLg+qKu6rgbzczjaUgsvl1b/aUo8JP+E hppcj3asomqjuRsJtV7cWeEQOQn+AM0yvU/BHRwiS4fN6B32aikw+MYx2odTGQ== X-Gm-Gg: ASbGncsQNeacOM75lVEdhoqmYYor+YjHPBhFPV9h9ldY2+hXx8LyB+LNcQmpVwrF4F0 wus2TlEW2g1uZ5TUwrX35pjew/2MRKCP9GAF+d5/RXySZk8xsb+SP/AmCLaeRtpD6lxNmZ/SVle cT9Nq9+Ibga4ZXFLPAAcxgkxeBHIsagtjbnbll9wMDUGWLNFE/04IKQr5YQX/PhdEPWf3IGnnax VaHnnKBGNSXOsWN4Mx2uoDJxeIvj1LidTenRpXrlSyAQozuY/LRVhWNb1tgx1YO/PEM6O0dYDHj 9VkfMKDdOusIuP/+muqpfP6zwO4bzbyBzUuO9uLADn0iQaPzNYbNXjetfQPi0Ve6DaUJrsJyOFP dwtL6emLRdZNp9Nwy5R+evPKyRybA8wfhG7RAMkpMuzZUFrXlEalsxa24gqBVblrUoTmEykaDcf qsYKBuqHOVRofpdVfoLTLySj3t5R9uxKtdXQMIsJbhOEQ4O3fjJrgfzbWQbYmFbhTMfoDiFTdEB krU X-Google-Smtp-Source: AGHT+IHjT2Muyh1KztAJQ+oI8oZQ5UImpqgnTJSQxTAfQOw7UBpVgU6AyTPRCGCif6FtEye2HWvkGg== X-Received: by 2002:a05:6e02:1563:b0:432:f835:2576 with SMTP id e9e14a558f8ab-432f904dfd1mr7270545ab.27.1761685406311; Tue, 28 Oct 2025 14:03:26 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-5aea78e1a56sm4749747173.18.2025.10.28.14.03.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Oct 2025 14:03:25 -0700 (PDT) Date: Tue, 28 Oct 2025 16:03:23 -0500 From: Nathan Bossart To: David Rowley Cc: Sami Imseih , Robert Haas , Jeremy Schneider , pgsql-hackers@postgresql.org Subject: Re: another autovacuum scheduling thread Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="skXIAVxeHUwbMCMJ" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --skXIAVxeHUwbMCMJ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Oct 28, 2025 at 11:47:08AM +1300, David Rowley wrote: > 1. I think the following code at the bottom of > relation_needs_vacanalyze() can be deleted. You've added the check to > ensure *doanalyze never gets set to true for pg_statistic. > > /* ANALYZE refuses to work with pg_statistic */ > if (relid == StatisticRelationId) > *doanalyze = false; > > 2. As #1, but in recheck_relation_needs_vacanalyze(), the following I > think can now be removed: > > /* ignore ANALYZE for toast tables */ > if (classForm->relkind == RELKIND_TOASTVALUE) > *doanalyze = false; Removed. > 3. Would you be able to include what the idea behind the * 1.05 in the > preceding comment? > > On Tue, 28 Oct 2025 at 05:06, Nathan Bossart wrote: >> + effective_xid_failsafe_age = Max(vacuum_failsafe_age, >> + autovacuum_freeze_max_age * 1.05); >> + effective_mxid_failsafe_age = Max(vacuum_multixact_failsafe_age, >> + autovacuum_multixact_freeze_max_age * 1.05); > > I assume it's to workaround some strange configuration settings, but > don't know for sure, or why 1.05 is a good value. This is lifted from vacuum_xid_failsafe_check(). As noted in the docs, the failsafe settings are silently limited to 105% of *_freeze_max_age. I expanded on this in the comment atop these lines. > 4. I think it might be neater to format the following as 3 separate "if" tests: > >> + if (force_vacuum || >> + vactuples > vacthresh || >> + (vac_ins_base_thresh >= 0 && instuples > vacinsthresh)) >> + { >> + *dovacuum = true; >> + *score = Max(*score, (double) vactuples / Max(vacthresh, 1)); >> + if (vac_ins_base_thresh >= 0) >> + *score = Max(*score, (double) instuples / Max(vacinsthresh, 1)); >> + } >> + else >> + *dovacuum = false; > > i.e: > > if (force_vacuum) > *dovacuum = true; > > if (vactuples > vacthresh) > { > *dovacuum = true; > *score = Max(*score, (double) vactuples / Max(vacthresh, 1)); > } > > if (vac_ins_base_thresh >= 0 && instuples > vacinsthresh) > { > *dovacuum = true; > *score = Max(*score, (double) instuples / Max(vacinsthresh, 1)); > } > > and also get rid of all the "else *dovacuum = false;" (and *dovacuum = > false) in favour of setting those to false at the top of the function. > It's just getting harder to track that those parameters are getting > set in all cases when they're meant to be. > > doing that also gets rid of the duplicative "if (vac_ins_base_thresh > >= 0)" check and also saves doing the score calc when the inputs to it > don't make sense. The current code is relying on Max always picking > the current *score when the threshold isn't met. Done. -- nathan --skXIAVxeHUwbMCMJ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=v6-0001-autovacuum-scheduling-improvements.patch