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 1sVOYQ-009ajN-Qh for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Jul 2024 04:52:14 +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 1sVOYN-005uaJ-8A for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Jul 2024 04:52:11 +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 1sVOYM-005uaB-Up for pgsql-hackers@lists.postgresql.org; Sun, 21 Jul 2024 04:52:11 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sVOYF-000eqH-Mh for pgsql-hackers@lists.postgresql.org; Sun, 21 Jul 2024 04:52:09 +0000 Received: from [172.20.10.7] (sp49-97-70-160.msc.spmode.ne.jp [49.97.70.160]) by oss.nttdata.com (Postfix) with ESMTPSA id 8C02E619AD; Sun, 21 Jul 2024 13:51:57 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at oss.nttdata.com Message-ID: <8acb1f83-2945-42cf-8795-780c94bbed36@oss.nttdata.com> Date: Sun, 21 Jul 2024 13:51:56 +0900 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Provide a pg_truncate_freespacemap function To: Ronan Dunklau , Stephen Frost Cc: pgsql-hackers@lists.postgresql.org References: <5446938.Sb9uPGUboI@aivenlaptop> <4331161.ejJDZkT8p0@aivenlaptop> Content-Language: en-US From: Fujii Masao In-Reply-To: <4331161.ejJDZkT8p0@aivenlaptop> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024/03/07 16:59, Ronan Dunklau wrote: > Le mercredi 6 mars 2024, 20:28:44 CET Stephen Frost a écrit : >> I agree that this would generally be a useful thing to have. > > Thanks ! > >> >>> Does that seem correct ? >> >> Definitely needs to have a 'REVOKE ALL ON FUNCTION' at the end of the >> upgrade script, similar to what you'll find at the bottom of >> pg_visibility--1.1.sql in the tree today, otherwise anyone could run it. >> >> Beyond that, I'd suggest a function-level comment above the definition >> of the function itself (which is where we tend to put those- not at the >> point where we declare the function). > > Thank you for the review. Here is an updated patch for both of those. Here are my review comments: The documentation for pg_freespace needs updating. A regression test for pg_truncate_freespace_map() should be added. + /* Only some relkinds have a freespace map */ + if (!RELKIND_HAS_TABLE_AM(rel->rd_rel->relkind)) + ereport(ERROR, + (errcode(ERRCODE_WRONG_OBJECT_TYPE), + errmsg("relation \"%s\" is of wrong relation kind", + RelationGetRelationName(rel)), + errdetail_relkind_not_supported(rel->rd_rel->relkind))); An index can have an FSM, but this code doesn't account for that. + smgrtruncate(RelationGetSmgr(rel), &fork, 1, &block); Shouldn't truncation be performed after WAL-logging due to the WAL rule? I'm not sure if the current order might actually cause significant issues in FSM truncation case, though. Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION