自己上手debug调试postgresql数据库

来源:互联网 发布:java 网络通讯框架 编辑:程序博客网 时间:2024/05/21 09:48

众所周知,postgresql是世界上功能最为强大的数据库,在世界上有诸多使用者和爱好者,废话不多说,想要成为PG数据库的小砖家,需要对PG代码熟悉,现在开始上手调试吧

  • PG必备网站
    postgresql官方网站 https://www.postgresql.org/
    postgresql中文社区 https://www.postgres.cn

PG Debug模式下编译安装

  • PG官网下载源码包
    postgresql-9.6.1.tar.gz

  • configure/make/make install
    debug模式(–enable-debug),编译器无优化(-O0)
    ./configure –enable-debug –enable-cassert –enable-thread-safety CFLAGS=’-O0 -g’ –prefix=/home/fly_pig/db_install/postgres
    并发编译,并发安装
    make -sj
    make install -sj

  • initdb
    编译安装后,初始化数据库
    initdb -D /home/fly_pig/postgres_data

  • 启动数据库
    pg_ctl start -D /home/fly_pig/postgres_data -l pg_log
    查看进程判断数据库是否正常运行

fly_pig@ubuntu:~/db_install$ ps ux | grep postgresfly_pig  3951  0.0  0.5 157396 10968 pts/7    S    00:02   0:00 /home/fly_pig/db_install/postgres/bin/postgres -D ./postgres_datafly_pig  3953  0.0  0.0 157396   764 ?        Ss   00:02   0:00 postgres: checkpointer process                                       fly_pig  3954  0.0  0.0 157396  1788 ?        Ss   00:02   0:00 postgres: writer process                                             fly_pig  3955  0.0  0.0 157396   764 ?        Ss   00:02   0:00 postgres: wal writer process                                         fly_pig  3956  0.0  0.0 157696  1856 ?        Ss   00:02   0:00 postgres: autovacuum launcher process                                fly_pig  3957  0.0  0.0  14724   988 ?        Ss   00:02   0:00 postgres: stats collector process

开始调试PG代码

psql 连接数据库后,pg会生成1个后台进行,如下图所示:

gdb attach [pid] 在numeric_add函数加断点

psql 端执行 select 1.0 + 1.0; 下面就可以开始调试啦

1 0
原创粉丝点击