|
1 |
| -select case when pg_is_in_recovery() then 'Replica' || ' (delay: ' |
2 |
| - || ((((case |
3 |
| - when pg_last_xlog_receive_location() = pg_last_xlog_replay_location() then 0 |
4 |
| - else extract (epoch from now() - pg_last_xact_replay_timestamp()) |
5 |
| - end)::int)::text || ' second')::interval)::text |
6 |
| - || '; paused: ' || pg_is_xlog_replay_paused()::text || ')' |
7 |
| - else 'Master' |
8 |
| -end as "Node Information"; |
| 1 | +with data as ( |
| 2 | + select * from pg_stat_database where datname not in ('postgres', 'template0', 'template1') order by tup_returned desc limit 1 |
| 3 | +) |
| 4 | +select 'Database Name' as metric, datname as value from data |
| 5 | +union all |
| 6 | +select 'Database Version' as metric, version() as value |
| 7 | +union all |
| 8 | +select |
| 9 | + 'Role' as metric, |
| 10 | + case |
| 11 | + when pg_is_in_recovery() then 'Replica' || ' (delay: ' |
| 12 | + || ((((case |
| 13 | + when pg_last_xlog_receive_location() = pg_last_xlog_replay_location() then 0 |
| 14 | + else extract (epoch from now() - pg_last_xact_replay_timestamp()) |
| 15 | + end)::int)::text || ' second')::interval)::text |
| 16 | + || '; paused: ' || pg_is_xlog_replay_paused()::text || ')' |
| 17 | + else 'Master' |
| 18 | + end as value |
| 19 | +union all |
| 20 | +select 'Database Size', (select pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname)) from pg_catalog.pg_database d where pg_catalog.has_database_privilege(d.datname, 'CONNECT') order by pg_catalog.pg_database_size(d.datname) desc limit 1) |
| 21 | +union all |
| 22 | +select 'Cache Effectiveness', (round(blks_hit * 100::numeric / (blks_hit + blks_read), 2))::text || '%' from data |
| 23 | +union all |
| 24 | +select 'Successful Commits', (round(xact_commit * 100::numeric / (xact_commit + xact_rollback), 2))::text || '%' from data |
| 25 | +union all |
| 26 | +select 'Conflicts', conflicts::text from data |
| 27 | +union all |
| 28 | +select 'Temp Files: total size (total number of files)', (pg_size_pretty(temp_bytes)::text || ' (' || temp_files::text || ')') from data |
| 29 | +union all |
| 30 | +select 'Deadlocks', deadlocks::text from data |
| 31 | +union all |
| 32 | +select 'Stat Since', stats_reset::text from data |
| 33 | +; |
0 commit comments