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 is used to raise errors and report messages, PostgreSQL provides various parameters to report an error, warning, and information at a detailed level.
To set a breakpoint at the first line of a program, right-click the name of the object you would like to debug, and select Set breakpoint from the Debugging sub-menu. The debugger window will open, waiting for another session to invoke the program.
The command enable-debug is used to enable the compilation of all the applications and libraries. The execution of this procedure usually impedes the system, but it also amplifies the binary file size.
The Syntax for PostgreSQL CREATE Function command is as follows: CREATE [OR REPLACE] FUNCTION function_name (arguments) RETURNS return_datatype. LANGUAGE plpgsql.
They can either be output to the Postgres log, reported back to the client, or both. These are controlled by server-side settings, log_min_messages
and 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/runtime-config-logging.html
As @a_horse_with_no_name suggested: These parameters can also be set via the SET
command from the client.
It can be set via the SQL: set client_min_messages to 'debug';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With