Created
October 27, 2017 02:23
-
-
Save allenyang79/163e4e3be921863a1aa3117697caae71 to your computer and use it in GitHub Desktop.
monitor psql db
This file contains hidden or 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
import sys | |
import psycopg2 | |
import psycopg2.extras | |
conn = psycopg2.connect("host=localhost port=5433 dbname=keycloak user=keycloak password=keycloak") | |
with conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur: | |
cur.execute('show pool_nodes') | |
result = cur.fetchall() | |
result = sorted(result, key=lambda x:x['hostname']) | |
#print result | |
if result[0]['status'] == 'up' and result[0]['role'] == 'primary' and result[0]['status'] == 'up': | |
sys.exit(0) | |
#print 'db ha error. primary is not standby' | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment