How to debug PostgreSQL function with pgAdminIII

How to debug plpgsql with pgAdminIII

[[email protected] soft_bak]# git clone git://git.postgresql.org/git/pldebugger.git

Initialized empty Git repository in /opt/soft_bak/pldebugger/.git/

remote: Counting objects: 445, done.

remote: Compressing objects: 100% (341/341), done.

remote: Total 445 (delta 285), reused 171 (delta 104)

Receiving objects: 100% (445/445), 170.50 KiB | 54 KiB/s, done.

Resolving deltas: 100% (285/285), done.

[[email protected] soft_bak]# cd pldebugger/

[[email protected] pldebugger]# ls

dbgcomm.c   Makefile           pldbgapi.control               pldebugger.proj     plugin_debugger.def  uninstall_pldbgapi.sql

dbgcomm.h   pldbgapi--1.0.sql  pldbgapi--unpackaged--1.0.sql  plpgsql_debugger.c  README.pldebugger

globalbp.h  pldbgapi.c         pldebugger.h                   plugin_debugger.c   settings.projinc

[[email protected] soft_bak]# cd postgresql-9.4.5/contrib/

[[email protected] contrib]# cp  -R /opt/soft_bak/pldebugger/ ./

[[email protected] contrib]# cd pldebugger/

[[email protected] pldebugger]# make

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -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 -fexcess-precision=standard -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 -fexcess-precision=standard -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 -fexcess-precision=standard -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 -fexcess-precision=standard -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,‘/ext4/pgdefaultgcc530/lib‘,--enable-new-dtags

[[email protected] pldebugger]# make install

/bin/mkdir -p ‘/ext4/pgdefaultgcc530/lib/postgresql‘

/bin/mkdir -p ‘/ext4/pgdefaultgcc530/share/postgresql/extension‘

/bin/mkdir -p ‘/ext4/pgdefaultgcc530/share/postgresql/extension‘

/bin/mkdir -p ‘/ext4/pgdefaultgcc530/share/doc//postgresql/extension‘

/usr/bin/install -c -m 755  plugin_debugger.so ‘/ext4/pgdefaultgcc530/lib/postgresql/plugin_debugger.so‘

/usr/bin/install -c -m 644 pldbgapi.control ‘/ext4/pgdefaultgcc530/share/postgresql/extension/‘

/usr/bin/install -c -m 644 pldbgapi--1.0.sql pldbgapi--unpackaged--1.0.sql ‘/ext4/pgdefaultgcc530/share/postgresql/extension/‘

/usr/bin/install -c -m 644 README.pldebugger ‘/ext4/pgdefaultgcc530/share/doc//postgresql/extension/‘

[[email protected] ~]# vim /ext4/pgdefaultgcc530/data/postgresql.conf

shared_preload_libraries = ‘$libdir/plugin_debugger‘

[[email protected] ~]# su - postgres

[[email protected] ~]$ cd /ext4/pgdefaultgcc530/bin/

[[email protected] bin]$ ./pg_ctl -D /ext4/pgdefaultgcc530/data/ restart

waiting for server to shut down.... done

server stopped

server starting

[[email protected] bin]$ LOG:  redirecting log output to logging collector process

HINT:  Future log output will appear in directory "pg_log".

[[email protected] bin]$ ./psql -h localhost -U postgres

psql (9.4.5)

Type "help" for help.

postgres=# CREATE EXTENSION pldbgapi;

CREATE EXTENSION

postgres=# CREATE TABLE accounts(owner text, balance numeric, amount numeric);

CREATE TABLE

postgres=# INSERT INTO accounts VALUES (‘Bob‘,100);

INSERT 0 1

postgres=# INSERT INTO accounts VALUES (‘Mary‘,200);

INSERT 0 1

postgres=# select * from accounts ;

owner | balance | amount

-------+---------+--------

Bob   |     100 |

Mary  |     200 |

(2 rows)

postgres=# CREATE OR REPLACE FUNCTION transfer(

