SlideShare ist ein Scribd-Unternehmen logo
1 von 30
Downloaden Sie, um offline zu lesen
PITR made easy

                    Joshua Drake
         United States PostgreSQL
      Software in the Public Interest
            Command Prompt, Inc.
Creative Commons Attribution-Share Alike 3.0 United States License
What is PITR




Log shipping/Warm Standby/Replication
What can you do with it?




Simple asynchronous fail over scenarios
         Low impact backups
           Simple archiving
What can't you do with it?




       Read only slave
Why is PITR hard?




It was written by open source engineers.
Uses the many tools to one solution


               rsync?
                nfs?
              walmgr?
                scp?
            Push or pull?
           Something else?
What makes PITR easy?



           PITR tools
          BSD Licensed
         Written in Python
   (theoretically cross platform)
What is PITRTools


A simple wrapper around all the utilities you
              already have.

     ssh,rsync,pg_standby,postgresql

     Designed by a consultant (KISS)
PITRTools Features?


       Warm standby
        Cold Storage
   Fail over (actionable)
Arbitrary alerts (monitoring)
 Single protocol (security)
How does it work?


               success
Master                       Slave
                 else




                Queue
The process on the archiver/master



On the archiver/Master:
 ● Configure ssh key for postgres user to


   standby/slave
 ● Configure archiver.ini

 ● cmd_archiver -C /path/to/archiver.ini -I
The archiver


The archiver calls cmd_archive.py which calls rsync to “push” the
file to the slave or queue.

Usage: cmd_archiver [options] arg1 arg2

Options:
  -h, --help            show this help message and exit
  -F FILE, --file=FILE Archive file
  -C FILE, --config=FILE
                        the name of the archiver config file
  -f, --flush           Flush all remaining archives to slave
  -I, --init            Initialize master environment
The archiver config file


            Useful but obvious parameters


[DEFAULT]
state: online
pgdata: /var/lib/postgresql/8.3/main
rsync_bin: /usr/bin/rsync
rsync_version = 2 # Because RH ships old software
user: postgres
timeout: 10
debug: on
ssh_debug: off
The “other” archiver options



r_archivedir: /var/lib/postgresql/archive
l_archivedir: /var/lib/postgresql/archive
rsync_version = 2
slaves: 192.168.1.201,192.168.1.202
notify_ok: /var/lib/postgresql/etc/archiver_ok.sh
notify_warning: /var/lib/postgresql/etc/archiver_warning.sh
notify_critical: /var/lib/postgresql/etc/archiver_critical.sh
Configuring archiver with pitrtools


    Edit the postgresql.conf change:
●

    ● archive_mode to on

    ● archive_command to:

      ● cmd_archiver -C /path/to/archiver.ini -F %p

    ● restart postgresql

    ● apply cmd_standby.sql to database of pitr user


      (usually postgres)
      ● psql -U postgres < /path/to/cmd_standby/sql
cmd_standby.py

    Works in conjunction with pg_standby



    Supports failover



    Supports recovery to a point in time



    Included with 8.3, available for 8.1 and 8.2 (8.1


    is flaky)
The process on the slave/standby




On the standby/slave:
 ● Configure SSH key for postgres user to master

 ● Configure cmd_standby.ini
The standby configuration

[DEFAULT]
pgversion: 8.2
numarchives: 10
ssh: /usr/bin/ssh
rsync: /usr/bin/rsync
pg_standby: /usr/lib/postgresql/8.3/bin/pg_standby
pg_ctl: /usr/lib/postgresql/8.3/bin/pg_ctl
r_psql: /usr/lib/postgresql/8.3/bin/psql
port: 6000
master_public_ip: 192.168.3.254
master_local_ip: 127.0.0.1
user: postgres
debug: off
ssh_timeout: 30
Configuring the standby cont...


