0
点赞
收藏
分享

微信扫一扫

PG 查看当前正在运行SQL的执行计划插件pg_show_plans


PG_SHOW_PLANS

下载

​​https://github.com/cybertec-postgresql/pg_show_plans​​

编译安装

cd postgresql-pg_version/contrib

tar zxvf pg_show_plans.tar.gz

cd pg_show_plans

make && make install

配置插件

  • 修改配置文件

 vim postgresql.conf
shared_preload_libraries='pg_show_plans'

  • 创建扩展

  psql -c "create extension pg_show_plans ;"

  • 重启数据库服务

  pg_ctl restart

测试该插件

  • 会话1


test=# create table test(id int, name varchar);
CREATE TABLE
test=# insert into test select n, n||'name' from generate_series(1,10000000)n;

INSERT 0 10000000
test=#
test=#
test=#
test=# select * from test where id>37;

  • 会话2

 test=#  SELECT p.pid, p.level, p.plan, a.query FROM pg_show_plans p 
LEFT JOIN pg_stat_activity a
ON p.pid = a.pid AND p.level = 0 where p.pid<>pg_backend_pid() ORDER BY p.pid, p.level ;
pid | level | plan | query
-------+-------+----------------------------------------------------------------+---------------------------------
30175 | 0 | Seq Scan on test (cost=0.00..179053.25 rows=9998860 width=15)+| select * from test where id>37;
| | Filter: (id > 37) |
(1 row)


举报

相关推荐

0 条评论