Logging slow queries on Google Cloud SQL PostgreSQL instances

前端 未结 4 822
死守一世寂寞
死守一世寂寞 2021-02-13 10:40

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

We\'re having performance issues and I thought it\'d be a good idea (among othe

4条回答
  •  日久生厌
    2021-02-13 11:24

    April 3, 2019 UPDATE

    It is now possible to log slow queries on Google Cloud SQL PostgreSQL instances, see https://cloud.google.com/sql/docs/release-notes#april_3_2019:

    database_flags = [
      {
        name = "log_min_duration_statement"
        value = "1000"
      },
    ]
    

    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]
    

    References:

    • 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

提交回复
热议问题