postgres(# i_payer text,

postgres(# i_recipient text,

postgres(# i_amount numeric(15,2))

postgres-# RETURNS text

postgres-# AS

postgres-# $$

postgres$# DECLARE

postgres$# payer_bal numeric;

postgres$# BEGIN

postgres$# SELECT balance INTO payer_bal

postgres$# FROM accounts

postgres$# WHERE owner = i_payer FOR UPDATE;

postgres$# IF NOT FOUND THEN

postgres$# RETURN ‘Payer account not found‘;

postgres$# END IF;

postgres$# IF payer_bal < i_amount THEN

postgres$# RETURN ‘Not enough funds‘;

postgres$# END IF;

postgres$# UPDATE accounts

postgres$# SET balance = balance + i_amount

postgres$# WHERE owner = i_recipient;

postgres$# IF NOT FOUND THEN

postgres$# RETURN ‘Recipient does not exist‘;

postgres$# END IF;

postgres$# UPDATE accounts

postgres$# SET balance = balance - i_amount

postgres$# WHERE owner = i_payer;

postgres$# RETURN ‘OK‘;

postgres$# END;

postgres$# $$ LANGUAGE plpgsql;

CREATE FUNCTION

postgres=# \df

List of functions

Schema |            Name             | Result data type |                       Argument data types                        |  Type

--------+-----------------------------+------------------+------------------------------------------------------------------+--------

public | pldbg_abort_target          | SETOF boolean    | session integer                                                  | normal

public | pldbg_attach_to_port        | integer          | portnumber integer                                               | normal

public | pldbg_continue              | breakpoint       | session integer                                                  | normal

public | pldbg_create_listener       | integer          |                                                                  | normal

public | pldbg_deposit_value         | boolean          | session integer, varname text, linenumber integer, value text    | normal

public | pldbg_drop_breakpoint       | boolean          | session integer, func oid, linenumber integer                    | normal

public | pldbg_get_breakpoints       | SETOF breakpoint | session integer                                                  | normal

public | pldbg_get_proxy_info        | proxyinfo        |                                                                  | normal

public | pldbg_get_source            | text             | session integer, func oid                                        | normal

public | pldbg_get_stack             | SETOF frame      | session integer                                                  | normal

public | pldbg_get_target_info       | targetinfo       | signature text, targettype "char"                                | normal

public | pldbg_get_variables         | SETOF var        | session integer                                                  | normal

public | pldbg_oid_debug             | integer          | functionoid oid                                                  | normal

public | pldbg_select_frame          | breakpoint       | session integer, frame integer                                   | normal

public | pldbg_set_breakpoint        | boolean          | session integer, func oid, linenumber integer                    | normal

public | pldbg_set_global_breakpoint | boolean          | session integer, func oid, linenumber integer, targetpid integer | normal

public | pldbg_step_into             | breakpoint       | session integer                                                  | normal

public | pldbg_step_over             | breakpoint       | session integer                                                  | normal

public | pldbg_wait_for_breakpoint   | breakpoint       | session integer                                                  | normal

public | pldbg_wait_for_target       | integer          | session integer                                                  | normal

public | plpgsql_oid_debug           | integer          | functionoid oid                                                  | normal

public | transfer                    | text             | i_payer text, i_recipient text, i_amount numeric                 | normal

(22 rows)

Connect to PostgreSQL Server with pgAdminIII

Find to postgreSQL function to be debuged transfer

Right click the transfer function and Input the parameter to be test

时间: 2024-12-27 20:37:00

How to debug PostgreSQL function with pgAdminIII的相关文章

The log use to debug the function of ChangeTemplate

2016-03-24 16:12:53,172 INFO [org.ovirt.engine.core.bll.aaa.LoginUserCommand] (http--0.0.0.0-8080-2) Running command: LoginUserCommand internal: false. 2016-03-24 16:12:53,180 INFO [org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector

用Eclipse追PostgreSQL源码

1.安装编译好的PostgreSQL(见Eclipse编译PostgreSQL 9.2.2). 2.在Eclipse上打开Make Target 视图(Window->Show View->Other->Make->Make Target).右键本工程,选择New,创建一个名字install. 3.安装: 1)双击install. 2)等待一小会儿,在控制台窗口显示PostgreSQL installation complete就安装成功了.显示如下: 3)安装的默认路径是在Ecl

FB AS3 中,使用条件编译,实现debug、release的代码分离编译。

问题的产生: 在项目中看到有关这样的代码,不理解,就查找了相关的资料. 在这里看懂CONFIG::release与CONFIG::dubug的用法,所以不理解. 查到网上,找到一个例子来介络,就拿来凑合用着,还是易懂的. 1. FB AS3 中,使用条件编译,效果类似:VS的#if DEBUG与#if RELEASE,相比之下,FB中的宏定义更灵活 这是一个有关的例子,具体可以参考这里:http://blog.csdn.net/linjf520/article/details/7728403.由

PostgreSQL 存储过程/函数

1.有用的链接 postgresql 常用小函数 Postgresql数据库的一些字符串操作函数 PostgreSQL function里面调用function PostgreSQL学习手册(函数和操作符<二>) PostgreSQL的存储过程简单入门 2.建立块环境(执行环境) do language plpgsql $$ declare begin ... .. . end $$; 如 do language plpgsql $$ declare today date :=now(); y

AngularJS1.X学习笔记11-服务

如果我没记错的话,spring里边有个service层.什么是服务呢?个人理解就是很多地方要用的,可以跨越控制器甚至是跨越模块的工具.AngularJS也为我们提供了服务这种机制,这让我们可以将一些不属于某个控制器独有的东西定义成一个服务,要用的时候直接拿过来就好.使用服务有什么好处呢?一是便于统一修改,二是调用者不用关心内部实现,三是便于测试. 一.factory <!DOCTYPE html> <html lang="en" ng-app='myApp'>

使用RStudio调试基础学习(一)

本文知识点: 使用Rstudio调试的基础知识 点击行号的左侧,即可设置断点(或者按下Shift+F9),如果没有出现,反而出现下图的警告: 那么只是因为我的坏习惯——写一段脚本测试的时候都是新建,但不save到本地,不喜欢保存,写的差不多了才开始取名字保存.... 写一个for循环测试下: test <-0 for(i in1:9){ j <- i+2 test[i+1]<- test[i]+3 k <- i } 将environment窗口下,选择grid(如果选来是list的

PHP 和 JS 导入导出csv表格(上)

CSV简介 在开发后台管理系统的时候,几乎无可避免的会遇到需要导入导出Excel表格的需求.csv也是表格的一种,其中文名为"逗号分隔符文件".在Excel中打开如下图左边所示,在记事本打开如下图右边所示: 再看包含特殊字符的表格 与xls或xlsx 表格相类似,CSV文件也是用来表示二维表格.而不同的是: 1.CSV是一种纯文本文件,任何编辑器都能打开并读取它:xls(x)是专用的二进制文件,要用表格软件才能正常打开,否则乱码: 2.CSV的体积很小,比如上面的表格内容,csv只有几

8个必备的PHP功能开发

这篇文章主要介绍了8个必备的PHP功能开发,需要的朋友可以参考下 PHP开发的程序员应该清楚,PHP中有很多内置的功能,掌握了它们,可以帮助你在做PHP开发时更加得心应手,本文将分享8个开发必备的PHP功能,个个都非常实用,希望各位PHP开发者能够掌握. 1.传递任意数量的函数参数  我们在.NET或者JAVA编程中,一般函数参数个数都是固定的,但是PHP允许你使用任意个数的参数.下面这个示例向你展示了PHP函数的默认参数: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14

SWFUpload批量上传插件

SWFUpload是一个批量上传插件,在HTML4.1里面,估计也只有Flash+javascript配合才能够做到了.先复制个重要的网址,这个应该是官方的文档了,相当齐全. http://leeon.me/upload/other/swfupload.html#uploadStart 这个是格式比较好看的. http://www.cnblogs.com/2050/archive/2012/08/29/2662932.html 算了,这个文档的内容太多,各种属性各种方法,记不了这么多,直接贴上个