SlideShare uma empresa Scribd logo
1 de 27
Baixar para ler offline
PITR made easy




       Joshua Drake
 United States PostgreSQL
Software in the Public Interest
   Command Prompt, Inc.
What is PITR




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




Simple asynchornous failover scenarios
         Low impact backups
           Simple archivals
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
Features?


       Warm standby
        Cold Storage
   Fail over (actionable)
Arbitrary alerts (monitoring)
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

 ● 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
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
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


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

 ● Configure cmd_standby.ini

 ● 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
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
Is the archiver working?
Is the standby is working?
How do I?

   Use PITRTools to simplify backups?
   Take the archiver offline?
   Configure send_nsca (nagios) for alerts
   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 "shoggoth;CMD_ARCHIVER;0;Archived to Yugg"| 
/usr/sbin/send_nsca -to 10 -H monitor -d ';' -c /etc/
  nagios/send_nsca.cfg
Donate to PostgreSQL

   For United States PostgreSQL:
     https://www.postgresql.us/donate

   For PostgreSQL Generally:
     http://www.postgresql.org/about/donate
Questions




  Hit me

Mais conteúdo relacionado

Mais procurados

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 networksMarian Marinov
 
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 readingKenny (netman)
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Jian-Hong Pan
 
Docker e postgresql
Docker e postgresqlDocker e postgresql
Docker e postgresqlFernando Ike
 
Linux fundamental - Chap 12 Hardware Management
Linux fundamental - Chap 12 Hardware ManagementLinux fundamental - Chap 12 Hardware Management
Linux fundamental - Chap 12 Hardware ManagementKenny (netman)
 
Talk 160920 @ Cat System Workshop
Talk 160920 @ Cat System WorkshopTalk 160920 @ Cat System Workshop
Talk 160920 @ Cat System WorkshopQuey-Liang Kao
 
LSA2 - 01 Virtualization with KVM
LSA2 - 01 Virtualization with KVMLSA2 - 01 Virtualization with KVM
LSA2 - 01 Virtualization with KVMMarian Marinov
 
LSA2 - 02 Control Groups
LSA2 - 02   Control GroupsLSA2 - 02   Control Groups
LSA2 - 02 Control GroupsMarian Marinov
 
Using cgroups in docker container
Using cgroups in docker containerUsing cgroups in docker container
Using cgroups in docker containerVinay Jindal
 
Recipe of a linux Live CD (archived)
Recipe of a linux Live CD (archived)Recipe of a linux Live CD (archived)
Recipe of a linux Live CD (archived)Bud Siddhisena
 
Linux fundamental - Chap 11 boot
Linux fundamental - Chap 11 bootLinux fundamental - Chap 11 boot
Linux fundamental - Chap 11 bootKenny (netman)
 
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 Sam Kim
 
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 linuxchinkshady
 
Linux fundamental - Chap 08 proc
Linux fundamental - Chap 08 procLinux fundamental - Chap 08 proc
Linux fundamental - Chap 08 procKenny (netman)
 
Lecture 6 Kernel Debugging + Ports Development
Lecture 6 Kernel Debugging + Ports DevelopmentLecture 6 Kernel Debugging + Ports Development
Lecture 6 Kernel Debugging + Ports DevelopmentMohammed Farrag
 
GStreamer 101
GStreamer 101GStreamer 101
GStreamer 101yuvipanda
 

Mais procurados (20)

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
 
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
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021
 
Docker e postgresql
Docker e postgresqlDocker e postgresql
Docker e postgresql
 
Linux fundamental - Chap 12 Hardware Management
Linux fundamental - Chap 12 Hardware ManagementLinux fundamental - Chap 12 Hardware Management
Linux fundamental - Chap 12 Hardware Management
 
Chap 19 web
Chap 19 webChap 19 web
Chap 19 web
 
testing-nfs
testing-nfstesting-nfs
testing-nfs
 
Talk 160920 @ Cat System Workshop
Talk 160920 @ Cat System WorkshopTalk 160920 @ Cat System Workshop
Talk 160920 @ Cat System Workshop
 
