监控 Django 中的数据库请求,与行号相关
我们的项目中发生了一些非常奇怪的无关数据库点击。有什么方法可以通过行号来监视请求的来源吗? SQL 打印中间件会有所帮助,但我们已经查找了可能生成此类请求的所有地方,但找不到来源。
如果上述不可能,任何有关缩小来源范围的指示将不胜感激。
We've got some really strange extraneous DB hits happening in our project. Is there any way to monitor where the requests are coming from, possibly by line number? The SQL printing middleware helps, but we've looked everywhere those kinds of requests might be generated and can't find the source.
If the above isn't possible, any pointers on narrowing down the source would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要查找执行查询的代码,您可以安装 django-debug-toolbar 来找出正在执行哪些命令以及它们正在操作哪些表。
完成此操作后,尝试连接适当的 Django 信号这些模型并使用
print
和assert
来缩小代码范围。我确信有更好的方法来完成其中的一些工作(Python 调试器?),但这是我首先想到的事情,也可能是我最终会自己做的事情。
To find the code executing queries, you can install django-debug-toolbar to figure out what commands are being executed and which tables they're operating on.
Once you've done that, try hooking into the appropriate Django signals for those models and using
print
andassert
to narrow the code.I'm sure there's a better way to do some of this (a python debugger?) but this is the first thing that comes to mind and probably what I would end up doing myself.
如果您想跟踪 SQL 查询以实现性能优化和调试目的以及如何在 Django 中监视查询调用
为此,此博客将帮助您
使用以下命令跟踪请求的 SQL 查询姜戈
if you want track SQL queries for performance optimization and debug purpose and how to monitor query call in Django
for that this blog will help you out
Tracking SQL Queries for a Request using Django