Question

Is there any way I can send a NOTIFY to a database other than the one that my connection has specified?

[CLARIFICATION]

Consider we have two databases within one instance of PostgreSQL. If you are connected to one of them and you are LISTENing and you won't be able to hear the notifications made on the other database (at least to my experience).

My scenario is:

I want to connect to one unique centeral database within each instance of PostgreSQL from my application. Then, having an arbitrary number of databases on the same instance, I'll be sending notifications to my application, no matter which database has triggered it and I won't need to establish a connection to each database separately.

Was it helpful?

Solution

If the other database has established a connection to the database to which you are connected and has issued a LISTEN, then you send a NOTIFY to it the same way you would send one to anything else using the NOTIFY/LISTEN interface.

If the other database has not volunteered to LISTEN, then NOTIFY is not the right tool for the job. You could use dblink or FDW to insert records into a queue table on the other database. Or, insert them into a local queue table, and have the other database fetch them when it wants to.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top