After restoring the application data and logs, you can recover the PostgreSQL database from the disk using PostgreSQL restore commands.
Procedure
Application-Free Restore Recovery - FSBasedBackupSet
-
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.
-
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"' -
For non-exclusive backups in 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 -
Start the PostgreSQL server.
-
After the PostgreSQL server is online, remove the recovery related parameters from the postgresql.conf file.
Application-Free Restore Recovery - DumpBasedBackupSet
Use the following pg_restore commands to restore the data from a dump file:
For a UNIX server, enter the following:
pg_restore -p <PORT> -U <USER> -C -d postgres -v /<staging_path>/<job_id>/<fifo_dbname>
To use parallel jobs to restore the database:
pg_restore -p <PORT> -U <USER> -C -d postgres -j <number_of_parallel_job> -v /<staging_path>/<job_id>/<fifo_dbname>
For a Windows server, enter the following:
pg_restore.exe -p <PORT> -U <USER> -C -d postgres -v "<staging_path>\<job_id>\<fifo_dbname>”
To use parallel jobs to restore the database:
pg_restore.exe -p <PORT> -U <USER> -C -d postgres -j <number_of_parallel_job> -v "<staging_path>\<job_id>\<fifo_dbname>”