Search code examples
postgresqlbashpsql

Test connection to postgres with SSL with the command line


I need to test a connection to a distant postgres database with SSL turned on, and be notified of the result. I have the following command:

psql "sslmode=verify-ca sslrootcert=myRootCert.crt sslcert=myPublicCert.crt sslkey=myPrivateKey.key hostaddr=host user=user port=port dbname=db password=passwd"

It works fine, I am logged in and I can start typing commands. But what I need is only the status of the connection test, I don't want to be logged in after.

I saw there is a pg_isready command, but I can not find how to use it with SSL.


Solution

  • You can use your connection string like this:

    pg_isready -d 'sslmode=verify-ca sslrootcert=myRootCert.crt sslcert=myPublicCert.crt sslkey=myPrivateKey.key hostaddr=host user=user port=port dbname=db password=passwd'