ANALYZE scans specified tables (or all tables in the current database if none are named) and builds statistical metadata that the optimizer uses to choose efficient query plans. Statistics include histogram bounds, most-common values, distinct counts, and correlation metrics. Running ANALYZE does not modify user data; it updates rows in the system catalog (such as pg_statistic in PostgreSQL). The command can be executed manually or automatically by a database autovacuum daemon. Frequent data changes, massive inserts, or after bulk loads usually warrant a manual ANALYZE to keep statistics accurate. VERBOSE output shows progress details. Sampling is used rather than a full scan to reduce overhead, but the sample size scales with table size to maintain accuracy. ANALYZE requires appropriate privileges (typically the table owner or a superuser).
table_name
(identifier) - Name of the table to analyze (optional, analyzes all tables if omitted)column_name
(identifier) - One or more columns to analyze selectively (optional)VERBOSE
(keyword) - Prints progress messages while running (optional)VACUUM, EXPLAIN, VACUUM ANALYZE, STATISTICS, AUTOVACUUM, UPDATE STATISTICS
PostgreSQL 6.5 (1999)
Execution time depends on table size and sampling rate. It is generally fast because it samples rows rather than scanning every row.
No. It only writes to system catalogs, leaving user data untouched.
No. VACUUM reclaims dead tuples and can optionally analyze. ANALYZE only gathers statistics.
Yes. In PostgreSQL the autovacuum process runs ANALYZE automatically based on insert and update thresholds.