Server IP : 103.119.228.120 / Your IP : 3.138.118.194 Web Server : Apache System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : nobody ( 99) PHP Version : 5.6.40 Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/local/ssl/share/doc/postgresql-9.2.24/html/ |
Upload File : |
<!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.2.24 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="2017-11-06T22:43:11"></HEAD ><BODY CLASS="REFENTRY" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="5" ALIGN="center" VALIGN="bottom" ><A HREF="index.html" >PostgreSQL 9.2.24 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="AEN79704" ></A ><H2 >Name</H2 >VACUUM -- garbage-collect and optionally analyze a database</DIV ><DIV CLASS="REFSYNOPSISDIV" ><A NAME="AEN79709" ></A ><H2 >Synopsis</H2 ><PRE CLASS="SYNOPSIS" >VACUUM [ ( { FULL | FREEZE | VERBOSE | ANALYZE } [, ...] ) ] [ <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="AEN79716" ></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 exclusive 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="AEN79737" ></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 > parameter set to zero. </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="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="AEN79776" ></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="AEN79781" ></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 55.3.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 18.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 23.1</A >. </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN79807" ></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="AEN79812" ></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="AEN79816" ></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 18.4.4</A >, <A HREF="routine-vacuuming.html#AUTOVACUUM" >Section 23.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 >