LSA2 - 01 Virtualization with KVM
LSA2 - 01 Virtualization with KVMLSA2 - 01 Virtualization with KVM
LSA2 - 01 Virtualization with KVM
 
LSA2 - 02 Control Groups
LSA2 - 02   Control GroupsLSA2 - 02   Control Groups
LSA2 - 02 Control Groups
 
Using cgroups in docker container
Using cgroups in docker containerUsing cgroups in docker container
Using cgroups in docker container
 
Recipe of a linux Live CD (archived)
Recipe of a linux Live CD (archived)Recipe of a linux Live CD (archived)
Recipe of a linux Live CD (archived)
 
Linux fundamental - Chap 11 boot
Linux fundamental - Chap 11 bootLinux fundamental - Chap 11 boot
Linux fundamental - Chap 11 boot
 
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
 
Go replicator
Go replicatorGo replicator
Go replicator
 
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
 
Linux fundamental - Chap 08 proc
Linux fundamental - Chap 08 procLinux fundamental - Chap 08 proc
Linux fundamental - Chap 08 proc
 
Vagrant
VagrantVagrant
Vagrant
 
Lecture 6 Kernel Debugging + Ports Development
Lecture 6 Kernel Debugging + Ports DevelopmentLecture 6 Kernel Debugging + Ports Development
Lecture 6 Kernel Debugging + Ports Development
 
GStreamer 101
GStreamer 101GStreamer 101
GStreamer 101
 

Destaque

PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...Command Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 
Not Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index ConstraintsNot Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index ConstraintsCommand Prompt., Inc
 
Londiste Replication system for PostgreSQL
Londiste Replication system for PostgreSQLLondiste Replication system for PostgreSQL
Londiste Replication system for PostgreSQLelliando dias
 
Scaling PostgreSQL with Skytools
Scaling PostgreSQL with SkytoolsScaling PostgreSQL with Skytools
Scaling PostgreSQL with SkytoolsGavin Roy
 
2014.10.15 Сергей Бурладян, Avito.ru
2014.10.15 Сергей Бурладян, Avito.ru2014.10.15 Сергей Бурладян, Avito.ru
2014.10.15 Сергей Бурладян, Avito.ruNikolay Samokhvalov
 
Monitoreo tunning postgresql_2011
Monitoreo tunning postgresql_2011Monitoreo tunning postgresql_2011
Monitoreo tunning postgresql_2011Lennin Caro
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL AdministrationCommand Prompt., Inc
 
PostgreSQL: Un motor Impulsado por una comunidad
PostgreSQL: Un motor Impulsado por una comunidadPostgreSQL: Un motor Impulsado por una comunidad
PostgreSQL: Un motor Impulsado por una comunidadSantiago Zarate
 
PostgreSQL High Availability via SLONY and PG POOL II
PostgreSQL High Availability via SLONY and PG POOL IIPostgreSQL High Availability via SLONY and PG POOL II
PostgreSQL High Availability via SLONY and PG POOL IICommand Prompt., Inc
 
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...Command Prompt., Inc
 
Replication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorReplication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorCommand Prompt., Inc
 
Implementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with TungstenImplementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with TungstenCommand Prompt., Inc
 
Python utilities for data presentation
Python utilities for data presentationPython utilities for data presentation
Python utilities for data presentationCommand Prompt., Inc
 

Destaque (20)

Basic Query Tuning Primer
Basic Query Tuning PrimerBasic Query Tuning Primer
Basic Query Tuning Primer
 
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
PostgreSQL, Extensible to the Nth Degree: Functions, Languages, Types, Rules,...
 
Bucardo
BucardoBucardo
Bucardo
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Not Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index ConstraintsNot Just UNIQUE: Generalized Index Constraints
Not Just UNIQUE: Generalized Index Constraints
 
The PostgreSQL Query Planner
The PostgreSQL Query PlannerThe PostgreSQL Query Planner
The PostgreSQL Query Planner
 
Londiste Replication system for PostgreSQL
Londiste Replication system for PostgreSQLLondiste Replication system for PostgreSQL
Londiste Replication system for PostgreSQL
 
Scaling PostgreSQL with Skytools
Scaling PostgreSQL with SkytoolsScaling PostgreSQL with Skytools
Scaling PostgreSQL with Skytools
 
