Re: need a method to ping a running database

From: Dmitry Tkach <dmitry(at)openratings(dot)com>
To: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
Cc: Travis Hume <travis(dot)hume(at)tenzing(dot)com>, pgsql-general(at)postgresql(dot)org, Breck Thomas <Breck(dot)Thomas(at)tenzing(dot)com>
Subject: Re: need a method to ping a running database
Date: 2003-06-12 20:12:37
Message-ID: 3EE8DEB5.4050904@openratings.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dmitry Tkach 2003-06-12 20:37:57 Re: Choosing Between PL/PGSQL or C/C++ for Triggers/Store
Previous Message Dann Corbit 2003-06-12 19:44:16 Re: Postgres performance comments from a MySQL user