Database Maintenance
Database Maintenance
Database Maintenance
It is off by default.
2. With the OS tool vacuumdb - This can be ran manually or scripted and automated
in cron
3. We can set up autovacumming in which case the postgres process will run a vacuum
every 60 secs by default.
show autovacuum;
select pg_reload_conf();
show autovacuum;
#\x
select * from pg_stat_user_tables
Pages contains the dead - deleted and the live rows: In pg_stat_user_tables
n_live_tup
n_dead_tup
analyze verbose tablename; --where tablename is the table you want to run analyze
on in a verbose manner.
How do we remove the dead rows or deal with the Fragmentation issue?
Vacuuming will help you shrink the data file size when required.
Vacuuming needs to take an exclusive lock so any long running transaction that is
already running can block the vacuum operation.
vacuum will clear the dead rows at the page level. it will not give the spave back
to the disk.
vacuump will update the visibility map that will help speed up the index only scan.
select pg_size_pretty(pg_relation_size('tablename'));
vacuum tablename;
select pg_size_pretty(pg_relation_size('tablename'));
analyze verbose tabblename;
select pg_size_pretty(pg_relation_size('tablename'));
vacuum full will release the disk space as its a more aggressive vacuum algorythym.