3939\setenv PAGER 'less -iMFXSx4R'
4040
4141select -- pg_backend_pid(), -- If we're connecting through pgbouncer, then prompt's %p is not real, so get real PID
42+ 4243 pg_is_in_recovery(), -- primary or standby
44+ 4345 current_setting('server_version') as server_version,
46+ 4447 (select count(*) from pg_stat_replication where state = 'streaming') as streaming_count,
48+ 4549 coalesce((select case when sender_host ~ '^\d+\.\d+\.\d+\.\d+$' then sender_host
4650 else split_part(sender_host, '.', 1)
4751 end
4852 from pg_stat_wal_receiver
4953 limit 1), '***LOST***') as primary_dsn,
54+ 5055 coalesce(nullif(concat(
5156 nullif(extract(day from lag), 0) || 'd',
5257 nullif(extract(hour from lag), 0) || 'h',
@@ -57,6 +62,7 @@ select -- pg_backend_pid(), -- If we're connecting through pgbouncer, then pr
5762 when epoch < 3600.0 then round(extract(second from lag)::numeric, 0) || 's'
5863 end
5964 ), ''), '?') as replication_lag,
65+ 6066 (with t as (
6167 select distinct on (name) *
6268 from pg_file_settings
@@ -66,6 +72,7 @@ select -- pg_backend_pid(), -- If we're connecting through pgbouncer, then pr
6672 from t
6773 join pg_settings as s on t.name = s.name
6874 where not applied) as pg_file_settings_error_count
75+ 6976from coalesce(case when not pg_is_in_recovery() then null -- not standby
7077 when not exists(select from pg_stat_wal_receiver) then null -- primary lost
7178 when pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn() then '0'::interval -- no lag
0 commit comments