Re: Cheapest way to poll for notifications?

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Cheapest way to poll for notifications?
Date: 2009-12-11 15:39:21
Message-ID: 4B2267A9.1080302@postnewspapers.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-jdbc

Scott, Tom, Merlin:

Thanks for the comments and help. It's all sorted now - the origin of
the confusion was some outdated information in the JDBC driver
documentation.

The question arose because I was originally looking at polling from JDBC
(which I know I forgot to mention), where the docs state that:

"A key limitation of the JDBC driver is that it cannot receive
asynchronous notifications and must poll the backend to check if any
notifications were issued."

http://jdbc.postgresql.org/documentation/84/listennotify.html

.... and show a `SELECT 1' being issued to push any notifications.

I'd assumed that was a JDBC limitation until I tested with psql and
found that it, too, required some kind of client-initiated communication
to see NOTIFY events, at which point I began wondering if the backend
pushed them at all rather than waiting for client interaction. Hence my
question.

Anyway, as pointed out, psql just doesn't bother polling for
notifications because it's not important for psql, but it could if it
needed to - the notifications are waiting in its recieve buffer for it
to notice and care.

As for the JDBC driver - it turns out that the documentation is
out-of-date and/or misleading. The JDBC driver *does* support reading
notifications the backend has pushed to its receive buffer, and does
*not* have to poll the backend or issue a statement to receive
notifications. Some searching suggests that this changed in 8.0 or 8.1 .
The documentation needs adjusting, so I've sent a patch to it off to the
JDBC folks.

--
Craig Ringer

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Eric B. Ridge 2009-12-11 15:45:13 Re: Postgres "locked up"
Previous Message Pavel Stehule 2009-12-11 15:32:21 Re: PIVOT tables and crosstab

Browse pgsql-jdbc by date

  From Date Subject
Next Message Craig Ringer 2009-12-11 15:52:42 PATCH: Update LISTEN/NOTIFY documentation, PGConnection JavaDoc
Previous Message Tom Lane 2009-12-11 15:26:26 Re: Connection.setReadOnly()