Is there any query to check the database status? I just want to know if it is active or not on the remote host.So, Is there any query which return 200 OK if db is running and other db detail?
2 Answers
https://www.postgresql.org/docs/current/static/app-pg-isready.html
-bash-4.2$ if pg_isready93 -d postgres://localhost:5432/template; then echo "200 OK"; else echo "500 NOT OK"; fi
200 OK
-bash-4.2$ if pg_isready93 -d postgres://localhost:5430/template; then echo "200 OK"; else echo "500 NOT OK"; fi
500 NOT OK
credits to Abelisto - I would not think of pg_isready in this context
3 Comments
Abelisto
BTW could be simplified like
(pg_isready -q -h 127.0.0.2 && echo Ok) || echo Fail "The exit status specifies the result of the connection check."Abelisto
PS Or using
if statement: if pg_isready -q -h 127.0.0.1; then echo Ok; else echo Fail; fiVao Tsun
@Abelisto it is your answer - just edit it as you think it should be :)
pg_isready?select pg_isready from pg_stat_activityAre you implying this?