主从环境安装扩展pg_stat_statements:


主从环境安装扩展pg_stat_statements:


主:
vi postgresql.conf


shared_preload_libraries = 'pg_stat_statements'         # (change requires restart)
pg_stat_statements.max = 1000
pg_stat_statements.track = top
pg_stat_statements.track_utility = true
pg_stat_statements.save = true


pg_ctl restart -m fast


主、从:
在源码包里安装
cd /soft/postgresql-9.4.4/contrib/pg_stat_statements
 make && make install


gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -fpic -I. -I. -I../../src/include -D_GNU_SOURCE -I/usr/include/libxml2   -c -o pg_stat_statements.o pg_stat_statements.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -fpic -shared -o pg_stat_statements.so pg_stat_statements.o -L../../src/port -L../../src/common -Wl,--as-needed -Wl,-rpath,'/opt/postgres/lib',--enable-new-dtags  
/bin/mkdir -p '/opt/postgres/lib'
/bin/mkdir -p '/opt/postgres/share/extension'
/bin/mkdir -p '/opt/postgres/share/extension'
/usr/bin/install -c -m 755  pg_stat_statements.so '/opt/postgres/lib/pg_stat_statements.so'
/usr/bin/install -c -m 644 pg_stat_statements.control '/opt/postgres/share/extension/'
/usr/bin/install -c -m 644 pg_stat_statements--1.2.sql pg_stat_statements--1.1--1.2.sql pg_stat_statements--1.0--1.1.sql pg_stat_statements--unpackaged--1.0.sql '/opt/postgres/share/extension/'






cd /opt/pgsql/share/extension
ls pg_sta*


主:
加载pg_stat_statements模块


psql -f /opt/postgres/share/extension/pg_stat_statements--1.2.sql -p 5432
psql -p 5432
CREATE EXTENSION pg_stat_statements;




测试:
SELECT pg_stat_statements_reset();  
SELECT count(*) FROM pg_stat_statements where total_time/calls>5;






查看插件:
SELECT
  pg_proc.proname AS "函数名称",
  pg_type.typname AS "返回值数据类型",
  pg_proc.pronargs AS "参数个数"
FROM
  pg_proc
    JOIN pg_type
   ON (pg_proc.prorettype = pg_type.oid)
WHERE
  pg_type.typname != 'void'
  AND pronamespace = (SELECT pg_namespace.oid FROM pg_namespace WHERE nspname = 'public');

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/91975/viewspace-1806480/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/91975/viewspace-1806480/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值