How to schedule postgresql auto vacuum in linux

This article describes How to schedule postgresql auto vacuum in linux

Step 1: Create a .pgpass file under your home directory.

                   [root@centos6 ~]# vim .pgpass


Step 2: Install Crond packages.     backup.html

Step 3: Edit crontab

                  [root@centos6 ~]# crontab -e

                  30      10      *      *      *      /opt/PostgreSQL/9.4/bin/psql dbname=bayaTRADETest --username=dbuser -c 'VACUUM FULL VERBOSE'

Step 4: Restart crontab

                 # service crond restart

Step 5: Add crontab on startup

                # chkconfig crond on


Vacuum reclaims storage occupied by dead tuples. In normal PostgreSQL operation, tuples that are deleted or obsoleted by an update are not physically removed from their table; they remain present until a Vacuum is done. Therefore it's necessary to do Vacuum periodically, especially on frequently-updated tables.

With no parameter, Vacuum processes every table in the current database that the current user has permission to vacuum. With a parameter, Vacuum processes only that table.

Plain Vacuum (without FULL) simply reclaims space and makes it available for re-use. This form of the command can operate in parallel with normal reading and writing of the table, as an exclusive lock is not obtained. However, extra space is not returned to the operating system (in most cases); it's just kept available for re-use within the same table. Vacuum FULL rewrites the entire contents of the table into a new disk file with no extra space, allowing unused space to be returned to the operating system. This form is much slower and requires an exclusive lock on each table while it is being processed.



Selects "full" vacuum, which can reclaim more space, but takes much longer and exclusively locks the table. This method also requires extra disk space, since it writes a new copy of the table and doesn't release the old copy until the operation is complete. Usually this should only be used when a significant amount of space needs to be reclaimed from within the table.


Selects aggressive "freezing" of tuples. Specifying FREEZE is equivalent to performing Vacuum with the vacuum_freeze_min_age parameter set to zero.


Prints a detailed vacuum activity report for each table.


Updates statistics used by the planner to determine the most efficient way to execute a query.


The name (optionally schema-qualified) of a specific table to vacuum. Defaults to all tables in the current database.


The name of a specific column to analyze. Defaults to all columns. If a column list is specified, ANALYZE is implied.

PostgreSQL Vacuum graphically 

Step 1: Right click on database and select maintenance. It will open a pop up window.

Step 2: Select maintenance operation as VACUUM.

Step 3: Select VACUUM option as FULL

Step 4: Click OK

No comments:

Powered by Blogger.