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

Syntax

Parameter Description

Examples

Create a partitioned table customer_address:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
DROP TABLE IF EXISTS customer_address;
CREATE TABLE customer_address
(
    ca_address_sk       INTEGER                  NOT NULL   ,
    ca_address_id       CHARACTER(16)            NOT NULL   ,
    ca_street_number    CHARACTER(10)                       ,
    ca_street_name      CHARACTER varying(60)               ,
    ca_street_type      CHARACTER(15)                       ,
    ca_suite_number     CHARACTER(10)                    
)
DISTRIBUTE BY HASH (ca_address_sk)
PARTITION BY RANGE(ca_address_sk)
(
        PARTITION P1 VALUES LESS THAN(2450815),
        PARTITION P2 VALUES LESS THAN(2451179),
        PARTITION P3 VALUES LESS THAN(2451544),
        PARTITION P4 VALUES LESS THAN(MAXVALUE)
);

Delete all tables in the current database.

1
VACUUM;

Reclaim the space of partition P2 of the customer_address table without updating statistics.

1
VACUUM FULL customer_address PARTITION(P2);

Reclaim the space of the customer_address table and update statistics.

1
VACUUM FULL ANALYZE customer_address;

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) customer_address;