VACUUM

Function

VACUUM reclaims storage space occupied by tables or B-tree indexes. In normal database operation, rows that have been deleted are not physically removed from their table; they remain present until a VACUUM is done. Therefore, it is necessary to execute VACUUM periodically, especially on frequently-updated tables.

Precautions

  • When a VACUUM FULL operation is performed on a table, it triggers table rebuilding. During this rebuilding process, data is dumped into a new data file. Once the rebuilding is complete, the original file is deleted. However, it is important to note that if the table is large, the rebuilding process can consume a significant amount of disk space. When the disk space is insufficient, exercise caution when performing the VACUUM FULL operation on large tables to prevent the cluster from being read-only.
  • Execute VACUUM FULL on tables with a high dirty page rate and small CU ratio exceeding 25% at regular intervals. Perform VACUUM FULL on common tables during low-traffic hours and on system tables when they are offline.
  • For more information about development and design specifications, see "GaussDB(DWS) Development and Design Proposal" in the Data Warehouse Service (DWS) Developer Guide.

Syntax

Parameter Description

Examples

Delete all tables in the current database.

1
VACUUM;

Reclaim the space of partition P2 of the tpcds.web_returns_p1 table without updating statistics.

1
VACUUM FULL tpcds.web_returns_p1 PARTITION(P2);

Reclaim the space of the tpcds.web_returns_p1 table and update statistics.

1
VACUUM FULL ANALYZE tpcds.web_returns_p1;

Delete all tables in the current database and collect statistics about the query optimizer.

1
VACUUM ANALYZE;

Delete only the reason table.

1
VACUUM (VERBOSE, ANALYZE) tpcds.reason;

Perform the DELTAMERGE operation on the column-store table table_delta.

1
VACUUM DELTAMERGE tpcds.table_delta;

Perform the DELTAMERGE operation only on partition p1 of the column-store table table_delta.

1
VACUUM DELTAMERGE tpcds.table_delta partition(p1);