PostgreSQL提供了client端之間通過服務器端進行消息通信的機制。這種機制是通過listen和notify命令來完成的。session1:postgres=# listen postgres;LISTENpostgres=# listen limingpostgres-# ;LISTENsession2:postgres=# notify postgres,'hello Word';NOTIFYpostgres=# notify liming,'hello liming';NOTIFYpostgres=#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已注冊了哪些消息監聽
新聞熱點
疑難解答