2014.10.15 Сергей Бурладян, Avito.ru
2014.10.15 Сергей Бурладян, Avito.ru2014.10.15 Сергей Бурладян, Avito.ru
2014.10.15 Сергей Бурладян, Avito.ru
 
Monitoreo tunning postgresql_2011
Monitoreo tunning postgresql_2011Monitoreo tunning postgresql_2011
Monitoreo tunning postgresql_2011
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
 
PostgreSQL: Un motor Impulsado por una comunidad
PostgreSQL: Un motor Impulsado por una comunidadPostgreSQL: Un motor Impulsado por una comunidad
PostgreSQL: Un motor Impulsado por una comunidad
 
PostgreSQL High Availability via SLONY and PG POOL II
PostgreSQL High Availability via SLONY and PG POOL IIPostgreSQL High Availability via SLONY and PG POOL II
PostgreSQL High Availability via SLONY and PG POOL II
 
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...
 
Backup and-recovery2
Backup and-recovery2Backup and-recovery2
Backup and-recovery2
 
Replication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorReplication using PostgreSQL Replicator
Replication using PostgreSQL Replicator
 
Pg migrator
Pg migratorPg migrator
Pg migrator
 
Implementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with TungstenImplementing the Future of PostgreSQL Clustering with Tungsten
Implementing the Future of PostgreSQL Clustering with Tungsten
 
Python utilities for data presentation
Python utilities for data presentationPython utilities for data presentation
Python utilities for data presentation
 
A Practical Multi-Tenant Cluster
A Practical Multi-Tenant ClusterA Practical Multi-Tenant Cluster
A Practical Multi-Tenant Cluster
 

Semelhante a configuring a warm standby, the easy way

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
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.4Denish 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
 
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)Denish Patel
 
Linux Common Command
Linux Common CommandLinux Common Command
Linux Common CommandJeff Yang
 
Streaming replication in practice
Streaming replication in practiceStreaming replication in practice
Streaming replication in practiceAlexey Lesovsky
 
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 &...NETWAYS
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsCommand Prompt., Inc
 
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 MoreMatt Harrison
 
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...Puppet
 
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 pgBackRestPGDay.Amsterdam
 
Pro PostgreSQL, OSCon 2008
Pro PostgreSQL, OSCon 2008Pro PostgreSQL, OSCon 2008
Pro PostgreSQL, OSCon 2008Robert Treat
 
Archivematica Technical Training Diagnostics Guide (September 2018)
Archivematica Technical Training Diagnostics Guide (September 2018)Archivematica Technical Training Diagnostics Guide (September 2018)
Archivematica Technical Training Diagnostics Guide (September 2018)Artefactual Systems - Archivematica
 
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 RPMAlexander Shopov
 
LCU14 201- Binary Analysis Tools
LCU14 201- Binary Analysis ToolsLCU14 201- Binary Analysis Tools
LCU14 201- Binary Analysis ToolsLinaro
 
Django deployment and rpm+yum
Django deployment and rpm+yumDjango deployment and rpm+yum
Django deployment and rpm+yumWalter Liu
 
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 pyxbackupJervin Real
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpen Gurukul
 

Semelhante a configuring a warm standby, the easy way (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)
 
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(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)
 
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)
 
Linux Common Command
Linux Common CommandLinux Common Command
Linux Common Command
 
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 &...
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System Administrators
 
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
 
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...
 
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
 
Archivematica Technical Training Diagnostics Guide (September 2018)
Archivematica Technical Training Diagnostics Guide (September 2018)Archivematica Technical Training Diagnostics Guide (September 2018)
Archivematica Technical Training Diagnostics Guide (September 2018)
 
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
 
LCU14 201- Binary Analysis Tools
LCU14 201- Binary Analysis ToolsLCU14 201- Binary Analysis Tools
LCU14 201- Binary Analysis Tools
 
Django deployment and rpm+yum
Django deployment and rpm+yumDjango deployment and rpm+yum
Django deployment and rpm+yum
 
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
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQL
 

