Logging all/slow queries

234 views
Skip to first unread message

David

unread,
Jul 19, 2011, 1:16:53 PM7/19/11
to Django developers
I think it would be useful to be able to log all queries and/or some
"slow" subset of queries in production (DEBUG=False). I understand
clearly the reasoning why queries are currently only logged in debug
mode, but not all problems crop up in debug mode. This does duplicate
some functionality of RDBMSs but aggregating queries across multiple
databases is really convenient rather than having to go to each
database's logs.

More concrete proposal:
- logging queries is disabled by default in production
- add an option to log all queries (CursorTimingWrapper?)
- add an option to log "slow" queries with a warning
- neither of these will populate BaseDatabaseWrapper.queries

Javier Guerra Giraldez

unread,
Jul 19, 2011, 1:38:30 PM7/19/11
to django-d...@googlegroups.com
On Tue, Jul 19, 2011 at 12:16 PM, David <djfi...@gmail.com> wrote:
> This does duplicate
> some functionality of RDBMSs but aggregating queries across multiple
> databases is really convenient rather than having to go to each
> database's logs.

i'd also like something like that to have better context. for
example, there are some views that have to finish quickly, and others
that could take longer. the database logs don't discriminate between
those, so it's not easy to see which queries are more important to
optimize.

and of course, it's not always easy to know which ORM produced which
SQL. knowing which Python code produced each SQL means a lot less
guesswork.

--
Javier

Alex Gaynor

unread,
Jul 19, 2011, 1:44:10 PM7/19/11
to django-d...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To post to this group, send email to django-d...@googlegroups.com.
To unsubscribe from this group, send email to django-develop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.


I'm fairly -1 on anything like this.  Performance logging is an incredibly complex task, there are entire companies built around doing it (/waves to our friends at New Relic), anything we try to ship in Django itself will a) be wrong for many users, and b) woefully inadequate for many more.

Alex

--
"I disapprove of what you say, but I will defend to the death your right to say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
"The people's good is the highest law." -- Cicero

Justin Holmes

unread,
Jul 19, 2011, 1:53:30 PM7/19/11
to django-d...@googlegroups.com
Sometimes I feel like the tool I really need is a "stupid query log."

There are times when the ORM produces SQL that is not what I expect,
and I often don't realize this until I go and look at the slow query
log, which is usually after the project is already in some stage of
production or at least staging.

Thus, I do think there is some room for a simple performance tool to
help with this situation, although Alex's point that performance
logging is an industry unto itself it sound. Is there a well-defined
bite that can be chewed?

--
Justin Holmes

Head Instructor, SlashRoot Collective
SlashRoot: Coffee House and Tech Dojo
60 Main Street
New Paltz, NY 12561
845.633.8330

Reply all
Reply to author
Forward
0 new messages