这里我们假设你的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导入项目
- 导入是点击Existing Code as Autotools projects,点击next。
- 取消勾选c++选项,填写项目名称等信息,同时选取Linux GCC。
检查编译环境
在项目的根目录有一个configure文件,主要是为了检查程序运行的依赖问题。如果出现依赖缺失问题,则安装相应的库,然后重新执行知道正常结束。
./configure --prefix=安装路径 --enable -depend --enable -cassert --enable -debug
然后依次执行
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