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

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay