forked from NikolayS/postgres_dba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
warmup.psql
36 lines (33 loc) · 1.42 KB
/
warmup.psql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
-- check if "\if" is supported (psql 10+)
\if false
\echo cannot work, you need psql version 10+ (Postgres server can be older)
select 1/0;
\endif
select regexp_replace(version(), '^PostgreSQL (\d+\.\d+).*$', e'\\1')::numeric >= 10 as postgres_dba_pgvers_10plus \gset
\if :postgres_dba_pgvers_10plus
\set postgres_dba_last_wal_receive_lsn pg_last_wal_receive_lsn
\set postgres_dba_last_wal_replay_lsn pg_last_wal_replay_lsn
\set postgres_dba_is_wal_replay_paused pg_is_wal_replay_paused
\else
\set postgres_dba_last_wal_receive_lsn pg_last_xlog_receive_location
\set postgres_dba_last_wal_replay_lsn pg_last_xlog_replay_location
\set postgres_dba_is_wal_replay_paused pg_is_xlog_replay_paused
\endif
-- TODO: improve work with custom GUCs for Postgres 9.5 and older
select regexp_replace(version(), '^PostgreSQL (\d+\.\d+).*$', e'\\1')::numeric >= 9.6 as postgres_dba_pgvers_96plus \gset
\if :postgres_dba_pgvers_96plus
select coalesce(current_setting('postgres_dba.wide', true), 'off') = 'on' as postgres_dba_wide \gset
\else
set client_min_messages to 'fatal';
do $$
declare
val text;
begin
select into val current_setting('postgres_dba.wide');
exception when others then
perform set_config('postgres_dba.wide', 'off', false);
end; $$ language plpgsql;
select current_setting('postgres_dba.wide') as postgres_dba_wide \gset
reset client_min_messages;
\endif
\set postgres_dba_interactive_mode false