How to debug plpgsql with pgAdminIII

[root@localhost 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.

[root@localhost soft_bak]# cd pldebugger/

[root@localhost 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

[root@localhost soft_bak]# cd postgresql-9.4.5/contrib/

[root@localhost contrib]# cp  -R /opt/soft_bak/pldebugger/ ./

[root@localhost contrib]# cd pldebugger/

[root@localhost 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

[root@localhost 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/'

[root@localhost ~]# vim /ext4/pgdefaultgcc530/data/postgresql.conf

shared_preload_libraries = '$libdir/plugin_debugger'

[root@localhost ~]# su - postgres

[postgres@localhost ~]$ cd /ext4/pgdefaultgcc530/bin/

[postgres@localhost bin]$ ./pg_ctl -D /ext4/pgdefaultgcc530/data/ restart

waiting for server to shut down.... done

server stopped

server starting

[postgres@localhost bin]$ LOG:  redirecting log output to logging collector process

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

[postgres@localhost 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

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

  1. debug PostgreSQL 9.6.18 using Eclipse IDE on CentOS7

    目录 debug PostgreSQL 9.6.18 using Eclipse IDE on CentOS7 1.概览 2.建立用户 3.编译postgre 4.启动Eclipse 5.设置环境变量 ...

  2. PostgreSQL function examples

    warehouse_db=# CREATE TABLE warehouse_tbl(warehouse_id INTEGER NOT NULL,warehouse_name TEXT NOT NULL ...

  3. postgresql function 返回 select

    pq函数功能很强大,我打算把统计的功能都放在数据库端.优势让运算离数据更近一些,缺点无法服用代码.牺牲了django的灵魂性,项目必须依赖postgresql. 项目中,希望实现返回select内容 ...

  4. 移植Oracle procedure 到 postgresql

    1.登录postgresql psql -h 192.168.137.131 -p 5432 postgres satusc@6789#JKL 2.创建用户 CREATE USER name thun ...

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

    点击行号的左侧,即可设置断点(或者按下Shift+F9),如果没有出现,反而出现下图的警告: 那么只是因为我的坏习惯--写一段脚本测试的时候都是新建,但不save到本地,不喜欢保存,写的差不多了才开始 ...

  6. WRITING POSTGRESQL TRIGGERS IN GO

    转自:https://www.opsdash.com/blog/postgresql-triggers-golang.html 可以学习如何使用golang 编写pg extension Trigge ...

  7. PostgreSQL 存储过程/函数

    1.有用的链接 postgresql 常用小函数 Postgresql数据库的一些字符串操作函数 PostgreSQL function里面调用function PostgreSQL学习手册(函数和操 ...

  8. postgresql spi开发笔记

    #include "postgres.h" #include "fmgr.h" #include <string.h> #ifdef PG_MODU ...

  9. PHP调试工具PHP DEBUG TOOLS 使用方法

    一.安装篇安装前的准备环境:必须得先装X-Debug,至于怎样安装X-Debug请看http://www.xdebug.org/docs/install 1. 从http://www.xdebug.o ...

随机推荐

  1. Windows Registry

    https://msdn.microsoft.com/en-us/library/windows/desktop/ms724871(v=vs.85).aspx https://msdn.microso ...

  2. by maintaining a log containing a record of each transaction’s activities - The Commit/Rollback Protocol

    Computer Science An Overview _J. Glenn Brookshear _11th Edition Before a transaction is allowed to a ...

  3. Delphi 如何清除动态数组的内存?

    SetLength(glb_IndexConfig,); FreeAndNil(glb_IndexConfig);

  4. Delphi的哈希表(一)

    哈希表是通过哈希值来访问的,通过一定的内存浪费获取检索速度,在检索项时是不需要逐一检索.在编程中有一定的好处. unit Unit1; interface uses Windows, Messages ...

  5. 如何去掉delphi2010的欢迎界面(welcome page)

    如何去掉delphi2010的欢迎界面(welcome page)方法一: 在电脑开始菜单下,找到delphi的快捷菜单,点击该菜单的属性,在“目标”的内容中,最后添加“-np”即可.如:D:\Win ...

  6. 【转】设计模式 ( 十七) 状态模式State(对象行为型)

    设计模式 ( 十七) 状态模式State(对象行为型) 1.概述 在软件开发过程中,应用程序可能会根据不同的情况作出不同的处理.最直接的解决方案是将这些所有可能发生的情况全都考虑到.然后使用if... ...

  7. EBS 资源路径

    /data03/DEV4/comn/java/cmcc/upload cd  $OA_HTML /data03/DEV4/comn/html 日志 $IAS_ORACLE_HOME/Apache/Js ...

  8. hadoop编程模型

    1. 拷贝数据 将一个超大的数据文件拷贝到hadoop集群中,hdfs将其分割成多个数据块,然后再把每一个数据块放到不同的节点里面. 2. map函数 提交一个map函数,此map函数可以被jobch ...

  9. github中国版本coding.net 的部署和使用

    1.在coding.net注册帐号. 2.安装github,自己百度github软件然后安装. 3.打开coding.net 输入帐号后新建项目 创建项目 创建后,创建ssh公钥,如果不创建的话,在每 ...

  10. Redis学习笔记(8)-发布/订阅

    package cn.com; import java.util.List; import redis.clients.jedis.Jedis; public class Redis_PubSub { ...