https://blog.youkuaiyun.com/ghostliming/article/details/54892658
PostgreSQL提供了client端之间通过服务器端进行消息通信的机制。这种机制是通过listen和notify命令来完成的。
session1:
postgres=# listen postgres;
LISTEN
postgres=# listen liming
postgres-# ;
LISTEN
session2:
postgres=# notify postgres,'hello word';
NOTIFY
postgres=# notify liming,'hello liming';
NOTIFY
postgres=#
session1;
postgres=# select 1; --随便执行了一个命令
?column?
----------
1
(1 row)
Asynchronous notification "postgres" with payload "hello word" received from server process with PID 12241.
Asynchronous notification "liming" with payload "hello liming" received from server process with PID 12241.
postgres=#
listen和notify的相关命令:
1. listen:监听消息通道
2. unlisten:取消先前的监听
3. notify:发送消息到消息通道中
4. pg_notify():与notify命令功能相同
5. pg_listening_channels():调用此函数可以查询当前session已注册了哪些消息监听
————————————————
版权声明:本文为优快云博主「丹心明月」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/ghostliming/article/details/54892658

本文深入探讨了PostgreSQL中的listen和notify命令,这是一种允许客户端通过服务器进行消息通信的机制。文章详细介绍了如何在不同会话间使用这些命令进行消息监听和发送,并提供了具体的示例。
4058

被折叠的 条评论
为什么被折叠?