archivedir: /data2/pgsql/archive/
pgdata: /data1/pgsql/data/
postgresql_conf: /var/lib/postgresql/etc/postgresql.conf
pg_hba_conf: /var/lib/postgresql/etc/pg_hba.conf
notify_critical: /var/lib/postgresql/etc/standby_critical.sh
notify_warning: /var/lib/postgresql/etc/standby_warning.sh
notify_ok: /var/lib/postgresql/etc/standby_ok.sh
action_failover: /var/lib/postgresql/pitr_tools/failover.sh
Start the standby

Usage: cmd_standby [options] arg1 arg2

Options:
  -h, --help            show this help message and exit
  -A start|stop, --action=start|stop|stop_basebackup
                        Start or Stop PostgreSQL
  -B, --basebackup      Start/Stop a base backup
  -C FILE, --config=FILE
                        Name of the archiver config file
  -F VALUE, --failover=VALUE
                        If you are serious, set -F999
  -I, --dbinit          Use before -B
  -P, --ping            Is my master alive?
  -R TIMESTAMP, --recovertotime=TIMESTAMP
                        To restore to a specific point in time
  -S, --standby         Enter standby mode
Initializing the slave/standby

    Initialize environment




        cmd_standby -C /path/to/cmd_standby.ini -I
    

    Start base backup




        cmd_standby -C /path/to/cmd_standby.ini -B
    

    Start standby




        cmd_standby -C /path/to/cmd_standby.ini -S
    
Is the archiver working?

    With debug: on

Is the standby is working?
How do I?

    Use PITRTools to simplify backups?



    Take the archiver offline?



    Configure send_nsca (nagios) for alerts



    Get PITRTools



    Donate to PostgreSQL?

Simplify backups

On the standby/slave:



        cmd_standby -C
    
        /var/lib/postgresql/etc/cmd_standby.ini -Astop
        tar -czvf /backups/database.`date +%a`.tar.gz
    
        /var/lib/pgsql/data
        cmd_standby -C
    
        /var/lib/postgresql/etc/cmd_standby.ini -S


You could also use rsync with a network volume to make
the backup more efficient (after stopping the standby)
Take the archiver offline

    Edit /var/lib/postgresql/etc/cmd_archiver.ini



    [DEFAULT]
    ; online or offline
    state: offline


    When you are ready to bring it back online, just
       change to online. No restarts on archiver or
                     standby required.
Configure send_nsca

    Example ok.sh for send_nsca





#!/bin/sh
echo quot;shoggoth;CMD_ARCHIVER;0;Archived to Yuggquot;| 
/usr/sbin/send_nsca -to 10 -H monitor -d ';' -c /etc/
  nagios/send_nsca.cfg
Get PITRTools




svn co 
https://projects.commandprompt.com/public 
/pitrtools/repo
Donate to PostgreSQL

    For United States PostgreSQL:



     https://www.postgresql.us/donate

    For PostgreSQL Generally:



     http://www.postgresql.org/about/donate
Questions




  Hit me

Weitere ähnliche Inhalte

Was ist angesagt?

9 steps to install and configure postgre sql from source on linux
9 steps to install and configure postgre sql from source on linux9 steps to install and configure postgre sql from source on linux
9 steps to install and configure postgre sql from source on linux
chinkshady
 
RPM (LINUX)
RPM (LINUX)RPM (LINUX)
RPM (LINUX)
Raghu nath
 

Was ist angesagt? (20)

Bundling Packages and Deploying Applications with RPM
Bundling Packages and Deploying Applications with RPMBundling Packages and Deploying Applications with RPM
Bundling Packages and Deploying Applications with RPM
 
Linux fundamental - Chap 12 Hardware Management
Linux fundamental - Chap 12 Hardware ManagementLinux fundamental - Chap 12 Hardware Management
Linux fundamental - Chap 12 Hardware Management
 
101 apend. backups
101 apend. backups101 apend. backups
101 apend. backups
 
Setting up LAMP for Linux newbies
Setting up LAMP for Linux newbiesSetting up LAMP for Linux newbies
Setting up LAMP for Linux newbies
 
