Ir al contenido principal

VACUUM - POSTGRESQL

 

Syntax

VACUUM [ FULL | SORT ONLY | DELETE ONLY | REINDEX ] [ [ table_name ] [ TO threshold PERCENT ] [ BOOST ] ]

Parameters

FULL

Sorts the specified table (or all tables in the current database) and reclaims disk space occupied by rows that were marked for deletion by previous UPDATE and DELETE operations. VACUUM FULL is the default.

A full vacuum doesn't perform a reindex for interleaved tables. To reindex interleaved tables followed by a full vacuum, use the VACUUM REINDEX option.

By default, VACUUM FULL skips the sort phase for any table that is already at least 95 percent sorted. If VACUUM is able to skip the sort phase, it performs a DELETE ONLY and reclaims space in the delete phase such that at least 95 percent of the remaining rows aren't marked for deletion.  

If the sort threshold isn't met (for example, if 90 percent of rows are sorted) and VACUUM performs a full sort, then it also performs a complete delete operation, recovering space from 100 percent of deleted rows.

You can change the default vacuum threshold only for a single table. To change the default vacuum threshold for a single table, include the table name and the TO threshold PERCENT parameter.

SORT ONLY

Sorts the specified table (or all tables in the current database) without reclaiming space freed by deleted rows. This option is useful when reclaiming disk space isn't important but re-sorting new rows is important. A SORT ONLY vacuum reduces the elapsed time for vacuum operations when the unsorted region doesn't contain a large number of deleted rows and doesn't span the entire sorted region. Applications that don't have disk space constraints but do depend on query optimizations associated with keeping table rows sorted can benefit from this kind of vacuum.

By default, VACUUM SORT ONLY skips any table that is already at least 95 percent sorted. To change the default sort threshold for a single table, include the table name and the TO threshold PERCENT parameter when you run VACUUM.

DELETE ONLY

Amazon Redshift automatically performs a DELETE ONLY vacuum in the background, so you rarely, if ever, need to run a DELETE ONLY vacuum.

A VACUUM DELETE reclaims disk space occupied by rows that were marked for deletion by previous UPDATE and DELETE operations, and compacts the table to free up the consumed space. A DELETE ONLY vacuum operation doesn't sort table data.

This option reduces the elapsed time for vacuum operations when reclaiming disk space is important but re-sorting new rows isn't important. This option can also be useful when your query performance is already optimal, and re-sorting rows to optimize query performance isn't a requirement.

By default, VACUUM DELETE ONLY reclaims space such that at least 95 percent of the remaining rows aren't marked for deletion. To change the default delete threshold for a single table, include the table name and the TO threshold PERCENT parameter when you run VACUUM. 

Some operations, such as ALTER TABLE APPEND, can cause tables to be fragmented. When you use the DELETE ONLY clause the vacuum operation reclaims space from fragmented tables. The same threshold value of 95 percent applies to the defragmentation operation.

REINDEX tablename

Analyzes the distribution of the values in interleaved sort key columns, then performs a full VACUUM operation. If REINDEX is used, a table name is required.

VACUUM REINDEX takes significantly longer than VACUUM FULL because it makes an additional pass to analyze the interleaved sort keys. The sort and merge operation can take longer for interleaved tables because the interleaved sort might need to rearrange more rows than a compound sort.

If a VACUUM REINDEX operation terminates before it completes, the next VACUUM resumes the reindex operation before performing the full vacuum operation.

VACUUM REINDEX isn't supported with TO threshold PERCENT. 

table_name

The name of a table to vacuum. If you don't specify a table name, the vacuum operation applies to all tables in the current database. You can specify any permanent or temporary user-created table. The command isn't meaningful for other objects, such as views and system tables.

If you include the TO threshold PERCENT parameter, a table name is required.

TO threshold PERCENT

A clause that specifies the threshold above which VACUUM skips the sort phase and the target threshold for reclaiming space in the delete phase. The sort threshold is the percentage of total rows that are already in sort order for the specified table prior to vacuuming.  The delete threshold is the minimum percentage of total rows not marked for deletion after vacuuming.

Because VACUUM re-sorts the rows only when the percent of sorted rows in a table is less than the sort threshold, Amazon Redshift can often reduce VACUUM times significantly. Similarly, when VACUUM isn't constrained to reclaim space from 100 percent of rows marked for deletion, it is often able to skip rewriting blocks that contain only a few deleted rows.

