Re: need a method to ping a running database - Mailing list pgsql-general

From Dmitry Tkach
Subject Re: need a method to ping a running database
Date
Msg-id 3EE8DEB5.4050904@openratings.com
Whole thread Raw
In response to Re: need a method to ping a running database  (Steve Crawford <scrawford@pinpointresearch.com>)
List pgsql-general
Steve Crawford wrote:

>>Sure. I did not say it was "incorrect"...
>>But it is *different* from most if not all other errors, because it
>>requires a different item...
>>
>>
>
>It just depends on the use of the script (about which I didn't know the
>details). If the only purpose is to determine if I can run queries then the
>simple test will do.
>
If that is your only purpose, you don't need any scripts - just proceed
directly to running your query, and see if it works :-)

>Not taste - just the voice of experience from one who has been burned. Suppose
>your db is on a remote machine and someone screws up DNS so the host doesn't
>resolve or the db admin has made an error in updating pg_hba.conf or a
>network cable is unplugged or a routing table is damaged. You can even have
>something as silly as psql being deleted or not in the path. None of these
>cases will yield the string "ERROR" so a script that looks for the absence of
>"ERROR" will say everything is OK.
>
No, not  "none of them" - the former will complain....
As for the latter, it doesn't matter what you grep for, because, the
'Command not found' thing will abort your script, so you'll never be
able to look at the results.
It is a good ide to check the exist status of the script, yes.

>
>I've given up trying to dream up/test for every possible error - there are too
>many and once I think I've thought of them all I "discover" another. :)
>
>Checking for a known expected result will definitely let you know if the db is
>or is not available
>
Oh, yeah? ;-)

Try this:
alias psql 'echo \!*'
psql -c "select 'It is running';" | grep -c "It is running"

:-)

> (note, not available != down - just not available to the
> testing program - again it depends on the purpose of your script).

If you are talking about the name of that variable I used in the original message, that is *definitely* a question of
taste:-) 




Dima



pgsql-general by date:

Previous
From: "Dann Corbit"
Date:
Subject: Re: Postgres performance comments from a MySQL user
Next
From: "Darko Prenosil"
Date:
Subject: Re: Choosing Between PL/PGSQL or C/C++ for Triggers/Store Procs