Reputation:
If I have a postgresql connection string:
export my_conn='postgresql://vadmin:[email protected]/prod'
how can I test this connection? I tried:
pqsl "$my_conn"
and it just hangs
Upvotes: 16
Views: 24541
Reputation: 246238
The best tool for the purpose is pg_isready
.
Simply run
pg_isready -d "$my_conn"
and check the return code.
Upvotes: 12
Reputation: 950
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.
Upvotes: 14