postgresql - Postgres - test de la connexion de base de données en bash

Mots clés : bashpostgresqldockercoreosbash

meilleur 3 Réponses postgresql - Postgres - test de la connexion de base de données en bash

vote vote

97

pg_isready -d <db_name> -h <host_name> -p <port_number> -U <db_user>                       
  0 - if the server is accepting connections normally,    1 - if the server is rejecting connections (for example during startup),    2 - if there was no response to the connection attempt, and    3 - if no attempt was made (for example due to invalid parameters). 
vote vote

89

#!/usr/bin/python2.4 # import psycopg2 try:     db = psycopg2.connect("dbname='...' user='...' host='...' password='...'") except:     exit(1)  exit(0) 
python psqltest.py && echo 'OK' || echo 'FAIL' 
vote vote

71

FROM postgres  ENTRYPOINT [ "psql", "-h", "$POSTGRES_PORT_5432_TCP_ADDR",  "-p", "$POSTGRES_PORT_5432_TCP_PORT" ] 
#!/bin/sh if ! docker run --link postgres:postgres psql --command "select * from foo;" ; then    # Do something fi 

Questions similaires