使用pgAdmin调试PostgreSQL函数 [英] Debug PostgreSQL function using pgAdmin
问题描述
我引用此以启用PostgreSQL服务器中的调试器,以便通过使用pgadmin逐步检查代码来调试plpgsql函数.
I refer this to enable the debugger in the PostgreSQL server in order to debugging the plpgsql function by stepping through the codes using the pgadmin.
我已经在postgresql.conf
中设置了shared_preload_libraries = '$libdir/plugins/plugin_debugger.dll'
,运行pldbgapi.sql
,然后重新启动了服务器.
I have already set shared_preload_libraries = '$libdir/plugins/plugin_debugger.dll'
in the postgresql.conf
, run pldbgapi.sql
, and restarted the server.
这些步骤应该已经成功运行,并且plugin_debugger.dll
应该已经成功加载,可以通过使用命令show shared_preload_libraries
进行验证,并且右键单击pgAdmin中的函数,可以在上下文菜单中看到调试选项. .
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.
选择调试"->调试"时,将弹出一个窗口,允许我输入输入参数的值.但是之后,当我按OK
时,它根本没有响应.
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.
在服务器上调试器的设置中有任何想法或我错过了什么吗?
Any ideas or did I miss something in the setup of the debugger on the server??
我正在使用PostgreSQL 8.3和pgAdmin 1.14
I am using PostgreSQL 8.3 and pgAdmin 1.14
推荐答案
您必须在两个位置启用调试.在PGAdmin和数据库本身上.您引用的那篇文章在解释它方面做得很好,但是有一些细微差别.
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
在更新您的postgresql.conf
文件以加载调试库时,我在Windows上运行PGAdmin ,因此该文件是在这里:
When updating your postgresql.conf
file to load the debugging library, I was running PGAdmin on Windows so the file was here:
C:\Program Files\PostgreSQL\9.4\data\postgresql.conf
plugin_debugger.dll
的路径实际上是
$libdir/plugin_debugger.dll
不是
$libdir/plugins/plugin_debugger.dll
如文章中所指定.因此,您的postgresql.conf
将需要这样的行
as specified in the article. So your postgresql.conf
would need a line like this
shared_preload_libraries = '$libdir/plugin_debugger.dll'
如有疑问,请搜索实际的.dll.如果您使用的是Linux,则要查找的文件是plugin_debugger.so
.不要忘记更改postgresql.conf
文件将需要重新启动才能使更改生效.
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.
PostgreSQL数据库
假设您正在Linux服务器上运行PostgreSQL数据库此要旨做得很好解释如何下载依赖项以启用调试的工作.安装时,请确保您以root用户身份运行.
Assuming you're running your PostgreSQL database on a Linux server this gist does an excellent job at explaining how to download the dependencies for enabling debugging. Make sure you're running as root when you install.
容易错过的部分是针对要调试的实际数据库发出命令.对于PostgreSQL上的较新版本,您需要做的是:
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:
CREATE EXTENSION IF NOT EXISTS pldbgapi;
如果那没有返回错误,那你应该走了.
If that doesn't return an error, you should be good to go.
一些其他注意事项:
- 如上所述,您只能在以超级用户帐户身份运行时进行调试
- 在其文档中,您只能调试pl/pgsql函数.因此,如果您的函数说出
LANGUAGE c
之类的字样,则在选择函数时PGAdmin甚至不会显示右键单击调试"菜单选项.查找具有LANGUAGE plpgsql
的内容,并且应该显示调试"菜单.
- As mentioned above, you can only debug when running as a super user account
- From their docs you 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.
这篇关于使用pgAdmin调试PostgreSQL函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!