PostgreSQL Debugging with GDB: A Step-by-Step Guide, Study notes of Relational Database Management Systems (RDBMS)

Learn how to debug postgresql using gdb (gnu debugger). This comprehensive guide covers creating test data, setting up the environment, using gdb commands, and debugging sequence scan and index scan. Recommended for university students and lifelong learners.

Typology: Study notes

2018/2019

Uploaded on 04/24/2019

stevenduan
stevenduan 🇨🇳

1 document

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1.创建测试数据
在进入数据库后:
1.1建表
createtablet1(c1intprimarykey,c2int);
1.2建索引
createindexindex1ont1(c2);
1.3插入测试数据
insertintot1SELECTgenerate_series(1,10000)askey,(random()*(10^3))::integer;
2调试语法树
2.1GDB
2.1.1代码查看行数setnu
2.1.2用到的GDB命令
1.backtrace:显示栈信息。简写为bt。
2.framex切换到第x帧。其中x会在bt命令中显示,从0开始。0表示栈顶。简写为f。
3.printx打印x的信息,x可以是变量,也可以是对象或者数组。简写为p。
4.print*/&x打印x的内容/地址。
5.breakx.cpp:n在x.cpp的第n行设置断点,然后gdb会给出断点编号m。命令可简写
为b
6.continue继续运行程序。进入调试模式后,若你已经获取了你需要的信息或者需要程序
继续运行时使用。可简写为c
7.step单步调试,步入当前函数。可简写为s
8.next单步调试,步过当前函数。可简写为n
9.setvarx=10改变当前变量x的值。也可以这样用:set{int}0x83040=10把内存地
址0x83040的值强制转换为int并赋值为10
10.infolocals打印当前栈帧的本地变量
2.2设置断点
2.3PG执行查询select*fromt1limit3;
2.4调试语法树
pf3
pf4
pf5

Partial preview of the text

Download PostgreSQL Debugging with GDB: A Step-by-Step Guide and more Study notes Relational Database Management Systems (RDBMS) in PDF only on Docsity!

create table t1 (c1 int primary key, c2 int ); 1.2 建索引 create index index1 on t1 (c2); 1.3 插入测试数据 insert into t1 SELECT generate_series(1,10000) as key, (random()*(10^3))::integer;

2 调试语法树 2.1 GDB 2.1.1 代码查看行数 set nu 2.1.2 用到的GDB命令

  1. backtrace:显示栈信息。简写为bt。
  2. frame x 切换到第x帧。其中x会在bt命令中显示,从0开始。0表示栈顶。简写为f。
  3. print x打印x的信息,x可以是变量,也可以是对象或者数组。简写为p。
  4. print */&x 打印x的内容/地址。
  5. break x.cpp:n 在x.cpp的第n行设置断点,然后gdb会给出断点编号m。命令可简写 为b
  6. continue 继续运行程序。进入调试模式后,若你已经获取了你需要的信息或者需要程序 继续运行时使用。可简写为c
  7. step 单步调试,步入当前函数。可简写为s
  8. next 单步调试,步过当前函数。可简写为n
  9. set var x=10 改变当前变量x的值。也可以这样用:set {int}0x83040 = 10把内存地 址0x83040的值强制转换为int并赋值为
  10. info locals 打印当前栈帧的本地变量 2.2 设置断点

2.3 PG 执行查询 select * from t1 limit 3; 2.4 调试 语法树

其中 SelectStmt

FromClause

2.5 Query Tree 查询树调试

  1. GDB 调试 Sequence Scan 2.1 查看执行计划

打断点 :b SeqNext 执行SQL :select * from t1 limit 3;