<!--
doc/src/sgml/ref/analyze.sgml
PostgreSQL documentation
-->
<refentry id="sql-analyze">
<indexterm zone="sql-analyze">
<primary>ANALYZE</primary>
</indexterm>
<refmeta>
<refentrytitle>ANALYZE</refentrytitle>
<manvolnum>7</manvolnum>
<refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta>
<refnamediv>
<refname>ANALYZE</refname>
<refpurpose>collect statistics about a database</refpurpose>
</refnamediv>
<refsynopsisdiv>
<synopsis>
ANALYZE [ ( <replaceable class="parameter">option</replaceable> [, ...] ) ] [ <replaceable class="parameter">table_and_columns</replaceable> [, ...] ]
<phrase>where <replaceable class="parameter">option</replaceable> can be one of:</phrase>
VERBOSE [ <replaceable class="parameter">boolean</replaceable> ]
SKIP_LOCKED [ <replaceable class="parameter">boolean</replaceable> ]
BUFFER_USAGE_LIMIT <replaceable class="parameter">size</replaceable>
<phrase>and <replaceable class="parameter">table_and_columns</replaceable> is:</phrase>
[ ONLY ] <replaceable class="parameter">table_name</replaceable> [ * ] [ ( <replaceable class="parameter">column_name</replaceable> [, ...] ) ]
</synopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
<command>ANALYZE</command> collects statistics about the contents
of tables in the database, and stores the results in the <link
linkend="catalog-pg-statistic"><structname>pg_statistic</structname></link>
system catalog. Subsequently, the query planner uses these
statistics to help determine the most efficient execution plans for
queries.
</para>
<para>
Without a <replaceable class="parameter">table_and_columns</replaceable>
list, <command>ANALYZE</command> processes every table and materialized view
in the current database that the current user has permission to analyze.
With a list, <command>ANALYZE</command> processes only those table(s).
It is further possible to give a list of column names for a table,
in which case only the statistics for those columns are collected.
</para>
</refsect1>
<refsect1>
<title>Parameters</title>
<variablelist>
<varlistentry>
<term><literal>VERBOSE</literal></term>
<listitem>
<para>
Enables display of progress messages at <literal>INFO</literal> level.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>SKIP_LOCKED</literal></term>
<listitem>
<para>
Specifies that <command>ANALYZE</command> should not wait for any
conflicting locks to be released when beginning work on a relation:
if a relation cannot be locked immediately without waiting, the relation
is skipped. Note that even with this option, <command>ANALYZE</command>
may still block when opening the relation's indexes or when acquiring
sample rows from partitions, table inheritance children, and some
types of foreign tables. Also, while <command>ANALYZE</command>
ordinarily processes all partitions of specified partitioned tables,
this option will cause <command>ANALYZE</command> to skip all
partitions if there is a conflicting lock on the partitioned table.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>BUFFER_USAGE_LIMIT</literal></term>
<listitem>
<para>
Specifies the
<glossterm linkend="glossary-buffer-access-strategy">Buffer Access Strategy</glossterm>
ring buffer size for <command>ANALYZE</command>. This size is used to
calculate the number of shared buffers which will be reused as part of
this strategy. <literal>0</literal> disables use of a
<literal>Buffer Access Strategy</literal>. When this option is not
specified, <command>ANALYZE</command> uses the value from
<xref linkend="guc-vacuum-buffer-usage-limit"/>. Higher settings can
allow <command>ANALYZE</command> to run more quickly, but having too
large a setting may cause