1. Stop postgres service
root@localhost:~# /etc/init.d/postgresql stop
2. Setup postgresql.conf file
root@localhost:~# nano /etc/postgresql/9.4/main/postgresql.conf
wal_level = archive
archive_mode = on
archive_command = 'cp %p /wal/archive/folder/9.4/%f'
archive_timeout = 300
3. Remove existing data directory in postgres cluster (to be replaced with base backup)
root@localhost:~# rm -r /var/lib/postgresql/9.4/main
4. Decrypt & uncompress backup file main.YYYMMDD.tgz.enc, and move to data directory
5. Remove any files present in /var/lib/postgresql/9.4/main/pg_xlog (probably obsolete rather than current)
6. Decrypt & uncompress wal files, and move to archive directory /wal/archive/folder/9.4/
7. Create file /var/lib/postgresql/9.4/main/recovery.conf with following configuration
# note: the decryption and uncompressing steps may optionally be
# done by this restore command
restore_command = 'cp /wal/archive/folder/9.4/%f %p'
#optional - by default, recovery will recover to the end of WAL log
recovery_target_time = 'yyyy-MM-dd hh:mm:ss.SSSSSS'
8. Change ownership of data/archive directory and sub files to postgres
9. Start postgres service
1. Stop postgres service
root@localhost:~# /etc/init.d/postgresql stop
2. Setup postgresql.conf file
root@localhost:~# nano /etc/postgresql/13/main/postgresql.conf
wal_level = replica
archive_mode = on
archive_command = '/home/backup/scripts/wal_archive_command.sh %f %p >>/home/backup/logs/wal_archive.log 2>&1'
archive_timeout = 300
# de-compress and copy wal file to target path
# in this case the wal files were compressed using tar -cvzf
restore_command = 'gunzip -c <path to wal files>/%f.tgz > "%p"'
#optional - by default, recovery will recover to the end of WAL log
recovery_target_time = 'yyyy-MM-dd hh:mm:ss.SSSSSS'
3. Remove existing data directory in postgres cluster (to be replaced with base backup)
root@localhost:~# rm -r /var/lib/postgresql/13/main
4. Decrypt & uncompress backup file main.YYYMMDD.tgz.enc, and move to data directory
Note: The decryption and decompression of wal files by optionally be done by the restore_command
5. Remove any files present in /var/lib/postgresql/13/main/pg_wal (probably obsolete rather than current)
6. Decrypt (if necessary) & uncompress wal files, and move to archive directory /wal/archive/folder/13/
7. Create file /var/lib/postgresql/13/main/recovery.signal
8. Change ownership of data/archive directory and sub files to postgres
9. Start postgres service