2

I'd like to know if anybody had success with debugging postgres through an IDE (NetBeans or Eclipse) by attaching the debugger to the process and still perform step debugging (stop at breakpoints and watch variables).

2
  • Er... as in, debug the server implementation or are you just trying to understand a particular query? Commented Jun 10, 2014 at 19:22
  • I need to modify the internals of postgres, so yes, I am looking at the server implemenations Commented Jun 11, 2014 at 15:42

1 Answer 1

4

For most cases, debugging PostgreSQL isn't significantly different to any other server in this regard.

You determine the process ID of the process you wish to examine, then attach the debugger to it and set breakpoints/watchpoints and continue execution. When you hit the break/watch, examine, step, etc as required.

You can SELECT pg_backend_pid() to get the process ID of the current session.

I usually start psql, SELECT pg_backend_pid(), attach gdb, set my breaks/watches, cont, and in my psql session run whatever I expect to trigger my breakpoint/watchpoint. The same principle applies with IDE debuggers (Visual Studio, Eclipse, NetBeans, whatever).

See: the PostgreSQL wiki for some instructions.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. I have used gdb before with postgres. But honestly, I am a fan of how IDEs navigate between files, so I'd rather use gdb from an IDE.
+1 for SELECT pg_backend_pid() , I didn't know that! Very useful when working on a server with multiple Postgres server instantiations
The principle is the same with an IDE - most IDEs support an option to attach to an external process by process ID. You just need to find the pid to attach to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.