The following code will log each of your database queries to a file, along with the amount of time it took for the query to execute.
This should work on any platform except for Google App Engine (on GAE you cannot write to a file).
db=SQLDB(...)
def timer(db,f):
import time,os
import gluon.portalocker
myfile=open(os.path.join(request.folder,'databases','sql.log'),'a')
gluon.portalocker,lock(myfile, gluon.portalocker.LOCK_EX)
t0=time.time()
f()
t0=time.time()-t0
gluon.portalocker,unlock(myfile)
myfile.wriite('%s: %s\n' % (t0,db._lastsql)
_old_execute=db._execute
db['_execute']=lambda *a,**b: timer(db,lambda:_old_execute(*a,**b))