Skip to content

Commit 40f9ebc

Browse files
authored
Merge pull request #13 from NikolayS/postgres10
Postgres10
2 parents cd96057 + 944b9c6 commit 40f9ebc

File tree

5 files changed

+51
-20
lines changed

5 files changed

+51
-20
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
environment:
88
- PGHOST: 127.0.0.1
99
- PGUSER: root
10-
- image: circleci/postgres:9.6
10+
- image: circleci/postgres:10
1111
environment:
1212
- POSTGRES_USER: root
1313
- POSTGRES_DB: test
@@ -34,5 +34,5 @@ jobs:
3434
#for f in ~/postgres_dba/sql/*; do psql test -f "$f">/dev/null; done
3535
#echo "\set postgres_dba_wide false" > ~/.psqlrc
3636
#for f in ~/postgres_dba/sql/*; do psql test -f "$f">/dev/null; done
37-
diff -b test/regression/1_basic.out <(psql test -f ~/postgres_dba/sql/1_basic.sql | grep Role)
38-
diff -b test/regression/a1_alignment_padding.out <(psql test -f ~/postgres_dba/sql/a1_alignment_padding.sql | grep align)
37+
diff -b test/regression/1_basic.out <(psql test -f warmup.psql -f ~/postgres_dba/sql/1_basic.sql | grep Role)
38+
diff -b test/regression/a1_alignment_padding.out <(psql test -f warmup.psql -f ~/postgres_dba/sql/a1_alignment_padding.sql | grep align)

init/generate.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,31 @@
22
# Generate start.psql based on the contents of "sql" directory
33
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
44

5+
WARMUP="warmup.psql"
56
OUT="start.psql"
67

8+
echo "" > "$WARMUP"
9+
echo "" > "$OUT"
10+
711
cd "$DIR/.."
8-
cat > "$OUT" <<- VersCheck
12+
cat > "$WARMUP" <<- VersCheck
913
-- check if "\if" is supported (psql 10+)
1014
\if false
1115
\echo cannot work, you need psql version 10+ (Postgres server can be older)
1216
select 1/0;
1317
\endif
1418
19+
select regexp_replace(version(), '^PostgreSQL (\d+\.\d+).*$', e'\\\\1')::numeric >= 10 as postgres_dba_pgvers_10plus \gset
20+
\if :postgres_dba_pgvers_10plus
21+
\set postgres_dba_last_wal_receive_lsn pg_last_wal_receive_lsn
22+
\set postgres_dba_last_wal_replay_lsn pg_last_wal_replay_lsn
23+
\set postgres_dba_is_wal_replay_paused pg_is_wal_replay_paused
24+
\else
25+
\set postgres_dba_last_wal_receive_lsn pg_last_xlog_receive_location
26+
\set postgres_dba_last_wal_replay_lsn pg_last_xlog_replay_location
27+
\set postgres_dba_is_wal_replay_paused pg_is_xlog_replay_paused
28+
\endif
29+
1530
-- TODO: improve work with custom GUCs for Postgres 9.5 and older
1631
select regexp_replace(version(), '^PostgreSQL (\d+\.\d+).*$', e'\\\\1')::numeric >= 9.6 as postgres_dba_pgvers_96plus \gset
1732
\if :postgres_dba_pgvers_96plus
@@ -22,6 +37,9 @@ select regexp_replace(version(), '^PostgreSQL (\d+\.\d+).*$', e'\\\\1')::numeric
2237
reset client_min_messages;
2338
\endif
2439
VersCheck
40+
41+
echo "\\i $WARMUP" >> "$OUT"
42+
2543
echo "\\echo '\\033[1;35mMenu:\\033[0m'" >> "$OUT"
2644
for f in ./sql/*.sql
2745
do

sql/1_basic.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ select
1111
case
1212
when pg_is_in_recovery() then 'Replica' || ' (delay: '
1313
|| ((((case
14-
when pg_last_xlog_receive_location() = pg_last_xlog_replay_location() then 0
14+
when :postgres_dba_last_wal_receive_lsn() = :postgres_dba_last_wal_replay_lsn() then 0
1515
else extract (epoch from now() - pg_last_xact_replay_timestamp())
1616
end)::int)::text || ' second')::interval)::text
17-
|| '; paused: ' || pg_is_xlog_replay_paused()::text || ')'
17+
|| '; paused: ' || :postgres_dba_is_wal_replay_paused()::text || ')'
1818
else 'Master'
1919
end as value
2020
union all

start.psql

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
-- check if "\if" is supported (psql 10+)
2-
\if false
3-
\echo cannot work, you need psql version 10+ (Postgres server can be older)
4-
select 1/0;
5-
\endif
61

7-
-- TODO: improve work with custom GUCs for Postgres 9.5 and older
8-
select regexp_replace(version(), '^PostgreSQL (\d+\.\d+).*$', e'\\1')::numeric >= 9.6 as postgres_dba_pgvers_96plus \gset
9-
\if :postgres_dba_pgvers_96plus
10-
select coalesce(current_setting('postgres_dba.wide', true), 'off') = 'on' as postgres_dba_wide \gset
11-
\else
12-
set client_min_messages to 'fatal';
13-
select :postgres_dba_wide as postgres_dba_wide \gset
14-
reset client_min_messages;
15-
\endif
2+
\i warmup.psql
163
\echo '\033[1;35mMenu:\033[0m'
174
\echo ' 1 – Node Information: master/replica, lag, DB size, tmp files, etc'
185
\echo ' 2 – Table Size'

warmup.psql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- check if "\if" is supported (psql 10+)
2+
\if false
3+
\echo cannot work, you need psql version 10+ (Postgres server can be older)
4+
select 1/0;
5+
\endif
6+
7+
select regexp_replace(version(), '^PostgreSQL (\d+\.\d+).*$', e'\\1')::numeric >= 10 as postgres_dba_pgvers_10plus \gset
8+
\if :postgres_dba_pgvers_10plus
9+
\set postgres_dba_last_wal_receive_lsn pg_last_wal_receive_lsn
10+
\set postgres_dba_last_wal_replay_lsn pg_last_wal_replay_lsn
11+
\set postgres_dba_is_wal_replay_paused pg_is_wal_replay_paused
12+
\else
13+
\set postgres_dba_last_wal_receive_lsn pg_last_xlog_receive_location
14+
\set postgres_dba_last_wal_replay_lsn pg_last_xlog_replay_location
15+
\set postgres_dba_is_wal_replay_paused pg_is_xlog_replay_paused
16+
\endif
17+
18+
-- TODO: improve work with custom GUCs for Postgres 9.5 and older
19+
select regexp_replace(version(), '^PostgreSQL (\d+\.\d+).*$', e'\\1')::numeric >= 9.6 as postgres_dba_pgvers_96plus \gset
20+
\if :postgres_dba_pgvers_96plus
21+
select coalesce(current_setting('postgres_dba.wide', true), 'off') = 'on' as postgres_dba_wide \gset
22+
\else
23+
set client_min_messages to 'fatal';
24+
select :postgres_dba_wide as postgres_dba_wide \gset
25+
reset client_min_messages;
26+
\endif

0 commit comments

Comments
 (0)