教你如何在eclipse中調試postgreSQL

這裏我們假設你的eclipse以及基本的java c/c++環境都已經配置完成

下載pg的git

mkdir project
cd project
git clone
git clone git://git.postgresql.org/git/postgresql.git

這個可能很慢,給你兩個建議:

  • 加上參數–depth=1 可以只拉取最新的分支。
  • 將git複製到碼雲一份,從碼雲上進行clone。

通過eclipse import導入項目

  1. 導入是點擊Existing Code as Autotools projects,點擊next。
  2. 取消勾選c++選項,填寫項目名稱等信息,同時選取Linux GCC。
    在這裏插入圖片描述
    在這裏插入圖片描述

檢查編譯環境

在項目的根目錄有一個configure文件,主要是爲了檢查程序運行的依賴問題。如果出現依賴缺失問題,則安裝相應的庫,然後重新執行知道正常結束。

./configure

然後依次執行

make
make all
make install

最終安裝成功時會顯示:

PostgreSQL installation complete.

如果期間任何一個環節報錯,請fix後從configure開始執行。如果安裝成功後,那麼整個程序將會安裝在以下路徑

/usr/local/pgsql/

接着配置環境變量。

#export pg path
export PATH=/usr/local/pgsql/bin/:$PATH
export PGDATA=$請輸入你的文件夾路徑$
#export pg path

編輯保存後,別忘了source!!!
接着我們輸入:

initdb

The files belonging to this database system will be owned by user "***".
This user must also own the server process.

The database cluster will be initialized with locale "zh_CN.UTF-8".
The default database encoding has accordingly been set to "UTF8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".

Data page checksums are disabled.

fixing permissions on existing directory /home/andyshen/project/temp ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
    pg_ctl -D /home/andyshen/project/temp -l logfile start

配置eclipse的debug config

當我們通過cmd連接server時,實際上會起一個新的線程。所有的客戶端連接都是由主進程來維護的,因此如果需要調試,我們需要調試的是客戶端與服務端的連接進程。因此,我們可以先起一個客戶端連接到server

psql test

獲取該進程的pid

- SELECT pg_backend_pid() 
- pg_backend_pid
- 20881

然後,雙擊c/c++ Attach Application 將會出現一個psql_Default,將代碼路徑/src/backend/postgres填寫到c/c++ Application 這個空白匡。
在這裏插入圖片描述
然後我們點擊運行debug
在這裏插入圖片描述
這是點擊ok,我們就可以進行調試了,你可以在客戶端連接發出sql查詢,在eclipse就可以進行調試了。

注:如果發現無法綁定客戶端連接,這個是權限問題,可以輸入以下命令解決

echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章