Mais de Command Prompt., Inc

Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableHowdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableCommand Prompt., Inc
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksElephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksCommand Prompt., Inc
 
Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2Command Prompt., Inc
 
Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1Command Prompt., Inc
 
Integrating PostGIS in Web Applications
Integrating PostGIS in Web ApplicationsIntegrating PostGIS in Web Applications
Integrating PostGIS in Web ApplicationsCommand Prompt., Inc
 
Postgres for MySQL (and other database) people
Postgres for MySQL (and other database) peoplePostgres for MySQL (and other database) people
Postgres for MySQL (and other database) peopleCommand Prompt., Inc
 
Building Grails applications with PostgreSQL
Building Grails applications with PostgreSQLBuilding Grails applications with PostgreSQL
Building Grails applications with PostgreSQLCommand Prompt., Inc
 
Not Just UNIQUE: Exclusion Constraints
Not Just UNIQUE: Exclusion ConstraintsNot Just UNIQUE: Exclusion Constraints
Not Just UNIQUE: Exclusion ConstraintsCommand Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 

Mais de Command Prompt., Inc (15)

Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and ExceptableHowdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
Howdah - An Application using Pylons, PostgreSQL, Simpycity and Exceptable
 
Temporal Data
Temporal DataTemporal Data
Temporal Data
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksElephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forks
 
5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance
 
Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2Normalization: A Workshop for Everybody Pt. 2
Normalization: A Workshop for Everybody Pt. 2
 
Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1Normalization: A Workshop for Everybody Pt. 1
Normalization: A Workshop for Everybody Pt. 1
 
Integrating PostGIS in Web Applications
Integrating PostGIS in Web ApplicationsIntegrating PostGIS in Web Applications
Integrating PostGIS in Web Applications
 
Postgres for MySQL (and other database) people
Postgres for MySQL (and other database) peoplePostgres for MySQL (and other database) people
Postgres for MySQL (and other database) people
 
Building Grails applications with PostgreSQL
Building Grails applications with PostgreSQLBuilding Grails applications with PostgreSQL
Building Grails applications with PostgreSQL
 
Pg amqp
Pg amqpPg amqp
Pg amqp
 
Not Just UNIQUE: Exclusion Constraints
Not Just UNIQUE: Exclusion ConstraintsNot Just UNIQUE: Exclusion Constraints
Not Just UNIQUE: Exclusion Constraints
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
Database Hardware Benchmarking
Database Hardware BenchmarkingDatabase Hardware Benchmarking
Database Hardware Benchmarking
 
Vertically Challenged
Vertically ChallengedVertically Challenged
Vertically Challenged
 
Simpycity and Exceptable
Simpycity and ExceptableSimpycity and Exceptable
Simpycity and Exceptable
 

configuring a warm standby, the easy way

  • 1. PITR made easy Joshua Drake United States PostgreSQL Software in the Public Interest Command Prompt, Inc.
  • 2. What is PITR Log shipping/Warm Standby/Replication
  • 3. What can you do with it? Simple asynchornous failover scenarios Low impact backups Simple archivals
  • 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
  • 9. Features? Warm standby Cold Storage Fail over (actionable) Arbitrary alerts (monitoring)
  • 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 ● 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
  • 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. 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)
  • 16. The process on the slave On the standby/slave: ● Configure SSH key for postgres user to master ● Configure cmd_standby.ini ● 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
  • 17. 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
  • 18. 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
  • 19. 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
  • 20. Is the archiver working?
  • 21. Is the standby is working?
  • 22. How do I?  Use PITRTools to simplify backups?  Take the archiver offline?  Configure send_nsca (nagios) for alerts  Donate to PostgreSQL?
  • 23. 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)
  • 24. 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.
  • 25. Configure send_nsca  Example ok.sh for send_nsca #!/bin/sh echo "shoggoth;CMD_ARCHIVER;0;Archived to Yugg"| /usr/sbin/send_nsca -to 10 -H monitor -d ';' -c /etc/ nagios/send_nsca.cfg
  • 26. Donate to PostgreSQL  For United States PostgreSQL:  https://www.postgresql.us/donate  For PostgreSQL Generally:  http://www.postgresql.org/about/donate