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 1tkOSU-003VSe-JS for pgsql-general@arkaria.postgresql.org; Tue, 18 Feb 2025 14:20:22 +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 1tkOST-00Aj7z-9c for pgsql-general@arkaria.postgresql.org; Tue, 18 Feb 2025 14:20:21 +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.94.2) (envelope-from ) id 1tk2nU-00GpPL-5W for pgsql-general@lists.postgresql.org; Mon, 17 Feb 2025 15:12:36 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tk2nS-001Joy-1J for pgsql-general@lists.postgresql.org; Mon, 17 Feb 2025 15:12:35 +0000 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5ded46f323fso5645189a12.1 for ; Mon, 17 Feb 2025 07:12:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739805153; x=1740409953; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=4vDOQjkay6b9Jjt0+v8tdFXQunFsJYxL4XBv36HDBvU=; b=OFAmPbUUYUe4hIEP/OgXpqSV0mYO/wgtI84NWPn0FY9ZIqkYJlANTI+7BdkT5pQ904 ugyHCynRdlWHJyksmi9YF2FxLzzOyjYdO1R0LcuY3XeHwHEpiKYT1ke4BiEI9LmxveQD FC4eEOEbvPFa6P3YtKGvvn5w3N+gm2aPS0hhKwkvK6HUTbFWuw7DIVBNRik3WtDG+Saz vVTTecUrqpPrextUHJL7Qte6NJJjt8ICqRwE713DwlXzjoFWBZsqKAE6DsZ+fx0y2ben XMT5os8lR2MOpR1AmHhg8ueEU8Xazoukupdmb6N/dnCHC2KwtQIdA+qWgCpucSpIgoaj njRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739805153; x=1740409953; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4vDOQjkay6b9Jjt0+v8tdFXQunFsJYxL4XBv36HDBvU=; b=MraxT0F4kfT37lFFwHLbMCo7nw1L8i/YMZ362WiXaUdoWxe/B2AGcaca50Ij7wdGxs 4SsRsO8WtGK/EcmGuci1Gsvu9rxizeYfaPAsy8p9sqz2EDBrsDex54smOgrGj+80OoId AM50qOaOMouFww+iKiQq86Kx+CWtUmw8Ak9w5rU46VmD3je4XJrAklcMttM2hWEWTyZc l85VDEszyQfhqcMyXpKZaUe1EdIb/i37V5MBofo0UzIe/BqLEdog/MLEztXWqRx7TPHN +owfE0tBSMpTJ+OOQdHChUi7YT+/lEkKLhYGyayUvDiXSQFcrPfAouHj3Ox2HdIOzli8 MufQ== X-Gm-Message-State: AOJu0YwhrGRDQwWIXaWBMI4vVG9uQAk5AFPwKX08pVxdzU9O74O+4o8u OEQaxe4rx1VQiCNQImzf2+t8uw1RjUHyxOYJTXb2CMa/r3Rx1r+a0Ja0jrvEew5M63+hwicwgtc 2in2FcxMB2KDjmvNdEiPkP35VAgXSZsXV X-Gm-Gg: ASbGnctCMFsIfSEDZTxdIFbfxMBkQJTyeW7DcAp2vEd29XvSZW+9ztU2hrhcELDxvRJ KsfhP7W8IxjlTo+nXtt7xjFmZZjkwJ7XAtihsi13G6k+1GGoJlNgA5ofNeptmjvNz4JO2wg== X-Google-Smtp-Source: AGHT+IENzU+hKh/XHOGoIwhmSt+sAHPFRpIugM/qzGRxLud4NRTG0xc6neAJLCIbQ/2se3I7Ckx9Cj48rmmcduDVGZs= X-Received: by 2002:a17:907:97d2:b0:ab7:8e0d:3d3c with SMTP id a640c23a62f3a-abb70dd71e8mr946321966b.42.1739805152468; Mon, 17 Feb 2025 07:12:32 -0800 (PST) MIME-Version: 1.0 From: Rucha Kulkarni Date: Mon, 17 Feb 2025 20:42:15 +0530 X-Gm-Features: AWEUYZnhFJZ5QtkBlc7jwdpBK47ct8F7eRVN9dA3VvrVLyGKuRbj9JRBHlXMaIs Message-ID: Subject: Doubts regarding pg_freespacemap extension To: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000176637062e57f4c6" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000176637062e57f4c6 Content-Type: text/plain; charset="UTF-8" Hi PostgreSQL Community, While exploring the pg_freespacemap extension, I came across a few doubts and would appreciate any insights or clarifications: 1. In the code, it defines NonLeafNodesPerPage as (BLCKSZ / 2 - 1) as can be seen here: https://github.com/postgres/postgres/blob/master/src/include/storage/fsm_internals.h#L54 For a binary tree, (BLCKSZ - 1) / 2 seems more appropriate when calculating the number of non-leaf nodes. Why does the code approximate it to (BLCKSZ / 2) - 1 ? 2. According to the comment mentioned here https://github.com/postgres/postgres/blob/master/src/backend/storage/freespace/indexfsm.c#L19 , 0 is used to denote unused pages and (BLCKSZ - 1) for used pages for indexes. This seems reversed, shouldn't 0 indicate space available for used pages, and (BLCKSZ - 1) indicate space available for unused pages? 3. Whenever I check the values for B-tree indexes, I observe all values to be 0. postgres=# select * from pg_freespace('xyz_btree'); blkno | avail -------+------- 0 | 0 1 | 0 2 | 0 3 | 0 4 | 0 (5 rows) How can non-zero values be observed in B-tree indexes? 4. For BRIN indexes, I see a value of 8128 instead of 8191 (BLCKSZ - 1). Is this due to the BRIN header occupying space, leading to category 254? postgres=# select * from pg_freespace('xyz_brin'); blkno | avail -------+------- 0 | 0 1 | 0 2 | 8128 (3 rows) Regards, Rucha Kulkarni --000000000000176637062e57f4c6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hi PostgreSQL Community,

