1. 搭本地debug环境
git clone git@github.com:postgres/postgres.git
cd postgres && mkdir bin
CFLAGS='-O0 -g3' ./configure --prefix=~/code/postgres/bin
make && make install
2. vscode + remote ssh + c/c++ + C/C++ Extension Pack 或者 clangd + codelldb
让c/c++ intelliSense 更好跳转,找到相关文件,用bear 工具生成compile_commands.json 文件
make clean && bear -- make
修改c_cpp_properties.json 文件,最后一行加上 ,
"compileCommands": "~/code/postgres/compile_commands.json"
gdb 远程debug,添加launch.json,内容如下
"version": "0.2.0","configurations": [{"name": "(gdb) Attach","type": "cppdbg","request": "attach","program": "~/code/postgres/bin/bin/postgres","processId": "${command:pickProcess}","MIMode": "gdb",}]
gdb调试时可能报错ptrace: Operation not permitted. 解决办法echo 0 > /proc/sys/kernel/yama/ptrace_scope
3. 启动postgres
initdb -D ~/code/postgres/data
postgres -D ~/code/postgres/data
createdb postgres
4. 安装 Sakila 示例数据库
git clone git@github.com:jOOQ/sakila.git
psql postgres
create database sakila;
\c sakila;
\i sakila\postgres-sakila-schema.sql
\i sakila\postgres-sakila-insert-data.sql
最后效果:

git clone git@github.com:postgres/postgres.git
cd postgres && mkdir bin
CFLAGS='-O0 -g3' ./configure --prefix=~/code/postgres/bin
make && make install
2. vscode + remote ssh + c/c++ + C/C++ Extension Pack 或者 clangd + codelldb
让c/c++ intelliSense 更好跳转,找到相关文件,用bear 工具生成compile_commands.json 文件
make clean && bear -- make
修改c_cpp_properties.json 文件,最后一行加上 ,
"compileCommands": "~/code/postgres/compile_commands.json"
gdb 远程debug,添加launch.json,内容如下
"version": "0.2.0","configurations": [{"name": "(gdb) Attach","type": "cppdbg","request": "attach","program": "~/code/postgres/bin/bin/postgres","processId": "${command:pickProcess}","MIMode": "gdb",}]
gdb调试时可能报错ptrace: Operation not permitted. 解决办法echo 0 > /proc/sys/kernel/yama/ptrace_scope
3. 启动postgres
initdb -D ~/code/postgres/data
postgres -D ~/code/postgres/data
createdb postgres
4. 安装 Sakila 示例数据库
git clone git@github.com:jOOQ/sakila.git
psql postgres
create database sakila;
\c sakila;
\i sakila\postgres-sakila-schema.sql
\i sakila\postgres-sakila-insert-data.sql
最后效果:
