4

How do I monitor a specific db with pg_isready?

Instance : DBSPG10T1 Version : 10.14 Port : 6241

postgres@postgres # SELECT datname FROM pg_database;
  datname
-----------
 postgres
 template1
 template0
 dbspg10t1

[postgres@HOSTNAME ~]$ if pg_isready -d postgres://localhost:6241/dbspg10t1; then echo "200 OK"; else echo "500 NOT OK"; fi
localhost:6241 - accepting connections
200 OK

The DB test does not exists but pg_isready still returns ok.

[postgres@HOSTNAME ~]$ if pg_isready -d postgres://localhost:6241/test; then echo "200 OK"; else echo "500 NOT OK"; fi
localhost:6241 - accepting connections
200 OK

Is this a syntax issue?

1 Answer 1

4

It looks like this might be a known bug. pg_isready doesn't use common code to the psql utility. See this pgsql-hackers thread on the topic from 2013: Re: -d option for pg_isready is broken.

Without diving too far into it, the relevant quotes seem to be...

Why aren't we using the exact same code as psql? Why does pg_isready have its own code for this?

Because pg_isready wants to print the host and port we actually tried to connect to, which no other utility does. Turns out, there's no clean API for that. We tried to invent something, but the evidence seems to indicate that what we invented bites.

But why wasn't it changed?

...the whole point of having both host and hostaddr seems to be that you can lie about where you're connecting. If you set host=some.pretty.domain.name hostaddr=1.2.3.4, the point is to say that you're connecting to the first while, under the covers, actually connecting to the second. Now, I am unclear what value this has, but someone at some point evidently thought it was a good idea, so we need to be careful about changing it.

To be fair, this is based on a very cursory reading of that one thread, but for your purposes, I think it's safe to treat this as a known bug

bash-4.4$ pg_isready
/tmp:5432 - accepting connections

bash-4.4$ pg_isready -d postgres://127.0.0.1
127.0.0.1:5432 - accepting connections

bash-4.4$ pg_isready -d postgres://127.0.0.1/foo
127.0.0.1:5432 - accepting connections

bash-4.4$ psql postgres://127.0.0.1/foo
psql: error: FATAL:  database "foo" does not exist

bash-4.4$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.