Performance comparison of Distributed File Systems on 1Gbit networks
Performance comparison of Distributed File Systems on 1Gbit networksPerformance comparison of Distributed File Systems on 1Gbit networks
Performance comparison of Distributed File Systems on 1Gbit networks
 
Linux fundamental - Chap 11 boot
Linux fundamental - Chap 11 bootLinux fundamental - Chap 11 boot
Linux fundamental - Chap 11 boot
 
9 steps to install and configure postgre sql from source on linux
9 steps to install and configure postgre sql from source on linux9 steps to install and configure postgre sql from source on linux
9 steps to install and configure postgre sql from source on linux
 
LSA2 - 01 Virtualization with KVM
LSA2 - 01 Virtualization with KVMLSA2 - 01 Virtualization with KVM
LSA2 - 01 Virtualization with KVM
 
Linux fundamental - Chap 08 proc
Linux fundamental - Chap 08 procLinux fundamental - Chap 08 proc
Linux fundamental - Chap 08 proc
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
Linux fundamental - Chap 09 pkg
Linux fundamental - Chap 09 pkgLinux fundamental - Chap 09 pkg
Linux fundamental - Chap 09 pkg
 
Make container without_docker_6-overlay-network_1
Make container without_docker_6-overlay-network_1 Make container without_docker_6-overlay-network_1
Make container without_docker_6-overlay-network_1
 
Kernel Recipes 2015 - Kernel dump analysis
Kernel Recipes 2015 - Kernel dump analysisKernel Recipes 2015 - Kernel dump analysis
Kernel Recipes 2015 - Kernel dump analysis
 
Importance of linux system fundamental in technical documentation reading
Importance of linux system fundamental in technical documentation readingImportance of linux system fundamental in technical documentation reading
Importance of linux system fundamental in technical documentation reading
 
LSA2 - 02 Control Groups
LSA2 - 02   Control GroupsLSA2 - 02   Control Groups
LSA2 - 02 Control Groups
 
GStreamer 101
GStreamer 101GStreamer 101
GStreamer 101
 
Chap 19 web
Chap 19 webChap 19 web
Chap 19 web
 
Linux Presentation
Linux PresentationLinux Presentation
Linux Presentation
 
RPM (LINUX)
RPM (LINUX)RPM (LINUX)
RPM (LINUX)
 
Linux: LVM
Linux: LVMLinux: LVM
Linux: LVM
 

Andere mochten auch

Researching postgresql
Researching postgresqlResearching postgresql
Researching postgresql
Fernando Ike
 

Andere mochten auch (9)

24/7 Monitoring and Alerting of PostgreSQL
24/7 Monitoring and Alerting of PostgreSQL24/7 Monitoring and Alerting of PostgreSQL
24/7 Monitoring and Alerting of PostgreSQL
 
Security Best Practices for your Postgres Deployment
Security Best Practices for your Postgres DeploymentSecurity Best Practices for your Postgres Deployment
Security Best Practices for your Postgres Deployment
 
Researching postgresql
Researching postgresqlResearching postgresql
Researching postgresql
 
Enterprise grade deployment and security with PostgreSQL
Enterprise grade deployment and security with PostgreSQLEnterprise grade deployment and security with PostgreSQL
Enterprise grade deployment and security with PostgreSQL
 
5 Tips to Simplify the Management of Your Postgres Database
5 Tips to Simplify the Management of Your Postgres Database5 Tips to Simplify the Management of Your Postgres Database
5 Tips to Simplify the Management of Your Postgres Database
 
PostgreSQL Conference: West 08
PostgreSQL Conference: West 08PostgreSQL Conference: West 08
PostgreSQL Conference: West 08
 
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
PostgreSQL Portland Performance Practice Project - Database Test 2 Filesystem...
 
PGDay India 2016
PGDay India 2016PGDay India 2016
PGDay India 2016
 
