Re: Cheapest way to poll for notifications? - Mailing list pgsql-general

From Craig Ringer
Subject Re: Cheapest way to poll for notifications?
Date
Msg-id 4B211D5E.2070107@postnewspapers.com.au
Whole thread Raw
In response to Re: Cheapest way to poll for notifications?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Cheapest way to poll for notifications?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
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

pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: Cheapest way to poll for notifications?
Next
From: Adrian Klaver
Date:
Subject: Re: pg_dump and ON DELETE CASCADE problem