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
  • 57,831
  • 112
  • 317
  • 501

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
  • 36,955
  • 19
  • 118
  • 157
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
  • 38,084
  • 5
  • 78
  • 83
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
  • 173,492
  • 58
  • 311
  • 399