Last Updated: February 25, 2016
· cstar

Debugging PostgreSQL queries with erlang and ChicagoBoss

Chicago Boss is a web framework in erlang.

It ships with boss_db, a very capable ORM.
Unfortunately, there is no debug output of the SQL generated.

redbug, tool of the eper erlang performance suite will do that for us.

Add :

{eper, ".*", {git, "git://",  "HEAD"}

to your webapp's rebar.config

./rebar get-deps compile

Restart Chicago Boss.

Launch redbug to intercept the messages to PostgreSQL :

(fenwick@Boulette)33> redbug:start({pgsql,equery}).
(fenwick@Boulette)34> scenarios_helper:acl_for(U,S).

17:35:32 <{boss_db_controller,init,1}> {pgsql,equery,
         ["SELECT * FROM ","acls"," WHERE ",
          ["scenario = 1 AND ",
           "fuser = 1 AND "," TRUE"],
          " ORDER BY ","id"," ","ASC",[]],
redbug done, timeout - 1  

It obviously works for any function of any module and many more, check out the man page.