DEV Community

Mohamed Mokhtar
Mohamed Mokhtar

Posted on • Updated on

[GDB] Debugging session PostgreSQL & AGE

Prerequisite

  • Having a running instance of Postgresql server and (having it surely installed beside of 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;
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
  • Open a new tab for having gdb there
sudo gdb
Enter fullscreen mode Exit fullscreen mode
  • Get the backend process's pid
SELECT pg_backend_pid();
Enter fullscreen mode Exit fullscreen mode
  • assume output is 666
  • Attach gdb to that process id
(gdb) attach 666
Enter fullscreen mode Exit fullscreen mode
  • Create break line at some where
(gdb) break src/backend/tcop/postgres.c:4483
Enter fullscreen mode Exit fullscreen mode
  • Execute a query at the backend session
select * from t where id > 1 and id < 10;
Enter fullscreen mode Exit fullscreen mode
  • 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

Top comments (0)