Using LISTEN / NOTIFY in psql clients

Viewed 492

I'm connected to same database server running in Docker container via psql client.

  1. In client A I run listen "virtual";
  2. In client B I run notify "virtual";

I would expect to see some kind of output in client A that it received asynchronous notification.

Can psql client be used this way?

1 Answers

The notification is only retrieved from the server as a payload to a request. If the client does not send a request to the server, it will not see the notification.

In psql you can run an empty statement (only a ;) to do that:

someuser=> ;
Asynchronous notification "virtual" received from server process with PID 11284.
someuser=>
Related