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 1w7dXK-005Y4z-2f for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2026 18:09:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w7dXJ-00C3Ou-0c for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2026 18:09:57 +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 1w7dXI-00C3Og-2V for pgsql-hackers@lists.postgresql.org; Tue, 31 Mar 2026 18:09:57 +0000 Received: from mail-oa1-x29.google.com ([2001:4860:4864:20::29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w7dXH-000000020ZQ-0gc7 for pgsql-hackers@postgresql.org; Tue, 31 Mar 2026 18:09:56 +0000 Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-40ea611d1a4so2402384fac.2 for ; Tue, 31 Mar 2026 11:09:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774980595; cv=none; d=google.com; s=arc-20240605; b=YbgWOKLzbGiMT0unVVBUgbni473H7DPAYsED953Eh2cq3L13qyOwGjKTu8njb1m76P uUX/+mTKITnDOi6z4gitxP24rUrDXiMHNBpmp+mKjhVaOl5Y7ts6kpYMcBmSLHRcbvrF IlJ2iBSIslB3tS9ozA2lfGv/czWOgzcWXsZEjVGA6GcBX1FgjeG4UN/s8h6VDD/EOEIN fAcyVfF60X8K2hlRrbHOqEM/AvSHOufu9QmPFEpM6/d63b22yQPDmfWG07GUSqn5aPS7 yNY7w+c2Y1zamJ6fx56FxtYx0Vgto3708FDyQkwHvfCXak5Nu3k4+mX0vydJfelrPC5w qh1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=dbgPop8L8xNY0zOWMnhxvp+vKx1PLK0VdjoNUSvweHk=; fh=nPMgw8J3ozwuzFJjatJjx2HXYBtSmkz7NE3Z3TMDtmQ=; b=Olej1dPaHQCukI7NPhhnp7velSoW+1e2L2Bvp3b1a/Rn/zyzhKgySz0y6CWfWve7At cut2uLVNU9K/rxKKzvwhU4lX5DYIdcVrzyIVHNpzzqGFeBVCdJIu6mvFYaItLYexsJzi BxfzAWGf/UkUS1fHg43K/fRS/4ZKPN/J61jdaghPsKiEQLkjxeyW8y6fne2eM82rNnHB eEI+ki9BtCuCwboemI6Suqlrim3ECP6hxaTMc++zr8v0yuvzmweW3HwWmyTXBSrTFXCf lFroS6PaCIqc6J3w0bfRiIahv+4wu+qQAA5MiorEPt3wn1/yrcsH4fEdFpIO/EZsPoCF 9wmw==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774980595; x=1775585395; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=dbgPop8L8xNY0zOWMnhxvp+vKx1PLK0VdjoNUSvweHk=; b=Kyw+ejVcXVK9CORLLdEQu8IV5jSJVKxsMFuC9EBpsxcnJfkRMFEC1qfyOeoGJkkZSD qV9uNyRs9rRFFEkT35L9c0LPtlz1EpXiAmp4GKgwNcUtS+FV4gg13gDWr20l3eZLPoHN aVTnkCJiZLOwqRJcCObA4NIj2gR5JrhvB5lscwctJejTdQj95D/KjI5vpXm20MasVm99 jToxLvp+fzAQCLvTplX3HjtSFmBes2U95REm0P+dU4vHr++m/O1CPa2qfUAmz6YSdl2I DuBWfV5ddzATZiLZcmwqctXbJ/IDVjhelk8QlvHjMtJgp9VCw5MHBgIluosmC6F9d1nB CjxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774980595; x=1775585395; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=dbgPop8L8xNY0zOWMnhxvp+vKx1PLK0VdjoNUSvweHk=; b=jcsrBgHqte1JwUoQ9i6Fv+4S/anl/Erx08DkhuNbJI42KR+tm01YuykYDKWt8o1mbi P3D6wOE4etS/d8NgBzXaKZfejhPOQWfk+AHvQ0AKkQg8oh2pUcyhkJxugl+HZ+Z0aRPZ ZocC5S0hCGfSPkRh8lyv6M7gb0FzioQoXmnTL8d3NG5CQmzj+8/ldGLSdv4TFUcxAoLX BN/oz/w557Wb7mIuurCdTSo5S+UXyUmfVYQ7GmGz5XZi7PjBny+9XkET682AJErBOCoP n/REIfXmmq7ragqMvdiVtRwzoXVuOEcWlZqlEHE8knTxxCVP68teUlXLPIGv2n2tpkLl zPoQ== X-Forwarded-Encrypted: i=1; AJvYcCWZHnysjLm6pMV143vEg0KSvaS9A79evkzRtKi13+k2cVusZLrgVGkY+rLLcIMn3EEhbpXoY4S7fOKBzrn3@postgresql.org X-Gm-Message-State: AOJu0YwxaCnqoseELJOdE61sYcOlD47AhZVMFSxQC4dsBmSpgKCjJbqp OWnOdwHpMck3y6zFp+iMDlXI1G+63uYFrrYNP2J7jZ6mnywBzt73dEJp7leTOTf8SGDiIP6fHgv C7YZuXyAYgR8FoB/LXWXMcHT55cVzyJz74ZI2aQE= X-Gm-Gg: ATEYQzyR47YORPxqU50EBOkElaB9ugh14mQX5qUznbs9yd819NbjaVw9AdErAPkOPel 4VLxuZ37rrYLk35+6mXdrDL41XehL8UDjU0yCh7SM+4hj7+DcXQHzuw13eySSi1p4OhPq2j2wLV KZ7vDI6NLUQUYn03jNvdor7qqO96vxx8E83DHnsUmb9Ekdoya/JPB2NGW4fRhnen8bZXxjX+OKK 8ntxXosFJ0SRiP4xXpWe8sKfFRhpz7qryyOy7KUx1zzdGSwec6ynbBHvboJKM6ZUTMCBWX6+lfQ g+3S/dpLpUKOIQvCL5pDTEkPXclNi+obcr/SUFwV X-Received: by 2002:a05:6820:1506:b0:67e:313e:22bf with SMTP id 006d021491bc7-67fabccb503mr139090eaf.31.1774980594710; Tue, 31 Mar 2026 11:09:54 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bharath Rupireddy Date: Tue, 31 Mar 2026 11:09:43 -0700 X-Gm-Features: AQROBzA_E94FVMILTeBkDQY3WEmajXWLr7XyLk5bbbYsz_RWbPf6oYyJbSeHW3o Message-ID: Subject: Re: Add pg_stat_autovacuum_priority To: Sami Imseih Cc: Robert Treat , satyanarlapuram@gmail.com, pgsql-hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Mon, Mar 30, 2026 at 11:16=E2=80=AFAM Sami Imseih = wrote: > > > I think we are also in agreement here, although based on my > > experience, filtering out things like system and toast tables will be > > common, but I don't see that changing what you said above. On a > > similar note, +1 to your changes in v2. > > Thanks! > > v3 now includes the refactoring [1] suggestion brought up by Alvarro Thank you for sending the latest patches. Here are some comments: 1/ + while ((classTup =3D heap_getnext(relScan, ForwardScanDirection)) !=3D= NULL) Missing check_for_interrupts call while scanning the pg_class system catalo= g. 2/ + avopts =3D extract_autovac_opts(classTup, pg_class_desc); + + compute_autovac_score(classTup, pg_class_desc, + effective_multixact_freeze_max_age, avopts, + true, &dovacuum, &doanalyze, + &wraparound, &scores); + + if (avopts) + pfree(avopts); + When a database has a large number of tables (which is quite common in production scenarios), I expect the costs of palloc and pfree being used for fetching autovacuum relopts would make this function slower. Can we invent a new function or pass a caller-allocated AutoVacOpts memory to just copy the relopts and use that in this tight loop when scanning for all the relations? 3/ + values[8] =3D Float8GetDatum(scores.vac_ins); + values[9] =3D Float8GetDatum(scores.anl); Nit: It's a matter of taste. How about using something like below instead of hardcoded column numbers? I expect this view to grow in the future, so it helps to keep things simple. values[i++] =3D Float8GetDatum(scores.anl); Assert(i =3D=3D NUM_AV_SCORE_COLS); 4/ + The + pg_stat_autovacuum_priority view can = be + used to inspect each table's autovacuum need and priority score. How about adding "as of the moment" to convey that it doesn't report what currently running autovacuum or pending autovacuum would consider? 5/ Also, can we add a simple paragraph on how to interpret and take actions based on the scores reported (like prioritizing one table over the other - adjust these parameters in the table's relopts or something like that - no need to cover all the possible cases, but just one example would be sufficient for the user to understand)? 6/ + descr =3D> 'statistics: autovacuum priority scores for all relations'= , s/"for all relations"/"for all relations in the current database" 7/ Addition of force_scores to relation_needs_vacanalyze makes the code unreadable (IMO) with a lot of if-else branching. Why not make force_vacuum an option and pass it as true from the stats function and leave a note in the function comment on when to use this parameter? Would something like that work? Also, when autovacuum is disabled (either via GUC or via relopts), we don't want to calculate and report any scores. IMHO, this keeps things simple and code readable. -- Bharath Rupireddy Amazon Web Services: https://aws.amazon.com