DEV Community

Mohamed Mokhtar
Mohamed Mokhtar

Posted on • Edited on

3 1 1 1 1

[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

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs