Hacker News new | ask | show | jobs
by wulczer 4600 days ago
Why can't you use a connection that has issued LISTEN for anything else? In fact, I'm fairly sure you can use it normally.

We're using NOTIFY to broadcast database changes to services that should react to them and it's quite a nice way to separate concerns: process A just writes to the database, a trigger issues a NOTIFY, process B checks and notices there's been a change.

Edit: I see, the code in the post suggests that the connection needs to be stuck in a select() (I should know, I contributed a largre chunk of psycopg2's async code handling). You just need to use an asynchronous driver and you can happily LISTEN and do queries at the same time (of course you won't get notifies while a query is processing - the Postgres protocol has no concept of multiplexing).

We're using Twisted and happily mixing queries and NOTIFY.

1 comments

It looks like you're right. This was/is a limitation of the node.js postgres adapter I was using.
We use node-postgres and this is not the case. I think node-postgres has one of the cleanest implementations of LISTEN due to nodejs event callbacks