Server IP : 103.119.228.120 / Your IP : 18.221.192.248 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/local/ssl/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 >ANALYZE</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="ALTER VIEW" HREF="sql-alterview.html"><LINK REL="NEXT" TITLE="BEGIN" HREF="sql-begin.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="ALTER VIEW" HREF="sql-alterview.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="BEGIN" HREF="sql-begin.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="SQL-ANALYZE" ></A >ANALYZE</H1 ><DIV CLASS="REFNAMEDIV" ><A NAME="AEN66264" ></A ><H2 >Name</H2 >ANALYZE -- collect statistics about a database</DIV ><DIV CLASS="REFSYNOPSISDIV" ><A NAME="AEN66269" ></A ><H2 >Synopsis</H2 ><PRE CLASS="SYNOPSIS" >ANALYZE [ VERBOSE ] [ <TT CLASS="REPLACEABLE" ><I >table_name</I ></TT > [ ( <TT CLASS="REPLACEABLE" ><I >column_name</I ></TT > [, ...] ) ] ]</PRE ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN66273" ></A ><H2 >Description</H2 ><P > <TT CLASS="COMMAND" >ANALYZE</TT > collects statistics about the contents of tables in the database, and stores the results in the <A HREF="catalog-pg-statistic.html" ><TT CLASS="STRUCTNAME" >pg_statistic</TT ></A > system catalog. Subsequently, the query planner uses these statistics to help determine the most efficient execution plans for queries. </P ><P > With no parameter, <TT CLASS="COMMAND" >ANALYZE</TT > examines every table in the current database. With a parameter, <TT CLASS="COMMAND" >ANALYZE</TT > examines only that table. It is further possible to give a list of column names, in which case only the statistics for those columns are collected. </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN66282" ></A ><H2 >Parameters</H2 ><P ></P ><DIV CLASS="VARIABLELIST" ><DL ><DT ><TT CLASS="LITERAL" >VERBOSE</TT ></DT ><DD ><P > Enables display of progress messages. </P ></DD ><DT ><TT CLASS="REPLACEABLE" ><I >table_name</I ></TT ></DT ><DD ><P > The name (possibly schema-qualified) of a specific table to analyze. If omitted, all regular tables (but not foreign tables) in the current database are analyzed. </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. </P ></DD ></DL ></DIV ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN66300" ></A ><H2 >Outputs</H2 ><P > When <TT CLASS="LITERAL" >VERBOSE</TT > is specified, <TT CLASS="COMMAND" >ANALYZE</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="AEN66305" ></A ><H2 >Notes</H2 ><P > Foreign tables are analyzed only when explicitly selected. Not all foreign data wrappers support <TT CLASS="COMMAND" >ANALYZE</TT >. If the table's wrapper does not support <TT CLASS="COMMAND" >ANALYZE</TT >, the command prints a warning and does nothing. </P ><P > In the default <SPAN CLASS="PRODUCTNAME" >PostgreSQL</SPAN > configuration, the autovacuum daemon (see <A HREF="routine-vacuuming.html#AUTOVACUUM" >Section 23.1.6</A >) takes care of automatic analyzing of tables when they are first loaded with data, and as they change throughout regular operation. When autovacuum is disabled, it is a good idea to run <TT CLASS="COMMAND" >ANALYZE</TT > periodically, or just after making major changes in the contents of a table. Accurate statistics will help the planner to choose the most appropriate query plan, and thereby improve the speed of query processing. A common strategy for read-mostly databases is to run <A HREF="sql-vacuum.html" >VACUUM</A > and <TT CLASS="COMMAND" >ANALYZE</TT > once a day during a low-usage time of day. (This will not be sufficient if there is heavy update activity.) </P ><P > <TT CLASS="COMMAND" >ANALYZE</TT > requires only a read lock on the target table, so it can run in parallel with other activity on the table. </P ><P > The statistics collected by <TT CLASS="COMMAND" >ANALYZE</TT > usually include a list of some of the most common values in each column and a histogram showing the approximate data distribution in each column. One or both of these can be omitted if <TT CLASS="COMMAND" >ANALYZE</TT > deems them uninteresting (for example, in a unique-key column, there are no common values) or if the column data type does not support the appropriate operators. There is more information about the statistics in <A HREF="maintenance.html" >Chapter 23</A >. </P ><P > For large tables, <TT CLASS="COMMAND" >ANALYZE</TT > takes a random sample of the table contents, rather than examining every row. This allows even very large tables to be analyzed in a small amount of time. Note, however, that the statistics are only approximate, and will change slightly each time <TT CLASS="COMMAND" >ANALYZE</TT > is run, even if the actual table contents did not change. This might result in small changes in the planner's estimated costs shown by <A HREF="sql-explain.html" >EXPLAIN</A >. In rare situations, this non-determinism will cause the planner's choices of query plans to change after <TT CLASS="COMMAND" >ANALYZE</TT > is run. To avoid this, raise the amount of statistics collected by <TT CLASS="COMMAND" >ANALYZE</TT >, as described below. </P ><P > The extent of analysis can be controlled by adjusting the <A HREF="runtime-config-query.html#GUC-DEFAULT-STATISTICS-TARGET" >default_statistics_target</A > configuration variable, or on a column-by-column basis by setting the per-column statistics target with <TT CLASS="COMMAND" >ALTER TABLE ... ALTER COLUMN ... SET STATISTICS</TT > (see <A HREF="sql-altertable.html" >ALTER TABLE</A >). The target value sets the maximum number of entries in the most-common-value list and the maximum number of bins in the histogram. The default target value is 100, but this can be adjusted up or down to trade off accuracy of planner estimates against the time taken for <TT CLASS="COMMAND" >ANALYZE</TT > and the amount of space occupied in <TT CLASS="LITERAL" >pg_statistic</TT >. In particular, setting the statistics target to zero disables collection of statistics for that column. It might be useful to do that for columns that are never used as part of the <TT CLASS="LITERAL" >WHERE</TT >, <TT CLASS="LITERAL" >GROUP BY</TT >, or <TT CLASS="LITERAL" >ORDER BY</TT > clauses of queries, since the planner will have no use for statistics on such columns. </P ><P > The largest statistics target among the columns being analyzed determines the number of table rows sampled to prepare the statistics. Increasing the target causes a proportional increase in the time and space needed to do <TT CLASS="COMMAND" >ANALYZE</TT >. </P ><P > One of the values estimated by <TT CLASS="COMMAND" >ANALYZE</TT > is the number of distinct values that appear in each column. Because only a subset of the rows are examined, this estimate can sometimes be quite inaccurate, even with the largest possible statistics target. If this inaccuracy leads to bad query plans, a more accurate value can be determined manually and then installed with <TT CLASS="COMMAND" >ALTER TABLE ... ALTER COLUMN ... SET (n_distinct = ...)</TT > (see <A HREF="sql-altertable.html" >ALTER TABLE</A >). </P ><P > If the table being analyzed has one or more children, <TT CLASS="COMMAND" >ANALYZE</TT > will gather statistics twice: once on the rows of the parent table only, and a second time on the rows of the parent table with all of its children. This second set of statistics is needed when planning queries that traverse the entire inheritance tree. The autovacuum daemon, however, will only consider inserts or updates on the parent table itself when deciding whether to trigger an automatic analyze for that table. If that table is rarely inserted into or updated, the inheritance statistics will not be up to date unless you run <TT CLASS="COMMAND" >ANALYZE</TT > manually. </P ><P > If the table being analyzed is completely empty, <TT CLASS="COMMAND" >ANALYZE</TT > will not record new statistics for that table. Any existing statistics will be retained. </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN66348" ></A ><H2 >Compatibility</H2 ><P > There is no <TT CLASS="COMMAND" >ANALYZE</TT > statement in the SQL standard. </P ></DIV ><DIV CLASS="REFSECT1" ><A NAME="AEN66352" ></A ><H2 >See Also</H2 ><A HREF="sql-vacuum.html" >VACUUM</A >, <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-alterview.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-begin.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >ALTER VIEW</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" >BEGIN</TD ></TR ></TABLE ></DIV ></BODY ></HTML >