3. Online Backup
Enable Archiving
Confidential information, for internal use only
• archive_command = 'cp %p /mnt/server/archivedir/%f‘
• wal_level = archive
• Archive_mode = on
Take a backup
• SELECT pg_start_backup('label');
• Take a backup (file system level copy)
• SELECT pg_stop_backup();
Alternative to Manual backup: Use pg_basebackup for taking a backup
•
pg_basebackup -D /opt/PostgresPlus/9.2AS/data -h 192.168.160.147 -W -p 5444 -Fp --xlogmethod=stream
3
4. Recovery: Restore the server
Confidential information, for internal use only
Stop the server, if it's running. Change the
pg_hba.conf to disallow user’s login during recovery
Keep a backup of original server or at least pg_xlog
Restore the database files from your file system
backup. Be sure about the ownership and soft links
4
5. Recovery: Prepare the Server
Remove any files present in pg_xlog/;
Confidential information, for internal use only
If you have unarchived WAL segment files that you saved (step 2), copy them into
pg_xlog/
Create a recovery command file recovery.conf in the cluster data directory:
• restore_command = 'cp /mnt/server/archivedir/%f "%p" '
If this is a point in time recovery to recover from a bad batch operation or a bad
command which has corrupted the data then add recovery_target_time to a timestamp
which is just before the bad command/batch was fired
• recovery_target_time = '18-JUL-13 23:07:05.39855'
5
6. Start the Recovery
Start the server
Confidential information, for internal use only
• The server will go into recovery mode and proceed to read through the archived
WAL files it needs
• Should the recovery be terminated because of an external error, the server can
simply be restarted and it will continue recovery
• Upon completion of the recovery process, the server will rename recovery.conf to
recovery.done
Inspect the contents of the database to ensure you have
recovered to the desired state. If not, restart the whole
process
6