postgres point-in-time recovery

Post on 11-Apr-2017

929 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

© 2015 EnterpriseDB Corporation. All rights reserved. 1

How to get your data back in Postgres – Point-in-Time Recovery (PITR) explained For more information on Postgres PITR please email sales@enterprisedb.com or visit www.enterprisedb.com

© 2015 EnterpriseDB Corporation. All rights reserved. 2

Agenda

•  Introduction •  Business Impact vs Cost •  Downtime Scenarios

•  Backup Methods •  Point-In-Time Recovery •  Summary

© 2015 EnterpriseDB Corporation. All rights reserved. 3

•  Disaster recovery strategies are key to the reliable operation of any business-critical environment.

•  Backup and recovery plans must consider various failure scenarios and compliance requirements, including device failure, operator error, and data corruption.

Introduction

© 2015 EnterpriseDB Corporation. All rights reserved. 4

Business Impact vs Cost

•  How long will recovery take? •  How long do we need to store backup data? •  How much will data storage cost?

•  Will an outage effect our brand? •  Can any part of the database remain operational whilst

I recover elsewhere?

•  Do I know when the problem I am recovering from started?

© 2015 EnterpriseDB Corporation. All rights reserved. 5

Downtime Scenarios

© 2015 EnterpriseDB Corporation. All rights reserved. 6

•  As with any database, a Postgres database should be backed up regularly. •  There are three fundamentally different approaches to backing up

Postgres data: −  SQL dump −  File system level backup −  Continuous archiving

Backup Methods

© 2015 EnterpriseDB Corporation. All rights reserved. 7

•  Generate a text file with SQL commands •  Postgres provides the utility program pg_dump for this purpose. •  pg_dump does not block readers nor writers.

•  Dumps created by pg_dump are internally consistent, that is, the dump represents a snapshot of the database as of the time pg_dump begins running.

•  Syntax: pg_dump [options] [dbname]

Backup – SQL Dump

© 2015 EnterpriseDB Corporation. All rights reserved. 8

Backup – Entire Cluster – SQL Dump

•  pg_dumpall is used to dump an entire database cluster in plain-text SQL format

•  pg_dumpall dumps global objects: users, groups, and associated permissions

•  Use PSQL to restore

•  Syntax: pg_dumpall [options] > filename.backup

© 2015 EnterpriseDB Corporation. All rights reserved. 9

•  Copy Postgres files from the file system. •  You can use whatever method you prefer for doing usual file system

backups, for example: tar -cvf backup.tar /usr/local/pgsql/data

•  The database server must be shut down in order to get a usable backup. •  File system backups only work for complete backups and recovery of an

entire database cluster.

Backup – Cold Backup

© 2015 EnterpriseDB Corporation. All rights reserved. 10

•  Database can stay operational during backup. •  Postgres maintains WAL logs for all transactions in the pg_xlog directory. •  When full, Postgres automatically switches WAL logs.

•  Continuous archiving can be setup to keep a copy of switched WAL logs which can later be used for recovery.

•  Enables online file system backup of a database cluster.

•  Requirements: wal_level = archive archive_mode = on archive_command = …

Backup – Hot Backup

© 2015 EnterpriseDB Corporation. All rights reserved. 11

1.  Connect using psql and issue SELECT pg_start_backup(‘any useful label’);

2.  Use a standard file system backup utility to back up the data directory.

3.  Connect using psql and issue SELECT pg_stop_backup();4.  Ensure to continuously archive WAL logs.

Online Base Backup

© 2015 EnterpriseDB Corporation. All rights reserved. 12

•  pg_basebackup takes a base backup of a Postgres cluster. •  Backup can be used to setup a standby with streaming replication and a

Point-In-Time Recovery (PITR).

•  pg_basebackup takes a binary copy of the database cluster files. •  pg_basebackup puts the database in and out of backup mode.

Online Base Backup using pg_basebackup

© 2015 EnterpriseDB Corporation. All rights reserved. 13

•  Point-in-time recovery (PITR) is the ability to restore a database cluster up to the present or to a specified point of time in the past.

•  Uses a full database cluster backup and applies the WAL logs.

•  Must be configured before it is needed. WAL log archiving must be enabled.

•  Must have information of when you want to recover to.

Point-in-Time Recovery

© 2015 EnterpriseDB Corporation. All rights reserved. 14

Point-in-Time Recovery Demo

© 2015 EnterpriseDB Corporation. All rights reserved. 15

•  pause_at_recovery_target = true•  hot_standby = on (if using pause_at_recovery_target) •  SELECT pg_is_xlog_replay_paused();•  SELECT pg_xlog_replay_resume();•  SELECT pg_catalog.pg_current_xlog_location();•  SELECT pg_xlogfile_name(’output from above command');•  SELECT pg_create_restore_point('webinar_restore');

Point-In-Time Recovery Help

© 2015 EnterpriseDB Corporation. All rights reserved. 16

Summary

•  Introduction •  Business Impact vs Cost •  Backup and Recovery Methods

−  SQL Dump −  Cold Backup (offline Backup) −  Hot Backup (online Backup) −  Continuous Archiving

•  Point-In Time Recovery •  Demo

© 2015 EnterpriseDB Corporation. All rights reserved. 17

•  EDB Postgres Advanced Server 9.5 Downloadhttp://www.enterprisedb.com/downloads/postgres-postgresql-downloads

•  Continuous Archiving and Point-in-Time Recovery (PITR) http://www.postgresql.org/docs/current/static/continuous-archiving.html

•  pg_dump http://www.postgresql.org/docs/9.5/static/app-pgdump.html

•  pg_dumpall http://www.postgresql.org/docs/current/static/app-pg-dumpall.html

•  pg_basebackup http://www.postgresql.org/docs/current/static/app-pgbasebackup.html

Contact sales@enterprisedb.com for more information on Postgres PITR

Resources

© 2015 EnterpriseDB Corporation. All rights reserved. 18

•  Take advantage of the most convenient training that best fits your learning style and get Postgres certified! −  EDB offers Classroom & on-site training globally −  Live virtual training courses can be taken from any location and maintains live communication

with the instructor to guide you and answer questions quickly.

•  EDB’s eSubscriptions −  This annual subscription provides access to the entire EDB library of on-demand training

courses for convenient access and training any time.

•  Postgres Training Credits (PTC) −  Training credits provide the flexibility to pre-purchase blocks of training credits that can be spent

on any combination of our training delivery methods. It is a convenient way to receive training with a built-in price discount.

•  Earn an Associate-level or Professional-level Postgres Certification

To learn more about EDB’s training schedule, Certification, eSubscriptions and Training Credits email training@enterprisedb.com

Sharpen your skills with Training and Certification

© 2015 EnterpriseDB Corporation. All rights reserved. 19

top related