From: Craig Ringer <craig@postnewspapers.com.au>
To: Maciek Sakrejda <msakrejda@truviso.com>
Cc: PG-JDBC Mailing List <pgsql-jdbc@postgresql.org>
Subject: Re: Cheapest way to poll for notifications? & Driver improvement question re SSL and notify
Date: Mon, 21 Dec 2009 15:52:30 +0800
Message-ID: <4B2F293E.5090103@postnewspapers.com.au> (raw)
In-Reply-To: <895e58dd0912201724r6b798469t4879e48a0d0abae2@mail.gmail.com>
References: <C746D04C.CAE15%scott_ribe@killerbytes.com>
<4B2267A9.1080302@postnewspapers.com.au>
<4B2C7A13.9080807@postnewspapers.com.au>
<895e58dd0912201724r6b798469t4879e48a0d0abae2@mail.gmail.com>
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
Attachments:trace.txt (text/plain, 1.6K) download
No. Time Source Destination Protocol Info
178 40.633175 127.0.0.1 127.0.0.1 PGSQL >P/B/D/E/S
Frame 178 (110 bytes on wire, 110 bytes captured)
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (127.0.0.1)
Transmission Control Protocol, Src Port: 59141 (59141), Dst Port: postgresql (5432), Seq: 3574, Ack: 53702, Len: 44
PostgreSQL
Type: Parse
Length: 8
Statement:
Query:
Parameters: 0
PostgreSQL
Type: Bind
Length: 12
Portal:
Statement:
Parameter formats: 0
Parameter values: 0
Result formats: 0
PostgreSQL
Type: Describe
Length: 6
Portal:
PostgreSQL
Type: Execute
Length: 9
Portal:
Returns: all rows
PostgreSQL
Type: Sync
Length: 4
No. Time Source Destination Protocol Info
179 40.633290 127.0.0.1 127.0.0.1 PGSQL <1/2/n/I/Z
Frame 179 (92 bytes on wire, 92 bytes captured)
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (127.0.0.1)
Transmission Control Protocol, Src Port: postgresql (5432), Dst Port: 59141 (59141), Seq: 53702, Ack: 3618, Len: 26
PostgreSQL
Type: Parse completion
Length: 4
PostgreSQL
Type: Bind completion
Length: 4
PostgreSQL
Type: No data
Length: 4
PostgreSQL
Type: Empty query
Length: 4
PostgreSQL
Type: Ready for query
Length: 5
Status: Idle (73)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: craig@postnewspapers.com.au, msakrejda@truviso.com
Subject: Re: Cheapest way to poll for notifications? & Driver improvement question re SSL and notify
In-Reply-To: <4B2F293E.5090103@postnewspapers.com.au>
References: <C746D04C.CAE15%scott_ribe@killerbytes.com> <4B2267A9.1080302@postnewspapers.com.au> <4B2C7A13.9080807@postnewspapers.com.au> <895e58dd0912201724r6b798469t4879e48a0d0abae2@mail.gmail.com> <4B2F293E.5090103@postnewspapers.com.au>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox