Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4028b6a

Browse files
authored
main query reduced
1 parent 2732df5 commit 4028b6a

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

‎psqlrc/psqlrc‎

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
\pset expanded auto
3939
\setenv PAGER 'less -iMFXSx4R'
4040

41+
with fs as (
42+
select distinct on (name) *
43+
from pg_file_settings
44+
order by name, seqno desc
45+
)
4146
select -- pg_backend_pid(), -- if we're connecting through pgbouncer, then prompt's %p is not real, so get real PID
4247

4348
pg_is_in_recovery(), -- primary or standby
@@ -65,38 +70,35 @@ select -- pg_backend_pid(), -- if we're connecting through pgbouncer, then promp
6570
end
6671
), ''), '?') as replication_lag,
6772

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,
7779

7880
exists(select from pg_hba_file_rules where error is not null) as is_hba_file_error,
7981

8082
exists(select from pg_settings where pending_restart) as is_pending_restart,
8183

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+
100102
extract(epoch from r.lag) as e(epoch)
101103
\gset
102104

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /