Last Updated: February 25, 2016
·
700
· chrisv2

Get Django SQL Queries on production server

Normally, django does not store queries when settings.DEBUG is turned off. However, since settings is just a python module, you can turn it on in the shell:

$ ./manage.py shell
>>> from django.conf import settings
>>> settings.debug=True
>>> from django.db import connection
>>> # ... 
>>> # exec function of interest here
>>> connection.queries
[{u'time': u'0.000', u'sql': u'SELECT ` ...