Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > 5fea23694c765462b86d6ddf74461eab > files > 916

postgresql9.6-docs-9.6.22-1.mga7.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>VACUUM</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 9.6.22 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="SQL Commands"
HREF="sql-commands.html"><LINK
REL="PREVIOUS"
TITLE="UPDATE"
HREF="sql-update.html"><LINK
REL="NEXT"
TITLE="VALUES"
HREF="sql-values.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2021-05-18T09:16:10"></HEAD
><BODY
CLASS="REFENTRY"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="4"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.6.22 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="UPDATE"
HREF="sql-update.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="sql-commands.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="VALUES"
HREF="sql-values.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="SQL-VACUUM"
></A
>VACUUM</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN93482"
></A
><H2
>Name</H2
>VACUUM&nbsp;--&nbsp;garbage-collect and optionally analyze a database</DIV
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN93485"
></A
><H2
>Synopsis</H2
><PRE
CLASS="SYNOPSIS"
>VACUUM [ ( { FULL | FREEZE | VERBOSE | ANALYZE | DISABLE_PAGE_SKIPPING } [, ...] ) ] [ <TT
CLASS="REPLACEABLE"
><I
>table_name</I
></TT
> [ (<TT
CLASS="REPLACEABLE"
><I
>column_name</I
></TT
> [, ...] ) ] ]
VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] [ <TT
CLASS="REPLACEABLE"
><I
>table_name</I
></TT
> ]
VACUUM [ FULL ] [ FREEZE ] [ VERBOSE ] ANALYZE [ <TT
CLASS="REPLACEABLE"
><I
>table_name</I
></TT
> [ (<TT
CLASS="REPLACEABLE"
><I
>column_name</I
></TT
> [, ...] ) ] ]</PRE
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN93492"
></A
><H2
>Description</H2
><P
>   <TT
CLASS="COMMAND"
>VACUUM</TT
> reclaims storage occupied by dead tuples.
   In normal <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> operation, tuples that
   are deleted or obsoleted by an update are not physically removed from
   their table; they remain present until a <TT
CLASS="COMMAND"
>VACUUM</TT
> is
   done.  Therefore it's necessary to do <TT
CLASS="COMMAND"
>VACUUM</TT
>
   periodically, especially on frequently-updated tables.
  </P
><P
>   With no parameter, <TT
CLASS="COMMAND"
>VACUUM</TT
> processes every table in the
   current database that the current user has permission to vacuum.
   With a parameter, <TT
CLASS="COMMAND"
>VACUUM</TT
> processes only that table.
  </P
><P
>   <TT
CLASS="COMMAND"
>VACUUM ANALYZE</TT
> performs a <TT
CLASS="COMMAND"
>VACUUM</TT
>
   and then an <TT
CLASS="COMMAND"
>ANALYZE</TT
> for each selected table.  This
   is a handy combination form for routine maintenance scripts.  See
   <A
HREF="sql-analyze.html"
>ANALYZE</A
>
   for more details about its processing.
  </P
><P
>   Plain <TT
CLASS="COMMAND"
>VACUUM</TT
> (without <TT
CLASS="LITERAL"
>FULL</TT
>) 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's just kept available for re-use within the
   same table.  <TT
CLASS="COMMAND"
>VACUUM FULL</TT
> 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 <TT
CLASS="LITERAL"
>ACCESS EXCLUSIVE</TT
> lock on each table while
   it is being processed.
  </P
><P
>   When the option list is surrounded by parentheses, the options can be
   written in any order.  Without parentheses, options must be specified
   in exactly the order shown above.
   The parenthesized syntax was added in
   <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> 9.0;  the unparenthesized
   syntax is deprecated.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN93514"
></A
><H2
>Parameters</H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="LITERAL"
>FULL</TT
></DT
><DD
><P
>      Selects <SPAN
CLASS="QUOTE"
>"full"</SPAN
> 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't 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.
     </P
></DD
><DT
><TT
CLASS="LITERAL"
>FREEZE</TT
></DT
><DD
><P
>      Selects aggressive <SPAN
CLASS="QUOTE"
>"freezing"</SPAN
> of tuples.
      Specifying <TT
CLASS="LITERAL"
>FREEZE</TT
> is equivalent to performing
      <TT
CLASS="COMMAND"
>VACUUM</TT
> with the
      <A
HREF="runtime-config-client.html#GUC-VACUUM-FREEZE-MIN-AGE"
>vacuum_freeze_min_age</A
> and
      <A
HREF="runtime-config-client.html#GUC-VACUUM-FREEZE-TABLE-AGE"
>vacuum_freeze_table_age</A
> parameters
      set to zero.  Aggressive freezing is always performed when the
      table is rewritten, so this option is redundant when <TT
CLASS="LITERAL"
>FULL</TT
>
      is specified.
     </P