For example, if you specify 75 for threshold, VACUUM skips the sort phase if 75 percent or more of the table's rows are already in sort order. For the delete phase, VACUUMS sets a target of reclaiming disk space such that at least 75 percent of the table's rows aren't marked for deletion following the vacuum. The threshold value must be an integer between 0 and 100. The default is 95. If you specify a value of 100, VACUUM always sorts the table unless it's already fully sorted and reclaims space from all rows marked for deletion. If you specify a value of 0, VACUUM never sorts the table and never reclaims space.

If you include the TO threshold PERCENT parameter, you must also specify a table name. If a table name is omitted, VACUUM fails.

You can't use the TO threshold PERCENT parameter with REINDEX.

BOOST

Runs the VACUUM command with additional resources, such as memory and disk space, as they're available. With the BOOST option, VACUUM operates in one window and blocks concurrent deletes and updates for the duration of the VACUUM operation. Running with the BOOST option contends for system resources, which might affect query performance. Run the VACUUM BOOST when the load on the system is light, such as during maintenance operations.

Consider the following when using the BOOST option:

  • When BOOST is specified, the table_name value is required.

  • BOOST isn't supported with REINDEX.

  • BOOST is ignored with DELETE ONLY.


Examples

Reclaim space and database and re-sort rows in all tables based on the default 95 percent vacuum threshold.

vacuum;

Reclaim space and re-sort rows in the SALES table based on the default 95 percent threshold.

vacuum sales;

Always reclaim space and re-sort rows in the SALES table.

vacuum sales to 100 percent;

Re-sort rows in the SALES table only if fewer than 75 percent of rows are already sorted.

vacuum sort only sales to 75 percent;

Reclaim space in the SALES table such that at least 75 percent of the remaining rows aren't marked for deletion following the vacuum.

vacuum delete only sales to 75 percent;

Reindex and then vacuum the LISTING table.

vacuum reindex listing;

The following command returns an error.

vacuum reindex listing to 75 percent;

Comentarios

Entradas más populares de este blog

DAHDI ASTERISK

  Comandos DAHDI interesantes dahdi_cfg Este comando configura los módulos del kernel DAHDI desde el archivo /etc/dahdi/system.conf,  No ejecutar este comando si ya tienes tu sistema trabajando correctamente. Ejemplo de uso: Solo escribir en la consola dahdi_cfg dahdi_genconf Este script genera archivos de configuración para hardware DAHDI.  No ejecutar este comando si ya tienes tu sistema trabajando correctamente. Ejemplo de uso: Solo escribir en la consola dahdi_genconf dahdi_hardware Muestra las tarjetas conectadas a nuestro servidor y que son detectadas por Asterisk DAHDI. Es util cuando quieres saber si tu Asterisk encontró la interfaz telefónica colocada. Puedes compararla con lspci de Linux. Ejemplo de uso: Solo escribir en la consola dahdi_hardware dahdi_monitor Es una representación gráfica de la intensidad del audio, facilita observar si las señales recibidas o transmitidas son demasiado alto o fuera de balance. De igual manera permite grabar el canel en un arch...

The Elder Scrolls III: Morrowind - Edición Juego del Año

  The Elder Scrolls III: Morrowind - Edición Juego del Año JUEGO COMPLETO PARA PC DISPONIBLE EN GOG.COM Morrowind es un RPG para un jugador, épico y de final abierto, que te permite crear cualquier tipo de personaje imaginable y jugar con él, y está disponible para los miembros KEY: QLZ627B0FD65E0541F SPARTAN!!! APOYEN DANDO LIKE A MIS REDES SPARTAN.!! #FREEGAMES #GAMING #JUEGOS #PCGAMING #JUEGOSGRATIS #SPARTAN #SPARTANFREE #TWITCH #GRACIASTOTALES #VTUBER #FREE #HAPPY #REGIO #GAMES #GAMER #GAMERS #GAMEOVER #FOLLOWTOFOLLOW #PROJECTFREE #GRATIS #JUEGOSGRATIS #FREESPARTAN #GIFTGAMES #KEYGAME #SERIALJUEGO SIGANME!!! youtube.com/@thespartanfreegames Se vienen juegos nuevos!!!! GRACIAS TOTALES! New games are coming!!!!