使用 pgAdmin 调试 PostgreSQL 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7865615/
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
Debug PostgreSQL function using pgAdmin
提问by Ken Chan
I refer thisto enable the debugger in the PostgreSQL server in order to debugging the plpgsql function by stepping through the codes using the pgadmin.
我参考这个来启用 PostgreSQL 服务器中的调试器,以便通过使用 pgadmin 单步调试代码来调试 plpgsql 函数。
I have already set shared_preload_libraries = '$libdir/plugins/plugin_debugger.dll'
in the postgresql.conf
, run pldbgapi.sql
, and restarted the server.
我已经shared_preload_libraries = '$libdir/plugins/plugin_debugger.dll'
在postgresql.conf
, run 中设置pldbgapi.sql
并重新启动了服务器。
These steps should have been run successfully and plugin_debugger.dll
should be loaded successfully as can be verified by using the command show shared_preload_libraries
, and I can see the debugging option in the context menu with a right click on a function in pgAdmin.
这些步骤应该已经成功运行并且plugin_debugger.dll
应该成功加载,可以使用命令进行验证show shared_preload_libraries
,我可以在上下文菜单中看到调试选项,右键单击 pgAdmin 中的一个函数。
When choosing "Debugging" --> Debug, a window pops up to allow me to enter the values for the input parameters. But after that, when I press OK
, it does not respond at all.
选择“调试”--> 调试时,会弹出一个窗口,让我输入输入参数的值。但在那之后,当我按下 时OK
,它根本没有反应。
Any ideas or did I miss something in the setup of the debugger on the server??
有什么想法还是我错过了服务器上调试器设置中的某些内容?
I am using PostgreSQL 8.3 and pgAdmin 1.14
我正在使用 PostgreSQL 8.3 和 pgAdmin 1.14
回答by Joel B
You have to enable debugging in two places. On PGAdmin and on the database itself. That article you referenced does a wonderful job explaining it but there were some nuances.
您必须在两个地方启用调试。在 PGAdmin 和数据库本身上。你引用的那篇文章很好地解释了它,但有一些细微差别。
PGAdmin
管理员
When updating your postgresql.conf
file to load the debugging library, I was running PGAdmin on Windowsso the file was here:
更新postgresql.conf
文件以加载调试库时,我在 Windows 上运行 PGAdmin,因此文件位于此处:
C:\Program Files\PostgreSQL.4\data\postgresql.conf
And the path to the plugin_debugger.dll
was actually
而通往 的路径plugin_debugger.dll
实际上是
$libdir/plugin_debugger.dll
not
不是
$libdir/plugins/plugin_debugger.dll
as specified in the article. So your postgresql.conf
would need a line like this
如文章所述。所以你postgresql.conf
需要这样一条线
shared_preload_libraries = '$libdir/plugin_debugger.dll'
Search for the actual .dll if you're in doubt. If you're on Linux the file you'll be looking for is plugin_debugger.so
. Don't forget that changing the postgresql.conf
file will require a restart for the change to take effect.
如果您有疑问,请搜索实际的 .dll。如果您使用的是 Linux,那么您要查找的文件是plugin_debugger.so
. 不要忘记更改postgresql.conf
文件需要重新启动才能使更改生效。
PostgreSQL Database
PostgreSQL 数据库
Assuming you're running your PostgreSQL database on a Linux server this gistdoes an excellent job at explaining how to download the dependencies for enabling debugging. Make sure you're running as root when you install.
假设你在 Linux 服务器上运行你的 PostgreSQL 数据库,这个要点很好地解释了如何下载依赖项以启用调试。确保您在安装时以 root 身份运行。
The part that's easy to miss is issuing the command against the actual database you want to debug. For newer versions on PostgreSQL all you'll need to do is this:
容易错过的部分是针对您要调试的实际数据库发出命令。对于 PostgreSQL 上的较新版本,您需要做的就是:
CREATE EXTENSION IF NOT EXISTS pldbgapi;
If that doesn't return an error, you should be good to go.
如果这没有返回错误,那么您应该很高兴。
Some additional things of note:
一些额外的注意事项:
- As mentioned above, you can only debug when running as a super user account
- From their docsyou can only debug pl/pgsql functions. So if your function says something like
LANGUAGE c
PGAdmin won't even show a right-click Debug menu option when you select the function. Look for something that hasLANGUAGE plpgsql
and the Debug menu should show.
- 如上所述,您只能在以超级用户帐户运行时进行调试
- 从他们的文档中,您只能调试 pl/pgsql 函数。因此,如果您的函数
LANGUAGE c
显示类似PGAdmin 的内容,则在您选择该函数时甚至不会显示右键单击调试菜单选项。寻找有的东西,LANGUAGE plpgsql
调试菜单应该显示。
回答by LR1234567
Ken,
肯,
Have you tried pgAdmin 1.8 to rule out issue with PgAdmin 1.14/ PostgreSQL 8.3 interaction. It's been a while since I've used 8.3 and for the article I wrote -- which you are referring to, I was testing with 1.14/ PostgreSQL 9.1 so it could very well be an issue with the interaction with older version. Unfortunately I don't have a 8.3 anymore to test with.
您是否尝试过 pgAdmin 1.8 来排除 PgAdmin 1.14/PostgreSQL 8.3 交互的问题。自从我使用 8.3 以来已经有一段时间了,对于我写的文章——你指的是,我正在用 1.14/PostgreSQL 9.1 进行测试,所以它很可能是与旧版本交互的问题。不幸的是,我不再有 8.3 可供测试了。
I vaguely remember having the issue you had once, but it was when I had another shared library in my postgresql.conf in addition to the pldebugger. Can't remember which one that was, but removing the other shared library fixed my issue.
我依稀记得你曾经遇到过这个问题,但那是当我的 postgresql.conf 中除了 pldebugger 之外还有另一个共享库时。不记得是哪一个,但删除另一个共享库解决了我的问题。
Hope some of these suggestions help, Regina
希望这些建议中的一些有帮助,里贾纳
回答by foo
I had the same problem. Make sure the onlyshared lib you′re loading in the postgres.conf is the debugger. Nothing else. Not even the profiler. If you get a SSL error when trying to debug a function, reconnect to the server.
我有同样的问题。确保你在 postgres.conf 中加载的唯一共享库是调试器。没有其他的。甚至没有分析器。如果在尝试调试函数时遇到 SSL 错误,请重新连接到服务器。