Re: BUG #15168: "pg_isready -d" effectively ignores given databasename - Mailing list pgsql-bugs

From jake
Subject Re: BUG #15168: "pg_isready -d" effectively ignores given databasename
Date
Msg-id 162fa45b1f0.e784e91e8344.4158165001514423492@zoho.com
Whole thread Raw
In response to Re: BUG #15168: "pg_isready -d" effectively ignores given databasename  (jake <jakelist@zoho.com>)
List pgsql-bugs
After discussing this with the Lead Developer of Snowdrift.coop, I'd like to humbly suggest that the specification be slightly adjusted to remove the surprising aspect.

Usually, an exit status of zero means that all went well. The aforementioned behavior is, by Postgres' own admittance, not only an error, but a fatal error, indicated in the log:
FATAL:  database "jibberish" does not exist

And yet, pg_isready exits with a zero, contradicting the usual meaning. Again, it is following spec perfectly; I only suggest a change to the spec.

Specifically, I suggest two small adjustments. One, an exit status of 4 would mean that a connection to the server was made, but the specified database does not exist. In the future, this may be generalized to mean that a connection was made, but some parameter value did not make sense with the cluster's current state. Though right now, the only possible such friction I see is that the specified database does not exist. And for the second adjustment: an exit status of 0 would mean "complete success": a connection was made and the parameters made sense.

Note the exit statuses of 1, 2 and 3 would keep their old meanings. In order to get an exit status of 4, the arguments must be syntactically valid. Otherwise, 3 is returned.

Jake T.

---- On Tue, 24 Apr 2018 13:01:46 -0700 jake <jakelist@zoho.com> wrote ----

Ah-ha. Thank you for pointing that out. I did not notice.

In case you're interested, I used a StackOverflow solution to programmatically determine whether a database exists, after first ensuring that the cluster has been initialized and that the server is running.

Thank you for your rapid response,
Jake
---- On Mon, 23 Apr 2018 21:29:11 -0700 David G. Johnston <david.g.johnston@gmail.com> wrote ----

On Monday, April 23, 2018, PG Bug reporting form <noreply@postgresql.org> wrote:
# Not expected, database "jibberish" does not exist:
$ pg_isready -d jibberish
/run/media/jthomas/BackupOne/development/snowdrift/.postgres-work:5432 -
accepting connections

The notes section of the docs for the command cover this behavior.  It is not a bug, the utility answers whether the server will accept connections generally, not that a specific connection string and credentials are valid.

David J.



pgsql-bugs by date:

Previous
From: Andres Freund
Date:
Subject: Re:Re: BUG #15169: create index CONCURRENTLY conflict with other table's COPY
Next
From: "David G. Johnston"
Date:
Subject: Re: BUG #15168: "pg_isready -d" effectively ignores given database name