From: Craig Ringer <craig@postnewspapers.com.au>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PG-General Mailing List <pgsql-general@postgresql.org>
Subject: Re: Cheapest way to poll for notifications?
Date: Fri, 11 Dec 2009 00:10:06 +0800
Message-ID: <4B211D5E.2070107@postnewspapers.com.au> (raw)
In-Reply-To: <25363.1260457864@sss.pgh.pa.us>
References: <4B20F639.4070706@postnewspapers.com.au>
<25363.1260457864@sss.pgh.pa.us>
Tom Lane wrote:
> Craig Ringer <craig@postnewspapers.com.au> writes:
>> As Pg doesn't presently support client push for notifications arising
>> from LISTEN/NOTIFY, I'm wondering if anybody here has done any research
>> into the cheapest statement to issue to check for such notifications.
>
> The backend certainly will push the notification. Maybe you just have
> a client-side-software issue?
Testing with two plain old psql sessions to an 8.4.1 DB on linux (Ubuntu
9.10) here, I don't see the asynchronous notification until I send some
other command to the database from the client. It's the same over a
local UNIX socket or a loopback TCP/IP connection (with SSL).
Neither listener nor notifier are in a transaction, though it doesn't
seem to make any difference if I "BEGIN; NOTIFY test; COMMIT;" instead.
I only waited a few minutes after sending NOTIFY to see if psql would
notice, but if it's server-pushed it should be immediate, right?
Is this a psql limitation rather than a backend one? I know the JDBC
driver has such a limitation, and in fact the psql man page suggests
that it does too:
"
Whenever a command is executed, psql also polls for asynchronous noti‐
fication events generated by LISTEN [listen(7)] and NOTIFY [notify(7)].
"
... but if that is the case, is there any client software that _does_
support truly asynchronous receipt of notifications?
=====(SESSION 1, psql 8.4.1, local socket)====
test=> LISTEN x;
LISTEN
test=> SELECT current_timestamp;
now
-------------------------------
2009-12-10 23:54:16.988355+08
(1 row)
test=> SELECT current_timestamp;
now
-------------------------------
2009-12-10 23:55:04.872358+08
(1 row)
Asynchronous notification "x" received from server process with PID 14623.
test=>
=====(SESSION 2, psql 8.4.1, local socket)====
test=> SELECT current_timestamp;
now
-------------------------------
2009-12-10 23:54:34.252394+08
(1 row)
test=> NOTIFY x;
NOTIFY
test=>
*Self* notifications ( where listener == notifier ) are issued
immediately, but a NOTIFY to another backend doesn't seem to get pushed.
--
Craig Ringer
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, tgl@sss.pgh.pa.us, pgsql-general@postgresql.org
Subject: Re: Cheapest way to poll for notifications?
In-Reply-To: <4B211D5E.2070107@postnewspapers.com.au>
References: <4B20F639.4070706@postnewspapers.com.au> <25363.1260457864@sss.pgh.pa.us> <4B211D5E.2070107@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