The auto_explain module provides a means for logging execution plans of slow statements automatically, without having to run EXPLAIN by hand. This is especially helpful for tracking down un-optimized queries in large applications.

https://www.postgresql.org/docs/current/static/auto-explain.html

postgresql.conf

shared_preload_libraries = 'auto_explain'

auto_explain.log_min_duration = 0 
auto_explain.log_analyze = true
auto_explain.log_verbose = true
auto_explain.log_buffers = true
auto_explain.log_buffers = true
auto_explain.log_timing = true
auto_explain.log_triggers = true

auto_explain.log_nested_statements = true

[root@test01 pg_log]# vim postgresql-2016-05-28_004047.csv

2016-05-28 00:41:23.990 CST,"postgres","postgres",7263,"[local]",574878a4.1c5f,3,"SELECT",2016-05-28 00:41:08 CST,2/3,0,LOG,00000,"duration: 0.808 ms plan:
Query Text: SELECT count(*)
FROM pg_class, pg_index
WHERE oid = indrelid AND indisunique;
Aggregate (cost=22.07..22.08 rows=1 width=0) (actual time=0.785..0.785 rows=1 loops=1)
Output: count(*)
Buffers: shared hit=46 read=1
-> Hash Join (cost=5.71..21.80 rows=109 width=0) (actual time=0.352..0.736 rows=109 loops=1)
Hash Cond: (pg_class.oid = pg_index.indrelid)
Buffers: shared hit=46 read=1
-> Index Only Scan using pg_class_oid_index on pg_catalog.pg_class (cost=0.15..12.81 rows=311 width=4) (actual time=0.088..0.285 rows=313 loops=1)
Output: pg_class.oid
Heap Fetches: 124
Buffers: shared hit=40 read=1
-> Hash (cost=4.20..4.20 rows=109 width=4) (actual time=0.187..0.187 rows=109 loops=1)
Output: pg_index.indrelid
Buckets: 1024 Batches: 1 Memory Usage: 12kB
Buffers: shared hit=3
-> Seq Scan on pg_catalog.pg_index (cost=0.00..4.20 rows=109 width=4) (actual time=0.008..0.094 rows=109 loops=1)
Output: pg_index.indrelid
Filter: pg_index.indisunique
Rows Removed by Filter: 11
Buffers: shared hit=3",,,,,,,,"explain_ExecutorEnd, auto_explain.c:333","psql.bin"
2016-05-28 00:41:23.990 CST,"postgres","postgres",7263,"[local]",574878a4.1c5f,4,"SELECT",2016-05-28 00:41:08 CST,2/0,0,LOG,00000,"duration: 5.327 ms",,,,,,,,"exec_simple_query, postgres.c:1174","psql.bin"

PostgreSQL auto_explain的更多相关文章

  1. postgresql常用命令

    1.createdb 数据库名称 产生数据库2.dropdb 数据库名称 删除数据库 3.CREATE USER 用户名称 创建用户4.drop User 用户名称 删除用户 5.SELECT use ...

  2. 使用pgstatspack分析PostgreSQL数据库性能

    pgstatspack [root@test01 soft]# wget http://pgfoundry.org/frs/download.php/3151/pgstatspack_version_ ...

  3. 在CentOS上编译安装PostgreSQL

    http://my.oschina.net/tashi/blog 第一步:准备阶段 获取必需软件包: CentOS中查看是否安装了某个软件的命令:rpm -qa | grep 软件名.which命令可 ...

  4. Postgresql 10 自带扩展模块功能说明

    adminpackadminpack提供了许多支持功能,pgAdmin 和其他管理和管理工具可以使用它们来提供其他功能,例如远程管理服务器日志文件.所有这些功能的使用仅限于超级用户. citext 该 ...

  5. PostgreSQL源代码中插件的使用

    如果编译数据库时使用了gmake world和gmake install-world, 所有的插件都会被安装, 那么就不需要再次安装了. 插件目录 contrib 进入要安装的插件目录, 例如 cd ...

  6. PostgreSQL+pgpooll+Keepalived双机HA方案

    PostgreSQL+pgpooll+Keepalived双机HA方案 (注:本文档中的所有操作在没有说明的情况下都应该使用postgres用户进行操作,postgres用户没有权限的操作方可采用ro ...

  7. postgresql 基本语法

    postgresql数据库创建/修改/删除等写入类代码语法总结: 1,创建库 2,创建/删除表 2.1 创建表 create table myTableName 2.2 如果表不存在则创建表 crea ...

  8. postgresql无法安装pldbgapi的问题

    要对函数进行调试需要安装插件pldbgapi,当初在windows上面的postgresql实例中执行了一下语句就安装上了: create extension pldbgapi; 但是在linux中执 ...

  9. ASP.NET MVC 使用 Petapoco 微型ORM框架+NpgSql驱动连接 PostgreSQL数据库

    前段时间在园子里看到了小蝶惊鸿 发布的有关绿色版的Linux.NET——“Jws.Mono”.由于我对.Net程序跑在Linux上非常感兴趣,自己也看了一些有关mono的资料,但是一直没有时间抽出时间 ...

随机推荐

  1. nginx高并发优化

    一、一般来说nginx 配置文件中对优化比较有作用的为以下几项: 1.  worker_processes 8; nginx 进程数,建议按照cpu 数目来指定,一般为它的倍数 (如,2个四核的cpu ...

  2. MySQL binlog-do-db选项是危险的

    很多人通过 binlog-do-db, binlog-ignore-db, replicate-do-db 和   replicate-ignore-db 来过滤复制(某些数据库), 尽管有些使用, ...

  3. add active class

    根据URI添加菜单的active css class Active item item in menu: <?php function aim($page) { if(stristr($_SER ...

  4. Support vector machine

    https://en.wikipedia.org/wiki/Support_vector_machine In machine learning, support vector machines (S ...

  5. diy-pagination-javascript 分页

    <?php isset($_REQUEST['form_single_page_num']) && !empty($_REQUEST['form_single_page_num' ...

  6. P1018 乘积最大

    开始定义状态f[i][j][k]为[i,j)区间插入k个括号,使用记忆化搜索,但是成功爆栈,得到4个mle #include <bits/stdc++.h> using namespace ...

  7. Win7+VS2005编译Qt4.7.3+phonon(需要安装新版本Windows SDK)

    Qt官网上下载的源代码在编译时并没有将phonon继承进去,只提供了源代码,而在Win7+VS2005中编译phonon时遇到不少的问题,因为phonon只是一个前端程序,要使用其实现多媒体的播放还需 ...

  8. Kib Kb KB KIB 区别

    今天和同事聊了一下Kib Kb KB KIB这几个单位的含义及其区别,自己在网上也查了查资料,总结如下: Ki 和 K 只是数学单位 Ki = 1024 K  = 1000 这二者之间没有任何联系 B ...

  9. 框架,公共模块,unified思想

    最近两周一直在加班加点refactor代码,贡献了2014年最后一个周末和2015年元旦三天假期,终于赶在了sprint结束之前完成. 可见,这个sprint做的并不理想! 项目逻辑本身并不复杂,从数 ...

  10. The Shortest Path in Nya Graph---hdu4725(spfa+扩点建图)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4725  有n个点,每个点都有一个层l[i],相邻层的边有一条无向带权边,权值为都为C,另外 ...