往往我们对着一堆系统状态视图不知所措,这里我整理一些学习到的脚本:
后续慢慢补充~
--20170913--
这部分参考了http://blog.postgresql-consulting.com
pg_stat_replication:
SELECT client_addr AS client, usename AS user, application_name AS name, state, sync_state AS mode, (pg_xlog_location_diff(pg_current_xlog_location(),sent_location) / 1024)::bigint as pending, (pg_xlog_location_diff(sent_location,write_location) / 1024)::bigint as write, (pg_xlog_location_diff(write_location,flush_location) / 1024)::bigint as flush, (pg_xlog_location_diff(flush_location,replay_location) / 1024)::bigint as replay, (pg_xlog_location_diff(pg_current_xlog_location(),replay_location))::bigint / 1024 as total_lag FROM pg_stat_replication;
pg_stat_all_tables:
SELECT schemaname, relname, seq_scan, seq_tup_read, seq_tup_read / seq_scan as avg_seq_tup_read FROM pg_stat_all_tables WHERE seq_scan > 0 ORDER BY 5 DESC LIMIT 5;
pg_stat_database:
查看数据库块命中率:
SELECT datname, 100 * blks_hit / (blks_hit + blks_read) as cache_hit_ratio FROM pg_stat_database WHERE (blks_hit + blks_read) > 0;
or:
SELECT
round(100 * sum(blks_hit) / sum(blks_hit + blks_read), 3) as cache_hit_ratio
FROM pg_stat_database;
SELECT datname, 100 * xact_commit / (xact_commit + xact_rollback) as commit_ratio FROM pg_stat_database WHERE (xact_commit + xact_rollback) > 0;
pg_stat_bgwriter:
pg_stat_bgwrite:
--20170913--