Listen and Notify

Поиск
Список
Период
Сортировка
Искать

Listen and Notify

От:
Alexander Reichstadt <lxr@mac.com>
Дата:
Hi,

From the documentation I was able to build a trigger firing upon deletion of a record a function that delivers tablename_operation as a notification one needs to subscribe to. So in terminal I can say LISTEN persons_delete and instantly will receive

	Asynchronous notification "persons_delete" received from server process with PID 54790.

if there was a delete. But what I don't fully understand is how to do this with PQnotifies. Following the docu I get no notifications even though I subscribe to them after successfully connecting to the server the same way I do using terminal.

Googling didn't give me examples I was able to use. Please, can someone help?

Thanks
Alex

Re: Listen and Notify

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Alexander Reichstadt  writes:
> But what I don't fully understand is how to do this with PQnotifies. Following the docu I get no notifications even though I subscribe to them after successfully connecting to the server the same way I do using terminal.

Maybe you forgot PQconsumeInput?  There's a working example in the
source tree:

http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/test/examples/testlibpq2.c

			regards, tom lane

Re: Listen and Notify

От:
Merlin Moncure <mmoncure@gmail.com>
Дата:
On Mon, Apr 30, 2012 at 1:47 AM, Alexander Reichstadt  wrote:
> Hi,
>
> From the documentation I was able to build a trigger firing upon deletion of a record a function that delivers tablename_operation as a notification one needs to subscribe to. So in terminal I can say LISTEN persons_delete and instantly will receive
>
>        Asynchronous notification "persons_delete" received from server process with PID 54790.
>
> if there was a delete. But what I don't fully understand is how to do this with PQnotifies. Following the docu I get no notifications even though I subscribe to them after successfully connecting to the server the same way I do using terminal.
>
> Googling didn't give me examples I was able to use. Please, can someone help?

I'm suspecting operator error because using PQnotifies is exactly what
psql does.  Maybe you could post a small test program?  Are you using
a mixed case notification name?

merlin

Re: Listen and Notify

От:
Mark Morgan Lloyd <markMLl.pgsql-general@telemetry.co.uk>
Дата:
Merlin Moncure wrote:
> On Mon, Apr 30, 2012 at 1:47 AM, Alexander Reichstadt  wrote:
>> Hi,
>>
>> From the documentation I was able to build a trigger firing upon deletion of a record a function that delivers tablename_operation as a notification one needs to subscribe to. So in terminal I can say LISTEN persons_delete and instantly will receive
>>
>>        Asynchronous notification "persons_delete" received from server process with PID 54790.
>>
>> if there was a delete. But what I don't fully understand is how to do this with PQnotifies. Following the docu I get no notifications even though I subscribe to them after successfully connecting to the server the same way I do using terminal.
>>
>> Googling didn't give me examples I was able to use. Please, can someone help?
> 
> I'm suspecting operator error because using PQnotifies is exactly what
> psql does.  Maybe you could post a small test program?  Are you using
> a mixed case notification name?

Works here in a Pascal program built using Lazarus. You /must/ however, 
ensure that the session requesting the notification is kept active and 
is the one that's regularly checked, it's easy to lose track of this in 
a development framework which isolates you from the low-level handles etc.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

Re: Listen and Notify

От:
Alexander Reichstadt <lxr@mac.com>
Дата:
The framework I am using is PGSQLKit for Mac OS X for which the source was available and which I downloaded and altered since. Actually it gives you access down to the pqlib calls.

The connection being closed was one of the issues. I had added convenience classes with class methods to the framework. The connection was kept in the background with its credentials and settings in place, but only opened on a per-request basis and closed afterwards which I changed now and now it works.

As to mixed case, no, it was all lower case, but using terminal for verification I had taken this into consideration so for listener and notifier to match.

Am 01.05.2012 um 14:51 schrieb Mark Morgan Lloyd:

> Merlin Moncure wrote:
>> On Mon, Apr 30, 2012 at 1:47 AM, Alexander Reichstadt  wrote:
>>> Hi,
>>> 
>>> From the documentation I was able to build a trigger firing upon deletion of a record a function that delivers tablename_operation as a notification one needs to subscribe to. So in terminal I can say LISTEN persons_delete and instantly will receive
>>> 
>>>       Asynchronous notification "persons_delete" received from server process with PID 54790.
>>> 
>>> if there was a delete. But what I don't fully understand is how to do this with PQnotifies. Following the docu I get no notifications even though I subscribe to them after successfully connecting to the server the same way I do using terminal.
>>> 
>>> Googling didn't give me examples I was able to use. Please, can someone help?
>> I'm suspecting operator error because using PQnotifies is exactly what
>> psql does.  Maybe you could post a small test program?  Are you using
>> a mixed case notification name?
> 
> Works here in a Pascal program built using Lazarus. You /must/ however, ensure that the session requesting the notification is kept active and is the one that's regularly checked, it's easy to lose track of this in a development framework which isolates you from the low-level handles etc.
> 
> -- 
> Mark Morgan Lloyd
> markMLl .AT. telemetry.co .DOT. uk
> 
> [Opinions above are the author's, not those of his employers or colleagues]
> 
> -- 
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

FAQ