Backup recovery - PostgreSQL Database

1,370 views

Published on

A quick synopsis of Backup-Recovery
in PostgreSQL - Logical Backup, Physical Backup and PITR

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,370
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
29
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Backup recovery - PostgreSQL Database

  1. 1. Backup-Recovery in PostgreSQL Logical Backup, Physical Backup and PITR 15/7/2013
  2. 2. Available Backup and Recovery Tools • • • • • pg_basebackup Compressed backup Recovery with WAL and archived WAL Recover to the point of crash Point in Time Recover to recover from data corruption due to a bad query/batch CONFIDENTIAL © 2012 EnterpriseDB. All rights reserved. Confidential information, for internal use only Physical and Logical Backup Logical Backup using pg_dump Instance level logical backup using pg_dumpall Table level, Schema level or DB level logical backup Different file formats available for pg_dump backup pg_restore to restore binary backup with pg_dump Physical Backups 2
  3. 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. 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. 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. 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
  7. 7. Sameer Kumar Ashnik Pte Ltd, Singapore www.ashnik.com | sameer.kumar@ashnik.com 7

×