Description
pgAudit records selected SQL operations inside a Cloud SQL for PostgreSQL database. Instance administration is audited separately.
Potential impact
Missing SQL records can leave gaps in an investigation. Recording too many operations can expose query values and increase disk usage and logging costs.
Remediation
- Schedule a maintenance window. Setting
cloudsql.enable_pgaudittoonrestarts the instance. - After the restart, reconnect with
psqland create the pgAudit extension. Setpgaudit.logto the classes of SQL operations you need to audit. - Enable the required Data Access audit logs in the project and find a test event in Cloud Logging. Check disk usage, limit read access and set retention.
Examples
Use a supported PostgreSQL version and supply the other required instance settings. You can enable the flag on the same engine version.
Before
hcl
resource "google_sql_database_instance" "example" {
name = "postgres-instance-with-flag"
database_version = "POSTGRES_14"
region = "us-central1"
settings {
database_flags {
name = "cloudsql.enable_pgaudit"
value = "off"
}
}
}
After
hcl
resource "google_sql_database_instance" "example" {
name = "postgres-instance-with-flag"
database_version = "POSTGRES_15"
region = "us-central1"
settings {
database_flags {
name = "cloudsql.enable_pgaudit"
value = "on"
}
}
}
The second excerpt turns on the instance flag. You still need to create the extension and choose which operations to record. Other server logging is configured separately.