Test postgresql connection string using psql at bash command line? Test postgresql connection string using psql at bash command line? shell shell

Test postgresql connection string using psql at bash command line?


The best tool for the purpose is pg_isready.

Simply run

pg_isready -d "$my_conn"

and check the return code.


Run this instead:

psql "$my_conn" -c "SELECT 1"

This would try to execute a simple query that always should return a one-row result and then exit.Also you could check the exit code of the operation by calling:

echo $?

Anything different than 0 would mean some error.