3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "VACUUM" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 VACUUM \- garbage\-collect and optionally analyze a database
35 VACUUM [ ( \fIoption\fR [, \&.\&.\&.] ) ] [ \fItable_and_columns\fR [, \&.\&.\&.] ]
37 where \fIoption\fR can be one of:
39 FULL [ \fIboolean\fR ]
40 FREEZE [ \fIboolean\fR ]
41 VERBOSE [ \fIboolean\fR ]
42 ANALYZE [ \fIboolean\fR ]
43 DISABLE_PAGE_SKIPPING [ \fIboolean\fR ]
44 SKIP_LOCKED [ \fIboolean\fR ]
45 INDEX_CLEANUP { AUTO | ON | OFF }
46 PROCESS_MAIN [ \fIboolean\fR ]
47 PROCESS_TOAST [ \fIboolean\fR ]
48 TRUNCATE [ \fIboolean\fR ]
49 PARALLEL \fIinteger\fR
50 SKIP_DATABASE_STATS [ \fIboolean\fR ]
51 ONLY_DATABASE_STATS [ \fIboolean\fR ]
52 BUFFER_USAGE_LIMIT \fIsize\fR
54 and \fItable_and_columns\fR is:
56 [ ONLY ] \fItable_name\fR [ * ] [ ( \fIcolumn_name\fR [, \&.\&.\&.] ) ]
61 reclaims storage occupied by dead tuples\&. In normal
63 operation, tuples that are deleted or obsoleted by an update are not physically removed from their table; they remain present until a
65 is done\&. Therefore it\*(Aqs necessary to do
67 periodically, especially on frequently\-updated tables\&.
70 \fItable_and_columns\fR
73 processes every table and materialized view in the current database that the current user has permission to vacuum\&. With a list,
75 processes only those table(s)\&.
82 for each selected table\&. This is a handy combination form for routine maintenance scripts\&. See
84 for more details about its processing\&.
89 FULL) simply reclaims space and makes it available for re\-use\&. This form of the command can operate in parallel with normal reading and writing of the table, as an exclusive lock is not obtained\&. However, extra space is not returned to the operating system (in most cases); it\*(Aqs just kept available for re\-use within the same table\&. It also allows us to leverage multiple CPUs in order to process indexes\&. This feature is known as
90 parallel vacuum\&. To disable this feature, one can use
92 option and specify parallel workers as zero\&.
94 rewrites the entire contents of the table into a new disk file with no extra space, allowing unused space to be returned to the operating system\&. This form is much slower and requires an
96 lock on each table while it is being processed\&.
103 vacuum, which can reclaim more space, but takes much longer and exclusively locks the table\&. This method also requires extra disk space, since it writes a new copy of the table and doesn\*(Aqt release the old copy until the operation is complete\&. Usually this should only be used when a significant amount of space needs to be reclaimed from within the table\&.
110 of tuples\&. Specifying
112 is equivalent to performing
115 vacuum_freeze_min_age
117 vacuum_freeze_table_age
118 parameters set to zero\&. Aggressive freezing is always performed when the table is rewritten, so this option is redundant when
125 Prints a detailed vacuum activity report for each table at
132 Updates statistics used by the planner to determine the most efficient way to execute a query\&.
135 DISABLE_PAGE_SKIPPING
139 will skip pages based on the
140 visibility map\&. Pages where all tuples are known to be frozen can always be skipped, and those where all tuples are known to be visible to all transactions may be skipped except when performing an aggressive vacuum\&. Furthermore, except when performing an aggressive vacuum, some pages may be skipped in order to avoid waiting for other sessions to finish using them\&. This option disables all page\-skipping behavior, and is intended to be used only when the contents of the visibility map are suspect, which should happen only if there is a hardware or software issue causing database corruption\&.
147 should not wait for any conflicting locks to be released when beginning work on a relation: if a relation cannot be locked immediately without waiting, the relation is skipped\&. Note that even with this option,
149 may still block when opening the relation\*(Aqs indexes\&. Additionally,
151 may still block when acquiring sample rows from partitions, table inheritance children, and some types of foreign tables\&. Also, while
153 ordinarily processes all partitions of specified partitioned tables, this option will cause
155 to skip all partitions if there is a conflicting lock on the partitioned table\&.
162 will skip index vacuuming when there are very few dead tuples in the table\&. The cost of processing all of the table\*(Aqs indexes is expected to greatly exceed the benefit of removing dead index tuples when this happens\&. This option can be used to force
164 to process indexes when there are more than zero dead tuples\&. The default is
167 to skip index vacuuming when appropriate\&. If
172 will conservatively remove all dead tuples from indexes\&. This may be useful for backwards compatibility with earlier releases of
174 where this was the standard behavior\&.
183 skip index vacuuming, even when there are many dead tuples in the table\&. This may be useful when it is necessary to make
185 run as quickly as possible to avoid imminent transaction ID wraparound (see
186 Section\ \&24.1.5)\&. However, the wraparound failsafe mechanism controlled by
188 will generally trigger automatically to avoid transaction ID wraparound failure, and should be preferred\&. If index cleanup is not performed regularly, performance may suffer, because as the table is modified indexes will accumulate dead tuples and the table itself will accumulate dead line pointers that cannot be removed until index cleanup is completed\&.
190 This option has no effect for tables that have no index and is ignored if the
192 option is used\&. It also has no effect on the transaction ID wraparound failsafe mechanism\&. When triggered it will skip index vacuuming, even when
202 should attempt to process the main relation\&. This is usually the desired behavior and is the default\&. Setting this option to false may be useful when it is only necessary to vacuum a relation\*(Aqs corresponding
211 should attempt to process the corresponding
213 table for each relation, if one exists\&. This is usually the desired behavior and is the default\&. Setting this option to false may be useful when it is only necessary to vacuum the main relation\&. This option is required when the
222 should attempt to truncate off any empty pages at the end of the table and allow the disk space for the truncated pages to be returned to the operating system\&. This is normally the desired behavior and is the default unless
224 is set to false or the
226 option has been set to false for the table to be vacuumed\&. Setting this option to false may be useful to avoid
228 lock on the table that the truncation requires\&. This option is ignored if the
235 Perform index vacuum and index cleanup phases of
239 background workers (for the details of each vacuum phase, please refer to
240 Table\ \&27.46)\&. The number of workers used to perform the operation is equal to the number of indexes on the relation that support parallel vacuum which is limited by the number of workers specified with
242 option if any which is further limited by
243 max_parallel_maintenance_workers\&. An index can participate in parallel vacuum if and only if the size of the index is more than
244 min_parallel_index_scan_size\&. Please note that it is not guaranteed that the number of parallel workers specified in
246 will be used during execution\&. It is possible for a vacuum to run with fewer workers than specified, or even with no workers at all\&. Only one worker can be used per index\&. So parallel workers are launched only when there are at least
248 indexes in the table\&. Workers for vacuum are launched before the start of each phase and exit at the end of the phase\&. These behaviors might change in a future release\&. This option can\*(Aqt be used with the
257 should skip updating the database\-wide statistics about oldest unfrozen XIDs\&. Normally
259 will update these statistics once at the end of the command\&. However, this can take awhile in a database with a very large number of tables, and it will accomplish nothing unless the table that had contained the oldest unfrozen XID was among those vacuumed\&. Moreover, if multiple
261 commands are issued in parallel, only one of them can update the database\-wide statistics at a time\&. Therefore, if an application intends to issue a series of many
263 commands, it can be helpful to set this option in all but the last such command; or set it in all the commands and separately issue
264 VACUUM (ONLY_DATABASE_STATS)
272 should do nothing except update the database\-wide statistics about oldest unfrozen XIDs\&. When this option is specified, the
273 \fItable_and_columns\fR
274 list must be empty, and no other option may be enabled except
281 Buffer Access Strategy
283 \fBVACUUM\fR\&. This size is used to calculate the number of shared buffers which will be reused as part of this strategy\&.
286 Buffer Access Strategy\&. If
288 is also specified, the
289 \fBBUFFER_USAGE_LIMIT\fR
290 value is used for both the vacuum and analyze stages\&. This option can\*(Aqt be used with the
294 is also specified\&. When this option is not specified,
297 vacuum_buffer_usage_limit\&. Higher settings can allow
299 to run more quickly, but having too large a setting may cause too many other useful pages to be evicted from shared buffers\&. The minimum value is
301 and the maximum value is
307 Specifies whether the selected option should be turned on or off\&. You can write
311 to enable the option, and
317 value can also be omitted, in which case
324 Specifies a non\-negative integer value passed to the selected option\&.
329 Specifies an amount of memory in kilobytes\&. Sizes may also be specified as a string containing the numerical size followed by any one of the following memory units:
344 The name (optionally schema\-qualified) of a specific table or materialized view to vacuum\&. If
346 is specified before the table name, only that table is vacuumed\&. If
348 is not specified, the table and all its inheritance child tables or partitions (if any) are also vacuumed\&. Optionally,
350 can be specified after the table name to explicitly indicate that inheritance child tables (or partitions) are to be vacuumed\&.
355 The name of a specific column to analyze\&. Defaults to all columns\&. If a column list is specified,
357 must also be specified\&.
365 emits progress messages to indicate which table is currently being processed\&. Various statistics about the tables are printed as well\&.
368 To vacuum a table, one must ordinarily have the
370 privilege on the table\&. However, database owners are allowed to vacuum all tables in their databases, except shared catalogs\&.
372 will skip over any tables that the calling user does not have permission to vacuum\&.
378 is temporarily changed to
379 pg_catalog, pg_temp\&.
382 cannot be executed inside a transaction block\&.
388 (in any form) also completes any pending index insertions, by moving pending index entries to the appropriate places in the main
390 index structure\&. See
394 We recommend that all databases be vacuumed regularly in order to remove dead rows\&.
398 facility which can automate routine vacuum maintenance\&. For more information about automatic and manual vacuuming, see
403 option is not recommended for routine use, but might be useful in special cases\&. An example is when you have deleted or updated most of the rows in a table and would like the table to physically shrink to occupy less disk space and allow faster table scans\&.
405 will usually shrink the table more than a plain
411 option is used only for vacuum purposes\&. If this option is specified with the
413 option, it does not affect
417 causes a substantial increase in I/O traffic, which might cause poor performance for other active sessions\&. Therefore, it is sometimes advisable to use the cost\-based vacuum delay feature\&. For parallel vacuum, each worker sleeps in proportion to the work done by that worker\&. See
425 option will report its progress in the
426 pg_stat_progress_vacuum
427 view\&. Backends running
429 will instead report their progress in the
430 pg_stat_progress_cluster
438 To clean a single table
439 onek, analyze it for the optimizer and print a detailed vacuum activity report:
445 VACUUM (VERBOSE, ANALYZE) onek;
454 statement in the SQL standard\&.
456 The following syntax was used before
458 version 9\&.0 and is still supported:
464 VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ ANALYZE ] [ \fItable_and_columns\fR [, \&.\&.\&.] ]
470 Note that in this syntax, the options must be specified in exactly the order shown\&.
472 \fBvacuumdb\fR(1), Section\ \&19.10.2, Section\ \&24.1.6, Section\ \&27.4.5, Section\ \&27.4.2