How to Debug PostgreSQL
First, compile the source code use ./configure --prefix=XXXX --enable-debug && CFLAGS=-O0
then make and make install.
IF you want to RESTART PG
Detected if there is an instance of Postgre server. If there is, kill it. use1 | ps -e | grep postgre |
to detect the pocess of postgresql and kill it.
then use:
1 | gdb postgresqlHomeDIR/bin/postgres -quiet |
here DATADIR and postgresqlDIR are your own directory.
IF you don't want to RESTART PG
1 | // find postgres pid |
then use
1 | ./psql test |
to test. Here test is your database name.
IF you want to debug contrib
make && make install in contrib/yourdir
then go to gdb to file your shard lib to load symbol. Here XXX.so is your contrib share lib.
1 | (gdb) file XXX.so |
if not, when you use break somefunction, it will report:
No symbol table is loaded. Use the “file” command.
Make breakpoint pending on future shared library load? (y or [n])