我想跟踪函数内的执行时间。例如,我有以下状态跟踪表:
CREATE TABLE status_table
(
run_id numeric NOT NULL,
start_ts timestamp(6) without time zone NOT NULL,
end_ts timestamp(6) without time zone NOT NULL
)
WITH (
OIDS=FALSE
)
DISTRIBUTED RANDOMLY;
Run Code Online (Sandbox Code Playgroud)
我有以下示例函数,它使用 PG_SLEEP(5) 作为对我的函数实际执行操作的模拟:
CREATE OR REPLACE FUNCTION wrapper_func(p_run_id numeric)
RETURNS numeric AS
$BODY$
Declare
tmp_start_ts timestamp(6) without time zone;
tmp_end_ts timestamp(6) without time zone;
BEGIN
tmp_start_ts := CURRENT_TIMESTAMP;
PERFORM PG_SLEEP(5);
tmp_end_ts := CURRENT_TIMESTAMP;
INSERT INTO status_table (run_id,start_ts,end_ts) VALUES (p_run_id,tmp_start_ts,tmp_end_ts);
RETURN 0;
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
Run Code Online (Sandbox Code Playgroud)
I then called this …