Configure AlloyDB Omni log rotation

This document describes how to configure when AlloyDB Omni Kubernetes operator diagnostic logs rotate. There are two log files located in the /obs/diagnostic/ directory:

  • postgresql.audit: This log file collects session and object access audit logs. To collect audit logs, you need to enable audit logs.

  • postgresql.log: This log file collects PostgreSQL server logs. These logs are always collected and don't need to be enabled.

When a log file rotates, the following occurs:

  1. The log file is copied to the /obs/diagnostic/archive/ directory. If a log file with the same name exists in that directory, then it's overwritten.

  2. The contents of the original rotated log file are deleted so that the file is empty.

  3. Log information immediately begins writing to the empty rotated log file. Log information is written to the log file until the file reaches a size or age threshold, at which point it rotates again. Logs rotate so that they don't become too large.

By default, the rotation setting is for each log file to rotate when its size reaches 200 MB. The default rotation doesn't include an age setting.

Enable audit logs

For session and object access logs to be collected in the postgresql.audit file, you need to enable the pgaudit database parameter. To enable pgaudit, add the following line to the parameters section of the v1_dbcluster_parameters.yaml file under Secret:

alloydb.enable_pgaudit: "on"

The following is an example of this might look like:

apiVersion: v1
kind: Secret
...
apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
   name: DB_CLUSTER_NAME
spec:
  databaseVersion: "15.7.0"
  primarySpec:
    ...
    parameters:
      ...
      alloydb.enable_pgaudit: "on"

For more information, see pgaudit in Supported database extensions, and PostgreSQL Auditing Extension. PostgreSQL server logs are always collected in the postgresql.log file and don't require enabling pgaudit.

Configure log rotation

If you want more control over when logs rotate, configure a maximum file size, a duration between log rotations, or both. The duration between log rotations is also called the age of the log. If you use both settings, then each log rotates when it reaches one of the thresholds.

To configure log rotation, you set one or both of the following parameters in the parameters section of the DBCluster manifest:

  • log_rotation_size: "SIZE_IN_KB"
  • log_rotation_age: "AGE_IN_MINUTES"

To disable one of the log rotation settings, set it to zero ("0"). To retain the default setting that rotates logs when their file size reaches 200 MB, don't set either parameter.

Log rotation maximum log size and duration example

The following sample sets logs to rotate when their file size reaches 400 MB or when the time between log rotations reaches one day, whichever happens first:

apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: DB_CLUSTER_NAME
spec:
...
  primarySpec:
  ...
    parameters:
      log_rotation_size: "400000" # 400 MB
      log_rotation_age: "1440" # 24 hours * 60 minutes = 1 day

Log rotation maximum log size example

The following sample sets logs to rotate when their file size reaches 400 MB:

apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: DB_CLUSTER_NAME
spec:
...
  primarySpec:
  ...
    parameters:
      log_rotation_size: "400000" # 400 MB
      log_rotation_age: "0" # Set to 0 to disable

Log rotation duration example

The following sample sets logs to rotate once every 24 hours:

apiVersion: alloydbomni.dbadmin.goog/v1
kind: DBCluster
metadata:
  name: DB_CLUSTER_NAME
spec:
...
  primarySpec:
  ...
    parameters:
      log_rotation_size: "0" # Set to 0 to disable
      log_rotation_age: "1440" # 24 hours * 60 minutes = 1 day

What's next