56
giovedì 4 ottobre 12

giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

  • Upload
    dokhanh

  • View
    224

  • Download
    0

Embed Size (px)

Citation preview

Page 1: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

giovedì 4 ottobre 12

Page 2: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

GABRIELE BARTOLINIPostgreSQL Sessions - Paris, 4 October 2012

giovedì 4 ottobre 12

Page 3: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

GABRIELE BARTOLINI

• Co-Founder and Manager of 2ndQuadrant Italia

•Data Architect, Business critical environments

•Data warehousing

• Co-Founder Italian PostgreSQL Users Group

• Co-Founder PostgreSQL Europe

• PostgreSQL Contributor and Advocate

giovedì 4 ottobre 12

Page 4: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

INGRES

Database

French Painter

Now

19th century

giovedì 4 ottobre 12

Page 5: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

BARTOLINI

Myself

Italian Sculptor(same family tree)

Now, here

19th century

giovedì 4 ottobre 12

Page 6: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

1799PARIS

BARTOLINIINGRES

2012PARIS

BARTOLINIPOSTGRES

giovedì 4 ottobre 12

Page 7: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

DISCLAIMERThis talk assumes you are familiar with disaster

recovery concepts and PostgreSQL implementation of Point In Time Recovery

giovedì 4 ottobre 12

Page 8: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

BE AWAREIn 2ndQuadrant, all these concepts usually fit in a 2 day workshop on Disaster Recovery and a 1 day

workshop on Barman alone

giovedì 4 ottobre 12

Page 9: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

MENU D'AUJOURD'HUI

• Business continuity / Disaster recovery for databases

•Disaster recovery with Barman for PostgreSQL

giovedì 4 ottobre 12

Page 11: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

BUSINESS CONTINUITYactivity performed by an organization to ensure that critical business functions will be available to customers, suppliers,

regulators, and other entities that must have access to those functions - Wikipedia

giovedì 4 ottobre 12

Page 12: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

INFORMATION TECHNOLOGY

• Business continuity

• High availability

• Disaster recovery

giovedì 4 ottobre 12

Page 13: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

LAW REQUIREMENTSIn Italy, the “Codice dell’Amministrazione Digitale” defines business continuity requirements for public

administrations

giovedì 4 ottobre 12

Page 14: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

DISASTER(touch wood)

system/hardware failuresaccidental errors

disaster

giovedì 4 ottobre 12

Page 18: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

“Plans are worthless, but planning is everything. There is a very great distinction

because when you are planning for an emergency you must start with this one thing: the very definition

of "emergency" is that it is unexpected, therefore it is not going to happen the way you are

planning.”- Dwight D. Eisenhower

giovedì 4 ottobre 12

Page 21: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

REQUIREMENTS

• Automated backups

• Notifications (anomalies)

• Frequency of backups

• Retention policies

• Data protection

• Availability for recovery

giovedì 4 ottobre 12

Page 22: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

POSTGRES BACKUP

• Hot backup

•MVCC

• Logical Backup

• pg_dump

• Physical Backup

• Full backup (base backup)

•Differential backup (WAL)

giovedì 4 ottobre 12

Page 23: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

TRADITIONAL DRWITH POSTGRESQL

• PostgreSQL primitives for DR are robust and reliable

• High level skills

•DBA

• Sysadmins

• Custom scripts

• Hard to integrate in:

• Backup solutions

•Disaster Recovery plans

• Hard to test!

giovedì 4 ottobre 12

Page 24: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

EXISTING TOOLS

•Omni-PITR

•WAL centric

•WALmgr

•WAL centric

• pg-rman

• Server centric

•WAL-E

• EC2 centric, but ...

• good

• came later

giovedì 4 ottobre 12

Page 25: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

NONE FOR DRNone of them was a pure disaster recovery solution.

We wanted something similar to Oracle’s RMAN.

giovedì 4 ottobre 12

Page 26: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

FILLING A HOLEThe lack of a DR solution is a barrier towards the adoption

of PostgreSQL from Oracle users’ point of view.

giovedì 4 ottobre 12

Page 27: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

DESIDERATA

• Hot, Full, Differential and incremental backups

•Multiple servers

• Remote backup & recovery

• Backup catalogues

• Retention policies

• Archival and compression

•WAL segments

• Periodical backups

• Automation

• Integration

• Usability

giovedì 4 ottobre 12

Page 28: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

WWW.PGBARMAN.ORG

giovedì 4 ottobre 12

Page 30: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

BARMAN

• GNU GPL 3

• Hosted on Sourceforge.net

• Python 2.6/2.7

• PostgreSQL 8.4, 9.0, 9.1, 9.2

• PyPI package

• RPM package

•Debian package (soon)

•Designed, developed, maintained by 2ndQuadrant

giovedì 4 ottobre 12

Page 31: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

Postgres Postgres Postgres

Barman

LAN, centralised architecture

Barman

LAN, hybrid architecture

tape

giovedì 4 ottobre 12

