Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-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: trace.txt
Description: text/plain (1.6 KB)

In response to

pgsql-jdbc by date

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

pgsql-general by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group