|
38 | 38 | \pset expanded auto |
39 | 39 | \setenv PAGER 'less -iMFXSx4R' |
40 | 40 |
|
| 41 | +with fs as ( |
| 42 | + select distinct on (name) * |
| 43 | + from pg_file_settings |
| 44 | + order by name, seqno desc |
| 45 | +) |
41 | 46 | select -- pg_backend_pid(), -- if we're connecting through pgbouncer, then prompt's %p is not real, so get real PID |
42 | 47 |
|
43 | 48 | pg_is_in_recovery(), -- primary or standby |
@@ -65,38 +70,35 @@ select -- pg_backend_pid(), -- if we're connecting through pgbouncer, then promp |
65 | 70 | end |
66 | 71 | ), ''), '?') as replication_lag, |
67 | 72 |
|
68 | | - exists((with t as ( |
69 | | - select distinct on (name) * |
70 | | - from pg_file_settings |
71 | | - order by name, seqno desc |
72 | | - ) |
73 | | - select |
74 | | - from t |
75 | | - join pg_settings as s on t.name = s.name |
76 | | - where not t.applied and not s.pending_restart)) as is_config_file_error, |
| 73 | + exists( |
| 74 | + select |
| 75 | + from fs |
| 76 | + join pg_settings as s on fs.name = s.name |
| 77 | + where not fs.applied and not s.pending_restart |
| 78 | + ) as is_config_file_error, |
77 | 79 |
|
78 | 80 | exists(select from pg_hba_file_rules where error is not null) as is_hba_file_error, |
79 | 81 |
|
80 | 82 | exists(select from pg_settings where pending_restart) as is_pending_restart, |
81 | 83 |
|
82 | | - exists(with f as ( |
83 | | - select distinct on (name) * |
84 | | - from pg_file_settings |
85 | | - order by name, seqno desc |
86 | | - ) |
87 | | - select |
88 | | - from f |
89 | | - cross join current_setting(f.name) as cs(setting) |
90 | | - join pg_settings as s on f.name = s.name |
91 | | - and f.setting is distinct from cs.setting |
92 | | - and f.setting is distinct from s.setting |
93 | | - and f.applied and not s.pending_restart) as is_pending_reload |
94 | | - |
95 | | -from coalesce(case when not pg_is_in_recovery() then null -- not standby |
96 | | - when not exists(select from pg_stat_wal_receiver) then null -- primary lost |
97 | | - when pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn() then '0'::interval -- no lag |
98 | | - else now() - pg_last_xact_replay_timestamp() |
99 | | - end) as r(lag), |
| 84 | + exists( |
| 85 | + select |
| 86 | + from fs |
| 87 | + cross join current_setting(fs.name) as cs(setting) |
| 88 | + join pg_settings as s on fs.name = s.name |
| 89 | + and fs.setting is distinct from cs.setting |
| 90 | + and fs.setting is distinct from s.setting |
| 91 | + and fs.applied and not s.pending_restart |
| 92 | + ) as is_pending_reload |
| 93 | + |
| 94 | +from coalesce( |
| 95 | + case when not pg_is_in_recovery() then null -- not standby |
| 96 | + when not exists(select from pg_stat_wal_receiver) then null -- primary lost |
| 97 | +when pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn() then '0'::interval -- no lag |
| 98 | + else now() - pg_last_xact_replay_timestamp() |
| 99 | + end |
| 100 | + ) as r(lag), |
| 101 | + |
100 | 102 | extract(epoch from r.lag) as e(epoch) |
101 | 103 | \gset |
102 | 104 |
|
|
0 commit comments