如何使用“RAISE INFO,RAISE LOG,RAISE DEBUG”来跟踪PostgreSQL
发布时间:2020-12-13 16:02:31 所属栏目:百科 来源:网络整理
导读:CREATE OR REPLACE FUNCTION mover(src text,dst text,cpquery text,conname text,ifbin boolean) returns void as$$ DECLARE cnt integer; dlcnt integer; del_count integer; ret text; BEGIN SELECT pg_catalog.dblink_copy_open(conname,dst,ifbin) INTO
CREATE OR REPLACE FUNCTION mover(src text,dst text,cpquery text,conname text,ifbin boolean) returns void as $$ DECLARE cnt integer; dlcnt integer; del_count integer; ret text; BEGIN SELECT pg_catalog.dblink_copy_open(conname,dst,ifbin) INTO ret ; RAISE LOG 'dblink_open %',ret; execute 'SELECT 1 as check FROM ' || src ||' limit 1' into cnt; IF cnt=0 THEN PERFORM pg_sleep(2); END IF; IF ifbin=true THEN RAISE DEBUG 'Start to Copy data with binary'; execute 'COPY (' || cpquery || ' ) to function pg_catalog.dblink_copy_write with binary'; RAISE DEBUG 'Finish Copy data'; ELSE RAISE DEBUG 'Start to Copy data without binary'; execute 'COPY (' || cpquery || ' ) to function pg_catalog.dblink_copy_write'; RAISE DEBUG 'Finish Copy data'; END IF; execute 'DELETE FROM ' || src; GET DIAGNOSTICS del_count=ROW_COUNT; RAISE INFO 'DELETE % rows',del_count; SELECT pg_catalog.dblink_copy_end() INTO ret; RAISE LOG 'dblink_end %',ret; END; $$ language plpgsql; 作为代码,我想通过使用RAISE将一些消息放入日志中,但位置在哪里 解决方法
它们可以输出到Postgres日志,报告回客户端,或两者都有.这些由服务器端设置,log_min_messages和client_min_messages控制.
有关详细信息,请参阅以下文档: http://www.postgresql.org/docs/current/static/plpgsql-errors-and-messages.html http://www.postgresql.org/docs/current/static/runtime-config-logging.html 由于@a_horse_with_no_name建议:也可以通过客户端的 它可以通过SQL:set client_min_messages设置为’debug’; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |