GDB Debugging session PostgreSQL & AGE

Mohamed MokhtarMohamed Mokhtar
2 min read

Prerequisite

  • Having a running instance of Postgresql server and (having it surely installed beside AGE and debug flag is enabled)

The following commands are used for loading AGE

CREATE EXTENSION age;
LOAD ‘age’;
SET search_path = ag_catalog, "$user", public;

STEPS

  • Open a psql session on a terminal
# create a test db if not having one
/usr/local/pgsql/bin/createdb test
# open psql
/usr/local/pgsql/bin/psql test
  • Open a new tab for having gdb there
sudo gdb
  • Get the backend process's pid
SELECT pg_backend_pid();
  • assume output is 666

  • Attach gdb to that process id

(gdb) attach 666
  • Create break line at some where
(gdb) break src/backend/tcop/postgres.c:4483
  • Execute a query at the backend session
select * from t where id > 1 and id < 10;
  • Trace at the GDB (press n)

Quick guide to GDB

  • To attach to a process: sudo gdb -p

  • Attach breakpoint: break :

  • Run until breakpoint: c

  • Single step into the function: s

  • Step over the function: n

  • Print a value: p or p *

  • Call a function: call

  • Print postgres node: call pprint()

  • Pressing enter key repeats last command.

  • Include directory (source code): dir

References & Resources

0
Subscribe to my newsletter

Read articles from Mohamed Mokhtar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mohamed Mokhtar
Mohamed Mokhtar

Computer Engineering graduate got my bachelors degree from Cairo University, Faculty of Engineering. I am an enthusiastic person to self-development and long-life learning (fast learner), I have the ability to adapt to new environments and technologies. As well as tackling large scale challenging projects and problems is a great passion of mine. I am a team player, able to work in a team and also lead a team. And a person who is always looking for new challenges and opportunities to learn and grow professionally.