In this PostgreSQL post explains more about the AUTOVACUUM daemon.
Introduced in PostgreSQL 8.1, the AUTOVACUUM daemon is an optional feature that automatically vacuums the database so that you don't have to manually run the VACUUM statement. The AUTOVACUUM daemon is enabled in the default configuration.
The AUTOVACUUM daemon is made up of multiple processes that reclaim storage by removing obsolete data or tuples from the database. It checks for tables that have a significant number of inserted, updated, or deleted records and vacuums these tables based on the configuration settings below.
The AUTOVACUUM settings for PostgreSQL can be found in the postgresql.conf file and control when/how the daemon runs. The following is an example of these settings:
You can view the AUTOVACUUM settings by one of two ways. You can either open the postgresql.conf file and view the AUTOVACUUM parameters (like above). Or if you are logged into the database, you can run the following query:
This query will return the current system settings for the AUTOVACUUM daemon, but it is important to note that you can not update these settings using a query.
To change the settings for the AUTOVACUUM daemon, you will need to find and edit the settings stored within the postgresql.conf file. The location of the postgresql.conf file will vary depending on the system that you are on.
Once you have edited the settings within the postgresql.conf file, you will be required to restart the database for the changes to take effect.
When the system settings for AUTOVACUUM are turned on, you can disable the autovacuum for a specific table, if you choose. This is done by running a query within the database.
The syntax to disable the autovacuum for a table in PostgreSQL is:
The table that you do not wish to autovacuum.
For example:
In this example, the AUTOVACUUM daemon would be overriden so that the products table is not vacuumed automatically.
If you are not sure whether a table's AUTOVACUUM feature has been disabled, you can run the following query:
This would return the AUTOVACUUM setting for the products table. If AUTOVACUUM has been disabled, your query will return something like this:
In this example, the products table has autovacuum_enabled set to false. This means that the AUTOVACUUM daemon will not try to vacuum the products table.