Managing Postgres with Ansible
Managing Postgres with AnsibleManaging Postgres with Ansible
Managing Postgres with Ansible
 

Ähnlich wie Pitr Made Easy

Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(pgconfsf)Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(pgconfsf)
Denish Patel
 
Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)
Denish Patel
 
Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)
Denish Patel
 
Out of the Box Replication in Postgres 9.4(PgConfUS)
Out of the Box Replication in Postgres 9.4(PgConfUS)Out of the Box Replication in Postgres 9.4(PgConfUS)
Out of the Box Replication in Postgres 9.4(PgConfUS)
Denish Patel
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and More
Matt Harrison
 
PHP selber bauen
PHP selber bauenPHP selber bauen
PHP selber bauen
Walter Ebert
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
Omar Reygaert
 

Ähnlich wie Pitr Made Easy (20)

Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(pgconfsf)Out of the Box Replication in Postgres 9.4(pgconfsf)
Out of the Box Replication in Postgres 9.4(pgconfsf)
 
Linux Common Command
Linux Common CommandLinux Common Command
Linux Common Command
 
Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)
 
Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)Out of the Box Replication in Postgres 9.4(PgCon)
Out of the Box Replication in Postgres 9.4(PgCon)
 
Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4Out of the box replication in postgres 9.4
Out of the box replication in postgres 9.4
 
Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)Out of the box replication in postgres 9.4(pg confus)
Out of the box replication in postgres 9.4(pg confus)
 
Out of the Box Replication in Postgres 9.4(PgConfUS)
Out of the Box Replication in Postgres 9.4(PgConfUS)Out of the Box Replication in Postgres 9.4(PgConfUS)
Out of the Box Replication in Postgres 9.4(PgConfUS)
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and More
 
Streaming replication in practice
Streaming replication in practiceStreaming replication in practice
Streaming replication in practice
 
OSBConf 2015 | Backups with rdiff backup and rsnapshot by christoph mitasch &...
OSBConf 2015 | Backups with rdiff backup and rsnapshot by christoph mitasch &...OSBConf 2015 | Backups with rdiff backup and rsnapshot by christoph mitasch &...
OSBConf 2015 | Backups with rdiff backup and rsnapshot by christoph mitasch &...
 
PGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRest
PGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRestPGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRest
PGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRest
 
Pro PostgreSQL, OSCon 2008
Pro PostgreSQL, OSCon 2008Pro PostgreSQL, OSCon 2008
Pro PostgreSQL, OSCon 2008
 
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
Continuous Infrastructure: Modern Puppet for the Jenkins Project - PuppetConf...
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System Administrators
 
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
 
LCU14 201- Binary Analysis Tools
LCU14 201- Binary Analysis ToolsLCU14 201- Binary Analysis Tools
LCU14 201- Binary Analysis Tools
 
PHP selber bauen
PHP selber bauenPHP selber bauen
PHP selber bauen
 
PLAM 2015 - Evolving Backups Strategy, Devploying pyxbackup
PLAM 2015 - Evolving Backups Strategy, Devploying pyxbackupPLAM 2015 - Evolving Backups Strategy, Devploying pyxbackup
PLAM 2015 - Evolving Backups Strategy, Devploying pyxbackup
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
 
Ceph Day Melbourne - Troubleshooting Ceph
Ceph Day Melbourne - Troubleshooting Ceph Ceph Day Melbourne - Troubleshooting Ceph
Ceph Day Melbourne - Troubleshooting Ceph
 

Mehr von Joshua Drake

Mehr von Joshua Drake (12)

Defining Your Goal: Starting Your Own Business
Defining Your Goal: Starting Your Own BusinessDefining Your Goal: Starting Your Own Business
Defining Your Goal: Starting Your Own Business
 
Defining Your Goal: Starting Your Own Business
Defining Your Goal: Starting Your Own BusinessDefining Your Goal: Starting Your Own Business
Defining Your Goal: Starting Your Own Business
 
