Recovering the PostgreSQL Database After an Application-Free Restore

After restoring the application data and logs, you can recover the PostgreSQL database from the disk using PostgreSQL restore commands.

Procedure

  1. For PostgreSQL version 11 or earlier, on the destination server, under the PostgreSQL Data directory, create a recovery.conf file.

    For PostgreSQL versions 12 and later, on the destination server, under the PostgreSQL Data directory, create an empty file named recovery.signal.

  2. Add the following restore commands to the recovery.conf file for PostgreSQL version 11 or earlier, and to the postgresql.conf file for PostgreSQL versions 12 and later:

    For a UNIX server, enter the following:

    restore_command = 'cp <TARGET_RESTORE_DIR>/%f "%p"'

    For example, enter the following:

    restore_command = 'cp /opt/PostgreSQL/9.6/restore_to_disk/9011/opt/PostgreSQL/9.6/wal/%f "%p"'

    For a Windows server, enter the following:

    restore_command = 'copy "<TARGET_RESTORE_DIR>\\%f" "%p"'

    For example, enter the following:

    restore_command = 'copy "C:\\PostgreSQL\\restore_to_disk\\9014\\PostgreSQL\\wal\\%f" "%p"'
  3. For PostgreSQL versions 9.5 and above, copy the backup_label file from archive log directory to the data directory.

    For example, enter the following:

    cp /opt/PostgreSQL/9.6/restore_to_disk/9011/opt/PostgreSQL/9.6/wal/backup_label /opt/PostgreSQL/9.6/restore_to_disk/9011/opt/PostgreSQL/9.6/data
  4. Start the PostgreSQL server.

  5. After the PostgreSQL server is online, remove the recovery related parameters from the postgresql.conf file.

Loading...