relpages of btree indexes are not truncating even after deleting all the tuples from table and doing vacuum

From: Mahendra Singh <mahi6run(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: relpages of btree indexes are not truncating even after deleting all the tuples from table and doing vacuum
Date: 2019-12-23 19:05:08
Message-ID: CAKYtNAo80dd9Sc3PhQzucrbP2XyD122zs-cFbY=-7e+8pxzh1w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi All,

While doing testing of "parallel vacuum" patch, I found that size of index
relation is not reducing even after deleting all the tuples and firing
vacuum command. I am not sure that this is expected behavior or not. For
reference, below I am giving one example.

postgres=# create table test (a int);
CREATE TABLE
postgres=# create index indx1 on test (a);
CREATE INDEX
postgres=# insert into test (select a from generate_series(1,100000) a);
INSERT 0 100000
postgres=# analyze ;
ANALYZE
postgres=# select relpages, relname from pg_class where relname = 'indx1';
relpages | relname
----------+---------
276 | indx1
(1 row)

-- delete all the tuples from table.
postgres=# delete from test ;
DELETE 100000

-- do vacuum to test tables
postgres=# vacuum test ;
VACUUM

-- check relpages in 'indx1' and 'test'
postgres=# select relpages, relname from pg_class where relname = 'indx1';
relpages | relname
----------+---------
276 | indx1
(1 row)

-- do vacuum to all the tables and check relpages in 'indx1'
postgres=# vacuum ;
VACUUM
postgres=# select relpages, relname from pg_class where relname = 'indx1';
relpages | relname
----------+---------
276 | indx1
(1 row)

-- check relpages in 'test' table
postgres=# select relpages, relname from pg_class where relname = 'test';
relpages | relname
----------+---------
0 | test
(1 row)

From above example, we can see that after deleting all the tuples from
table and firing vacuum command, size of table is reduced but size of index
relation is same as before vacuum.

Please let me your thoughts.

Thanks and Regards
Mahendra Singh Thalor
EnterpriseDB: http://www.enterprisedb.com

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2019-12-23 19:51:56 string literal continuations in C
Previous Message Tom Lane 2019-12-23 18:57:47 Re: unsupportable composite type partition keys