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).
从以上可以看到,只需make&make install,然后进行配置等。按以上要求具体安装如下:
[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 = '$libdir/plugin_debugger'时,如果该参数有多个,只需加逗号即可,如
shared_preload_libraries = 'xxxxxx,$libdir/plugin_debugger'
* shared_preload_libraries 的路径实际便是postgres的安装路径,在make install完毕后会提示,比如上面的make install安装提示:/usr/bin/install -c -m 755 plugin_debugger.so '/usr/local/pgsql9.5.0/lib/plugin_debugger.so' 后面的路径即为 shared_preload_libraries,所有将 shared_preload_libraries =‘/usr/local/...‘也是可以的。
重启数据库,到需要进行函数调试数据库中执行CREATE EXTENSION pldbgapi;
注意:每次换一个库时,都要重新执行。
经过以上过程,打开pgadmin,选择某个函数可以看到如下:
出现了调试功能,安装成功。