Review the Cloud SQL PostgreSQL server-log threshold

Retain required server messages while reducing unnecessary log volume.

Description

log_min_messages controls which PostgreSQL messages reach the server log. The default is WARNING. Client messages and SQL statement auditing have their own settings.

Potential impact

Verbose logs can hide important errors and increase costs. A high threshold can hide warnings needed for an investigation.

Remediation

  • Start with WARNING. If you need NOTICE for a diagnosis, switch back when it ends.
  • Check that the server logs contain the messages you need at a manageable volume. Set retention and read access accordingly.

Examples

Supply the other required settings for your supported PostgreSQL version. Changing this flag alone requires no engine upgrade.

Before

hcl
resource "google_sql_database_instance" "example" {
  name             = "postgres-instance-with-flag"
  database_version = "POSTGRES_14"
  region           = "us-central1"

  settings {
    database_flags {
      name  = "log_min_messages"
      value = "NOTICE"
    }
  }
}

After

hcl
resource "google_sql_database_instance" "example" {
  name             = "postgres-instance-with-flag"
  database_version = "POSTGRES_15"
  region           = "us-central1"

  settings {
    database_flags {
      name  = "log_min_messages"
      value = "WARNING"
    }
  }
}

The first setting includes notices and warnings. The second keeps warnings and more severe messages and leaves out notices.

References