暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

PostgreSQL plpgsql 函数 trace - plpgsql_check

digoal 2020-08-14
457

作者

digoal

日期

2020-08-14

标签

PostgreSQL , plpgsql , 跟踪


背景

plpgsql_check 新版本增加功能, 支持plpgsql trace.

https://github.com/okbob/plpgsql_check#tracer

http://okbob.blogspot.com/2020/08/plpgsqlcheck-now-supports-tracing.html

The extension plpgsql_check can be used like linter, validator for PLpgSQL language. It can be used like profiler with possibility to calculate some basic coverage metrics. And now it can be used for code tracing. In this mode, plpgsql_check raises notice when function or statent is starting or is fininshing:

Example of output in default verbosity level:

postgres=# do $$ begin perform fx(10,null, 'now', e'stěhule'); end; $$; NOTICE: #0 ->> start of block inline_code_block (oid=0) NOTICE: #2 ->> start of function fx(integer,integer,date,text) (oid=16405) NOTICE: #2 call by inline_code_block line 1 at PERFORM NOTICE: #2 "a" => '10', "b" => null, "c" => '2020-08-05', "d" => 'stěhule' NOTICE: #4 ->> start of function fx(integer) (oid=16404) NOTICE: #4 call by fx(integer,integer,date,text) line 1 at PERFORM NOTICE: #4 "a" => '10' NOTICE: #4 <<- end of function fx (elapsed time=0.336 ms) NOTICE: #2 <<- end of function fx (elapsed time=0.631 ms) NOTICE: #0 <<- end of block (elapsed time=0.978 ms) DO

Example of output in verbose verbosity level:

postgres=# set plpgsql_check.tracer_verbosity TO verbose; SET postgres=# do $$ begin perform fx(10,null, 'now', e'stěhule'); end; $$; NOTICE: #0 ->> start of block inline_code_block (oid=0) NOTICE: #0.1 1 --> start of PERFORM (expr='fx(10,null, 'now', e'stěhule' ..') NOTICE: #2 ->> start of function fx(integer,integer,date,text) (oid=16405) NOTICE: #2 call by inline_code_block line 1 at PERFORM NOTICE: #2 "a" =>; '10', "b" => null, "c" => '2020-08-05', "d" => 'stěhule' NOTICE: #2.1 1 --> start of PERFORM (expr='fx(a)') NOTICE: #2.1 "a" => '10' NOTICE: #4 ->> start of function fx(integer) (oid=16404) NOTICE: #4 call by fx(integer,integer,date,text) line 1 at PERFORM NOTICE: #4 "a" => '10' NOTICE: #4.3 6 --> start of IF (cond='a > 10') NOTICE: #4.3 "a" => '10' NOTICE: #4.3 8 ELSEIF (expr='a < 0') NOTICE: #4.3 "a" => '10' NOTICE: #4.3 <-- end of IF (elapsed time=0.056 ms) NOTICE: #4.4 12 --> start of assignment (expr='100 + a + b') NOTICE: #4.4 "a" => '10', "b" => '20' NOTICE: #4.4 <-- end of assignment (elapsed time=0.024 ms) NOTICE: #4.4 "res" => '130' NOTICE: #4.5 13 --> start of RETURN NOTICE: #4.5 "res" => '130' NOTICE: #4.5 <-- end of RETURN (elapsed time=0.045 ms) NOTICE: #4 <<- end of function fx (elapsed time=0.248 ms) NOTICE: #2.1 <-- end of PERFORM (elapsed time=0.354 ms) NOTICE: #2 <<- end of function fx (elapsed time=0.441 ms) NOTICE: #0.1 <-- end of PERFORM (elapsed time=0.710 ms) NOTICE: #0 <<- end of block (elapsed time=0.777 ms)

PostgreSQL 许愿链接

您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。开不开森.

9.9元购买3个月阿里云RDS PostgreSQL实例

PostgreSQL 解决方案集合

德哥 / digoal's github - 公益是一辈子的事.

digoal's wechat

文章转载自digoal,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论