PostgreSQL log retention needs review

Review whether PostgreSQL log retention and storage meet investigation and audit requirements.

Description

On Azure Database for PostgreSQL Flexible Server, enable capture of downloadable server logs and choose how far back investigators need to look.

Potential impact

Once logs expire, investigators and auditors lose the records from the time of a failure or security event.

Remediation

Set logfiles.download_enable to on and logfiles.retention_days to 1–7 days. For a longer history, export the required logs through diagnostic settings and set retention at the destination. Check that investigators can retrieve a recent record and one from the required period.

Examples

The first task uses Single Server, which retired on March 28, 2025. The second example requires an existing Flexible Server and azure.azcollection 3.18.0 or later.

Before

yaml
- name: PostgreSQL 설정 변경
  azure_rm_postgresqlconfiguration:
    resource_group: myResourceGroup
    server_name: myServer
    name: log_retention
    value: off

Changing log_retention from off to on does not set a retention period.

After

yaml
- name: PostgreSQL 로그 수집 활성화
  azure.azcollection.azure_rm_postgresqlflexibleconfiguration:
    resource_group: myResourceGroup
    server_name: myServer
    name: logfiles.download_enable
    value: "on"

- name: PostgreSQL 로그 보존 기간 설정
  azure.azcollection.azure_rm_postgresqlflexibleconfiguration:
    resource_group: myResourceGroup
    server_name: myServer
    name: logfiles.retention_days
    value: "7"

The two tasks enable capture for download and retain those files for seven days.

References