auto_explain

一个自动记录慢查询执行计划的 contrib 模块

auto_explain 是一个 contrib 模块,它使 PostgreSQL 能够自动记录慢查询的执行计划。

auto_explainPostgreSQL 8.4 中被添加。

变更历史

配置

通常,auto_explain 会被包含在 postgresql.confshared_preload_libraries 选项中,以跟踪所有数据库会话中的慢查询。超级用户也可以通过 LOAD 'auto_explain' 将其加载到单个会话中。请注意,无法为单个数据库启用 auto_explain

使用 auto_explain 会带来一些额外的开销,并可能影响整体数据库性能。因此,应仅在需要时启用它。

默认情况下,auto_explain 在显式配置之前不会激活。至少,必须将 auto_explain.log_min_duration 设置为零(“记录所有计划”)或更大的值(要记录的语句的最小持续时间,以毫秒为单位)。有关所有配置选项的详细信息,请参阅 auto_explain 文档。配置选项只能由超级用户设置。

示例

在单个会话中启用 auto_explain

postgres=# LOAD 'auto_explain';
LOAD
postgres=# SET auto_explain.log_min_duration = 0;
SET
postgres=# SELECT count(*)
             FROM pgbench_branches b
             JOIN pgbench_accounts a ON b.bid = a.bid;
 count  
--------
 100000
(1 row)

服务器日志将包含类似以下的输出

LOG:  duration: 26.516 ms  plan:
        Query Text: SELECT count(*)
                      FROM pgbench_branches b
                      JOIN pgbench_accounts a ON b.bid = a.bid;
        Aggregate  (cost=4141.01..4141.02 rows=1 width=0)
          ->  Nested Loop  (cost=0.00..3891.01 rows=100000 width=0)
                Join Filter: (b.bid = a.bid)
                ->  Seq Scan on pgbench_branches b  (cost=0.00..1.01 rows=1 width=4)
                ->  Seq Scan on pgbench_accounts a  (cost=0.00..2640.00 rows=100000 width=4)

分类

Contrib 模块, 性能

反馈

在此处提交有关“auto_explain”的任何评论、建议或更正 此处