通過安裝第三方插件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,選擇某個函數可以看到如下:
出現了調試功能,安裝成功。