postgreSQL13.8源码安装与GDB调试

1. 源码下载

https://www.postgresql.org/ftp/source/

2. 安装依赖

yum install readline-devel zlib-devel flex bison

3. 编译配置

./configure --prefix=/usr/local/postgres --enable-debug --enable-cassert --enable-depend CFLAGS=-O0
  • –prefix : 指定安装的目录
  • –enable-debug : 把所有程序和库以带有调试符号的方式编译
  • –enable-cassert : 打开服务器中的断言(assertion)检查,它会检查许多”不可能发生”的条件。
  • -enable-depend : 打开自动依赖性跟踪。
  • CFLAGS=-O0 : 关闭优化

3. 编译与安装

make  
make install 

4. 初始化及启动数据库

sudo  adduser bxy     //新建一个用户
sudo chown bxy:bxy -R /usr/local/postgres //将安装好的数据库目录的拥有者这改为新创建的用户
sudo su bxy   //切换用户
/usr/local/postgres/bin/initdb –D /usr/local/postgres/data  //初始化数据库
/usr/local/postgres/bin/pg_ctl -D /usr/local/postgres/data start  //启动数据库
/usr/local/postgres/bin/psql -d postgres               //连接数据库

5. GDB调试

1.查看进程号,在数据库中执行以下语句:

select pg_backend_pid();

2.gdb调试

gdb attach 进程号

进入之后,设置相应的断点进行单步调试。

6. 相关堆栈

select语句堆栈:

(gdb) bt
#0  ExecScan (node=0x2542bf8, accessMtd=0x757930 <SeqNext>, recheckMtd=0x7579d5 <SeqRecheck>)
    at execScan.c:245
#1  0x0000000000757a1f in ExecSeqScan (pstate=0x2542bf8) at nodeSeqscan.c:112
#2  0x000000000071b584 in ExecProcNodeFirst (node=0x2542bf8) at execProcnode.c:450
#3  0x000000000070faec in ExecProcNode (node=0x2542bf8) at ../../../src/include/executor/executor.h:248
#4  0x00000000007125a0 in ExecutePlan (estate=0x25429c0, planstate=0x2542bf8, use_parallel_mode=false, 
    operation=CMD_SELECT, sendTuples=true, numberTuples=0, direction=ForwardScanDirection, dest=0x2528a08, 
    execute_once=true) at execMain.c:1632
#5  0x0000000000710110 in standard_ExecutorRun (queryDesc=0x25799d0, direction=ForwardScanDirection, 
    count=0, execute_once=true) at execMain.c:350
#6  0x000000000070ff38 in ExecutorRun (queryDesc=0x25799d0, direction=ForwardScanDirection, count=0, 
    execute_once=true) at execMain.c:294
#7  0x0000000000938692 in PortalRunSelect (portal=0x24cef20, forward=true, count=0, dest=0x2528a08)
    at pquery.c:921
#8  0x000000000093834b in PortalRun (portal=0x24cef20, count=9223372036854775807, isTopLevel=true, 
    run_once=true, dest=0x2528a08, altdest=0x2528a08, qc=0x7ffe5d339fa0) at pquery.c:765
#9  0x000000000093256e in exec_simple_query (query_string=0x246cf80 "select * from t_insert where id=4;")
    at postgres.c:1238
#10 0x00000000009365a4 in PostgresMain (argc=1, argv=0x2496fe0, dbname=0x2469c58 "postgres", 
    username=0x2496f00 "bxy") at postgres.c:4347
#11 0x000000000088517a in BackendRun (port=0x248eee0) at postmaster.c:4550
#12 0x000000000088496a in BackendStartup (port=0x248eee0) at postmaster.c:4234
#13 0x0000000000880f6e in ServerLoop () at postmaster.c:1739
#14 0x0000000000880845 in PostmasterMain (argc=3, argv=0x2467bc0) at postmaster.c:1412
#15 0x00000000007873c8 in main (argc=3, argv=0x2467bc0) at main.c:210

insert语句堆栈:

