LoginSignup
8
7

More than 5 years have passed since last update.

PostgreSQLのPL/pgSQLのデバッガpldebuggerを使ってみる

Last updated at Posted at 2015-09-11

PostgreSQLのPL/pgSQLのデバッガpldebuggerを使ってみる

pldebuggerを使うとpgAdmin III上でPL/pgSQLのストアドプロシージャのデバッグができます。

インストール

CentOS6+SCL+PostgreSQL 9.2向けのansible play bookはこちらになります。

ざっくりこんな手順になってます。(rootで作業するものとします。)

1. PostgreSQLのヘッダファイル類をインストールします

yum install postgresql92-postgresql-devel

2. gitからcloneしてきます

git clone git://git.postgresql.org/git/pldebugger.git

3. Makefileを修正します

cd pldebugger
sed -i.bak -e "s/\$(top_builddir)\/src\/pl\/plpgsql\/src/\/opt\/rh\/postgresql92\/root\/usr\/include\/pgsql\/server/g" /root/pldebugger/Makefile
※ postgresql-develまたはPostgreSQLのヘッダファイル類が以下にあることを仮定しています
    /opt/rh/postgresql92/root/usr/include/pgsql/server

4. コンパイル&インストールします

env USE_PGXS=1 make
env USE_PGXS=1 make install

5. postgresql.confを変更します

sed -i.bak -e "s/#shared_preload_libraries = ''/shared_preload_libraries = '\/opt\/rh\/postgresql92\/root\/usr\/lib64\/pgsql\/plugin_debugger.so'/" /opt/rh/postgresql92/root/var/lib/pgsql/data/postgresql.conf

6. PostgreSQLをリスタートします

service postgresql92-postgresql restart

pgAdmin III上での初期設定

  1. DBに接続します
  2. 「Extensions」→「New Extension...」
  3. 「名前」で「pldbgapi」を選択して「OK」
  4. pgAdmin IIIを一度終了して再度起動してください

pgAdmin III上でのデバッガの利用

  1. DBに接続します
  2. 「関数」からデバッグしたい関数を選択して右クリックメニューの「デバッグ」→「ブレークポイントの設定」
    • デバッガのウィンドウが開いてストアドプロシージャの先頭にブレークポイントが設定された状態になります
  3. SQLクエリーからストアドプロシージャを実行
    • デバッガのウィンドウでブレークされた状態になります

注意点

  • デバッガはやや不安定でpgAdmin IIIごと強制終了することがあります
  • そのため、SQLクエリーで実行するSQL文はきちんとテキストファイルで保存しておくことをおすすめします
8
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
7