框架上的数据
在像 框架,我们将收到大量数据-每月超过6700万个事件。高效的分析对于保持市场领导者地位至关重要,我们使用大量工具:
这意味着我们的数据仓库经常受到大量查询的攻击,无论是在Cron计划中还是在员工探索我们的数据集方面都如此。
数量问题
管理如此大量的查询可能很困难。
- PostgreSQL表可以锁定-例如,在其他人查询表时尝试交换/删除表将导致它们锁定。理想情况下,分析表仅应进行增量更新,但有时设计限制会阻止这种情况。
- SQL GUI可能会随机超时,这对快速检查数据库以查看它们是否仍在运行很有用。
- Using a combination of
screen
andpsql
to run queries in the background requires monitoring. Dima is great for that. - 数百万行表上没有LIMIT的意外SELECT可能会使SQL GUI崩溃。
- 有时候,一个大查询不是您想要的。 伪装l没有取消按钮,而托管的GUI(如Redash和Looker)具有“取消”按钮,这些按钮对于长时间运行的查询通常无响应。
迪玛
为了帮助解决此问题,我构建了一个名为dima的小型命令行工具。它最初代表“数据库完整性监控”&分析”,但现在只是“ dima”。它非常简单,而且非常有用,因此我可以将其开源。
Dima is a 蟒蛇 script that basically lets you quickly summarize or inspect the pg_stat_activity
internal table in Postgres via the psycopg2 library. If you want to kill a query it will call pg_terminate
on the PID.
查看 //github.com/Frameio/homebrew-dima.
Install using pip install dima-db
or brew tap Frameio/homebrew-dima && brew install dima
指令
dima
—正在运行的查询摘要
dima show [PID]
-检查特定的正在运行的查询
dima rm [-f] Some PID or Keyword
—杀死查询/查询