Created
April 19, 2017 09:04
-
-
Save yumminhuang/b5a15745e6896a0dfd28058199c9e240 to your computer and use it in GitHub Desktop.
Monitoring WAL lag in PostgreSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# set -x | |
PG_PRIMARY='db1.example.com' | |
PG_STANDBY='db2.example.com' | |
PG_ROLE='user' | |
PG_DB='test' | |
PASSWORD='password' | |
primary_xloc=$(PGPASSWORD=$PASSWORD psql -U$PG_ROLE -d $PG_DB -h $PG_PRIMARY -q -t -A -c 'select * from pg_current_xlog_location()' | cut -c 3- | bc) | |
standby_xloc=$(PGPASSWORD=$PASSWORD psql -U$PG_ROLE -d $PG_DB -h $PG_STANDBY -q -t -A -c 'select * from pg_last_xlog_replay_location()' | cut -c 3- | bc) | |
if [ $(( $primary_xloc - $standby_xloc )) -eq 0 ]; then | |
exit 0 | |
else | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment