=?UTF-8?B?5aSn5aGa5oay5Y+4?= <otsuka.kenji@nttcom.co.jp> writes:
> It seems that description of index_size that is returned by pgstatindex() is wrong.
> The document says "Total number of pages in index".
> But it looks like the number of bytes is stored in index_size.
Hmm, you're right, because what the code does is
values[j++] = psprintf(INT64_FORMAT,
(indexStat.root_pages +
indexStat.leaf_pages +
indexStat.internal_pages +
indexStat.deleted_pages +
indexStat.empty_pages) * BLCKSZ);
so the result is clearly measured in bytes not pages.
I was going to just change the docs to say "Total index size in bytes",
but then I noticed that this number is not that either: it does not
count the metapage and therefore is BLCKSZ less than the true file
size. As an example:
regression=# select * from pgstatindex('tenk1_unique1');
version | tree_level | index_size | root_block_no | internal_pages | leaf_pages
| empty_pages | deleted_pages | avg_leaf_density | leaf_fragmentation
---------+------------+------------+---------------+----------------+-----------
-+-------------+---------------+------------------+--------------------
2 | 1 | 237568 | 3 | 0 | 28
| 0 | 0 | 87.91 | 0
(1 row)
regression=# select relfilenode from pg_class where relname = 'tenk1_unique1';
relfilenode
-------------
27449
(1 row)
$ ls -l 27449
-rw-------. 1 postgres postgres 245760 Feb 17 18:58 27449
I think this is a bug and we ought to fix the code to include the
metapage in the reported index_size. Thoughts?
regards, tom lane