PostgreSQL 使用anto_explain自动记录超时SQL的执行计划
来源:互联网 发布:mac 自带五笔 编辑:程序博客网 时间:2024/05/31 06:24
1. auto_explain 模块简单介绍
auto_explain 模块能够自动记录慢查询语句的执行计划,而不需要手工执行 Explain 命令,在比较大的业务系统中,这个模块专门用来跟踪尚未优化的查询SQL。
2. auto_explain 模块启用
如果已经编译并安装了 auto_explain 模块,只要配置参数 shared_preload_libraries 和 custom_variable_classes 参数,如下所示。
3. postgresql.conf 典型参数配置
shared_preload_libraries = ‘auto_explain’
custom_variable_classes = ‘auto_explain’
auto_explain.log_min_duration = ‘0’
备注:
auto_explain.log_min_duration 参数在配置文件里 PostgreSQL.conf 没有,需要手工添加,这个参数用来控制执行时间在指定值以上的SQL的执行计划被记录。参数修改后,需要重启 PostgreSQL 服务。
auto_explain.log_min_duration 设置成了 0, 表示记录所有语句的PLAN,这是为了测试需要,在生产情况时,可以根据需求设置,一般设置成 1000ms。
0 表示记录所有的语句的PLAN,默认什为 -1,表示不记录语句的PLAN。
4. 创建表测试下
postgres=# create table tb3(id integer,name character varying);CREATE TABLE
postgres=# insert into tb3 select generate_series(1,100000) ,'john';INSERT 0 100000
postgres=# create index idx_tb3_id on tb3 using btree (id);CREATE INDEX
postgres=# select * from tb3 where id=10; id | name ----+------ 10 | john(1 row)
查看cvs日志
2015-04-20 00:07:07.378 PDT,,,2343,,553469d3.927,13,,2015-04-19 19:52:03 PDT,,0,LOG,00000,"checkpoint starting: time",,,,,,,,,""2015-04-20 00:07:07.619 PDT,,,2343,,553469d3.927,14,,2015-04-19 19:52:03 PDT,,0,LOG,00000,"checkpoint complete: wrote 3 buffers (0.0%); 0 transaction log file(s) added, 0 removed, 0 recycled; write=0.209 s, sync=0.005 s, total=0.240 s; sync files=3, longest=0.003 s, average=0.001 s",,,,,,,,,""2015-04-20 00:27:07.923 PDT,"postgres","postgres",2350,"[local]",553469da.92e,20,"SELECT",2015-04-19 19:52:10 PDT,2/21,0,LOG,00000,"duration: 24.106 ms plan:Query Text: select * from tb3 where id=10;Index Scan using idx_tb3_id on tb3 (cost=0.29..8.31 rows=1 width=9) Index Cond: (id = 10)",,,,,,,,,"psql"
当执行查询后,PG的日志里记录了语句的PLAN具体信息。
参考:http://francs3.blog.163.com/blog/static/405767272011791573867/
- PostgreSQL 使用anto_explain自动记录超时SQL的执行计划
- PostgreSQL 设置单条SQL的执行超时
- PostgreSQL 设置单条SQL的执行超时
- PostgreSQL 设置单条SQL的执行超时
- PostgreSQL SQL的性能调试方法3--查看执行计划
- PostgreSQL SQL的性能调试方法3--查看执行计划
- 查看PostgreSQL数据库中SQL语句的执行计划
- PostgreSQL SQL的性能调试方法 查看执行计划
- PostgreSQL执行计划的解释
- PostgreSQL的执行计划分析
- PostgreSQL执行计划的解释
- PostgreSQL的执行计划分析
- PostgreSQL的执行计划分析
- PostgreSQL执行计划的解释
- PostgreSQL执行计划的解释
- SQL执行计划、绑定变量的使用
- PostgreSql的执行计划1--获取执行计划
- SQL的执行计划
- Prim算法求最小生成树
- 【cofface】MTK 67xx系列机型线刷recovery教程(基本通用)
- SQLite3 C语言API使用说明
- 行情软件的实现
- iOS 自己总结的一些学习资料
- PostgreSQL 使用anto_explain自动记录超时SQL的执行计划
- (1.5.2.1)求二进制数中1的个数
- 2015去哪网实习招聘笔试题
- ECSHOP结算中心"立即使用支付宝支付"按钮如何美化
- java反射机制(三)
- arcgis for android常见问题回答
- 从4个层面扩展和自定义Calabash-Android
- 关键路径
- Spark学习之2:Worker启动流程