darold / pgbadger

A fast PostgreSQL Log Analyzer
http://pgbadger.darold.net/
PostgreSQL License
3.49k stars 349 forks source link

GCP CloudSQL Logs not parsing #747

Closed photomattmills closed 1 year ago

photomattmills commented 2 years ago

Hello--

I'm having an issue parsing logs downloaded from cloudSQL. Seems like none of the queries are getting picked up; here's one example:

{
    "textPayload": "2022-07-30 05:04:30.061 UTC [4075710]: [2-1] db=redacted_production,user=redacted_admin STATEMENT:  SELECT \"reasons\".* FROM \"reasons\" WHERE \"reasons\".\"id\" IN (103, 74, 88, 79)",
    "insertId": "s=dae075e20970467694b8d6255e6bab26;i=c74058;b=08fca606ae1942789f34157f32eab680;m=5f63da18332;t=5e4feb3a1281e;x=7e65830180008d9-0-0@a1",
    "resource": {
      "type": "cloudsql_database",
      "labels": {
        "region": "us-central",
        "database_id": "redacted-production:redacted-core-production-pg-11",
        "project_id": "redacted-production"
      }
    },
    "timestamp": "2022-07-30T05:04:30.062622Z",
    "severity": "INFO",
    "labels": {
      "LOG_BUCKET_NUM": "60"
    },
    "logName": "projects/redacted-production/logs/cloudsql.googleapis.com%2Fpostgres.log",
    "receiveTimestamp": "2022-07-30T05:05:00.846932756Z"
  }

I tried entering a --prefix "%m [%p]: db=%d,user=%u to get it to pick up things, but it didn't seem to help; whatever the [2-1] is I couldn't figure out the escape sequence for it and it's different in different log lines. Deleting it from the lines with sed and running the tool against that, it only picked up logs pertaining to temp files.

{
  "textPayload": "2022-07-30 03:42:01.355 UTC [4006290]: db=redacted_production,user=redacted_admin LOG:  temporary file: path \"base/pgsql_tmp/pgsql_tmp4006290.1\", size 1632288",
  "insertId": "s=dae075e20970467694b8d6255e6bab26;i=c71a29;b=08fca606ae1942789f34157f32eab680;m=5f516aa3e42;t=5e4fd8ca9e32d;x=83810cda9a70c7b5-0-0@a1",
  "resource": {
    "type": "cloudsql_database",
    "labels": {
      "database_id": "redacted-production:redacted-core-production-pg-11",
      "region": "us-central",
      "project_id": "redacted-production"
    }
  },
  "timestamp": "2022-07-30T03:42:01.356077Z",
  "severity": "INFO",
  "labels": {
    "LOG_BUCKET_NUM": "60"
  },
  "logName": "projects/redacted-production/logs/cloudsql.googleapis.com%2Fpostgres.log",
  "receiveTimestamp": "2022-07-30T03:42:08.269378594Z"
}

Let me know if I can add anything else, I can send you un-redacted logs (about 13mb in total) if that will help. Thanks!

darold commented 1 year ago

Well looks like log_statement in GCP CloudSQL Logs is not well supported, you should use log_min_duration_statement instead.

I have done some minimal try to fix that without success but anyway using log_min_duration_statement will brings many more information in your reports.