1

I am new at PostgreSQL LISTEN/NOTIFY features. After the LISTEN command,

LISTEN mychannel;

We can NOTIFY messages to the channel.

NOTIFY mychannel 'Hello';
  1. This NOTIFY messages is saved somewhere in database. Where? Can I see messages using select query from a table?

  2. If I NOTIFY 3 or 5 messages, these are saved on queue. I run the LISTEN command using a programming language, all messages handled and messages removed from queue. If my client crashed, all messages will be lost. How can I solve this problem?

1 Answer 1

2

I am afraid that you misunderstand LISTEN. It is for asynchronous communication between active sessions. The messages are not stored anywhere.

If you want a persistent dara structure for communication between two parts of your application, you are probably looking for a queue.

Since queues are notoriously hard to implement in relational databases, I suggest that you use one of the existing third party implementations for PostgreSQL.

LISTEN / NOTIFY can be part of such a queue implementation to make it unnecessary for the recipients to poll the queue regularly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.