{
    "content": [
        {
            "type": "text",
            "text": "# ANALYZE (man)\n\n## NAME\n\nANALYZE - collect statistics about a database\n\n## SYNOPSIS\n\nANALYZE [ ( option [, ...] ) ] [ tableandcolumns [, ...] ]\nANALYZE [ VERBOSE ] [ tableandcolumns [, ...] ]\nwhere option can be one of:\nVERBOSE [ boolean ]\nSKIPLOCKED [ boolean ]\nand tableandcolumns is:\ntablename [ ( columnname [, ...] ) ]\n\n## DESCRIPTION\n\nANALYZE collects statistics about the contents of tables in the database, and stores the\nresults in the pgstatistic system catalog. Subsequently, the query planner uses these\nstatistics to help determine the most efficient execution plans for queries.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **PARAMETERS**\n- **OUTPUTS**\n- **NOTES**\n- **COMPATIBILITY**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "ANALYZE",
        "section": "",
        "mode": "man",
        "summary": "ANALYZE - collect statistics about a database",
        "synopsis": "ANALYZE [ ( option [, ...] ) ] [ tableandcolumns [, ...] ]\nANALYZE [ VERBOSE ] [ tableandcolumns [, ...] ]\nwhere option can be one of:\nVERBOSE [ boolean ]\nSKIPLOCKED [ boolean ]\nand tableandcolumns is:\ntablename [ ( columnname [, ...] ) ]",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "VACUUM",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/VACUUM/7/json"
            },
            {
                "name": "vacuumdb",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/vacuumdb/1/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "PARAMETERS",
                "lines": 27,
                "subsections": []
            },
            {
                "name": "OUTPUTS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "NOTES",
                "lines": 85,
                "subsections": []
            },
            {
                "name": "COMPATIBILITY",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "ANALYZE - collect statistics about a database\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "ANALYZE [ ( option [, ...] ) ] [ tableandcolumns [, ...] ]\nANALYZE [ VERBOSE ] [ tableandcolumns [, ...] ]\n\nwhere option can be one of:\n\nVERBOSE [ boolean ]\nSKIPLOCKED [ boolean ]\n\nand tableandcolumns is:\n\ntablename [ ( columnname [, ...] ) ]\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "ANALYZE collects statistics about the contents of tables in the database, and stores the\nresults in the pgstatistic system catalog. Subsequently, the query planner uses these\nstatistics to help determine the most efficient execution plans for queries.\n\nWithout a tableandcolumns list, ANALYZE processes every table and materialized view in the\ncurrent database that the current user has permission to analyze. With a list, ANALYZE\nprocesses only those table(s). It is further possible to give a list of column names for a\ntable, in which case only the statistics for those columns are collected.\n\nWhen the option list is surrounded by parentheses, the options can be written in any order.\nThe parenthesized syntax was added in PostgreSQL 11; the unparenthesized syntax is\ndeprecated.\n",
                "subsections": []
            },
            "PARAMETERS": {
                "content": "VERBOSE\nEnables display of progress messages.\n\nSKIPLOCKED\nSpecifies that ANALYZE should not wait for any conflicting locks to be released when\nbeginning work on a relation: if a relation cannot be locked immediately without waiting,\nthe relation is skipped. Note that even with this option, ANALYZE may still block when\nopening the relation's indexes or when acquiring sample rows from partitions, table\ninheritance children, and some types of foreign tables. Also, while ANALYZE ordinarily\nprocesses all partitions of specified partitioned tables, this option will cause ANALYZE\nto skip all partitions if there is a conflicting lock on the partitioned table.\n\nboolean\nSpecifies whether the selected option should be turned on or off. You can write TRUE, ON,\nor 1 to enable the option, and FALSE, OFF, or 0 to disable it. The boolean value can also\nbe omitted, in which case TRUE is assumed.\n\ntablename\nThe name (possibly schema-qualified) of a specific table to analyze. If omitted, all\nregular tables, partitioned tables, and materialized views in the current database are\nanalyzed (but not foreign tables). If the specified table is a partitioned table, both\nthe inheritance statistics of the partitioned table as a whole and statistics of the\nindividual partitions are updated.\n\ncolumnname\nThe name of a specific column to analyze. Defaults to all columns.\n",
                "subsections": []
            },
            "OUTPUTS": {
                "content": "When VERBOSE is specified, ANALYZE emits progress messages to indicate which table is\ncurrently being processed. Various statistics about the tables are printed as well.\n",
                "subsections": []
            },
            "NOTES": {
                "content": "To analyze a table, one must ordinarily be the table's owner or a superuser. However,\ndatabase owners are allowed to analyze all tables in their databases, except shared catalogs.\n(The restriction for shared catalogs means that a true database-wide ANALYZE can only be\nperformed by a superuser.)  ANALYZE will skip over any tables that the calling user does not\nhave permission to analyze.\n\nForeign tables are analyzed only when explicitly selected. Not all foreign data wrappers\nsupport ANALYZE. If the table's wrapper does not support ANALYZE, the command prints a\nwarning and does nothing.\n\nIn the default PostgreSQL configuration, the autovacuum daemon (see Section 25.1.6) takes\ncare of automatic analyzing of tables when they are first loaded with data, and as they\nchange throughout regular operation. When autovacuum is disabled, it is a good idea to run\nANALYZE periodically, or just after making major changes in the contents of a table. Accurate\nstatistics will help the planner to choose the most appropriate query plan, and thereby\nimprove the speed of query processing. A common strategy for read-mostly databases is to run\nVACUUM and ANALYZE once a day during a low-usage time of day. (This will not be sufficient if\nthere is heavy update activity.)\n\nANALYZE requires only a read lock on the target table, so it can run in parallel with other\nactivity on the table.\n\nThe statistics collected by ANALYZE usually include a list of some of the most common values\nin each column and a histogram showing the approximate data distribution in each column. One\nor both of these can be omitted if ANALYZE deems them uninteresting (for example, in a\nunique-key column, there are no common values) or if the column data type does not support\nthe appropriate operators. There is more information about the statistics in Chapter 25.\n\nFor large tables, ANALYZE takes a random sample of the table contents, rather than examining\nevery row. This allows even very large tables to be analyzed in a small amount of time. Note,\nhowever, that the statistics are only approximate, and will change slightly each time ANALYZE\nis run, even if the actual table contents did not change. This might result in small changes\nin the planner's estimated costs shown by EXPLAIN. In rare situations, this non-determinism\nwill cause the planner's choices of query plans to change after ANALYZE is run. To avoid\nthis, raise the amount of statistics collected by ANALYZE, as described below.\n\nThe extent of analysis can be controlled by adjusting the defaultstatisticstarget\nconfiguration variable, or on a column-by-column basis by setting the per-column statistics\ntarget with ALTER TABLE ... ALTER COLUMN ... SET STATISTICS. The target value sets the\nmaximum number of entries in the most-common-value list and the maximum number of bins in the\nhistogram. The default target value is 100, but this can be adjusted up or down to trade off\naccuracy of planner estimates against the time taken for ANALYZE and the amount of space\noccupied in pgstatistic. In particular, setting the statistics target to zero disables\ncollection of statistics for that column. It might be useful to do that for columns that are\nnever used as part of the WHERE, GROUP BY, or ORDER BY clauses of queries, since the planner\nwill have no use for statistics on such columns.\n\nThe largest statistics target among the columns being analyzed determines the number of table\nrows sampled to prepare the statistics. Increasing the target causes a proportional increase\nin the time and space needed to do ANALYZE.\n\nOne of the values estimated by ANALYZE is the number of distinct values that appear in each\ncolumn. Because only a subset of the rows are examined, this estimate can sometimes be quite\ninaccurate, even with the largest possible statistics target. If this inaccuracy leads to bad\nquery plans, a more accurate value can be determined manually and then installed with ALTER\nTABLE ... ALTER COLUMN ... SET (ndistinct = ...).\n\nIf the table being analyzed has inheritance children, ANALYZE gathers two sets of statistics:\none on the rows of the parent table only, and a second including rows of both the parent\ntable and all of its children. This second set of statistics is needed when planning queries\nthat process the inheritance tree as a whole. The child tables themselves are not\nindividually analyzed in this case. The autovacuum daemon, however, will only consider\ninserts or updates on the parent table itself when deciding whether to trigger an automatic\nanalyze for that table. If that table is rarely inserted into or updated, the inheritance\nstatistics will not be up to date unless you run ANALYZE manually.\n\nFor partitioned tables, ANALYZE gathers statistics by sampling rows from all partitions; in\naddition, it will recurse into each partition and update its statistics. Each leaf partition\nis analyzed only once, even with multi-level partitioning. No statistics are collected for\nonly the parent table (without data from its partitions), because with partitioning it's\nguaranteed to be empty.\n\nThe autovacuum daemon does not process partitioned tables, nor does it process inheritance\nparents if only the children are ever modified. It is usually necessary to periodically run a\nmanual ANALYZE to keep the statistics of the table hierarchy up to date.\n\nIf any child tables or partitions are foreign tables whose foreign data wrappers do not\nsupport ANALYZE, those tables are ignored while gathering inheritance statistics.\n\nIf the table being analyzed is completely empty, ANALYZE will not record new statistics for\nthat table. Any existing statistics will be retained.\n\nEach backend running ANALYZE will report its progress in the pgstatprogressanalyze view.\nSee Section 28.4.1 for details.\n",
                "subsections": []
            },
            "COMPATIBILITY": {
                "content": "There is no ANALYZE statement in the SQL standard.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "VACUUM(7), vacuumdb(1), Section 20.4.4, Section 25.1.6, Section 28.4.1\n\n\n\nPostgreSQL 14.23                                2026                                      ANALYZE(7)",
                "subsections": []
            }
        }
    }
}