Description
In RDS for PostgreSQL, log_statement selects the SQL statement types to log. log_min_duration_statement sets a duration threshold. Use -1 to disable duration-based logging, 0 to record every duration or a positive value for statements taking at least that many milliseconds.
Potential impact
A high threshold can hide slow queries. Detailed logs can capture sensitive values, including passwords, and increase storage costs.
Remediation
Choose both values for your audit needs and workload. Attach a parameter group from the matching engine family to the instance, verify that the settings took effect and check the logs for a query that meets your settings. Restrict readers, set retention and enable export separately if you need CloudWatch Logs.
Examples
The examples define a postgres14 parameter group. In the first, none and -1 disable logging by statement type and duration. Login failures and errors can still be recorded.
Before
resource "aws_db_parameter_group" "postgres_logging" {
name = "postgres-logging"
family = "postgres14"
parameter {
name = "log_statement"
value = "none"
}
parameter {
name = "log_min_duration_statement"
value = "-1"
}
}
After
resource "aws_db_parameter_group" "postgres_logging" {
name = "postgres-logging"
family = "postgres14"
parameter {
name = "log_statement"
value = "all"
}
parameter {
name = "log_min_duration_statement"
value = "1"
}
}
The second logs all statement types and records the duration of statements taking at least one millisecond. On a busy instance, that can produce a large volume of logs.