Other Articles

PostgreSQL Flexible Server – Configure Log File Retention

This check ensures that the log_file_retention_days parameter is configured to retain PostgreSQL Flexible Server logs for more than three days. Proper log retention supports effective troubleshooting, auditing, and security monitoring.

Check Details

  • Resource: Azure Database for PostgreSQL – Flexible Server
  • Check: Ensure log_file_retention_days Is Greater Than 3
  • Risk: If PostgreSQL logs are retained for an insufficient period, critical audit records and diagnostic information may be lost. This may hinder incident investigations, regulatory compliance, and long-term troubleshooting efforts.

Remediation via Azure Portal

  1. Log in to the Azure Portal. Azure Portal dashboard
  2. Navigate to Azure Database for PostgreSQL Flexible Servers and select the affected server. PostgreSQL Flexible Server list
  3. Under Settings, select Server parameters. PostgreSQL server parameters
  4. In the search bar, locate the parameter logfiles.retention_days.
  5. Ensure the value is set to greater than 3 days (for example, 4 days or more). PostgreSQL server log file retention
  6. Click Save to apply the configuration.

Remediation via Azure CLI

  1. Open Azure Cloud Shell or a local terminal with Azure CLI installed. Azure Cloud Shell
  2. Check the current value of log_file_retention_days:

    az postgres flexible-server parameter show \
     --resource-group <resource-group> \
     --server-name <server-name> \
     --name logfiles.retention_days
    
  3. Update the parameter to retain logs for more than three days:

    az postgres flexible-server parameter set \
     --resource-group <resource-group> \
     --server-name <server-name> \
     --name logfiles.retention_days \
     --value 4
    
  4. Verify the updated configuration:

    az postgres flexible-server parameter show \
     --resource-group <resource-group> \
     --server-name <server-name> \
     --name logfiles.retention_days \
     --query value
    

Replace <resource-group> and <server-name> with your actual values. The output should confirm that the value of log_file_retention_days is greater than 3.