An evening with Postgresql
An evening with PostgresqlAn evening with Postgresql
An evening with Postgresql
 
Dumb Simple PostgreSQL Performance (NYCPUG)
Dumb Simple PostgreSQL Performance (NYCPUG)Dumb Simple PostgreSQL Performance (NYCPUG)
Dumb Simple PostgreSQL Performance (NYCPUG)
 
East09 Keynote
East09 KeynoteEast09 Keynote
East09 Keynote
 
Go Replicator
Go ReplicatorGo Replicator
Go Replicator
 
Introduction to PgBench
Introduction to PgBenchIntroduction to PgBench
Introduction to PgBench
 
Developing A Procedural Language For Postgre Sql
Developing A Procedural Language For Postgre SqlDeveloping A Procedural Language For Postgre Sql
Developing A Procedural Language For Postgre Sql
 
PostgreSQL Conference: East 08
PostgreSQL Conference: East 08PostgreSQL Conference: East 08
PostgreSQL Conference: East 08
 
What MySQL can learn from PostgreSQL
What MySQL can learn from PostgreSQLWhat MySQL can learn from PostgreSQL
What MySQL can learn from PostgreSQL
 
Northern Arizona State ACM talk (10/08)
Northern Arizona State ACM talk (10/08)Northern Arizona State ACM talk (10/08)
Northern Arizona State ACM talk (10/08)
 
Plproxy
PlproxyPlproxy
Plproxy
 

KĂźrzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

