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 1vVSC6-003yaW-2o for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Dec 2025 10:22:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vVSC5-005opg-2i for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Dec 2025 10:22:14 +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 1vVSC5-005opX-0S for pgsql-hackers@lists.postgresql.org; Tue, 16 Dec 2025 10:22:14 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vVSC1-000wnh-2y for pgsql-hackers@lists.postgresql.org; Tue, 16 Dec 2025 10:22:13 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4779cb0a33fso53289905e9.0 for ; Tue, 16 Dec 2025 02:22:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765880528; x=1766485328; darn=lists.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=nFb4Mc0ajQJLuBV27CJjXVWcJUEK7By7EsH54lvr8Wo=; b=Ux9I3oospZAHrEgDsK6ZxSRnLphLUuBtz6m4lgVfKb1dNToGsNGtQY0LhfIZzEeH37 17O4uw/nnhyqg1bq3Mh/FLPD2ZOte+GZ1hB9FETfZcV/pC/HLwnqFNevdSAB5M/AhBj6 npsE5GZ6HyyCv/7C+Tmn04dl9apljQO4C2m4ONyzttkHXyMnB5fPjYtGr2gPaV+sZWmp D0FgLTcJrhwnplFatJfObX7HoFqm4wYEz0HF4GCAfIi8U57UY1tlBvBn9XtV0UFQ63YS iKTBGCw+pbNF3gSyJBs1ysYlZFq3weup+0GZvtJFtTM6I+hjKFzQVyDtkqQbbGRNhdR8 KD/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765880528; x=1766485328; 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=nFb4Mc0ajQJLuBV27CJjXVWcJUEK7By7EsH54lvr8Wo=; b=jDB+Iam9C90MGEWXESrd2lcEI6P53QL0ktzCSDSYshZ/24wT1PXxfsPE1/z1ZQwKg2 HvIOD0alQ8VFU+wuK7aiV6ljsehD4B6DjUO2mntDjioKPn1enAIu3saoI09P4zD4agUO yFnpy7ES6xZPYbZSeDtyT8HVzXC6tfQg07I8Mw/uPGeTVtbXheQJebsPgNMJZ6MF0kkF NmCjrC25j0/2SVdcxxtI426GK4mkgOnFNRSkzDRsVc1jljT7vpTFyUuTRuCO+cCZUsYo 5cB9rbDYhPuVIii3Ryt0deiNkNQTATYDK/wxtvhDs5ERpJ7F0oMRncvXMfqq8SlewsNZ Jdmg== X-Forwarded-Encrypted: i=1; AJvYcCWbm8itRt7SJJjpNm2wWZHBslCuro54f5XnH/vVWZfw8S7qSm6Vm/rPnbTbsd6Q0pmH0BbtzIfgz/wj74zM@lists.postgresql.org X-Gm-Message-State: AOJu0YwzodR3V6Tu8J+yqEPyoRJ0sSlOdaRvgu42YcV8HydTK6kcX9c7 QJUfKbT/1yj3Oqh+Ho3oDIJ1GsNlKZGJvLmjGvJ7gabMFir1p/dfqhjb X-Gm-Gg: AY/fxX55m2c4e2sRRYjtEinmwjPXYHfq3mwBsTw+vyOZvZ9s4g0E9+hl4HzLajD3bXy UGzYfehywSSBxr9OfKZDQHIHrune9Y1qXWsyB9CHOM3Hkm6aODBjyeBjZ7JrVIlDlIwlOEyqDb/ HTbl85nZr62KOpv7Tga01b3xV82I09EvbksfekeH/jRdBQ0JVOfcRHzAl1EcUDZupCnI9xqWcX+ NufS5ji5pKTyYNQeJH3x0wWzrYFeEfrFH3/Mp2zcus2jEMQQicx5q1M0m4ooDaVc5kZwYzgvZSp iimBi0vh41ty0na6BDnyBONkgqdwrBY4L2pptJneTs75O7hK9/NkHv6S+JiI/KxGCESHgj3PQnF cJfuOfsbbx3NxP/QWFWnA6YWxsidbcQKhjl0ILNLQyBJAZ8j3y11km0a1O0ItG4ffjiU4uzigvv /y6HGA3VZ4gjBhiaOnk1+d4IdBwHbD9M/W9T6U+mWIlF3MGceUQgyFDtt53DdMZ3hZ9FEgiyv5n OVPrl6xqsIpQazCdQYyiQQZMSY5dvrtvBRA3Sl/s8GTFQ== X-Google-Smtp-Source: AGHT+IECpGR6oxwQupKDImEmaQntbP78kZYkYUPfrsUI3bVIt6WDspWAsSNNOZexclEh9tc0eoixqQ== X-Received: by 2002:a05:600c:8b62:b0:477:abea:901c with SMTP id 5b1f17b1804b1-47a953da53fmr106145645e9.11.1765880527981; Tue, 16 Dec 2025 02:22:07 -0800 (PST) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47a957de489sm273454995e9.5.2025.12.16.02.22.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Dec 2025 02:22:07 -0800 (PST) Date: Tue, 16 Dec 2025 10:22:06 +0000 From: Bertrand Drouvot To: Andres Freund Cc: Michael Paquier , Kirill Reshke , Robert Haas , pgsql-hackers@lists.postgresql.org Subject: Re: relfilenode statistics Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="tV2Nti+lXhoeT6I5" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --tV2Nti+lXhoeT6I5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On Mon, Dec 15, 2025 at 12:48:25PM -0500, Andres Freund wrote: > On 2025-12-15 16:29:18 +0000, Bertrand Drouvot wrote: > > From 7908ba56cb8b6255b869af6be13077aa0315d5f1 Mon Sep 17 00:00:00 2001 > > I think this needs to make more explicit that this works because the object ID > now is a uint64, and that both the inputs are 32 bits. Yeah, it's now added in the commit message (mentioning b14e9ce7d55c). > > diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c > > index 62035b7f9c3..a9b2b4e1033 100644 > > --- a/src/backend/access/heap/vacuumlazy.c > > +++ b/src/backend/access/heap/vacuumlazy.c > > @@ -961,8 +961,7 @@ heap_vacuum_rel(Relation rel, const VacuumParams params, > > * soon in cases where the failsafe prevented significant amounts of heap > > * vacuuming. > > */ > > - pgstat_report_vacuum(RelationGetRelid(rel), > > - rel->rd_rel->relisshared, > > + pgstat_report_vacuum(rel->rd_locator, > > Max(vacrel->new_live_tuples, 0), > > vacrel->recently_dead_tuples + > > vacrel->missed_dead_tuples, > > Why not pass in the Relation itself? Given that we do that already for > pgstat_report_analyze(), it seems like that'd be an improvement even > independent of this change? Makes sense, done in [1]. > > diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c > > index 1bd3924e35e..563a3697690 100644 > > --- a/src/backend/postmaster/autovacuum.c > > +++ b/src/backend/postmaster/autovacuum.c > > @@ -2048,8 +2048,7 @@ do_autovacuum(void) > > > > /* Fetch reloptions and the pgstat entry for this table */ > > relopts = extract_autovac_opts(tuple, pg_class_desc); > > - tabentry = pgstat_fetch_stat_tabentry_ext(classForm->relisshared, > > - relid); > > + tabentry = pgstat_fetch_stat_tabentry_ext(relid); > > > > /* Check if it needs vacuum or analyze */ > > relation_needs_vacanalyze(relid, relopts, classForm, tabentry, > > I don't think this is good - now do_autovacuum() will do a separate syscache > lookup to fetch information the caller already has (due to the > pgstat_reloid_to_relfilelocator() in pgstat_fetch_stat_tabentry_ext()). That's > not too bad for things like viewing stats, but do_autovacuum() does this for > every table in a database... Good point. In the attached I added pgstat_fetch_stat_tabentry_by_locator(). It's called directly in do_autovacuum() and also in pgstat_fetch_stat_tabentry_ext(). I did not check if there are other places where we can call pgstat_fetch_stat_tabentry_by_locator() directly. I want first to validate this idea makes sense, does it? > I don't think this is true as stated. Two reasons: > > 1) This afaict guarantees that the relfilenode will not class with oids, but > it does *NOT* guarantee that it does not clash with other relfilenodes > 2) Note that GetNewRelFileNumber() does *NOT* check for conflicts when > creating a new relfilenode for an existing relation: > * If the relfilenumber will also be used as the relation's OID, pass the > * opened pg_class catalog, and this routine will guarantee that the result > * is also an unused OID within pg_class. If the result is to be used only > * as a relfilenumber for an existing relation, pass NULL for pg_class. Oh right, in case of OID wraparound. In the attached I added a new " #define PSEUDO_PARTITION_TABLE_SPCOID 1665 " to ensure uniqueness then. [1]: https://www.postgresql.org/message-id/flat/aUEA6UZZkDCQFgSA%40ip-10-97-1-34.eu-west-3.compute.internal Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com --tV2Nti+lXhoeT6I5 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0001-Key-PGSTAT_KIND_RELATION-by-relfile-locator.patch"