Search code examples
shelldb2stracedb2-luw

using strace to debug db2 CLI executing a query


I would like to use strace to debug a strange behaviour I have with db2. I have a SQL function myFoo() implemented in C that doesn't get called for some reason (some code access path not existing or not authorized see here). My Sql Function call a function Fooin shared library in /usr/local/lib/libmyfoo (so in db2 term /usr/local/lib/libmyfoo!Foo).

If I use strace directly with db2 and the query I have an error saying

   A database connection does not exist

so i created a script call debug.sh with the following. The idea is to have a shell with the db2 connection active and trace it.

db2 "connect to MYDB"
db2 "select * from table(myFoo())" # this calls /usr/local/lib/libmyfoo!Foo
db2 "disconnect MYDB"

It doesn't work cos I realized that strace works with binary so I have the error

Exec Format Error

Solution

  • Probably you are calling each DB2 command in different subshells. You can fix that problem by executing everything in just one subshell, for example

    VALUE=$(. /home/db2inst1/sqllib/db2profile ; db2 connect to MYDB ; db2 "select * from table(myFoo())")