Routine System Maintenance Tasks
A newer version of this documentation is available. Click here to view the most up-to-date release of the Greenplum 4.x documentation.
Routine System Maintenance Tasks
Greenplum Database requires that certain tasks be performed regularly to achieve optimal performance. The tasks discussed here are required, but database administrators can automate them using standard UNIX tools such as cron scripts. An administrator sets up the appropriate scripts and checks that they execute successfully.
Routine Vacuum and Analyze
Because of the MVCC transaction concurrency model used in Greenplum Database, deleted or updated data rows still occupy physical space on disk even though they are not visible to new transactions. If your database has many updates and deletes, many expired rows will exist. The VACUUM command collects table-level statistics such as number of rows and pages, so it is also necessary to vacuum append-optimized tables, even when there is no space from updated or deleted rows to reclaim.
Vacuuming an append-optimized table follows a different process than vacuuming heap tables. On each segment, a new segment file is created and visible rows are copied into it from the current segment. When the segment file has been copied, the original is scheduled to be dropped and the new segment file is made available. This requires sufficient available disk space for a copy of the visible rows until the original segment file is dropped.
If the ratio of hidden rows to total rows in a segment file is less than a threshold value (10, by default), the segment file is not compacted. The threshold value can be configured with the gp_appendonly_compaction_threshold Greenplum Database server configuration parameter. VACUUM FULL ignores the value of gp_appendonly_compaction_threshold and rewrites the segment file regardless of the ratio.
VACUUM can be disabled for append-optimized tables using the gp_appendonly_compaction server configuration parameter.
For details about vacuuming a database, see Vacuuming the Database. For information about gp_appendonly_compaction_threshold server configuration parameter and the VACUUM command, see the Greenplum Database Reference Guide.
Transaction ID Management
Greenplum’s MVCC transaction semantics depend on comparing transaction ID (XID) numbers to determine visibility to other transactions. Because transaction ID numbers have an upper limit, a Greenplum system that runs more than 4 billion transactions experiences transaction ID wraparound: the XID counter reverts to zero, and past transactions appear to be in the future. This means past transactions’ outputs become invisible. Therefore, it is necessary to VACUUM every table in every database at least once per two billion transactions.
Greenplum Database issues the following warning when a significant portion of the transaction IDs are no longer available and before transaction ID wraparound occurs:
WARNING: database "database_name" must be vacuumed within number_of_transactions transactions
When the warning is issued, a VACUUM operation is required. If a VACUUM operation is not performed, Greenplum Database stops creating transactions when it reaches a limit prior to when transaction ID wraparound occurs. Greenplum Database issues this error when it stops creating transactions to avoid possible data loss:
FATAL: database is not accepting commands to avoid wraparound data loss in database "database_name"
The Greenplum Database configuration parameter xid_warn_limit controls when the warning is displayed. The parameter xid_stop_limit controls when Greenplum Database stops creating transactions.
Recovering from a Transaction ID Limit Error
When Greenplum Database reaches the xid_stop_limit transaction ID limit due to infrequent VACUUM maintenance, it becomes unresponsive. To recover from this situation, perform the following steps as database administrator:
- Shut down Greenplum Database.
- Temporarily lower the xid_stop_limit by 10,000,000.
- Start Greenplum Database.
- Run VACUUM FREEZE on all affected databases.
- Reset the xid_stop_limit to its original value.
- Restart Greenplum Database.
For information about the configuration parameters, see the Greenplum Database Reference Guide. For information about transaction ID wraparound see the PostgreSQL documentation.
System Catalog Maintenance
Numerous database updates with CREATE and DROP commands increase the system catalog size and affect system performance. For example, running many DROP TABLE statements degrades the overall system performance due to excessive data scanning during metadata operations on catalog tables. The performance loss occurs between thousands to tens of thousands of DROP TABLE statements depending on the system.
Greenplum recommends you regularly run a system catalog maintenance procedure to reclaim the space occupied by deleted objects. If a regular procedure has not been run for a long time, you may need to run a more intensive procedure to clear the system catalog. This topic describes both procedures.
Regular System Catalog Maintenance
It is recommended that you periodically run VACUUM on the system catalog to clear the space that deleted objects occupy. If regular database operations include numerous DROP statements, it is safe and appropriate to run a system catalog maintenance procedure with VACUUM daily at off-peak hours. You can do this while the system is available.
The following example script performs a VACUUM of the Greenplum Database system catalog:
#!/bin/bash DBNAME="<database_name>" VCOMMAND="VACUUM ANALYZE" psql -tc "select '$VCOMMAND' || ' pg_catalog.' || relname || ';' from pg_class a,pg_namespace b where a.relnamespace=b.oid and b.nspname='pg_catalog' and a.relkind='r'" $DBNAME | psql -a $DBNAME
Intensive System Catalog Maintenance
If a system catalog maintenance procedure has not been performed in a long time, the catalog can become bloated with dead space; this causes excessively long wait times for simple metadata operations. A wait of more than two seconds to list user tables, such as with the \d metacommand from within psql, is an indication of catalog bloat.
If you see indications of system catalog bloat, you must perform an intensive system catalog maintenance procedure with VACUUM FULL during a scheduled downtime period. During this period, stop all catalog activity on the system; the FULL system catalog maintenance procedure takes exclusive locks against the system catalog.
Running regular system catalog maintenance procedures can prevent the need for this more costly procedure.
Vacuum and Analyze for Query Optimization
Greenplum Database uses a cost-based query planner that relies on database statistics. Accurate statistics allow the query planner to better estimate selectivity and the number of rows that a query operation retrieves. These estimates help it choose the most efficient query plan. The ANALYZE command collects column-level statistics for the query planner.
You can run both VACUUM and ANALYZE operations in the same command. For example:
=# VACUUM ANALYZE mytable;
For B-tree indexes, a freshly-constructed index is slightly faster to access than one that has been updated many times because logically adjacent pages are usually also physically adjacent in a newly built index. Reindexing older indexes periodically can improve access speed. If all but a few index keys on a page have been deleted, there will be wasted space on the index page. A reindex will reclaim that wasted space. In Greenplum Database it is often faster to drop an index (DROP INDEX) and then recreate it (CREATE INDEX) than it is to use the REINDEX command.
Bitmap indexes are not updated when changes are made to the indexed column(s). If you have updated a table that has a bitmap index, you must drop and recreate the index for it to remain current.
Managing Greenplum Database Log Files
Database Server Log Files
Greenplum Database log output tends to be voluminous, especially at higher debug levels, and you do not need to save it indefinitely. Administrators rotate the log files periodically so new log files are started and old ones are removed.
Greenplum Database has log file rotation enabled on the master and all segment instances. Daily log files are created in pg_log of the master and each segment data directory using the naming convention of: gpdb-YYYY-MM-DD_hhmmss.csv. Although log files are rolled over daily, they are not automatically truncated or deleted. Administrators need to implement scripts or programs to periodically clean up old log files in the pg_log directory of the master and each segment instance.
For information about viewing the database server log files, see Viewing the Database Server Log Files.
Management Utility Log Files
Log files for the Greenplum Database management utilities are written to ~/gpAdminLogs by default. The naming convention for management log files is:
The log entry format is:
The log file for a particular utility execution is appended to its daily log file each time that utility is run.