Re: Synchronous LISTEN/NOTIFY?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Synchronous LISTEN/NOTIFY?
Дата
Msg-id 29095.978666476@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Synchronous LISTEN/NOTIFY?  (Lincoln Yeoh <lyeoh@pop.jaring.my>)
Ответы Re: Synchronous LISTEN/NOTIFY?  (Lincoln Yeoh <lyeoh@pop.jaring.my>)
Список pgsql-general
Lincoln Yeoh <lyeoh@pop.jaring.my> writes:
> Basically you now can have apps use the database for instant messaging :).

My former company was doing that since Postgres 6.4 or so.

> Right now it looks like B has to keep polling regularly.

No, it just has to use select() to wait on the postgres connection
(plus any other input files it wants to pay attention to).

> Basically LISTEN doesn't wait.

LISTEN has nothing to do with waiting.  It merely informs the backend
of your interest in subsequently receiving notices of a particular type.
Perhaps you should think of it as like signal(2).

See
http://www.postgresql.org/devel-corner/docs/postgres/libpq-notify.htm
but in brief the idea is:

1. The outer event loop of your application uses select() to wait on
the PQsocket() fd as well as any other interesting fds.

2. When you see input ready on the PQsocket() fd, call PQconsumeInput(),
then check PQnotifies().

3. Also check PQnotifies() after any PQexec(), to see if notify messages
came in during the query.

Keep in mind also that notifications are only delivered when you are
not within a transaction block (BEGIN/END).

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Lincoln Yeoh
Дата:
Сообщение: Synchronous LISTEN/NOTIFY?
Следующее
От: Lamar Owen
Дата:
Сообщение: Re: 7.0.3 rpm testing & other problems