Chapter 22. Routine Database Maintenance Tasks

Table of Contents
22.1. Routine Vacuuming
22.1.1. Vacuuming Basics
22.1.2. Recovering Disk Space
22.1.3. Updating Planner Statistics
22.1.4. Updating The Visibility Map
22.1.5. Preventing Transaction ID Wraparound Failures
22.1.6. The Autovacuum Daemon
22.2. Routine Reindexing
22.3. Log File Maintenance

Note: XCONLY: The following description applies only to Postgres-XC.

Please note that this chapter describes database maintenance task of individual Coordinator and Datanode. Please remember that these tasks should be done for each of them.

Note: The following description applies both to Postgres-XC and PostgreSQL if not described explicitly. You can read PostgreSQL as Postgres-XC except for version number, which is specific to each product.

PostgreSQL, like any database software, requires that certain tasks be performed regularly to achieve optimum performance. The tasks discussed here are required, but they are repetitive in nature and can easily be automated using standard tools such as cron scripts or Windows' Task Scheduler. It is the database administrator's responsibility to set up appropriate scripts, and to check that they execute successfully.

One obvious maintenance task is the creation of backup copies of the data on a regular schedule. Without a recent backup, you have no chance of recovery after a catastrophe (disk failure, fire, mistakenly dropping a critical table, etc.). The backup and recovery mechanisms available in PostgreSQL are discussed at length in Chapter 23.

The other main category of maintenance task is periodic "vacuuming" of the database. This activity is discussed in Section 22.1. Closely related to this is updating the statistics that will be used by the query planner, as discussed in Section 22.1.3.

Another task that might need periodic attention is log file management. This is discussed in Section 22.3.

check_postgres is available for monitoring database health and reporting unusual conditions. check_postgres integrates with Nagios and MRTG, but can be run standalone too.

PostgreSQL is low-maintenance compared to some other database management systems. Nonetheless, appropriate attention to these tasks will go far towards ensuring a pleasant and productive experience with the system.