Re: Cheapest way to poll for notifications? & Driver improvement question re SSL and notify

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Maciek Sakrejda <msakrejda(at)truviso(dot)com>
Cc: PG-JDBC Mailing List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Cheapest way to poll for notifications? & Driver improvement question re SSL and notify
Date: 2009-12-21 07:52:30
Message-ID: 4B2F293E.5090103@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-jdbc

Maciek Sakrejda wrote:
>> So my question is: is there any particularly low-overhead statement that
>> might be suitable for generating pointless client/server chat to check for
>> received async notifications? Should I just use "SELECT 1" ? Or would I be
>> better off using a SHOW statement like "SHOW role" to avoid creating a
>> snapshot etc?
>>
>
> Does the jdbc driver work with EmptyQueryResponse?

It seems to.

> At the protocol
> level, if you send a Query message with an all-whitespace sql string,
> the backend is supposed to reply with a single EmptyQueryResponse
> message and then issue ReadyForQuery again. I have a feeling that jdbc
> is probably "too smart" for this to work, but it could be worth a
> shot.

The JDBC driver isn't too smart for this - it doesn't catch the empty
query, but instead merrily passes it on to the backend as part of an
extended query request.

See the attached text file - it shows the client/server chat for one
such round trip.

So: the server doesn't consider the empty query an error, so it won't
affect any currently running transactions. It's a cheap single-message
each way round-trip, and it doesn't have any planning or snapshot
creation costs. Looks good to me :-)

Since I can't imagine an app _needing_ the JDBC driver to ignore empty
queries, is this something that it might be reasonable to document as
expected behavior from the driver - that it _will_ send even empty
queries to the server?

Thanks _VERY_ much for the tip. You've saved me and my logs quite a bit
of pain. It's not as good as client-side-only polling, but it's a whole
nicer than a full dummy statement, and I can easily do it only when an
SSL connection is detected.

--
Craig Ringer

Attachment Content-Type Size
trace.txt text/plain 1.6 KB

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dave Page 2009-12-21 08:43:55 Re: PostgreSQL@FOSDEM 2010 - Call for talks
Previous Message Mihamina Rakotomandimby 2009-12-21 07:11:41 Re: Server Requirements

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2009-12-21 08:08:13 Re: Issue with the JDBC driver doing timezone conversions on "java.sql.Date"?
Previous Message Craig Ringer 2009-12-21 06:59:58 Re: Cheapest way to poll for notifications? & Driver improvement question re SSL and notify