Skip to content

Ensure the filename pattern for log files is set correctly

Description

The log_filename setting specifies the filename pattern for log files. The value for log_filename should match your organization's logging policy.

The value is treated as a strftime pattern, so %-escapes can be used to specify time- varying filenames. The supported %-escapes are similar to those listed in the Open Group's

strftime specification. If you specify a filename without escapes, you should plan to use a log rotation utility to avoid eventually filling the partition that contains log_directory. If there are any time-zone-dependent %-escapes, the computation is done in the zone

specified by log_timezone. Also, the system's strftime is not used directly, so platform- specific (nonstandard) extensions do not work.

If CSV-format output is enabled in log_destination, .csv will be appended to the log filename. (If log_filename ends in .log, the suffix is replaced instead.)

Rationale

If log_filename is not set, then the value of log_directory is appended to an empty string and PostgreSQL will fail to start as it will try to write to a directory instead of a file.

Applies To

  • Databases

Tags

This rule is applied when the following tags are present:

Tag With Value
secureclouddb/provider aws
secureclouddb/service rds
secureclouddb/engine postgres

Default Rule

const { getServerSetting } = module

/**
 * @param {Object} databaseSettings - database settings object
 * @returns {boolean} true if the pattern for logs is set correctly
 */
function validate(databaseSettings) {

    const settingName = 'logging_filename'
    const currentValue = getServerSetting(databaseSettings, settingName)
    const success = !!currentValue

    return {
        success,
    }
}

// invoke
validate(databaseSettings);