online_advisor
在线建议缺失索引、扩展统计信息与预备语句
online_advisor · 在线建议缺失索引、扩展统计信息与预备语句
概览
| ID | 扩展 | 软件包 | 版本 | 类别 | 许可证 | 编程语言 |
|---|---|---|---|---|---|---|
| 5270 | online_advisor | online_advisor | 1.0 | ADMIN | PostgreSQL | C |
| 属性 | 可执行文件 | 动态库 | 需要预加载 | 需要建扩展 | 可迁移 | 可信 |
|---|---|---|---|---|---|---|
| --sLd-r | 否 | 是 | 是 | 是 | 是 | 否 |
| 关联 | |
|---|---|
| 相关扩展 | pg_qualstats hypopg index_advisor pg_hint_plan pg_stat_plans plan_filter pg_relusage pg_track_optimizer pg_strom pg_orca |
Requires shared_preload_libraries=online_advisor on PostgreSQL 14-16; PGSTY backports upstream PG18 hook compatibility.
软件包
| Linux / PG | PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|---|
| el8.x86_64 | N/A | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| el8.aarch64 | N/A | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| el9.x86_64 | N/A | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| el9.aarch64 | N/A | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| el10.x86_64 | N/A | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| el10.aarch64 | N/A | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| d12.x86_64 | N/A | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| d12.aarch64 | N/A | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| d13.x86_64 | N/A | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| d13.aarch64 | N/A | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u22.x86_64 | N/A | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u22.aarch64 | N/A | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u24.x86_64 | N/A | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u24.aarch64 | N/A | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u26.x86_64 | N/A | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u26.aarch64 | N/A | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
源码
安装
将扩展加入 shared_preload_libraries,详见配置说明。
在数据库中创建扩展。
用法
来源:
online_advisor 观察PostgreSQL执行计划和工作负载时间,然后推荐索引、扩展统计信息或准备语句。它仅报告候选方案;从不自动创建索引或统计对象。
核心流程
预加载库并重启PostgreSQL:
在每个需要观察工作负载的数据库中创建并激活扩展:
运行代表性的工作负载后,检查推荐方案:
在应用生成的 create_index 或 create_statistics 语句之前,请审查每个建议。在创建索引或统计对象之后运行 ANALYZE,以便规划器可以使用当前统计数据。
对象和设置
proposed_indexes:propose_indexes(combine, reset)的视图,并带有过滤体积、调用次数、耗时以及候选的CREATE INDEX语句。proposed_statistics:propose_statistics(combine, reset)的视图,并带有误估数、调用次数、耗时以及候选的CREATE STATISTICS语句。get_executor_stats(reset): 返回聚合规划和执行时间、查询计数及规划开销比率。online_advisor.filtered_threshold: 考虑为索引建议的过滤行数最小值,默认值为1000。online_advisor.misestimation_threshold: 实际到估计行数比值,用于统计;默认值为10。online_advisor.min_rows: 误估分析中返回的最小行数,默认值为1000。online_advisor.max_index_proposals和online_advisor.max_stat_proposals: 建议容量;在激活扩展之前设置它们。online_advisor.do_instrumentation,online_advisor.log_duration, 和online_advisor.prepare_threshold: 控制收集和准备语句建议。
注意事项
- 仪器化会增加工作负载开销,请在目标系统上进行测量,并在不需要时禁用数据收集。
- 索引启发式算法不考虑复合索引、连接索引或仅用于避免排序的索引的操作符顺序问题。
- 扩展不会估计建议索引的好处。在构建昂贵的索引之前,使用计划审查或假设性索引工具进行评估。
- 建议是数据库本地的,并依赖于激活或重置以来观察到的工作负载。