Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 79276632CA0 for ; Thu, 10 Dec 2009 12:10:19 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 90220-08 for ; Thu, 10 Dec 2009 16:10:12 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by mail.postgresql.org (Postfix) with ESMTP id 770CE632A0B for ; Thu, 10 Dec 2009 12:10:11 -0400 (AST) Received: from localhost (access [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id D46151E0440; Fri, 11 Dec 2009 00:10:08 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (access.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id TWfxR39f0RAM; Fri, 11 Dec 2009 00:10:07 +0800 (WST) Received: from [10.1.1.5] (124-169-88-117.dyn.iinet.net.au [124.169.88.117]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id DAD771E043C; Fri, 11 Dec 2009 00:10:06 +0800 (WST) Message-ID: <4B211D5E.2070107@postnewspapers.com.au> Date: Fri, 11 Dec 2009 00:10:06 +0800 From: Craig Ringer User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Tom Lane CC: PG-General Mailing List Subject: Re: Cheapest way to poll for notifications? References: <4B20F639.4070706@postnewspapers.com.au> <25363.1260457864@sss.pgh.pa.us> In-Reply-To: <25363.1260457864@sss.pgh.pa.us> X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200912/440 X-Sequence-Number: 156660 Tom Lane wrote: > Craig Ringer 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