1VACUUM(7) PostgreSQL 9.2.24 Documentation VACUUM(7)
2
3
4
6 VACUUM - garbage-collect and optionally analyze a database
7
9 VACUUM [ ( { FULL | FREEZE | VERBOSE | ANALYZE } [, ...] ) ] [ table_name [ (column_name [, ...] ) ] ]
10 VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ table_name ]
11 VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] ANALYZE [ table_name [ (column_name [, ...] ) ] ]
12
14 VACUUM reclaims storage occupied by dead tuples. In normal PostgreSQL
15 operation, tuples that are deleted or obsoleted by an update are not
16 physically removed from their table; they remain present until a VACUUM
17 is done. Therefore it's necessary to do VACUUM periodically, especially
18 on frequently-updated tables.
19
20 With no parameter, VACUUM processes every table in the current database
21 that the current user has permission to vacuum. With a parameter,
22 VACUUM processes only that table.
23
24 VACUUM ANALYZE performs a VACUUM and then an ANALYZE for each selected
25 table. This is a handy combination form for routine maintenance
26 scripts. See ANALYZE(7) for more details about its processing.
27
28 Plain VACUUM (without FULL) simply reclaims space and makes it
29 available for re-use. This form of the command can operate in parallel
30 with normal reading and writing of the table, as an exclusive lock is
31 not obtained. However, extra space is not returned to the operating
32 system (in most cases); it's just kept available for re-use within the
33 same table. VACUUM FULL rewrites the entire contents of the table into
34 a new disk file with no extra space, allowing unused space to be
35 returned to the operating system. This form is much slower and requires
36 an exclusive lock on each table while it is being processed.
37
38 When the option list is surrounded by parentheses, the options can be
39 written in any order. Without parentheses, options must be specified in
40 exactly the order shown above. The parenthesized syntax was added in
41 PostgreSQL 9.0; the unparenthesized syntax is deprecated.
42
44 FULL
45 Selects “full” vacuum, which can reclaim more space, but takes much
46 longer and exclusively locks the table. This method also requires
47 extra disk space, since it writes a new copy of the table and
48 doesn't release the old copy until the operation is complete.
49 Usually this should only be used when a significant amount of space
50 needs to be reclaimed from within the table.
51
52 FREEZE
53 Selects aggressive “freezing” of tuples. Specifying FREEZE is
54 equivalent to performing VACUUM with the vacuum_freeze_min_age
55 parameter set to zero.
56
57 VERBOSE
58 Prints a detailed vacuum activity report for each table.
59
60 ANALYZE
61 Updates statistics used by the planner to determine the most
62 efficient way to execute a query.
63
64 table_name
65 The name (optionally schema-qualified) of a specific table to
66 vacuum. Defaults to all tables in the current database.
67
68 column_name
69 The name of a specific column to analyze. Defaults to all columns.
70 If a column list is specified, ANALYZE is implied.
71
73 When VERBOSE is specified, VACUUM emits progress messages to indicate
74 which table is currently being processed. Various statistics about the
75 tables are printed as well.
76
78 To vacuum a table, one must ordinarily be the table's owner or a
79 superuser. However, database owners are allowed to vacuum all tables in
80 their databases, except shared catalogs. (The restriction for shared
81 catalogs means that a true database-wide VACUUM can only be performed
82 by a superuser.) VACUUM will skip over any tables that the calling
83 user does not have permission to vacuum.
84
85 VACUUM cannot be executed inside a transaction block.
86
87 For tables with GIN indexes, VACUUM (in any form) also completes any
88 pending index insertions, by moving pending index entries to the
89 appropriate places in the main GIN index structure. See Section 55.3.1,
90 “GIN Fast Update Technique”, in the documentation for details.
91
92 We recommend that active production databases be vacuumed frequently
93 (at least nightly), in order to remove dead rows. After adding or
94 deleting a large number of rows, it might be a good idea to issue a
95 VACUUM ANALYZE command for the affected table. This will update the
96 system catalogs with the results of all recent changes, and allow the
97 PostgreSQL query planner to make better choices in planning queries.
98
99 The FULL option is not recommended for routine use, but might be useful
100 in special cases. An example is when you have deleted or updated most
101 of the rows in a table and would like the table to physically shrink to
102 occupy less disk space and allow faster table scans. VACUUM FULL will
103 usually shrink the table more than a plain VACUUM would.
104
105 VACUUM causes a substantial increase in I/O traffic, which might cause
106 poor performance for other active sessions. Therefore, it is sometimes
107 advisable to use the cost-based vacuum delay feature. See Section
108 18.4.4, “Cost-based Vacuum Delay”, in the documentation for details.
109
110 PostgreSQL includes an “autovacuum” facility which can automate routine
111 vacuum maintenance. For more information about automatic and manual
112 vacuuming, see Section 23.1, “Routine Vacuuming”, in the documentation.
113
115 To clean a single table onek, analyze it for the optimizer and print a
116 detailed vacuum activity report:
117
118 VACUUM (VERBOSE, ANALYZE) onek;
119
121 There is no VACUUM statement in the SQL standard.
122
124 vacuumdb(1), Section 18.4.4, “Cost-based Vacuum Delay”, in the
125 documentation, Section 23.1.6, “The Autovacuum Daemon”, in the
126 documentation
127
128
129
130PostgreSQL 9.2.24 2017-11-06 VACUUM(7)