pg_listening_channels() is not returning the channels name

≯℡__Kan透↙ 提交于 2019-12-24 18:06:31

问题


1) i want to know the channels name which are listing on my database but pg_listening_channels() name always returning null value (blank) even some clients are listening on this database.

below is my pgsql code. is any thing wrong in this code.

CREATE OR REPLACE FUNCTION query_trigger()
  RETURNS trigger AS
$BODY$
DECLARE
 send_message  text;
 queryString  text;
 channelNameArray text[];
 channelNames text;
      BEGIN
        queryString = current_query();
        channelNameArray = pg_listening_channels();
        channelNames = array_to_string(channelNameArray , ',');

           send_message := queryString || '  ' || channelNames;
           insert into "Client_Address" values (channelNames , queryString) ;
           PERFORM pg_notify('myChannel', send_message  );
           RETURN NULL;
          END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION query_trigger() OWNER TO postgres;

Schema of Client_Address table
Notify_node   text;
query         text;  

回答1:


pg_listening_channels reports listens in your own session. It won't (and can't) report listens from other sessions.

There's no way to get that information in Pg 9.2 via the system directly. You could always maintain a side-table with the info but you'd have the usual problems with keeping it in sync.

Why do you want to do this anyway? It's kind of bizarre to use NOTIFY like this. Why not have everyone listen on the same channel and notify them all with a single call?

Are you attempting to write audit logging? If so consider using one of the existing solutions or just using csv logging.



来源:https://stackoverflow.com/questions/18202091/pg-listening-channels-is-not-returning-the-channels-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!