(gdb) bt
#0  PageAddItemExtended (page=0x7fc1b6dc2f00 "", item=0x2543b18 "\351\001", size=61, offsetNumber=0, flags=2)
    at bufpage.c:212
#1  0x0000000000501719 in RelationPutHeapTuple (relation=0x7fc1c664b8e0, buffer=363, tuple=0x2543b00, 
    token=false) at hio.c:53
#2  0x00000000004e7a2c in heap_insert (relation=0x7fc1c664b8e0, tup=0x2543b00, cid=0, options=0, bistate=0x0)
    at heapam.c:1920
#3  0x00000000004f894a in heapam_tuple_insert (relation=0x7fc1c664b8e0, slot=0x25439b0, cid=0, options=0, 
    bistate=0x0) at heapam_handler.c:251
#4  0x000000000074f9d8 in table_tuple_insert (rel=0x7fc1c664b8e0, slot=0x25439b0, cid=0, options=0, 
    bistate=0x0) at ../../../src/include/access/tableam.h:1156
#5  0x0000000000750d7f in ExecInsert (mtstate=0x2542d50, slot=0x25439b0, planSlot=0x25439b0, srcSlot=0x0, 
    returningRelInfo=0x2542c38, estate=0x25429c0, canSetTag=true) at nodeModifyTable.c:644
#6  0x0000000000753520 in ExecModifyTable (pstate=0x2542d50) at nodeModifyTable.c:2323
#7  0x000000000071b584 in ExecProcNodeFirst (node=0x2542d50) at execProcnode.c:450
#8  0x000000000070faec in ExecProcNode (node=0x2542d50) at ../../../src/include/executor/executor.h:248
#9  0x00000000007125a0 in ExecutePlan (estate=0x25429c0, planstate=0x2542d50, use_parallel_mode=false, 
    operation=CMD_INSERT, sendTuples=false, numberTuples=0, direction=ForwardScanDirection, dest=0x2529038, 
    execute_once=true) at execMain.c:1632
#10 0x0000000000710110 in standard_ExecutorRun (queryDesc=0x2559cc0, direction=ForwardScanDirection, 
    count=0, execute_once=true) at execMain.c:350
#11 0x000000000070ff38 in ExecutorRun (queryDesc=0x2559cc0, direction=ForwardScanDirection, count=0, 
    execute_once=true) at execMain.c:294
#12 0x000000000093751d in ProcessQuery (plan=0x2528ec8, 
    sourceText=0x246cf80 "insert into t_insert values(4,'Jim','Green','Bob');", params=0x0, queryEnv=0x0, 
    dest=0x2529038, qc=0x7ffe5d339fa0) at pquery.c:160
#13 0x0000000000938def in PortalRunMulti (portal=0x24cef20, isTopLevel=true, setHoldSnapshot=false, 
    dest=0x2529038, altdest=0x2529038, qc=0x7ffe5d339fa0) at pquery.c:1271
#14 0x00000000009383de in PortalRun (portal=0x24cef20, count=9223372036854775807, isTopLevel=true, 
    run_once=true, dest=0x2529038, altdest=0x2529038, qc=0x7ffe5d339fa0) at pquery.c:788
#15 0x000000000093256e in exec_simple_query (
    query_string=0x246cf80 "insert into t_insert values(4,'Jim','Green','Bob');") at postgres.c:1238
#16 0x00000000009365a4 in PostgresMain (argc=1, argv=0x2496fe0, dbname=0x2469c58 "postgres", 
    username=0x2496f00 "bxy") at postgres.c:4347
#17 0x000000000088517a in BackendRun (port=0x248eee0) at postmaster.c:4550
#18 0x000000000088496a in BackendStartup (port=0x248eee0) at postmaster.c:4234
#19 0x0000000000880f6e in ServerLoop () at postmaster.c:1739
#20 0x0000000000880845 in PostmasterMain (argc=3, argv=0x2467bc0) at postmaster.c:1412
#21 0x00000000007873c8 in main (argc=3, argv=0x2467bc0) at main.c:210
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值