Description
Azure PostgreSQL Flexible Server can keep downloadable logs for 1–7 days. Capture is off by default. Once enabled, the default retention is 3 days.
Potential impact
Logs may expire before the team investigates an error or unusual connection.
Remediation
Set logfiles.download_enable to on and choose logfiles.retention_days. For a longer window, send logs to a destination such as Azure Storage and set its access and retention policies. Check that fresh logs arrive. As logs accumulate, confirm you can retrieve the oldest records your investigations need.
Examples
The first setting is for retired Single Server. The second excerpt enables downloadable logs on an existing Flexible Server and keeps them for 5 days. Choose the period your investigation requires.
Before
resource "azurerm_postgresql_configuration" "example" {
name = "log_retention_days"
resource_group_name = azurerm_resource_group.example.name
server_name = azurerm_postgresql_server.example.name
value = 2
}
After
resource "azurerm_postgresql_flexible_server_configuration" "download_logs" {
name = "logfiles.download_enable"
server_id = azurerm_postgresql_flexible_server.example.id
value = "on"
}
resource "azurerm_postgresql_flexible_server_configuration" "example" {
name = "logfiles.retention_days"
server_id = azurerm_postgresql_flexible_server.example.id
value = "5"
}