Autoanalyze 的注意事项

简介:

根据官方文档的说明  http://www.postgresql.org/docs/9.2/static/sql-analyze.html

Analyze 的基本作用:

ANALYZE collects statistics about the contents of tables in the database, and stores the results in the pg_statistic system catalog. Subsequently, the query planner uses these statistics to help determine the most efficient execution plans for queries.

那么,auto analyze 如何设置呢:

auto analyze 由 autovacuum 发起,舍此没有别的机会:

复制代码
In the default PostgreSQL configuration, the autovacuum daemon (see Section 23.1.6) takes care of automatic analyzing of tables when they are first loaded with data, and as they change throughout regular operation. When autovacuum is disabled, it is a good idea to run ANALYZE periodically, or just after making major changes in the contents of a table. Accurate statistics will help the planner to choose the most appropriate query plan, and thereby improve the speed of query processing. A common strategy for read-mostly databases is to run VACUUM and ANALYZE once a day during a low-usage time of day. (This will not be sufficient if there is heavy update activity.)
复制代码

看一下 配置:

复制代码
#------------------------------------------------------------------------------
# AUTOVACUUM PARAMETERS
#------------------------------------------------------------------------------

#autovacuum = on                        # Enable autovacuum subprocess?  'on'
                                        # requires track_counts to also be on.
#log_autovacuum_min_duration = -1       # -1 disables, 0 logs all actions and
                                        # their durations, > 0 logs only
                                        # actions running at least this number
                                        # of milliseconds.
#autovacuum_max_workers = 3             # max number of autovacuum subprocesses
                                        # (change requires restart)
#autovacuum_naptime = 1min              # time between autovacuum runs
#autovacuum_vacuum_threshold = 50       # min number of row updates before
                                        # vacuum
#autovacuum_analyze_threshold = 50      # min number of row updates before
                                        # analyze
#autovacuum_vacuum_scale_factor = 0.2   # fraction of table size before vacuum
#autovacuum_analyze_scale_factor = 0.1  # fraction of table size before analyze
#autovacuum_freeze_max_age = 200000000  # maximum XID age before forced vacuum
                                        # (change requires restart)
#autovacuum_vacuum_cost_delay = 20ms    # default vacuum cost delay for
                                        # autovacuum, in milliseconds;
                                        # -1 means use vacuum_cost_delay
#autovacuum_vacuum_cost_limit = -1      # default vacuum cost limit for
                                        # autovacuum, -1 means use
                                        # vacuum_cost_limit
复制代码

analyze 还有一个弱点值得注意:

If the table being analyzed has one or more children, ANALYZE will gather statistics twice: once on the rows of the parent table only, and a second time on the rows of the parent table with all of its children. This second set of statistics is needed when planning queries that traverse the entire inheritance tree. The autovacuum daemon, however, will only consider inserts or updates on the parent table itself when deciding whether to trigger an automatic analyze for that table. If that table is rarely inserted into or updated, the inheritance statistics will not be up to date unless you run ANALYZE manually.

对于有主表和子表的,仅当主表被认为需要analyze时,才会进行 analayze 动作。










本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/p/3274141.html,如需转载请自行联系原作者

目录
相关文章
|
6月前
|
存储 算法 测试技术
关于HOperatorSet.CountChannels的注意事项
关于HOperatorSet.CountChannels的注意事项
|
2月前
|
前端开发 JavaScript API
reactAPI讲解以及注意事项
reactAPI讲解以及注意事项
12 2
|
网络协议
AFNetWork3.0使用注意事项
AFNetWork3.0使用注意事项
95 0
|
Python
函数注意事项
# 函数的位置参数必须要传实参,可以按位置,也可以按关键字传 # 函数的默认参数可以不传实参,可以按位置,也可以按关键字 # 不定长参数*args只收集位置参数形成元组,不定长参数应放在后面,要不会把实参当做位置参数然后报错 # 用**,只要定义了关键字参数,以后针对这个参数传值就必须是关键字形式...
960 0