Re: BUG #13830: pg_table_size and pg_indexes_size

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: foggyglass(at)163(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #13830: pg_table_size and pg_indexes_size
Date: 2015-12-23 18:22:51
Message-ID: 2682.1450894971@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

foggyglass(at)163(dot)com writes:
> postgres=# create table b(id int);
> CREATE TABLE
> postgres=# create index b_idx on b(id);
> CREATE INDEX
> postgres=# select relname , pg_table_size(oid),pg_indexes_size(oid)
> postgres-# from pg_class where relname in ('b','b_idx');
> relname | pg_table_size | pg_indexes_size
> ---------+---------------+-----------------
> b | 0 | 8192
> b_idx | 8192 | 0
> (2 rows)

Seems fine to me. b is empty at this point, so it has size zero.
btree indexes, on the other hand, never have size zero because their
metapage is created immediately. b_idx has no indexes attached to it,
so pg_indexes_size finds nothing to report on and returns zero for
that.

If you insert any actual data, the results change:

regression=# insert into b values(33);
INSERT 0 1
regression=# select relname , pg_table_size(oid),pg_indexes_size(oid) from pg_class where relname in ('b','b_idx');
relname | pg_table_size | pg_indexes_size
---------+---------------+-----------------
b | 8192 | 16384
b_idx | 16384 | 0
(2 rows)

which maybe looks a bit saner.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2015-12-24 00:21:46 Re: [BUGS] BUG #13741: vacuumdb does not accept valid password
Previous Message David G. Johnston 2015-12-23 18:18:02 Re: BUG #13830: pg_table_size and pg_indexes_size