While exploring the pg_f= reespacemap extension, I came across a few doubts and would appreciate any = insights or clarifications:

1. In the code, it defines NonLeafNodesPe= rPage as (BLCKSZ / 2 - 1) as can be seen here:

=C2=A0https://github.com/postgres/postgres/blob/master= /src/include/storage/fsm_internals.h#L54=C2=A0

For a binary tree, (BLCKSZ - 1) / 2=C2=A0seems more appropriate when calculati= ng the number of non-leaf nodes. Why does the code approximate it to=20 (BLCKSZ / 2) - 1 ?

2. According to the comment mentioned here https://github.com/postgres/postgr= es/blob/master/src/backend/storage/freespace/indexfsm.c#L19 , 0 is used= to denote unused pages and (BLCKSZ - 1) for used pages for indexes. This s= eems reversed, shouldn't 0 indicate space available for us= ed pages, and (BLCKSZ - 1)=C2=A0indicate space available for unused pages?<= br>
3. Whenever I check the values for B-tree indexes, I observe all val= ues to be 0.

postgres=3D# select * from pg_freespace('xyz_btree&#= 39;);
=C2=A0blkno | avail
-------+-------
=C2=A0 =C2=A0 =C2=A00 |= =C2=A0 =C2=A0 0
=C2=A0 =C2=A0 =C2=A01 | =C2=A0 =C2=A0 0
=C2=A0 =C2= =A0 =C2=A02 | =C2=A0 =C2=A0 0
=C2=A0 =C2=A0 =C2=A03 | =C2=A0 =C2=A0 0=C2=A0 =C2=A0 =C2=A04 | =C2=A0 =C2=A0 0
(5 rows)

How can non-zero= values be observed in B-tree indexes?

4. For BRIN indexes, I see a value of 8128 instead of 8191 (BLCKSZ - 1).=20 Is this due to the BRIN header occupying space, leading to category 254?

postgres=3D# select * from pg_freespace('xyz_brin');
=C2=A0b= lkno | avail
-------+-------
=C2=A0 =C2=A0 =C2=A00 | =C2=A0 =C2=A0 0=
=C2=A0 =C2=A0 =C2=A01 | =C2=A0 =C2=A0 0
=C2=A0 =C2=A0 =C2=A02 | =C2= =A08128
(3 rows)

Regards,

Rucha Kulkarni

--000000000000176637062e57f4c6--