Determine if a user and database are available - Mailing list pgsql-general

From Jeffrey Walton
Subject Determine if a user and database are available
Date
Msg-id CAH8yC8=fbU-DWSNso7qKDSNCj52hTop8ENKxF7_4a=hjY-nn6w@mail.gmail.com
Whole thread Raw
Responses Re: Determine if a user and database are available
Re: Determine if a user and database are available
Re: Determine if a user and database are available
List pgsql-general
Hi Everyone,

I have another beginner question. I am trying to use pg_isready to
determine if a database and user are present. The program seems to
always succeed, even when I delete the user or the database.

This baffles me from the man page. I guess this explains the behavior
I am seeing.

    NOTES
       It is not necessary to supply correct user name, password, or database
       name values to obtain the server status; however, if incorrect values
       are provided, the server will log a failed connection attempt.

A typical usage is shown below, where variables are parsed from a config file.

    password=$(grep 'DD_DB_Rpass' dojoConfig.yml | awk '{ print $2 }')
    hostname=$(grep 'DD_DB_Host' dojoConfig.yml | awk '{ print $2 }')
    database=$(grep 'DD_DB_Name' dojoConfig.yml | awk '{ print $2 }')
    username=$(grep 'DD_DB_Ruser' dojoConfig.yml | awk '{ print $2 }')

    PGPASSWORD=${password} pg_isready \
         -h "${hostname}" -U "${username}" -d "${database}"

Given the NOTES in the man page, how do we determine if a user and
database are present using the shell? Is there another utility we
should be using?

Thanks in advance,

Jeff



pgsql-general by date:

Previous
From: Meera Nair
Date:
Subject: RE: Unable to archive logs in standby server
Next
From: Christophe Pettus
Date:
Subject: Re: Determine if a user and database are available