# Configuring the PostgreSQL Archive Log Directory

Archive log files are stored in the Archive Log directory.

Note

- The archive log directory must be outside the data directory.

- The archive log directory must be on a drive or volume with sufficient free space.

- Make sure that this path does not point to pg_log or log directories and pg_xlog or pg_wal directories.

Ensure to follow the below checkpoints before running the PostgreSQL FS backup:

## Procedure

- Specify the Archive log directory path in the postgresql.conf file prior to performing the PostgreSQL FS backup.

      archive_command = 'cp %p /wal directory path/%f'  # UNIX
      archive_command = 'copy "%p" "D:\\PostgreSQL\\wal\\%f"' #Windows

  Note

  While the path specified in the archive_command can vary depending on your environment, the filename placeholder must always be %f. Using any other filename format can prevent logs and WAL files from being backed up correctly. Ensure that the %f placeholder is preserved in the archive_command configuration. For more information, refer to the PostgreSQL documentation.

- For PostgreSQL 8.3 version and later, use the following configuration to turn on the archive_mode. This feature is not supported for PostgreSQL 8.2 and earlier versions.

      archive_mode = on

- The archive_mode cannot be enabled when wal_level is set to minimal. Configure it based on the replication type for your instance.

  For a standalone instance, you may set it to archive or replica as applicable for your PostgreSQL version.

  For more information, refer PostgreSQL Documentation, Write Ahead Log.

- Verify that the archive command provided in the postgresql.conf file is correct. You can test this by running the following commands and verifying that they successfully complete.

  For PostgreSQL 15 and more recent versions:

      select pg_backup_start('t', 'f');
      select pg_backup_stop();

  For PostgreSQL versions 9.5 to 14:

      select pg_start_backup(‘test’, 'f', 'f');
      select pg_stop_backup('f');

  For PostgreSQL versions older than 9.5:

      Select pg_start_backup(‘Test’);
      Select pg_stop_backup();

  ## Related Topic

Optimizing PostgresSQL log backup.

×

Loading...