I am just going through one scenario, where I am not at all getting the clue for my issue.
I have one table called names (with columns name and time). This table is being inserted numerous number of rows at every mins. And these inserted record would be deleted on particular time interval. So, finally I stopped inserting the data and deleted all the rows from the table.
My database version details
impss=# SELECT version();
version
----------------------------------------------------------------------------------------------
PostgreSQL 8.3.7 on i486-pc-linux-gnu, compiled by GCC gcc-4.3.real (Debian 4.3.2-1.1) 4.3.2
(1 row)
But when I issue the query for finding the size of the table, I still get some size.
impss=# SELECT pg_size_pretty( pg_total_relation_size('names')) ;
pg_size_pretty
----------------
1504 kB
(1 row)
First Question why still it shows some size though I have deleted all the records from the table.
To find when last autovacuum was done I have issued following query:
Current Time is
impss=# select now();
now
----------------------------------
2012-11-08 20:21:10.550434+05:30
(1 row)
impss=# SELECT last_autovacuum from pg_stat_user_tables where relname='names';
last_autovacuum
----------------------------------
2012-11-08 17:51:31.995618+05:30
Second question: Why has the autovacuum process has not been performed after this time although my database is not a busy one and I have already stopped all my transactions towards this table.
So, please tell me whether I have to do any specific configuration to do the frequent vacuum so that I could get back all my space once records get deleted.
first query – autovacuum doesn’t invoke VACUUM FULL – so it has not impact on relation size (usually, but it can trim relation file from end to last living tuple when there are no other requests for access to relation at moment of vacuum execution), second query – autovacuum is executed when autovacuum_vacuum_threshold rows are modified and modified rows / all rows is higher to autovacuum_vacuum_scale_factor. Both these values are in postgresql.conf and default values is 50 rows and 20%.
Autovacuum execution doesn’t depend on current database load – it depends only on number of updated/deleted rows.