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).
-
Er... as in, debug the server implementation or are you just trying to understand a particular query?SingleNegationElimination– SingleNegationElimination2014-06-10 19:22:59 +00:00Commented Jun 10, 2014 at 19:22
-
I need to modify the internals of postgres, so yes, I am looking at the server implemenationsMFARID– MFARID2014-06-11 15:42:32 +00:00Commented Jun 11, 2014 at 15:42
1 Answer
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.