Control: 4.3.7 Ensure server parameter 'log_retention_days' is greater than 3 days for PostgreSQL Database Server
Description
It is recommended to enable log_retention_days on PostgreSQL Servers. Enabling log_retention_days helps PostgreSQL database to sets number of days a log file is retained which in turn generates query and error logs. Query and error logs can be used to identify, troubleshoot, and repair configuration errors and sub-optimal performance.
Remediation
From Console
- Login to Azure console and navigate to PostgreSQL Servers.
- For each database, go to
Settings
section from left pane. - Click on
Server parameters
. - Search for
log_retention_days
. - Enter value in range of
4-7
and click save.
From Command Line
Command to update log_retention_days
configuration
az postgres server configuration show --resource-group <resourceGroupName> --server-name <serverName> --name log_retention_days
Usage
Run the control in your terminal:
powerpipe control run azure_compliance.control.cis_v130_4_3_7
Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run azure_compliance.control.cis_v130_4_3_7 --share
SQL
This control uses a named query:
select s.id as resource, case when (config -> 'ConfigurationProperties' ->> 'value')::integer <= 3 then 'alarm' else 'ok' end as status, case when (config -> 'ConfigurationProperties' ->> 'value')::integer <= 3 then s.name || ' log files are retained for 3 days or lesser.' else s.name || ' log files are retained for more than 3 days.' end as reason , s.resource_group as resource_group , sub.display_name as subscriptionfrom azure_postgresql_server s, jsonb_array_elements(server_configurations) as config, azure_subscription subwhere config ->> 'Name' = 'log_retention_days' and sub.subscription_id = s.subscription_id;