place to compile, debug, and mangle postgres
Mangler is built and deployed using Docker
-
Build Mangler
docker build -t postgres_debug . -
Run Mangler
docker run -it --rm postgres_debug bash
-
Create a new postgres database cluster
initdb -D /usr/local/pgsql/data -
Start the database server
pg_ctl -D /usr/local/pgsql/data -l logfile start -
Create a test database
createdb my_test_db -
Connect to the new database
psql my_test_db -
Create a new table
create table author( id serial primary key, name varchar(200) ); -
Create some test data
insert into author (name) values ('Daniel Silva'); insert into author (name) values ('Tom Clancy'); -
Quit the postgres connection
\q -
Go to another terminal tab, exec to the existing container, and start a postgres connection
psql my_test_db -
Get the process id for this connection
select pg_backend_pid(); -
Go back to the original window and start a debugging session and attach this process id (example using process id 100)
gdb attach -p 100 -
Set a breakpoint at the beginning of executing a sql statement
exec_simple_queryShows output:
Breakpoint 1 at 0x6e1db9: file postgres.c, line 885. -
Go back to the second terminal and issue a select statement - it shouldn't return because it should hit the breakpoint
select name from author where id = 1; -
Go back to the original terminal and enjoy debugging!