通过安装第三方插件pldebugger,可实现在pgadmin客户端对函数设置断点、调试,具体过程如下:
1.下载pldebugger安装包:
http://git.postgresql.org/gitweb/ 所有第三方插件都可在此下载,此处下载pldebugger.git
2.拷贝安装
将下载好的压缩包(pldebugger-14c6caf.tar.gz)拷贝到postgresql安装目录contrib,
解压:
tar zxvf pldebugger-14c6caf.tar.gz
查看reademe文件,看安装要求:
Installation
------------
- Copy this directory to contrib/ in your PostgreSQL source tree.
- Run 'make; make install'
- Edit your postgresql.conf file, and modify the shared_preload_libraries config
option to look like:
shared_preload_libraries = '$libdir/plugin_debugger'
- Restart PostgreSQL for the new setting to take effect.
- Run the following command in the database or databases that you wish to
debug functions in:
CREATE EXTENSION pldbgapi;
(on server versions older than 9.1, you must instead run the pldbgapi--1.0.sql
script directly using psql).
按以上要求进行安装。
[root@localhost pldebugger-14c6caf]# make
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -fpic -I../../src/pl/plpgsql/src -I. -I. -I../../src/include -D_GNU_SOURCE -c -o plpgsql_debugger.o plpgsql_debugger.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -fpic -I. -I. -I../../src/include -D_GNU_SOURCE -c -o plugin_debugger.o plugin_debugger.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -fpic -I. -I. -I../../src/include -D_GNU_SOURCE -c -o dbgcomm.o dbgcomm.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -fpic -I. -I. -I../../src/include -D_GNU_SOURCE -c -o pldbgapi.o pldbgapi.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -fpic -shared -o plugin_debugger.so plpgsql_debugger.o plugin_debugger.o dbgcomm.o pldbgapi.o -L../../src/port -L../../src/common -Wl,--as-needed -Wl,-rpath,'/usr/local/pgsql9.5.0/lib',--enable-new-dtags
[root@localhost pldebugger-14c6caf]# make install
/bin/mkdir -p '/usr/local/pgsql9.5.0/lib'
/bin/mkdir -p '/usr/local/pgsql9.5.0/share/extension'
/bin/mkdir -p '/usr/local/pgsql9.5.0/share/extension'
/bin/mkdir -p '/usr/local/pgsql9.5.0/share/doc//extension'
/usr/bin/install -c -m 755 plugin_debugger.so '/usr/local/pgsql9.5.0/lib/plugin_debugger.so'
/usr/bin/install -c -m 644 ./pldbgapi.control '/usr/local/pgsql9.5.0/share/extension/'
/usr/bin/install -c -m 644 ./pldbgapi--1.0.sql ./pldbgapi--unpackaged--1.0.sql '/usr/local/pgsql9.5.0/share/extension/'
/usr/bin/install -c -m 644 ./README.pldebugger '/usr/local/pgsql9.5.0/share/doc//extension/'
可以看到,改插件被安装在postgresql目录的Lib文件中,查看lib目录可以看到:
-bash-4.1$ ll |grep debug
-rwxr-xr-x. 1 root root 62025 Mar 10 09:09 plugin_debugger.so
*此处注意在配置参数shared_preload_libraries = '$libdir/plugin_debugger'时,如果该参数有多个,只需加逗号即可,如
shared_preload_libraries = 'xxxxxx,$libdir/plugin_debugger'
安装
3.重启数据库,到需要进行函数调试数据库中执行CREATE EXTENSION pldbgapi;
注意:每次换一个库时,都要重新执行
经过以上过程,打开pgadmin,选择某个函数可以看到如下:
出现了调试功能,安装成功。