Overview
Ensure logfiles.retention_days on PostgreSQL flexible servers is set to an appropriate value.
Rationale
Configuring logfiles.retention_days determines the duration in days that Azure Database for PostgreSQL retains log files. Query and error logs can be used to identify, troubleshoot, and repair configuration errors and sub-optimal performance.
Impact
Configuring this setting will result in logs being retained for the specified number of days. If this is configured on a high traffic server, the log may grow quickly to occupy a large amount of disk space. In this case you may want to set this to a lower number.
Default Value
By default, logfiles.retention_days is set to 3.
Remediation guidance
Remediate from Azure Portal
- Open the server using the
Open in Azurebutton - Under
Settings, clickServer parameters. - In the filter bar, type
logfiles.retention_days. - Set the
VALUEforlogfiles.retention_daystoON. - Click
Save.
Remediate from Azure CLI
Use the below command to update logfiles.retention_days:
az postgres flexible-server parameter set --resource-group <resourceGroup> --server-name <serverName> --name logfiles.retention_days --value <4-7>
Remediate from PowerShell
Use the below command to update logfiles.retention_days:
Update-AzPostgreSqlFlexibleServerConfiguration -ResourceGroupName <resourceGroup> -ServerName <serverName> -Name logfiles.retention_days -Value <4-7>
Service-wide remediation
Recommended when many resources are affected: fix the platform baseline first so new resources inherit the secure setting, then remediate the existing flagged resources in batches.
Azure
Use management group or subscription Azure Policy assignments, remediation tasks where supported, landing-zone standards, and IaC modules so drift is prevented at scale.
Operational rollout
- Fix the baseline first at the account, subscription, project, cluster, or tenant scope that owns this control.
- Remediate the currently affected resources in batches, starting with internet-exposed and production assets.
- Re-scan and track approved exceptions with an owner and expiry date.
Query logic
These are the stored checks tied to this control.
Azure PostgreSQL Flex Servers with low logfiles retention days
Connectors
Covered asset types
Expected check: eq []
{
postgreSqlFlexibleServers(
where: {
configurations_SOME: {
name: "logfiles.retention_days"
value_MATCHES: "[0-3]"
}
}
) {
...AssetFragment
}
}
Microsoft Azure