今天学习了下postgres 的statpack 功能,设置PG的statpack功能需要下载一个包,并安装;PG的statspack功能和Oracle 的Statspack功能相似,用来统计一个时间段内数据库的运行指标只是PG 的statpack报告内容相比Oracle的没有那么详尽,下面介绍下PG statspack安装和使用过程。
安装 pgstatspack
1.1 下载 pgstatspack tar包 ,下载地址
http://pgfoundry.org/frs/?group_id=1000375&release_id=1321
我下载的是pgstatspack_version_2.1.tar.gz, 是目前的最新版本;
1.2 创建一个超级用户,如果使用postgres用户,则不用新建;
1.3 开始安装,执行脚本 install_pgstats.sh (以postgres OS用户执行脚本)
1 |
cd pgstatspack的解压目录 |
这个脚本将在各个数据库(postgres.templates库除外)上安装统计信息表和函数;
1.4 创建 snapshot,有两种方式:
方式一: 手工方式创建 snapshot
1 |
Snapshot with comment: |
方式二:crontab 方式自动创建 snapshots
以下是我本机的crontab,每15分钟创建一个snapshot
1 |
#Automated snapshots every 15 mins |
生成报表
1 |
cd pgstatspack的解压目录/bin |
执行这个脚本后,就会提示输入begin snapid,end snapid,这里和生成Oracle 的statspack报告内似; 这个脚本生成的报告默认是在/tmp目录下,可以修改下这个脚本,将目录生成在指定目录
1 |
vi pgstatspack_report.sh,修改FILENAME变量即为报告存放目录。 |
报告内容
1 |
napshot information |
注意: 以下是报告的部分内容, 详细内容可以参照报告模板,解压包的目录下有份报告模板 pgstatspack_sample_report.txt。
报告字段解释
tps – transactions per second
Number of committed transactions between snapshots, devided by the number of seconds between the two snapshots.
pg_stat_database.xact_commit – number of committed transactions
hitrate : cache命中率
Number of cache reads as a percentage of the total number of reads (cache and physical) between the two snapshots.
pg_stat_database.blks_hit – cache reads
pg_stat_database.blks_read – physical reads
lio_ps: 逻辑读
Number of logical reads between snapshots, devided by the number of seconds between the two snapshots.
Logical reads is in postgresql the number of physical reads + the number of cache reads.
pg_stat_database.blks_hit – cache reads
pg_stat_database.blks_read – physical reads
pio_ps: 物理读
Number of physical reads between snapshots, devided by the number of seconds between the two snapshots.
pg_stat_database.blks_read – physical reads
rollbk_ps
Number of rollbacks between snapshots, devided by the number of seconds between the two snapshots.
pg_stat_database.xact_rollback
Pgstatspack 相关表
1 |
pgstatspack_snap |
原创文章,作者:kepupublish,如若转载,请注明出处:https://blog.ytso.com/236323.html