Django + postgresql:记录查询执行的时间长度?

时间:2013-06-13 11:37:47

标签: django postgresql

初学者问题,这可能是重复的,对不起!但我无法通过谷歌搜索或在这里搜索找到答案。

我的Django / postgres应用程序很慢。我知道如何记录queries being executed on postgres,所以我正在这样做。

现在,我如何识别哪些是慢的...没有在我自己输入所有内容,并使用秒表?

简而言之:有没有办法记录每个查询执行的时间,使用Django ORM&一个postgres数据库?

3 个答案:

答案 0 :(得分:1)

您需要django-debug-toolbar。谢谢我以后。

或者如果你想手动完成,那么:

import time

start = time.time()
# execute your query here
stop = time.time() - start
print stop # or log this time

答案 1 :(得分:1)

记录所有慢查询

在postgresql.conf文件中设置log_min_duration_statement = 200ms

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

答案 2 :(得分:0)

我已经使用pgFouine来分析我的postgres日志 - 请参阅http://pgfouine.projects.pgfoundry.org/tutorial.html了解如何设置日志记录以及如何使用pgFouine进行分析。