Autoanalyze 的注意事项

本文详细阐述了PostgreSQL中ANALYZE与autoanalyze的作用、配置方法及其在数据管理中的应用策略。着重讨论了如何通过合理设置自动分析功能,优化查询性能,并特别关注主表和子表结构下的分析处理细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

磨砺技术珠矶,践行数据之道,追求卓越价值

回到上一级页面:PostgreSQL内部结构与源代码研究索引页    回到顶级页面:PostgreSQL索引页

 

根据官方文档的说明  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 动作。

 

回到上一级页面:PostgreSQL内部结构与源代码研究索引页    回到顶级页面:PostgreSQL索引页

磨砺技术珠矶,践行数据之道,追求卓越价值

 

root@cpms-linux:~# docker logs fossology-new ***************************************************** WARNING: No database host was set and therefore the internal database without persistency will be used. THIS IS NOT RECOMENDED FOR PRODUCTIVE USE! ***************************************************** Starting PostgreSQL 11 database server: main. *** Running postinstall for common actions*** *** Creating user and group *** NOTE: group 'fossy' already exists, good. NOTE: user 'fossy' already exists, good. *** Making sure needed dirs exist with right ownership/permissions *** *** clearing file cache *** NOTE: Repository already exists at /srv/fossology/repository NOTE: Running the PostgreSQL vacuum and analyze command can result in a large database performance improvement. We suggest that you either configure postgres to run its autovacuum and autoanalyze daemons, or maintagent -D in a cron job, or run Admin > Maintenance on a regular basis. Admin > Dashboard will show you the last time vacuum and analyze have been run. *** Setting up the FOSSology database *** NOTE: fossology database already exists, not creating *** Checking for plpgsql support *** NOTE: plpgsql already exists in fossology database, good *** Checking for 'uuid-ossp' support *** NOTE: 'uuid-ossp' already exists in fossology database, good *** update the database and license_ref table *** Old release was 3.3.0 Applying database functions DB schema has been updated for fossology. Database schema update completed successfully. Update reference licenses *** Instance UUID ***INSTANCE UUID: a527ab24-e3ad-4472-90d5-68483f7376d3 *** Table copyright already migrated to copyright_event table *** *** Table author already migrated to author_event table *** *** Table ecc already migrated to ecc_event table *** *** Table keyword already migrated to keyword_event table *** FOSSology postinstall complete, but sure to complete the remaining steps in the INSTALL instructions. Fossology initialisation complete; Starting up... Starting periodic command scheduler: cron. 2025-03-21 08:18:26 scheduler [155] :: NOTE: ***************************************************************** 2025-03-21 08:18:26 scheduler [155] :: NOTE: *** FOSSology scheduler started *** 2025-03-21 08:18:26 scheduler [155] :: NOTE: *** pid: 155 *** 2025-03-21 08:18:26 scheduler [155] :: NOTE: *** verbose: 3 *** 2025-03-21 08:18:26 scheduler [155] :: NOTE: *** config: /usr/local/etc/fossology *** 2025-03-21 08:18:26 scheduler [155] :: NOTE: ***************************************************************** AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message [Fri Mar 21 08:18:26.602843 2025] [core:warn] [pid 158] AH00098: pid file /var/run/apache2/apache2.pid overwritten -- Unclean shutdown of previous Apache run? [Fri Mar 21 08:18:26.618724 2025] [mpm_prefork:notice] [pid 158] AH00163: Apache/2.4.38 (Debian) mod_ldap_userdir/1.1.19 configured -- resuming normal operations [Fri Mar 21 08:18:26.620058 2025] [core:notice] [pid 158] AH00094: Command line: '/usr/sbin/apache2 -D FOREGROUND' 10.194.150.5 - - [21/Mar/2025:08:18:27 +0000] "GET / HTTP/1.1" 200 3380 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0" 10.194.150.5 - - [21/Mar/2025:08:18:32 +0000] "GET /repo HTTP/1.1" 404 495 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0" 10.194.150.5 - - [21/Mar/2025:08:19:24 +0000] "-" 408 0 "-" "-"
最新发布
03-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值