如何调试 postgresql 存储过程?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20190406/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 00:30:00  来源:igfitidea点击:

How to debug postgresql stored procedures?

postgresqldebuggingstored-procedures

提问by mark

I realize that there is nothing similar to SQL Server Management Studio, so I am mentally prepared to use the good old printf debugging.

我意识到没有类似于 SQL Server Management Studio 的东西,所以我有心理准备使用好的旧 printf 调试。

The only question is how to do "printf" from a stored procedure?

唯一的问题是如何从存储过程中执行“printf”?

回答by a_horse_with_no_name

To "print" a message, you can use raise noticefrom within a PL/pgSQL function:
http://www.postgresql.org/docs/current/static/plpgsql-errors-and-messages.html

要“打印”消息,您可以raise notice在 PL/pgSQL 函数中使用:http:
//www.postgresql.org/docs/current/static/plpgsql-errors-and-messages.html

Note that the client must have set the value of "client_min_messages" to the appropriate level in order to receive the "notice".

请注意,客户端必须将“client_min_messages”的值设置为适当的级别才能接收“通知”。

pgAdmin has a debugger for functions: http://www.pgadmin.org/docs/1.18/debugger.html

pgAdmin 有一个功能调试器:http: //www.pgadmin.org/docs/1.18/debugger.html

(But I have never use it as I don't use pgAdmin).

(但我从未使用过它,因为我不使用 pgAdmin)。

回答by Joel B

It sounds like you're looking for actual debugging capability. PostgreSQL actually introduced this functionality starting with PostgreSQL 8.3.

听起来您正在寻找实际的调试功能。PostgreSQL 实际上从PostgreSQL 8.3开始引入了这个功能。

Debugger

调试器

It's fantastic and totally makes PostgreSQL live up to it's tagline "the world's most advanced open source database". It's kind of a hassle to get running but theselinksmight help get you started. Once enabled it allows you to set breakpoints or define inputs & evaluate functions all through a handy right-click menu in PGAdmin. Right click menu

它太棒了,完全让 PostgreSQL 不辜负它的标语“世界上最先进的开源数据库”。运行起来有点麻烦,但这些链接可能会帮助您入门。启用后,它允许您通过 PGAdmin 中方便的右键单击菜单来设置断点或定义输入和评估函数。 右键菜单

回答by bma

Along with the trusty ol' RAISEcommands, there are also a couple 3rd-party tools that I have heard of, though I've never used them.

除了可靠的 ol'RAISE命令外,还有一些我听说过的第 3 方工具,尽管我从未使用过它们。