0
点赞
收藏
分享

微信扫一扫

PostgreSQL查询引擎——编译调试


创建用户:useradd postgresql

postgresql 12.6调试环境:./configure --prefix=/home/postgresql/pg12 --with-pgport=1921 --enable-debug

修改src/Makefile.global,删除-O2,添加-g

260 CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat -sercurity -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g

PostgreSQL查询引擎——编译调试_2d


make && make install

初始化数据库集簇:/home/postgresql/pg12/bin/initdb -D /home/postgresql/pg12data

启动数据库:/home/postgresql/pg12/bin/pg_ctl -D /home/postgresql/pg12data start

连接数据库:/home/postgresql/pg12/bin/psql -U postgresql -h 127.0.0.1 -p 1921 -d postgres

获取后端进程号:psql > select pg_backend_pid();

另开窗口调试进程:gdb postgres 服务进程pid

打印bison语法分析过程:修改gram.c,去掉78行的注释(​​#define YYDEBUG 1​​​),将25201行的​​int yydebug;​​​赋值为1(​​int yydebug = 1;​​​)
打印语法解析后的原始语法树(Raw Syntax Tree, Raw Parse Tree)
src/include/utils/guc.h增加extern bool Debug_print_raw;
src/backend/utils/misc/guc.c增加bool Debug_print_raw = false;
{
{“debug_print_raw”, PGC_USERSET, LOGGING_WHAT, gettext_noop(“Logs each query’s raw tree”), NULL},
&Debug_print_raw,
false,
NULL, NULL, NULL
},
src/backend/tcop/postgres.c if (Debug_print_raw) elog_node_display(LOG, “raw tree”, parsetree, Debug_pretty_print); --> 打印函数放置到pg_analyze_and_rewrite开头
src/backend/utils/misc/postgres.conf.sample增加#debug_print_raw = off

打印parsetree_list:
call elog_node_display(17, “parsetree_list”, parsetree_list, 0)
call elog_node_display(17, “parsetree_list”, parsetree_list, 1)
打印parsetree、querytree、plantree:在postgresql.conf文件中,修改如下配置为on
#debug_print_parse = off --> 打印函数处于postgres.c 773行 pg_rewrite_query函数 if(Debug_print_parse) elog_node_display(LOG, “parse tree”, query, Debug_pretty_print);
#debug_print_rewritten = off --> 打印函数处于postgres.c 848行 pg_rewrite_query函数 if(Debug_print_rewritten) elog_node_display(LOG, “rewritten parse tree”, querytree_list, Debug_pretty_print);
#debug_print_plan = off --> 打印函数处于postgres.c 929行 pg_plan_query函数 if(Debug_print_plan) elog_node_display(LOG, “plan”, plan, Debug_pretty_print)
#debug_pretty_print = on
在gdb调试下,使用(gdb) call elog_node_display(17, “随便”, Node *变量, 0或1) --> 17代表INFO,详见elog.h,比如希望打印在日志例,将17替换成16;0或1取决于debug_pretty_print为on还是off

sed -n ‘beginlinenum,endlinenump’ logfilename > tree.node
图形化工具:https://github.com/shenyuflying/pgNodeGraph
yum install graphviz
copy and paste the node tree in text form.
put it in node dir
run ./pgNodeGraph

在docker中安装gp单节点并进行调试
​​ https://www.imooc.com/article/276654​​ debuginfo-install libstdc+±4.8.5-44.el7.x86_64
​​​ https://stackoverflow.com/questions/65068241/why-debug-files-of-libstc-are-installed-via-glibc-debuginfo-and-gcc-debuginfo​​​

举报

相关推荐

0 条评论