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 1wAXUW-0004Sw-1C for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Apr 2026 18:19:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wAXUU-001GJ3-2K for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Apr 2026 18:19:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wAXUU-001GIv-1T for pgsql-hackers@lists.postgresql.org; Wed, 08 Apr 2026 18:19:03 +0000 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wAXUS-000000002Ce-3zzY for pgsql-hackers@postgresql.org; Wed, 08 Apr 2026 18:19:02 +0000 Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-46eca92a29bso15962b6e.0 for ; Wed, 08 Apr 2026 11:19:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775672340; x=1776277140; 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=1RKT/880jrxO5j0YuiVwsr2h5su/4RmnrzYb+K+RSUM=; b=B9Pyoiq1TLoxTpTFTNiq3uYcKEQ87WHHdeEnwewpy70MAGqRN+/g1k1IcjrWanf73C Ipd0sGfh2S8bwEEZ8sHvverp70rj75JBqXYkoZsvOWequ4RkAsNkKlbmWbNjP9V/SRYT jtpEo/YLe1TtAg7MIAMjt/3qsfImxTKZo7plz2vor4/iB8ytuBo9BHQasgCUHYJJR2DF WyiAGemND9a2TaR2zRs2za2O+lKNC1BdinqcUtXf+WshdwT3Xk/mKZCpHOvCWdFvYbpO Wm17VxOjdLe5z9PBJQJp3BKLS0rc1FMf1XUGGYy1ENEApUg085fFm2vcO+Am+sm69GYY ci0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775672340; x=1776277140; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1RKT/880jrxO5j0YuiVwsr2h5su/4RmnrzYb+K+RSUM=; b=EVinCvtP48cbjNZEwdGFhTYWuKkCj5WWCK9yxSW4Ft83PJhepPQKByrRjYEduuWVeT fevQ1hmWUAO0lTJ5BRWPGrXCXh8mamJRut4TuEwjMQM89hT0DpUM0vz2aLyPoraEw/ai lWlobGLVhDVgUhIAcwrgOX8GqFJOcyTj+zKfe1vqBc+hinpjjQ/bARZCSaYuRmLOBl2r pWwBYlCPxFmGihXDMQ6af5MhmCpwcXFPhrC/3TtYxMKj6Eu8mpEQgLQSXq5gxrieL7qw r1fB+HDgEs67rEmUZdXmvUGXeSY69T3VgyFRPWTKBKsdzfxA4xH2SlOTGy2teo4rEj6Q e3Tg== X-Forwarded-Encrypted: i=1; AJvYcCUo8yWqYT3vCNLnQHz29W69omUT+i1D34xEvmWJA6Q8hEo5GSUZYIdcSgjR42AWRsvsBQFCpG7oQ06ObDlR@postgresql.org X-Gm-Message-State: AOJu0YzYcyHmSB1WHKdK90OCjISc6cJ2vOFiW5JYRieJ67gII7m5aQ0b ke14l8nRBhSXWA6AakOxIsxdDahmvwpxpwh1zT3wX6qMVDIA2eb9Gb1e X-Gm-Gg: AeBDietfPDNYKHuUCkG5HuFkhoM9duzrwEmATQ4mlpW8g0rX4yCY3Ezaz/7uiZkUMrh UvwCGxi0Q6IwI5oUmXe5Ro+uH8Mk6P6LsoeSK0Te0/hghKW3d1+MSO4N/bhL2M7ppG5EC7GAvss LwGykfSH6hLQEyOarm/m/AYMGy9TewU8dOSxSghpsikukmZ07PIfJD8c93DIO5gxnI6Y/5El0Ef sYj6dTJpNXCMwzkYNhbW+dOisbKBA87qVWzStQnHTCLecR5QXuqKirBd6ghp0/pb7Yeza9n7UMc vuyGWpI6DZ9MDDIJ94GTJjKJ0qjFYaNjAMNf/TymcRtAiEq3JmMa1bXAecaNm237sVrOG6f3cKs PI6kyPdFHneGBVv3d+IqpaRIX1PfhvydEH1S4pB2uTxxbzct9GzaESs+psw0ruKwGqM+5WNkjsS 1aDSEwftzA6u90sGehlGGYkNDQ9gG7t2j1dzXSQGa1NYbFafqluZApiQ7mocZrHBo+NyE1ABHRn c4GYtA1c/zzIQrrA7te515qqyDzalA8 X-Received: by 2002:a05:6808:c414:b0:468:776:1ec3 with SMTP id 5614622812f47-477238794f7mr369893b6e.24.1775672340609; Wed, 08 Apr 2026 11:19:00 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 5614622812f47-46d9387a763sm12229333b6e.18.2026.04.08.11.18.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2026 11:19:00 -0700 (PDT) Date: Wed, 8 Apr 2026 13:18:58 -0500 From: Nathan Bossart To: Tom Lane Cc: Alexander Lakhin , Sami Imseih , Bharath Rupireddy , Robert Treat , satyanarlapuram@gmail.com, pgsql-hackers , tndrwang@gmail.com Subject: Re: Add pg_stat_autovacuum_priority Message-ID: References: <5684f479-858e-4c5d-b8f5-bcf05de1f909@gmail.com> <3077290.1775668665@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Apr 08, 2026 at 12:56:09PM -0500, Nathan Bossart wrote: > Hm. I can't get excited about checking pgstat_fetch_consistency (as > proposed in that other report), but I see that commit 02502c1bca added the > freeing behavior in question. I wonder if it makes sense to just skip > freeing when relation_needs_vacanalyze() is called from the view, i.e., not > an autovacuum worker. On the other hand, maybe we shouldn't be caching > entries for a view like this that looks through all tables in the > database... Concretely, this is what I'm thinking: diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index bd626a16363..6d4a34257fb 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -3327,7 +3327,15 @@ relation_needs_vacanalyze(Oid relid, anltuples, anlthresh, scores->anl, scores->xid, scores->mxid); - pfree(tabentry); + /* + * Avoid leaking pgstat entries until the end of autovacuum. Elsewhere, + * we let the commit/abort machinery take care of freeing it. While + * autovacuum workers set stats_fetch_consistency to "none", it might be + * set to a different value in other processes, so we can't safely free it + * here for them. + */ + if (AmAutoVacuumWorkerProcess()) + pfree(tabentry); } /* -- nathan