因此咱就先從如何用GDB調試PostgreSQL開始談起: 首先,咱們得定義一下,咱們知道Postmaster啓動做爲後端damon進程,等待前端如PSQL的請求,而後Fork()一個Postgres進程來處理該請求,因此咱們在服務器上就有Postmaster和處理該請求的Postgres (一個請求一個該進程)了,那麼咱們該調試哪一個呢?是Postmaster仍是Postgre呢?因此有以下定義(轉載於 http://www-inst.eecs.berkeley.edu/~cs186/fa04/usingddd.pdf ): There are two ways to debug postgres (a) in the interactive mode and (b) in the bare backend mode. The interactive mode is where you start up the postmaster process (with pg ctl), use psql to connect to it, which spawns off a separate postgres process that is dedicated to serving requests from the psql client. This is the mode that the scripts in the Hw1/exec directory use, and the mode you used in Hw0. In the second mode, you don’t create a separate postmaster process and don’t use psql at all. Instead, you start up postgres from the command line and directly interact with it. While the latter is a very user-unfriendly way of using postgres it has the advantage that it is very easy to use a debugger (like ddd) with it. 原文講的很清楚了,爲了再清楚一點,我稍做解釋,調試分紅兩類,一類是 interactive mode 二類是bare backend mode。第一類是先啓動Postmaster,再啓動Postgres,而後調試Postgres。第二類是隻啓動Postgres,直接調試Postgres。 我發現第一類比較符合CDT的狀況,並且上面所引的文章中主要講了第二類,因此第二類咱們就無論了。因此結論是咱們調試第一類的Postgres,而若是你對Postmaster的調試也感興趣,其實更簡單了,拔高一籌理論上講豈不是和第二類同樣了。
2.在Ubuntu中先下載必要的依賴文件,並安裝: 先安裝:libreadline6-dev sudo apt-get install libreadline6-dev 而後安裝zlib tar zxvf zlib-1.2.3.tar.gz cd zlib-1.2.3/ make sudo make install
GNU gdb (GDB) 7.0-ubuntu Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i486-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... progres: No such file or directory. Attaching to process 2184 ptrace: Operation not permitted. /home/postgres/2184: No such file or directory. (gdb)