1VACUUM()                         SQL Commands                         VACUUM()
2
3
4

NAME

6       VACUUM - garbage-collect and optionally analyze a database
7
8

SYNOPSIS

10       VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ table ]
11       VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] ANALYZE [ table [ (column [, ...] ) ] ]
12
13

DESCRIPTION

15       VACUUM  reclaims  storage  occupied by deleted tuples.  In normal Post‐
16       greSQL operation, tuples that are deleted or obsoleted by an update are
17       not  physically  removed  from their table; they remain present until a
18       VACUUM is done. Therefore it's necessary  to  do  VACUUM  periodically,
19       especially on frequently-updated tables.
20
21       With  no  parameter,  VACUUM processes every table in the current data‐
22       base. With a parameter, 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 [analyze(7)] for more details about  its  process‐
27       ing.
28
29       Plain  VACUUM  (without FULL) simply reclaims space and makes it avail‐
30       able for re-use. This form of the command can operate in parallel  with
31       normal  reading  and  writing of the table, as an exclusive lock is not
32       obtained. VACUUM FULL does more extensive processing, including  moving
33       of tuples across blocks to try to compact the table to the minimum num‐
34       ber of disk blocks. This form is much slower and requires an  exclusive
35       lock on each table while it is being processed.
36

PARAMETERS

38       FULL   Selects ``full'' vacuum, which may reclaim more space, but takes
39              much longer and exclusively locks the table.
40
41       FREEZE Selects aggressive ``freezing'' of tuples.  Specifying FREEZE is
42              equivalent  to  performing VACUUM with the vacuum_freeze_min_age
43              parameter set to zero. The FREEZE option is deprecated and  will
44              be removed in a future release; set the parameter instead.
45
46       VERBOSE
47              Prints a detailed vacuum activity report for each table.
48
49       ANALYZE
50              Updates  statistics  used  by  the planner to determine the most
51              efficient way to execute a query.
52
53       table  The name (optionally schema-qualified) of a  specific  table  to
54              vacuum. Defaults to all tables in the current database.
55
56       column The  name  of a specific column to analyze. Defaults to all col‐
57              umns.
58

OUTPUTS

60       When VERBOSE is specified, VACUUM emits progress messages  to  indicate
61       which  table is currently being processed. Various statistics about the
62       tables are printed as well.
63

NOTES

65       VACUUM cannot be executed inside a transaction block.
66
67       We recommend that active production databases  be  vacuumed  frequently
68       (at  least  nightly),  in order to remove expired rows. After adding or
69       deleting a large number of rows, it may be a good idea to issue a  VAC‐
70       UUM ANALYZE command for the affected table. This will update the system
71       catalogs with the results of all recent changes, and  allow  the  Post‐
72       greSQL query planner to make better choices in planning queries.
73
74       The  FULL  option is not recommended for routine use, but may be useful
75       in special cases. An example is when you have deleted most of the  rows
76       in a table and would like the table to physically shrink to occupy less
77       disk space. VACUUM FULL will usually shrink the table more than a plain
78       VACUUM  would.   The  FULL  option  does not shrink indexes; a periodic
79       REINDEX is still recommended. In fact, it is often faster to  drop  all
80       indexes, VACUUM FULL, and recreate the indexes.
81
82       VACUUM  causes  a  substantial increase in I/O traffic, which can cause
83       poor performance for other active sessions. Therefore, it is  sometimes
84       advisable to use the cost-based vacuum delay feature.  See in the docu‐
85       mentation for details.
86
87       PostgreSQL includes an ``autovacuum'' facility which can automate  rou‐
88       tine  vacuum maintenance. For more information about automatic and man‐
89       ual vacuuming, see in the documentation.
90

EXAMPLES

92       The following is an example from running  VACUUM  on  a  table  in  the
93       regression database:
94
95       regression=# VACUUM VERBOSE ANALYZE onek;
96       INFO:  vacuuming "public.onek"
97       INFO:  index "onek_unique1" now contains 1000 tuples in 14 pages
98       DETAIL:  3000 index tuples were removed.
99       0 index pages have been deleted, 0 are currently reusable.
100       CPU 0.01s/0.08u sec elapsed 0.18 sec.
101       INFO:  index "onek_unique2" now contains 1000 tuples in 16 pages
102       DETAIL:  3000 index tuples were removed.
103       0 index pages have been deleted, 0 are currently reusable.
104       CPU 0.00s/0.07u sec elapsed 0.23 sec.
105       INFO:  index "onek_hundred" now contains 1000 tuples in 13 pages
106       DETAIL:  3000 index tuples were removed.
107       0 index pages have been deleted, 0 are currently reusable.
108       CPU 0.01s/0.08u sec elapsed 0.17 sec.
109       INFO:  index "onek_stringu1" now contains 1000 tuples in 48 pages
110       DETAIL:  3000 index tuples were removed.
111       0 index pages have been deleted, 0 are currently reusable.
112       CPU 0.01s/0.09u sec elapsed 0.59 sec.
113       INFO:  "onek": removed 3000 tuples in 108 pages
114       DETAIL:  CPU 0.01s/0.06u sec elapsed 0.07 sec.
115       INFO:  "onek": found 3000 removable, 1000 nonremovable tuples in 143 pages
116       DETAIL:  0 dead tuples cannot be removed yet.
117       There were 0 unused item pointers.
118       0 pages are entirely empty.
119       CPU 0.07s/0.39u sec elapsed 1.56 sec.
120       INFO:  analyzing "public.onek"
121       INFO:  "onek": 36 pages, 1000 rows sampled, 1000 estimated total rows
122       VACUUM
123
124

COMPATIBILITY

126       There is no VACUUM statement in the SQL standard.
127

SEE ALSO

129       vacuumdb [vacuumdb(1)], in the documentation
130
131
132
133SQL - Language Statements         2008-06-08                          VACUUM()
Impressum