37 lines
1.3 KiB
SQL
37 lines
1.3 KiB
SQL
-- Analyze stats for a table testanalyze(schema is public)
|
|
|
|
dbaclass=# analyze testanalyze;
|
|
ANALYZE
|
|
|
|
-- For analyzing selected columns for emptab table ( schema is dbatest)
|
|
|
|
dbaclass=# analyze dbatest.emptab (datname,datdba);
|
|
ANALYZE
|
|
|
|
dbaclass=# select relname,reltuples from pg_class where relname in ('testanalyze','emptab');
|
|
relname | reltuples
|
|
-------------+-----------
|
|
testanalyze | 4
|
|
emptab | 4
|
|
(2 rows)
|
|
|
|
dbaclass=# select schemaname,relname,analyze_count,last_analyze,last_autoanalyze from pg_stat_user_tables where relname in ('testanalyze','emptab');
|
|
schemaname | relname | analyze_count | last_analyze | last_autoanalyze
|
|
------------+-------------+---------------+----------------------------------+------------------
|
|
public | testanalyze | 1 | 2020-07-21 17:00:49.687053+05:30 |
|
|
dbatest | emptab | 1 | 2020-07-21 17:10:01.111517+05:30 |
|
|
(2 rows)
|
|
|
|
---Analyze command with verbose command
|
|
|
|
dbaclass=# analyze verbose dbatest.emptab (datname,datdba);
|
|
|
|
INFO: analyzing "dbatest.emptab"
|
|
INFO: "emptab": scanned 1 of 1 pages, containing 4 live rows and 0 dead rows; 4 rows in sample, 4 estimated total rows
|
|
ANALYZE
|
|
|
|
---Analyze tables in the current schema that the user has access to.
|
|
|
|
|
|
|
|
dbaclass=# analyze ; |