VACUUM

Nombre

VACUUM -- limpia y opcionalmente analiza una base de datos

Sinopsis

VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ tabla ]
VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] ANALYZE [ tabla [ (columna [,  ...] ) ] ]

Descripción

VACUUM reclama el almacenamiento ocupado por tuplas muertas. En la operación normal de PostgreSQL, las tuplas que son eliminadas o obsoletas por una actualización no son fisicamente removidas de su tabla; permanecen presentes hasta que se hace un VACUUM. Por lo tanto, es necesario hacer un VACUUM periodicamente, especialmente sobre tablas actualizadas frecuentemente.

Sin parámetros, VACUUM procesa cada tabla en la base de datos actual de la cual el usuario tiene permisos de vaciado. Con un parámetro, VACUUM procesa solo la tabla especificada.

VACUUM ANALYZE realiza un VACUUM y luego un ANALYZE para cada tabla seleccionada. Esto es una combinación a mano para scripts de mantenimiento rutinario. vER ANALYZE para más detalles sobre su procesamiento.

Un VACUUM plano (sin FULL) simplemente reclama el espacio y lo hace disponible para su reuso. Esta forma del comando puede operar en paralelo con lecturas y escrituras normales a la tabla, ya que no se obtiene un bloqueo exclusivo. VACUUM FULL hace un procesamiento más extensivo, incluyendo mover las tuplas entre bloques para tratar de compactar la tabla a un número mínimo de bloques de disco. Esta forma es mucho más lenta y requiere un bloqueo exclusivo en cada tabla que esta siendo procesada.

Parámetros

FULL
Selecciona el vaciamiento "completo", el cual reclama más espacio, pero toma mucho más tiempo y bloquea exclusivamente la tabla.
FREEZE
Selecciona el "congelamiento" agresivo de tuplas. Especificar FREEZE es equivalente a realizar un VACUUM con el parámetro  vacuum_freeze_min_age establecido a cero. La opción FREEZE esta depreciada y será removida en liberaciones futuras; en su lugar establezca el parámetro.
VERBOSE
Imprime un reporte detallado de la actividad de vaciamiento para cada tabla.
ANALYZE
Actualiza las estadisticas usadas por el planeador para determinar la forma más eficiente de ejecutar una consulta.
tabla
El nombre de una columna (opcionalmente calificada por el esquema) de una tabla específica a vaciar. Por defecto se toman todas las tablas de la base de datos actual.
columna
El nombre de una columna específica a analizar. Por defecto se toman todas las columnas.

Salida

Cuando se especifica VERBOSE, VACUUM emite mensajes de progreso para indicar que tabla esta siendo actualmente procesada. También se imprimen varias estadísticas sobre las tablas.

Notes

To vacuum a table, one must ordinarily be the table's owner or a superuser. However, database owners are allowed to vacuum all tables in their databases, except shared catalogs. (The restriction for shared catalogs means that a true database-wide VACUUM can only be performed by a superuser.) VACUUM will skip over any tables that the calling user does not have permission to vacuum.

VACUUM cannot be executed inside a transaction block.

For tables withGINindexes, VACUUM (in any form) also completes any pending index insertions, by moving pending index entries to the appropriate places in the mainGINindex structure. See  Section 52.3.1 for details.

We recommend that active production databases be vacuumed frequently (at least nightly), in order to remove dead rows. After adding or deleting a large number of rows, it might be a good idea to issue a VACUUM ANALYZE command for the affected table. This will update the system catalogs with the results of all recent changes, and allow the PostgreSQL query planner to make better choices in planning queries.

The FULL 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. VACUUM FULL will usually shrink the table more than a plain VACUUM would. The FULL option does not shrink indexes; a periodic REINDEX is still recommended. In fact, it is often faster to drop all indexes, VACUUM FULL, and recreate the indexes.

VACUUM 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. See  Section 18.4.3 for details.

PostgreSQL includes an "autovacuum" facility which can automate routine vacuum maintenance. For more information about automatic and manual vacuuming, see  Section 23.1.

Examples

The following is an example from running VACUUM on a table in the regression database:

regression=# VACUUM VERBOSE ANALYZE onek;
INFO:  vacuuming "public.onek"
INFO:  index "onek_unique1" now contains 1000 tuples in 14 pages
DETAIL:  3000 index tuples were removed.
0 index pages have been deleted, 0 are currently reusable.
CPU 0.01s/0.08u sec elapsed 0.18 sec.
INFO:  index "onek_unique2" now contains 1000 tuples in 16 pages
DETAIL:  3000 index tuples were removed.
0 index pages have been deleted, 0 are currently reusable.
CPU 0.00s/0.07u sec elapsed 0.23 sec.
INFO:  index "onek_hundred" now contains 1000 tuples in 13 pages
DETAIL:  3000 index tuples were removed.
0 index pages have been deleted, 0 are currently reusable.
CPU 0.01s/0.08u sec elapsed 0.17 sec.
INFO:  index "onek_stringu1" now contains 1000 tuples in 48 pages
DETAIL:  3000 index tuples were removed.
0 index pages have been deleted, 0 are currently reusable.
CPU 0.01s/0.09u sec elapsed 0.59 sec.
INFO:  "onek": removed 3000 tuples in 108 pages
DETAIL:  CPU 0.01s/0.06u sec elapsed 0.07 sec.
INFO:  "onek": found 3000 removable, 1000 nonremovable tuples in 143 pages
DETAIL:  0 dead tuples cannot be removed yet.
There were 0 unused item pointers.
0 pages are entirely empty.
CPU 0.07s/0.39u sec elapsed 1.56 sec.
INFO:  analyzing "public.onek"
INFO:  "onek": 36 pages, 1000 rows sampled, 1000 estimated total rows
VACUUM

Compatibility

There is no VACUUM statement in the SQL standard.

See Also

 vacuumdb,  Cost-Based Vacuum Delay,  The Autovacuum Daemon