2

我正在使用 postgreSQL-9.1.6 并尝试为 postgreSQL 服务器构建监控应用程序。

我打算从pg_stat_*信息表中选择 PHYSICAL 和 LOGICAL I/O stat。

根据MA​​NUAL中的字段单位PG_STAT_DATABASEBLOCK,这意味着大小为8KB

postgres=# select * from pg_stat_database where datname='postgres';    
-[ RECORD 3 ]-+------------------------------
datid         | 12780
datname       | postgres
numbackends   | 2
xact_commit   | 974
xact_rollback | 57
blks_read     | 210769
blks_hit      | 18664177
tup_returned  | 16074339
tup_fetched   | 35121
tup_inserted  | 18182015
tup_updated   | 572
tup_deleted   | 3075
conflicts     | 0

我可以算出使用* 8KBPHYSICAL READ的大小。blks_read但是,没有关于 stats 中的单位的评论PG_STAT_BGWRITER

postgres=# select * from pg_stat_bgwriter;
-[ RECORD 1 ]---------+------------------------------
checkpoints_timed     | 276
checkpoints_req       | 8
buffers_checkpoint    | 94956
buffers_clean         | 0
maxwritten_clean      | 0
buffers_backend       | 82618
buffers_backend_fsync | 0
buffers_alloc         | 174760
stats_reset           | 2013-07-15 22:27:05.503125+09

如何计算PHYSICAL WRITE通过的大小buffers_checkpoint

任何建议将不胜感激。

4

1 回答 1

2

摘自 Greg Smith 的事实上的性能手册“Postgresql 9.0 High Performance”,在数据库活动和统计一章中:

  • 根据活动而不是时间流逝请求检查点的时间百分比是多少?
  • 平均检查点写入多少数据?
  • 被写出的数据的百分比分别来自检查点和后端?
SELECT
    (100 * checkpoints_req) /
        (checkpoints_timed + checkpoints_req) AS checkpoints_req_pct,
    pg_size_pretty(buffers_checkpoint * block_size /
         (checkpoints_timed + checkpoints_req)) AS avg_checkpoint_write,
    pg_size_pretty(block_size *
        (buffers_checkpoint + buffers_clean + buffers_backend)) AS total_written,
    100 * buffers_checkpoint /
        (buffers_checkpoint + buffers_clean + buffers_backend) AS checkpoint_write_pct,
    100 * buffers_backend /
        (buffers_checkpoint + buffers_clean + buffers_backend) AS backend_write_pct,
    *
FROM pg_stat_bgwriter,
(SELECT cast(current_setting('block_size') AS integer) AS block_size) bs;
于 2013-07-17T15:51:19.153 回答