pg_class.relpages not updated for toast index

Started by Fabrízio de Royes Melloabout 2 years ago1 messages
#1Fabrízio de Royes Mello
fabriziomello@gmail.com

Hi all,

Was doing a relation size estimation based on pg_class.relpages of the
relation and the related objects (index, toast) and noticed that it is not
updated for the toast index, for example:

fabrizio=# CREATE TABLE t(c TEXT);
INSERT INTO t VALUES (repeat('x', (8192^2)::int));

VACUUM (ANALYZE) t;
CREATE TABLE
INSERT 0 1
VACUUM
fabrizio=# \x on
Expanded display is on.
fabrizio=# SELECT
c.oid,
c.relname,
c.relpages,
t.relname,
t.relpages AS toast_pages,
ci.relname,
ci.relpages AS toast_index_pages,
(pg_stat_file(pg_relation_filepath(ci.oid))).size AS toast_index_size
FROM
pg_class c
JOIN pg_class t ON t.oid = c.reltoastrelid
JOIN pg_index i ON i.indrelid = t.oid
JOIN pg_class ci ON ci.oid = i.indexrelid
WHERE
c.oid = 't'::regclass;
-[ RECORD 1 ]-----+---------------------
oid | 17787
relname | t
relpages | 1
relname | pg_toast_17787
toast_pages | 97
relname | pg_toast_17787_index
toast_index_pages | 1
toast_index_size | 16384

Are there any reasons for toast index relpages not to be updated? Or is it
a bug?

Regards,

--
Fabrízio de Royes Mello