合 PG插件之auto_explain记录慢查询执行计划
Tags: PG慢查询auto_explain
简介
auto_explain模块提供了一种自动记录慢语句执行计划的方法,而不必手动运行EXPLAIN。这对于在大型应用程序中跟踪未优化的查询特别有帮助。
该模块不提供sql可访问的函数。要使用它,只需将它加载到服务器。你可以将它加载到一个单独的会话中:
1 | load 'auto_explain' |
如果想在全局开启该功能,可以在配置文件postgres.conf文件中通过session_preload_libraries或shared_preload_libraries进行配置。不过会有一定开销产生。
比如:
1 2 3 | # postgresql.conf session_preload_libraries = 'auto_explain' auto_explain.log_min_duration = '2s' |