0

Beginner question, and it's probably a duplicate, sorry! But I can't find the answer by Googling or by searching on here.

My Django/postgres application is slow. I know how to log the queries being executed on postgres, so I'm doing that.

Now, how do I identify which of them are slow... short of typing them all in myself, and using a stopwatch?

In short: is there a way to log how long each query took to execute, using Django ORM & a postgres database?

Community
  • 1
  • 1
Richard
  • 62,943
  • 126
  • 334
  • 542

3 Answers3

1

You need django-debug-toolbar. Thanks me later.

Or if you want to do it manually then:

import time

start = time.time()
# execute your query here
stop = time.time() - start
print stop # or log this time
Aamir Rind
  • 38,793
  • 23
  • 126
  • 164
1

log all slow queries

set log_min_duration_statement = 200ms in postgresql.conf file

http://www.postgresql.org/docs/9.2/static/runtime-config-logging.html

Pavel Stehule
  • 42,331
  • 5
  • 91
  • 94
0

I have used pgFouine to analyse my postgres logs - see http://pgfouine.projects.pgfoundry.org/tutorial.html for how to set up logging and how to analyse them with pgFouine.

Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408