KĂźrzlich hochgeladen (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 

Pitr Made Easy

  • 1. PITR made easy Joshua Drake United States PostgreSQL Software in the Public Interest Command Prompt, Inc. Creative Commons Attribution-Share Alike 3.0 United States License
  • 2. What is PITR Log shipping/Warm Standby/Replication
  • 3. What can you do with it? Simple asynchronous fail over scenarios Low impact backups Simple archiving
  • 4. What can't you do with it? Read only slave
  • 5. Why is PITR hard? It was written by open source engineers.
  • 6. Uses the many tools to one solution rsync? nfs? walmgr? scp? Push or pull? Something else?
  • 7. What makes PITR easy? PITR tools BSD Licensed Written in Python (theoretically cross platform)
  • 8. What is PITRTools A simple wrapper around all the utilities you already have. ssh,rsync,pg_standby,postgresql Designed by a consultant (KISS)
  • 9. PITRTools Features? Warm standby Cold Storage Fail over (actionable) Arbitrary alerts (monitoring) Single protocol (security)
  • 10. How does it work? success Master Slave else Queue
  • 11. The process on the archiver/master On the archiver/Master: ● Configure ssh key for postgres user to standby/slave ● Configure archiver.ini ● cmd_archiver -C /path/to/archiver.ini -I
  • 12. The archiver The archiver calls cmd_archive.py which calls rsync to “push” the file to the slave or queue. Usage: cmd_archiver [options] arg1 arg2 Options: -h, --help show this help message and exit -F FILE, --file=FILE Archive file -C FILE, --config=FILE the name of the archiver config file -f, --flush Flush all remaining archives to slave -I, --init Initialize master environment
  • 13. The archiver config file Useful but obvious parameters [DEFAULT] state: online pgdata: /var/lib/postgresql/8.3/main rsync_bin: /usr/bin/rsync rsync_version = 2 # Because RH ships old software user: postgres timeout: 10 debug: on ssh_debug: off
  • 14. The “other” archiver options r_archivedir: /var/lib/postgresql/archive l_archivedir: /var/lib/postgresql/archive rsync_version = 2 slaves: 192.168.1.201,192.168.1.202 notify_ok: /var/lib/postgresql/etc/archiver_ok.sh notify_warning: /var/lib/postgresql/etc/archiver_warning.sh notify_critical: /var/lib/postgresql/etc/archiver_critical.sh
  • 15. Configuring archiver with pitrtools Edit the postgresql.conf change: ● ● archive_mode to on ● archive_command to: ● cmd_archiver -C /path/to/archiver.ini -F %p ● restart postgresql ● apply cmd_standby.sql to database of pitr user (usually postgres) ● psql -U postgres < /path/to/cmd_standby/sql
  • 16. cmd_standby.py Works in conjunction with pg_standby  Supports failover  Supports recovery to a point in time  Included with 8.3, available for 8.1 and 8.2 (8.1  is flaky)
  • 17. The process on the slave/standby On the standby/slave: ● Configure SSH key for postgres user to master ● Configure cmd_standby.ini
  • 18. The standby configuration [DEFAULT] pgversion: 8.2 numarchives: 10 ssh: /usr/bin/ssh rsync: /usr/bin/rsync pg_standby: /usr/lib/postgresql/8.3/bin/pg_standby pg_ctl: /usr/lib/postgresql/8.3/bin/pg_ctl r_psql: /usr/lib/postgresql/8.3/bin/psql port: 6000 master_public_ip: 192.168.3.254 master_local_ip: 127.0.0.1 user: postgres debug: off ssh_timeout: 30
  • 19. Configuring the standby cont... archivedir: /data2/pgsql/archive/ pgdata: /data1/pgsql/data/ postgresql_conf: /var/lib/postgresql/etc/postgresql.conf pg_hba_conf: /var/lib/postgresql/etc/pg_hba.conf notify_critical: /var/lib/postgresql/etc/standby_critical.sh notify_warning: /var/lib/postgresql/etc/standby_warning.sh notify_ok: /var/lib/postgresql/etc/standby_ok.sh action_failover: /var/lib/postgresql/pitr_tools/failover.sh
  • 20. Start the standby Usage: cmd_standby [options] arg1 arg2 Options: -h, --help show this help message and exit -A start|stop, --action=start|stop|stop_basebackup Start or Stop PostgreSQL -B, --basebackup Start/Stop a base backup -C FILE, --config=FILE Name of the archiver config file -F VALUE, --failover=VALUE If you are serious, set -F999 -I, --dbinit Use before -B -P, --ping Is my master alive? -R TIMESTAMP, --recovertotime=TIMESTAMP To restore to a specific point in time -S, --standby Enter standby mode
  • 21. Initializing the slave/standby Initialize environment  cmd_standby -C /path/to/cmd_standby.ini -I  Start base backup  cmd_standby -C /path/to/cmd_standby.ini -B  Start standby  cmd_standby -C /path/to/cmd_standby.ini -S 
  • 22. Is the archiver working? With debug: on 
  • 23. Is the standby is working?
  • 24. How do I? Use PITRTools to simplify backups?  Take the archiver offline?  Configure send_nsca (nagios) for alerts  Get PITRTools  Donate to PostgreSQL? 
  • 25. Simplify backups On the standby/slave:  cmd_standby -C  /var/lib/postgresql/etc/cmd_standby.ini -Astop tar -czvf /backups/database.`date +%a`.tar.gz  /var/lib/pgsql/data cmd_standby -C  /var/lib/postgresql/etc/cmd_standby.ini -S You could also use rsync with a network volume to make the backup more efficient (after stopping the standby)
  • 26. Take the archiver offline Edit /var/lib/postgresql/etc/cmd_archiver.ini  [DEFAULT] ; online or offline state: offline When you are ready to bring it back online, just change to online. No restarts on archiver or standby required.
  • 27. Configure send_nsca Example ok.sh for send_nsca  #!/bin/sh echo quot;shoggoth;CMD_ARCHIVER;0;Archived to Yuggquot;| /usr/sbin/send_nsca -to 10 -H monitor -d ';' -c /etc/ nagios/send_nsca.cfg
  • 28. Get PITRTools svn co https://projects.commandprompt.com/public /pitrtools/repo
  • 29. Donate to PostgreSQL For United States PostgreSQL:   https://www.postgresql.us/donate For PostgreSQL Generally:   http://www.postgresql.org/about/donate