Home > Archive > PostgreSQL JDBC > December 2005 > Re: an efficient way of checking if the connection to a db









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: an efficient way of checking if the connection to a db
Kris Jurka

2005-12-15, 8:25 pm



On Thu, 15 Dec 2005, Assad Jarrahian wrote:

> Trying to check if a connection is actually open every time I perform
> an operation (if not, I want to reopen it and perform that operation).
> isClosed() is no good, as in, it only guarantees true if close() was
> actually called on it.
>
> The documentation says, the only real way is to actually call an sql
> statement on it. That seems inefficient. Is there any other way that is
> recommended?


The overhead of a query like "SELECT 1" can't be that much. If this is a
concern you could add some code to the V3 QueryExecutor that issued just a
Sync message which would tell you if the connection was still good. Then
you'd have to call a pg specific interface to access this functionality.

Getting the official driver to provide this interface would require
demonstrating that the overhead of SELECT 1 is significantly higher than
Sync.

Kris Jurka

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Tom Lane

2005-12-15, 8:25 pm

Kris Jurka <books@ejurka.com> writes:
> Getting the official driver to provide this interface would require
> demonstrating that the overhead of SELECT 1 is significantly higher than
> Sync.


It probably is. However, sending an empty query string to the backend
to execute ought to be competitive with a bare Sync. libpq supports
that; does JDBC?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com