Allow tracing for database activity.

This commit adds the ability to trace database activity on a per thread
basis. 

Signed-off-by: Gunnar Wagenknecht <gunnar@ageto.net>