></DD
><DT
><TT
CLASS="LITERAL"
>VERBOSE</TT
></DT
><DD
><P
>      Prints a detailed vacuum activity report for each table.
     </P
></DD
><DT
><TT
CLASS="LITERAL"
>ANALYZE</TT
></DT
><DD
><P
>      Updates statistics used by the planner to determine the most
      efficient way to execute a query.
     </P
></DD
><DT
><TT
CLASS="LITERAL"
>DISABLE_PAGE_SKIPPING</TT
></DT
><DD
><P
>      Normally, <TT
CLASS="COMMAND"
>VACUUM</TT
> will skip pages based on the <A
HREF="routine-vacuuming.html#VACUUM-FOR-VISIBILITY-MAP"
>visibility map</A
>.  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 the contents of the visibility map are thought to
      be suspect, which should happen only if there is a hardware or software
      issue causing database corruption.
     </P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>table_name</I
></TT
></DT
><DD
><P
>      The name (optionally schema-qualified) of a specific table to
      vacuum. Defaults to all tables in the current database.
     </P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>column_name</I
></TT
></DT
><DD
><P
>      The name of a specific column to analyze. Defaults to all columns.
      If a column list is specified, <TT
CLASS="LITERAL"
>ANALYZE</TT
> is implied.
     </P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN93562"
></A
><H2
>Outputs</H2
><P
>    When <TT
CLASS="LITERAL"
>VERBOSE</TT
> is specified, <TT
CLASS="COMMAND"
>VACUUM</TT
> emits
    progress messages to indicate which table is currently being
    processed.  Various statistics about the tables are printed as well.
   </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN93567"
></A
><H2
>Notes</H2
><P
>    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
    <TT
CLASS="COMMAND"
>VACUUM</TT
> can only be performed by a superuser.)
    <TT
CLASS="COMMAND"
>VACUUM</TT
> will skip over any tables that the calling user
    does not have permission to vacuum.
   </P
><P
>    <TT
CLASS="COMMAND"
>VACUUM</TT
> cannot be executed inside a transaction block.
   </P
><P
>    For tables with <ACRONYM
CLASS="ACRONYM"
>GIN</ACRONYM
> indexes, <TT
CLASS="COMMAND"
>VACUUM</TT
> (in
    any form) also completes any pending index insertions, by moving pending
    index entries to the appropriate places in the main <ACRONYM
CLASS="ACRONYM"
>GIN</ACRONYM
> index
    structure.  See <A
HREF="gin-implementation.html#GIN-FAST-UPDATE"
>Section 63.4.1</A
> for details.
   </P
><P
>    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 <TT
CLASS="COMMAND"
>VACUUM
    ANALYZE</TT
> command for the affected table. This will update the
    system catalogs with
    the results of all recent changes, and allow the
    <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> query planner to make better
    choices in planning queries.
   </P
><P
>    The <TT
CLASS="OPTION"
>FULL</TT
> 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. <TT
CLASS="COMMAND"
>VACUUM FULL</TT
> will usually shrink the table
    more than a plain <TT
CLASS="COMMAND"
>VACUUM</TT
> would.
   </P
><P
>    <TT
CLASS="COMMAND"
>VACUUM</TT
> 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 <A
HREF="runtime-config-resource.html#RUNTIME-CONFIG-RESOURCE-VACUUM-COST"
>Section 19.4.4</A
> for details.
   </P
><P
>    <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> includes an <SPAN
CLASS="QUOTE"
>"autovacuum"</SPAN
>
    facility which can automate routine vacuum maintenance.  For more
    information about automatic and manual vacuuming, see
    <A
HREF="routine-vacuuming.html"
>Section 24.1</A
>.
   </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN93593"
></A
><H2
>Examples</H2
><P
>   To clean a single table <TT
CLASS="LITERAL"
>onek</TT
>, analyze it for
   the optimizer and print a detailed vacuum activity report:

</P><PRE
CLASS="PROGRAMLISTING"
>VACUUM (VERBOSE, ANALYZE) onek;</PRE
><P></P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN93598"
></A
><H2
>Compatibility</H2
><P
>   There is no <TT
CLASS="COMMAND"
>VACUUM</TT
> statement in the SQL standard.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN93602"
></A
><H2
>See Also</H2
><A
HREF="app-vacuumdb.html"
><SPAN
CLASS="APPLICATION"
>vacuumdb</SPAN
></A
>, <A
HREF="runtime-config-resource.html#RUNTIME-CONFIG-RESOURCE-VACUUM-COST"
>Section 19.4.4</A
>, <A
HREF="routine-vacuuming.html#AUTOVACUUM"
>Section 24.1.6</A
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="sql-update.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="sql-values.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>UPDATE</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="sql-commands.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>VALUES</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>