Page 32: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

Postgres

Barman

Continuous archiving(WAL shipping via SSH)

SSH commandsSQL commands

giovedì 4 ottobre 12

Page 33: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

secure channel

Postgres Barman

WAL cron

Barman’sWAL archive

giovedì 4 ottobre 12

Page 34: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

Postgres

Full backup - Sat 1, 4AM

Full backup - Sat 8, 4AM

Full backup - Sat 15, 4AM

Full backup - Sat 22, 4AM

Barman

Periodical backup (weekly)Differential backupBackup catalogue

giovedì 4 ottobre 12

Page 35: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

CONVENTION OVER CONFIGURATION

global/per server optionsdefault directory layout

giovedì 4 ottobre 12

Page 36: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

CONFIGURATION FILE

[barman]barman_home = /srv/barmanbarman_user = barmanlog_file = /var/log/barman/barman.loglog_level = NOTICEcompression = gzip

[production]description = Production PostgreSQLssh_command = ssh pg.2ndQuadrant.itconninfo = host=pg.2ndQuadrant.it user=postgrescompression = bzip2

giovedì 4 ottobre 12

Page 37: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

CONVENTIONAL DIRECTORIES FOR BARMAN

• barman_home (/srv/barman)

• server directory (/srv/barman/production)

• base directory (/srv/barman/production/base)

•WAL directory (/srv/barman/production/wals)

• incoming directory (/srv/barman/production/incoming)

giovedì 4 ottobre 12

Page 38: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

MULTI-SERVER CONFIGURATION

[barman]; General configuration; …[server_one]; Configuration for Server 1; …[server_two]; Configuration for Server 2; …[server_X]; …

giovedì 4 ottobre 12

Page 39: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

GLOBAL COMMANDS

• List of managed servers

• barman list-server

• Maintenance operations

• barman cron

giovedì 4 ottobre 12

Page 40: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

SERVER COMMANDS

• Information and diagnostics

• barman status

• barman check

• barman show-server

• barman list-backup

• Backup control

• Recovery control

giovedì 4 ottobre 12

Page 41: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

giovedì 4 ottobre 12

Page 42: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

BACKUP CONTROL

• barman backup

• barman show-backup

• barman list-files

• standalone, data, wal, full

• barman delete

giovedì 4 ottobre 12

Page 43: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

giovedì 4 ottobre 12

Page 44: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

SHOW BACKUP

• General

• Server name, Postgres version, status, ...

• Base backup

• Start/End time, first/last WAL, disk usage, ...

• WAL

•Number of associated files

• disk usage

• Context

• Previous/Next backup

giovedì 4 ottobre 12

Page 45: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

giovedì 4 ottobre 12

Page 46: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

RECOVERY CONTROL

• Recovery target (full / point in time)

• Local recovery

• barman recover

• Remote recovery

• barman recover --remote-ssh-command

giovedì 4 ottobre 12

Page 47: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

ADVANCED RECOVERY

• Point In Time Recovery

• --target-time = TIME

• --target-xid = XID

• Relocation of tablespaces

• --tablespace NAME:LOCATION [...]

giovedì 4 ottobre 12

Page 48: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

COMMON USE CASES

• Accidental errors recovery

•Disaster recovery

• Sandbox server (BI, staging, ...)

giovedì 4 ottobre 12

Page 49: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

giovedì 4 ottobre 12

Page 50: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

SPONSOR A FEATURE!

• Retention policies

• Sandbox recovery

• Replication protocol support (client / server)

• Incremental backup

• reduce backup time and size

giovedì 4 ottobre 12

Page 51: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

RETENTION POLICY CONFIGURATION

; Base backup retention policyretention_policy = 'redundancy 3'retention_policy = 'recovery window of 30 days'

; WAL retention policywal_retention_policy = 'base' ;wal_retention_policy = 'recovery window of 14 days'

giovedì 4 ottobre 12

Page 52: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

OUR COMMITMENT

• Keep it open source

• Reinvest money from sale of DR turnkey solutions in R&D

• Support and maintain RPM/Debian packages

• Accept sponsorships for new features development

giovedì 4 ottobre 12

Page 53: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

CONCLUSIONS

• Hides complexity of PITR / Keeps unaltered PITR strenghts

•Not invasive

• Fosters migrations from Oracle

• “Standard de facto” for PostgreSQL Disaster Recovery

• Advice: plan for DR (if you have not done it yet)

giovedì 4 ottobre 12

Page 54: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

QUESTIONS?

[email protected] : _GBartolini_www.pgbarman.org

giovedì 4 ottobre 12

Page 55: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

MERCI BEAUCOUP!

giovedì 4 ottobre 12

Page 56: giovedì 4 ottobre 12 - PostgreSQL Sessions · • Disaster recovery with Barman for PostgreSQL giovedì 4 ottobre 12. PART I Business continuity / Disaster recovery for databases

LICENSE

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Copyright (c) 2012 - 2ndQuadrant.it

giovedì 4 ottobre 12