Review Azure PostgreSQL log retention

Check collection and actual retention of Azure PostgreSQL server logs.

Description

Azure Database for PostgreSQL Flexible Server keeps downloadable logs for three days by default once capture is enabled, up to a maximum of seven. For a longer history, export logs through diagnostic settings.

Potential impact

Missing records make it harder to investigate a past connection problem or query error, or to account for a database event during an audit.

Remediation

Set logfiles.download_enable to on and logfiles.retention_days to 1–7 days. For exported logs, choose destination retention based on investigation needs and storage costs. Use the investigator’s permissions to retrieve recent and older records and check the period they cover.

Examples

Both azurerm_postgresql_configuration excerpts are historical Single Server settings. Single Server retired on March 28, 2025.

Before

hcl
resource "azurerm_postgresql_configuration" "example" {
  name                = "log_retention"
  resource_group_name = data.azurerm_resource_group.example.name
  server_name         = azurerm_postgresql_server.example.name
  value               = "OFF"
}

After

hcl
resource "azurerm_postgresql_configuration" "example" {
  name                = "log_retention"
  resource_group_name = data.azurerm_resource_group.example.name
  server_name         = azurerm_postgresql_server.example.name
  value               = "ON"
}

Changing log_retention from OFF to ON sets no retention period for Flexible Server or its export destination.

References