Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the total number of SQL queries made by a django application?

Tags:

django

Is there a way to find out how many SQL queries made by django app. when I try to load a page? What I like to do as I browse from page to page.. is to record the following in a text file... or see it in stdout.

  1. page url
  2. total queries
  3. total query execution time

is there such tool/script?

Cheers

like image 325
wailer Avatar asked Dec 02 '09 03:12

wailer


People also ask

What is q in django?

Q object encapsulates a SQL expression in a Python object that can be used in database-related operations. Using Q objects we can make complex queries with less and simple code. For example, this Q object filters whether the question starts wiht 'what': from django. db.

How can I see SQL query generated by Django?

Documentation and source is available at http://django-debug-toolbar.readthedocs.io/. debug_toolbar is especially useful when you have a query that's failing with a SQL syntax error; it will display the last query that attempted to run (and failed), making it easier to debug.


1 Answers

Use debug_toolbar app, it prints not only number of queries, but each one of them and how long they took to run + a lot more useful info.

One thing to remember - this app makes django use quite a bit more memory, so it's best used only in the test environment.

Here is a related question with good answers.

like image 147
Evgeny Avatar answered Oct 20 '22 07:10

Evgeny