在Google Cloud SQL PostgreSQL实例上记录慢查询 [英] Logging slow queries on Google Cloud SQL PostgreSQL instances

查看:99
本文介绍了在Google Cloud SQL PostgreSQL实例上记录慢查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的公司使用Google Cloud SQL来管理其生产中的SQL数据库.

The company I work for uses Google Cloud SQL to manage their SQL databases in production.

我们遇到了性能问题,我认为查看/监视所有超过特定阈值(例如250ms)的查询是一个好主意.

We're having performance issues and I thought it'd be a good idea (among other things) to see/monitor all queries above a specific threshold (e.g. 250ms).

通过查看

By looking at the PostgreSQL documentation I think log_min_duration_statement seems like the flag I need.

log_min_duration_statement(整数)

如果语句至少运行了指定的毫秒数,将导致记录每个完成的语句的持续时间.将此设置为零将打印所有语句持续时间.

Causes the duration of each completed statement to be logged if the statement ran for at least the specified number of milliseconds. Setting this to zero prints all statement durations.

但是从Cloud SQL文档来看,我看到只能设置一组狭窄的数据库标志(就像在每个数据库实例中一样),但是您可以从

But judging from the Cloud SQL documentation I see that is only possible to set a narrow set of database flags (as in for each DB instance) but as you can see from here log_min_duration_statement is not among those supported flags.

因此,问题来了.如何使用Google Cloud SQL记录/监视慢速PostgreSQL查询?如果不可能的话,您建议我使用哪种工具/方法来获得类似的结果?

So here comes the question. How do I log/monitor my slow PostgreSQL queries with Google Cloud SQL? If not possible then what kind of tool/methodologies do you suggest I use to achieve a similar result?

推荐答案

2019年4月3日更新

现在可以 在Google Cloud SQL PostgreSQL实例上记录慢速查询,请参见

启用 log_min_duration_statement 后,您可以使用Stackdriver日志查看日志.选择 Cloud SQL数据库-> cloudsql.googleapis.com/postgres.log ,您将看到这样的日志.

Once you enable log_min_duration_statement, you can view the logs using Stackdriver logging. Select Cloud SQL Database -> cloudsql.googleapis.com/postgres.log and you will see the log like this.

[103402]: [9-1] db=cloudsqladmin,user=cloudsqladmin LOG: duration: 11.211 ms statement: [YOUR SQL HERE]

参考文献:

  • Full list of supported flags (CTRL+F for log_min_duration_statement): https://cloud.google.com/sql/docs/postgres/flags#postgres-l
  • Issue tracker: https://issuetracker.google.com/issues/74578509#comment54
  • PostgreSQL docs: https://www.postgresql.org/docs/9.6/runtime-config-logging.html#GUC-LOG-MIN-DURATION-STATEMENT

这篇关于在Google Cloud SQL PostgreSQL实例上记录慢查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