SlideShare uma empresa Scribd logo
1 de 7
Baixar para ler offline
Backup-Recovery
in PostgreSQL
Logical Backup, Physical Backup and PITR

15/7/2013
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
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
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
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
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
Sameer Kumar
Ashnik Pte Ltd, Singapore
www.ashnik.com | sameer.kumar@ashnik.com

7

Mais conteúdo relacionado

Mais de Ashnikbiz

Mais de Ashnikbiz (20)

Deploy and automate ‘Secrets Management’ for a multi-cloud environment
Deploy and automate ‘Secrets Management’ for a multi-cloud environmentDeploy and automate ‘Secrets Management’ for a multi-cloud environment
Deploy and automate ‘Secrets Management’ for a multi-cloud environment
 
Deploy, move and manage Postgres across cloud platforms
Deploy, move and manage Postgres across cloud platformsDeploy, move and manage Postgres across cloud platforms
Deploy, move and manage Postgres across cloud platforms
 
Deploy, move and manage Postgres across cloud platforms
Deploy, move and manage Postgres across cloud platformsDeploy, move and manage Postgres across cloud platforms
Deploy, move and manage Postgres across cloud platforms
 
The Best Approach For Multi-cloud Infrastructure Provisioning-2
The Best Approach For Multi-cloud Infrastructure Provisioning-2The Best Approach For Multi-cloud Infrastructure Provisioning-2
The Best Approach For Multi-cloud Infrastructure Provisioning-2
 
The Best Approach For Multi-cloud Infrastructure Provisioning
The Best Approach For Multi-cloud Infrastructure ProvisioningThe Best Approach For Multi-cloud Infrastructure Provisioning
The Best Approach For Multi-cloud Infrastructure Provisioning
 
Which PostgreSQL is right for your multi cloud strategy? P2
Which PostgreSQL is right for your multi cloud strategy? P2Which PostgreSQL is right for your multi cloud strategy? P2
Which PostgreSQL is right for your multi cloud strategy? P2
 
Which PostgreSQL is right for your multi cloud strategy? P1
Which PostgreSQL is right for your multi cloud strategy? P1Which PostgreSQL is right for your multi cloud strategy? P1
Which PostgreSQL is right for your multi cloud strategy? P1
 
Reduce the complexities of managing Kubernetes clusters anywhere 2
Reduce the complexities of managing Kubernetes clusters anywhere 2Reduce the complexities of managing Kubernetes clusters anywhere 2
Reduce the complexities of managing Kubernetes clusters anywhere 2
 
Reduce the complexities of managing Kubernetes clusters anywhere
Reduce the complexities of managing Kubernetes clusters anywhereReduce the complexities of managing Kubernetes clusters anywhere
Reduce the complexities of managing Kubernetes clusters anywhere
 
Enhance your multi-cloud application performance using Redis Enterprise P2
Enhance your multi-cloud application performance using Redis Enterprise P2Enhance your multi-cloud application performance using Redis Enterprise P2
Enhance your multi-cloud application performance using Redis Enterprise P2
 
Enhance your multi-cloud application performance using Redis Enterprise P1
Enhance your multi-cloud application performance using Redis Enterprise P1Enhance your multi-cloud application performance using Redis Enterprise P1
Enhance your multi-cloud application performance using Redis Enterprise P1
 
Gain multi-cloud versatility with software load balancing designed for cloud-...
Gain multi-cloud versatility with software load balancing designed for cloud-...Gain multi-cloud versatility with software load balancing designed for cloud-...
Gain multi-cloud versatility with software load balancing designed for cloud-...
 
Gain multi-cloud versatility with software load balancing designed for cloud-...
Gain multi-cloud versatility with software load balancing designed for cloud-...Gain multi-cloud versatility with software load balancing designed for cloud-...
Gain multi-cloud versatility with software load balancing designed for cloud-...
 
Enterprise-class security with PostgreSQL - 1
Enterprise-class security with PostgreSQL - 1Enterprise-class security with PostgreSQL - 1
Enterprise-class security with PostgreSQL - 1
 
Enterprise-class security with PostgreSQL - 2
Enterprise-class security with PostgreSQL - 2Enterprise-class security with PostgreSQL - 2
Enterprise-class security with PostgreSQL - 2
 
Securing Your CI Pipeline with HashiCorp Vault - P2
Securing Your CI Pipeline with HashiCorp Vault - P2Securing Your CI Pipeline with HashiCorp Vault - P2
Securing Your CI Pipeline with HashiCorp Vault - P2
 
Build robust streaming data pipelines with MongoDB and Kafka P2
Build robust streaming data pipelines with MongoDB and Kafka P2Build robust streaming data pipelines with MongoDB and Kafka P2
Build robust streaming data pipelines with MongoDB and Kafka P2
 
Build robust streaming data pipelines with MongoDB and Kafka
Build robust streaming data pipelines with MongoDB and KafkaBuild robust streaming data pipelines with MongoDB and Kafka
Build robust streaming data pipelines with MongoDB and Kafka
 
Kubernetes with Docker Enterprise for multi and hybrid cloud strategy
Kubernetes with Docker Enterprise for multi and hybrid cloud strategyKubernetes with Docker Enterprise for multi and hybrid cloud strategy
Kubernetes with Docker Enterprise for multi and hybrid cloud strategy
 
How EDB Postgres helps achieve business continuity for database?
How EDB Postgres helps achieve business continuity for database?How EDB Postgres helps achieve business continuity for database?
How EDB Postgres helps achieve business continuity for database?
 

Último

Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
FIDO Alliance
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 

Último (20)

Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Your enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4jYour enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4j
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 

Backup recovery - PostgreSQL Database

  • 1. Backup-Recovery in PostgreSQL Logical Backup, Physical Backup and PITR 15/7/2013
  • 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. 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
  • 7. Sameer Kumar Ashnik Pte Ltd, Singapore www.ashnik.com | sameer.kumar@ashnik.com 7