Recovering the PostgreSQL Database After an Application-Free Restore

Updated

On this page

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 13, 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 version 12:

    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. Start the PostgreSQL server.

  4. After the PostgreSQL is online, remove the parameters from the postgresql.conf file.