postgresql 如何使用“RAISE INFO, RAISE LOG, RAISE DEBUG”来追踪登录PostgreSQL的功能?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26967663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use "RAISE INFO, RAISE LOG, RAISE DEBUG” to track log in PostgreSQL function?
提问by Simon Su
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;
As code, I want to put some message into log by using RAISE
, but where is the location
of my log file ? and where RAISE DEBUG
output?
作为代码,我想通过使用将一些消息放入日志中RAISE
,但是我的日志文件的位置在哪里?哪里RAISE DEBUG
输出?
回答by khampson
They can either be output to the Postgreslog, reported back to the client, or both. These are controlled by server-side settings, log_min_messages
and client_min_messages
.
它们可以输出到Postgres日志,报告回客户端,或两者兼而有之。这些由服务器端设置控制,log_min_messages
并且client_min_messages
.
See the following doc for more details:
有关更多详细信息,请参阅以下文档:
http://www.postgresql.org/docs/current/static/plpgsql-errors-and-messages.html
http://www.postgresql.org/docs/current/static/plpgsql-errors-and-messages.html
http://www.postgresql.org/docs/current/static/runtime-config-logging.html
http://www.postgresql.org/docs/current/static/runtime-config-logging.html
As @a_horse_with_no_namesuggested: These parameters can also be set via the SET
command from the client.
正如@a_horse_with_no_name 所建议的:这些参数也可以通过SET
客户端的命令设置。
It can be set via the SQL: set client_min_messages to 'debug';
它可以通过SQL设置:set client_min_messages to 'debug';