【问题标题】:How to use "RAISE INFO, RAISE LOG, RAISE DEBUG” to track log in PostgreSQL function?PostgreSQL函数中如何使用“RAISE INFO, RAISE LOG, RAISE DEBUG”来跟踪日志?
【发布时间】:2014-11-17 07:35:29
【问题描述】:
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 将一些消息放入日志,但位置在哪里 我的日志文件? RAISE DEBUG 输出在哪里?

【问题讨论】:

    标签: postgresql plpgsql debug-print


    【解决方案1】:

    它们可以被输出到 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 建议的那样:这些参数也可以通过客户端的 SET 命令设置。

    可以通过SQL设置:set client_min_messages to 'debug';

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-28
      • 2019-07-07
      • 2018-07-24
      • 2017-11-03
      • 2017-09-11
      • 2012-08-08
      • 2011-06-15
      • 2021-04-14
      相关资源
      最近更新 更多