如何在Linux下調試PostgreSQL

來源:互聯網
上載者:User

由於工作關係,需要調試postgreSQL源碼,恰好同事寫了這樣一個文檔,貼出來共用。

在Linux下面調試Postgres,需要進行如下幾個步驟:
1. 安裝Linux作業系統
注意把gdb、Emacs或DDD這些開發工具都安裝上。如果是在虛擬機器上安裝,依然需要設定Linux系統的網路環境;另外需要設定檔案分享權限設定,方便windows下面的postgreSQL源碼能在Linux下面訪問到。

2. 安裝PostgreSQL
useradd postgre

(自動建立 postgre 組;設計人員為了安全考慮,PostgreSQL 不能以root 使用者運行,所以必須建立對應的使用者和組。)
解壓到 /usr/local/src
tar xvfz postgresql-8.4.tar.gz
cd postgresql-8.4
./configure --prefix=/usr/local/pgsql --enable-debug --enable-assert --without-readline --without-zlib
make
make install
chown  -R  postgre.postgre  /usr/local/pgsql


3. 設定Postgres環境變數(非必須)
vi ~postgre/.bash_profile
添加:
PGLIB=/usr/local/pgsql/lib
PGDATA=$HOME/data
PATH=$PATH:/usr/local/pgsql/bin
MANPATH=$MANPATH:/usr/local/pgsql/man
export PGLIB PGDATA PATH MANPATH

4. 建立資料庫
以 postgres 使用者登入:
su  postgre
建立資料庫目錄:
mkdir data
啟動資料庫引擎:
initdb –D “資料庫目錄”
之後可以根據提示,通過psql進入資料庫

5. 構造PostgreSQL調試環境
先 psql template1進去,然後
select pg_backend_pid();
獲得id,就是gdb後面用到的數字
gdb /usr/local/pgsql/bin/postgres 997(pid的數字)
如果只使用gdb,全部是命令列介面;而Emac、DDD分別是彩色、黑白使用者互動式圖形介面。

6. 使用gdb進行調試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.