13

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?

3
  • 2
    pg_isready? Commented Sep 13, 2017 at 9:42
  • @Abelisto select pg_isready from pg_stat_activity Are you implying this? Commented Sep 13, 2017 at 9:46
  • Follow the link provided. It is utility that checks is PostgreSQL server ready to receive connection requests. To execute a query you should to be able to connect to the server first which is impossible in case if the server is down. Probably I misunderstood your question. Commented Sep 13, 2017 at 9:50

2 Answers 2

15

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

Sign up to request clarification or add additional context in comments.

3 Comments

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."
PS Or using if statement: if pg_isready -q -h 127.0.0.1; then echo Ok; else echo Fail; fi
@Abelisto it is your answer - just edit it as you think it should be :)
5
systemctl status postgresql

was what I was looking for

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.