简体   繁体   中英

postgresql notification channel

I am currently playing with the Notify/Listen mechanism of postgresql and try to combine it with the trigger to detect changes in db tables and send it to a external watcher written in Java. During my test I found that it seems the channel created by either notify or listen will not last if there is no connection to it. For example, if a notifier execute a NOTIFY mymessage, 'blah-blah' sql script and then close the connection, if there is no current listener listening to the channel "mymessage", the channel will be removed, which means that the payload 'blah-blah' will be lost.

Does anyone knows how to configure the postgresql database to make a created notification channel permanent so as to prevent message lost? Or, does anyone knows how to prevent a detected event in a postgresql table from being lost?

Thanks

docs state:

all the sessions currently listening on that notification channel are notified

(emphasis mine). So no - there is nothing to configure.

If you want to save some message somewhere so other sessions could later read it, you should use publicly readable table for it Eg: (message_id bigint, message_text text) . Of course it will require more one more relation like (last_listened_message_id bigint, pid int) not to read ALL messages once and once again.

And if you want to mock up channels, you should either create more similar tables or add columns to two above...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM