highgo=# \d test;
数据表 "public.test"
栏位 | 类型 | 修饰词
------+---------+--------
id | integer |
索引:
"t1_idx" btree (id)
highgo=# select schemaname ,relname,last_analyze from pg_stat_all_tables where relname='test';
schemaname | relname | last_analyze
------------+---------+-------------------------------
public | test | 2017-10-05 11:15:35.877243+08
(1 行记录)
highgo=# \! time
当前时间: 11:21:33.07
输入新时间:
highgo=# analyze test;
ANALYZE
highgo=# select schemaname ,relname,last_analyze from pg_stat_all_tables where relname='test';
schemaname | relname | last_analyze
------------+---------+-------------------------------
public | test | 2017-10-05 11:21:42.321886+08
(1 行记录)
highgo=#
数据表 "public.test"
栏位 | 类型 | 修饰词
------+---------+--------
id | integer |
索引:
"t1_idx" btree (id)
highgo=# select schemaname ,relname,last_analyze from pg_stat_all_tables where relname='test';
schemaname | relname | last_analyze
------------+---------+-------------------------------
public | test | 2017-10-05 11:15:35.877243+08
(1 行记录)
highgo=# \! time
当前时间: 11:21:33.07
输入新时间:
highgo=# analyze test;
ANALYZE
highgo=# select schemaname ,relname,last_analyze from pg_stat_all_tables where relname='test';
schemaname | relname | last_analyze
------------+---------+-------------------------------
public | test | 2017-10-05 11:21:42.321886+08
(1 行记录)
highgo=#

本文展示了如何使用 PostgreSQL 的 ANALYZE 命令来更新表的统计信息,并通过实际操作对比了更新前后 test 表的 last_analyze 时间,有助于理解数据库优化的重要性。
1991

被折叠的 条评论
为什么被折叠?



