Skip to content

Commit 4a128c1

Browse files
authored
Merge pull request #84 from NikolayS/feat/wal-info-0node
feat(0): add WAL and replication slot info to node report
2 parents 350ca05 + 3bc9401 commit 4a128c1

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

sql/0_node.sql

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,43 @@ union all
4545
from repl_groups
4646
)
4747
union all
48+
select
49+
'WAL',
50+
case when pg_is_in_recovery() then 'N/A (replica)'
51+
else (
52+
select
53+
'Current LSN: ' || pg_current_wal_lsn()::text
54+
|| e'\n' || 'WAL files: ' || count(*)::text
55+
|| ', ' || pg_size_pretty(sum(size))
56+
from pg_ls_waldir()
57+
)
58+
end
59+
union all
60+
(
61+
with slot_info as (
62+
select
63+
slot_name,
64+
slot_type,
65+
case when active then 'active' else 'inactive' end as status,
66+
case
67+
when not pg_is_in_recovery()
68+
then pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn))
69+
else null
70+
end as lag
71+
from pg_replication_slots
72+
)
73+
select
74+
'Replication Slots',
75+
coalesce(
76+
string_agg(
77+
slot_name || ' (' || slot_type || '/' || status || coalesce(', lag: ' || lag, '') || ')',
78+
e'\n'
79+
),
80+
'none'
81+
)
82+
from slot_info
83+
)
84+
union all
4885
select 'Started At', pg_postmaster_start_time()::timestamptz(0)::text
4986
union all
5087
select 'Uptime', (now() - pg_postmaster_start_time())::interval(0)::text

0 commit comments

Comments
 (0)