SlideShare una empresa de Scribd logo
1 de 50
/
Out of the Box Replication
In
Postgres 9.4
Denish Patel
Lead Database Architect
Who am I ?
•  Database Architect with OmniTI for last 8+ years
•  Expertise in PostgreSQL , Oracle, MySQL, NoSQL
•  Contact : denish@omniti.com
•  Twitter: @DenishPatel
•  Blog: http://www.pateldenish.com
•  Providing Solutions for business problems to deliver
•  Scalability
•  Reliability
•  High Availability
•  Security
We are hiring!!
Apply @ l42.org/lg
1
Agenda
! What is WAL?
! Postgres Replication History
! How you setup replication now?
! What’s missing ?
! Why replication slots?
! Demo
I’m NOT going to discuss …
! SLONY or other 3rd party replication tools
! 3rd party replication management tools
2
WAL - Write Ahead Log
• Roll-forward recovery aka REDO
• flushed to disk to guarantee commit durability
• sequential writes
• lower cost than flushing page cache
• Allows us to do cool things
• Crash recovery
• Binary backups
• Point-In Time Recovery
• Replication
3
WAL Internals (Basic)
• Automatically enabled; no action required
• Make sure to have enough space on server
• Stored under pg_xlog directory
• Normally, 16MB in size
" --with-wal-segsize config option at build
• Each segment is divided into pages (8 kB page)
" --with-wal-blocksize config option at build
• Segment name starts with..
000000010000000000000000
4
What is logged?
select * from pg_settings where name='wal_level';
name | wal_level
setting | hot_standby
unit |
category | Write-Ahead Log / Settings
short_desc | Set the level of information written to the WAL.
extra_desc |
context | postmaster
vartype | enum
source | configuration file
min_val |
max_val |
enumvals | { minimal, archive, hot_standby, logical }
boot_val | minimal
reset_val | hot_standby
sourcefile | /var/lib/pgsql/9.4/data/postgresql.auto.conf
sourceline | 4
5
What’s NOT logged?
Almost everything is replicated, but...
! unlogged tables (As name suggests)
! temporary tables
! hash indexes? (generally don’t use?)
6
Postgres Replication History
Postgres 7.0: WAL
Postgres 8.0: PITR (Point-In-Time-Recovery)
Postgres 8.2: pg_standby
Postgres 9.0: Hot_standby, Streaming replication
Postgres 9.1: pg_basebackup, Synchronous replication
Postgres 9.2: Cascading Replication
Postgres 9.3: Standby can switch timeline to follow new
master
Postgres 9.4: Replication Slots , Logical decoding
7
Basic Steps to Setting up Replication
initdb
8
Postgresql.conf
! max_wal_senders=10
! wal_level=hot_standby
! hot_standby=on (on standby)
9
pg_hba.conf
#TYPE DATABASE USER ADDRESS METHOD
host replication replication 10.0.0.1/32 md5
10
Restart database …
pg_ctl restart
11
Create replication user
CREATE ROLE replication WITH LOGIN
REPLICATION;
password replication
12
Take Backup
! Take file system level backups
! What tools you are using for backups?
13
Recovery.conf
primary_conninfo = 'host=primaryhost user=replication
password=replication'
standby_mode = on
14
Startup standby db
pg_ctl start
15
Not done yet!
Have you configured archiving?
16
Don’t forget about this setting?
wal_keep_segments
17
Setup archiving . . .
! postgresql.conf
archive_mode = on
archive_command = 'cp %p /some/where/%f'
18
Setup restore command
! recovery.conf
restore_command = 'cp /some/where/%f %p'
19
Archiving Options
! local or remote copy
! Scp
! Rsync
! NFS
! pg_archivecleanup
20
What if you have more standby machines?
archive_command = 'rsync %p standby1::pg/%f && rsync
%p standby2::pg/%f'
archive_command = 'echo standby1 standby2 ...
| xargs -d" " -I{} -n1 -P0 -r rsync %p {}::pg/%f'
21
Replication management tools?
! OmniPITR
! WAL-E
! Repmgr
! Pgbarman
! Skytools
! A lot of Custom scripts
22
What about fsync?
! fsync capabilities
! cp: no
! dd: GNU coreutils
! SSH: OpenSSH 6.5 sftp-server (Jan 2014)
! rsync: patch or wrapper
! NFS: Supported
23
Postgres 9.4 ; Enter Replication Slots
24
Postgresql.conf
max_replication_slots = 8
25
Create Slot
SELECT * FROM
pg_create_physical_replication_slot('name');
26
Primary knows the status of standbys
select * from pg_replication_slots ;
slot_name |plugin |slot_type |datoid|database|active|xmin|catalog_xmin|restart_lsn
------------+--------+-----------+--------+----------+--------+------+--------------+---
standby1 | | physical | | | t | | |0/21000058
standby2 | | physical | | | t | | |0/21000058
standby3 | | physical | | | t | | |0/21000058
27
Recovery.conf
primary_slot_name = ‘name'
28
Replication slots benefits
! Keep necessary WAL files
! Each standby can have different WAL apply status
! Single access control setup
! fsync on receiving side
29
pg_basebackup
pg_basebackup 
-h primaryhost
-U replication 
-D $PGDATA 
-X stream 
–P –v -R
30
How about archiving?
! Meet pg_receivexlog
! (Available since Postgers 9.1!)
pg_receivexlog 
-D archivedir 
--slot archivingslot 
-h primaryhost -U replication
! -- synchronous option in 9.5
31
Postgres 9.4 – Out of the Box Replication
Are you ready to setup replication without any external
tools?
1.  pg_basebackup
2. streaming with Replication Slots
3. pg_receivexlog
32
Tutorial – Let’s bring up VM!
! Google Drive: https://drive.google.com/open?
id=0BxnXwkT5PRBdeVByQVYySkhIemc
! Login: pgtraining/pgcon
! pgtraining user has sudo access
! You can access terminal on the desktop
! Internet should be working within VM
! Copy/paste should work between VM and Host
! Take snapshot along the process so you can rollback
easily
33
Installing Postgres
! Remove Postgres 8.4 version
sudo yum erase postgresql.*
! Setup yum repo for your desired version
sudo yum install http://yum.postgresql.org/9.4/redhat/rhel-6-
x86_64/pgdg-redhat94-9.4-1.noarch.rpm
! Install PostgreSQL 9.4 & Contrib modules
sudo yum install postgresql94-server postgresql94-contrib
! Create postgres cluster & initial automatic startup
sudo service postgresql-9.4 initdb
sudo chkconfig postgresql-9.4 on
sudo service postgresql-9.4 start
34
Create Role and Database
! Become postgres system user
sudo su - postgres
! Log into database using psql (? to see all available commands)
! Create a role & database for yourself
CREATE ROLE pgtraining WITH LOGIN SUPERUSER;
CREATE DATABASE pgtraining;
! You can login as pgtraining user (psql –U pgtraining –d pgtraining)
! Create replication role for later
CREATE ROLE replication WITH LOGIN REPLICATION;
! Set password (”replication”)
password replication
35
Configure pg_hba.conf
! http://www.postgresql.org/docs/9.4/static/auth-pg-
hba-conf.html
! Find location of hba_file
postgres=# show hba_file;
! Add following entry for replication user
! Try to avoid trust authentication
! [pgtraining@localhost ~]$ sudo vi /var/lib/pgsql/9.4/
data/pg_hba.conf
host replication replication 127.0.0.1/32 md5
36
Prepare Primary DB server
alter system set wal_level = hot_standby;
alter system set archive_mode=on;
alter system set max_replication_slots=8;
alter system set archive_timeout = 60;
alter system set max_wal_senders = 8;
alter system set wal_keep_segments=100;
alter system set logging_collector=on;
37
Restart Primary DB server
! Restart database
sudo service postgresql-9.4 restart
! Verify settings
psql=# show max_wal_senders;
38
Create replication slot
SELECT * FROM pg_create_physical_replication_slot('standby1');
39
Let’s take backup
sudo su - postgres
pg_basebackup -h 127.0.0.1 -U replication -D /var/
lib/pgsql/9.4/slave -R -Xs -P -v
40
Prepare standby db server …
cd /var/lib/pgsql/9.4/slave
! Edit Standby postgresql.conf file
port = 5433
hot_standby = on
! Edit Standby recovery.conf file
standby_mode = 'on'
primary_conninfo = 'user=replication password=replication
host=127.0.0.1 port=5432'
primary_slot_name='standby1'
trigger_file = '/var/lib/pgsql/9.4/slave/finish.recovery'
recovery_target_timeline='latest'
41
Configure Standby with init
! Copy existing init file
sudo cp /etc/init.d/postgresql-9.4 /etc/init.d/postgresql-9.4-5433
! Edit config file to change (as root):
PGDATA=/var/lib/pgsql/9.4/slave
PGLOG=/var/lib/pgsql/9.4/pgstartup-5433.log
PGUPLOG=/var/lib/pgsql/$PGMAJORVERSION/
pgupgrade-5433.log
! Register service, start up slave
sudo chkconfig postgresql-9.4-5433 on
sudo service postgresql-9.4-5433 start
42
Status: pg_stat_replication
pgtraining=# x
pgtraining=# select * from pg_stat_replication;
-[ RECORD 1 ]----+------------------------------
pid | 3260
usesysid | 24576
usename | replication
application_name | walreceiver
client_addr | 127.0.0.1
client_hostname |
client_port | 53206
backend_start | 2015-06-08 14:47:50.057326-04
backend_xmin |
state | streaming
sent_location | 0/240000B8
write_location | 0/240000B8
flush_location | 0/240000B8
replay_location | 0/240000B8
sync_priority | 0
sync_state | async
43
Status : pg_replication_slots
pgtraining=# select * from pg_replication_slots;
-[ RECORD 1 ]+-----------
slot_name | standby1
plugin |
slot_type | physical
datoid |
database |
active | t
xmin |
catalog_xmin |
restart_lsn | 0/270000EC
44
What about archiving?
! Create slot for archiving:
SELECT * FROM
pg_create_physical_replication_slot('archiver1');
! Create archive directory
mkdir /var/lib/pgsql/9.4/archive
! Start archiving process in background
/usr/pgsql-9.4/bin/pg_receivexlog -h 127.0.0.1 -p 5432 -U
replication –S 'archiver1' -n -v -D /var/lib/pgsql/9.4/
archive
! Put under init.d for continuous run
! Switch xlog : primary_db_sever# select pg_switch_xlog();
45
Monitoring
! Monitor Disk space
! Monitor slave lag
select pg_xlog_location_diff(sent_location, write_location) AS
byte_lag
from pg_stat_replication
where application_name='pg_receivexlog';
! Monitor WAL archive process
select pg_xlog_location_diff(sent_location, write_location) AS
byte_lag
from pg_stat_replication
where application_name='walreceiver';
46
Monitoring
• Number of pg_xlogs on master
• Monitor pg_recievexlog process
• Make sure archive location has new files
• pg_basebackup log files for successful backup… look
for “pg_basebackup: base backup completed”
47
Thanks to….
! OmniTI for travel sponsorships
! Pgcon conference committee
! Peter Eisentraut
! You!!
48
Questions?
denish@omniti.com
Twitter: DenishPatel
49

Más contenido relacionado

La actualidad más candente

PostgreSQL Streaming Replication Cheatsheet
PostgreSQL Streaming Replication CheatsheetPostgreSQL Streaming Replication Cheatsheet
PostgreSQL Streaming Replication CheatsheetAlexey Lesovsky
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL AdministrationEDB
 
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...PostgreSQL-Consulting
 
PostgreSQL Extensions: A deeper look
PostgreSQL Extensions:  A deeper lookPostgreSQL Extensions:  A deeper look
PostgreSQL Extensions: A deeper lookJignesh Shah
 
High Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniHigh Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniZalando Technology
 
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte DataProblems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte DataJignesh Shah
 
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Replication in 10  Minutes - SCALEPostgreSQL Replication in 10  Minutes - SCALE
PostgreSQL Replication in 10 Minutes - SCALEPostgreSQL Experts, Inc.
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldJignesh Shah
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldJignesh Shah
 
PostgreSQL Hangout Parameter Tuning
PostgreSQL Hangout Parameter TuningPostgreSQL Hangout Parameter Tuning
PostgreSQL Hangout Parameter TuningAshnikbiz
 
Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer Sameer Kumar
 
pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)
pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)
pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)Wei Shan Ang
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuningelliando dias
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PGConf APAC
 
Percona Toolkit for Effective MySQL Administration
Percona Toolkit for Effective MySQL AdministrationPercona Toolkit for Effective MySQL Administration
Percona Toolkit for Effective MySQL AdministrationMydbops
 

La actualidad más candente (19)

PostgreSQL Streaming Replication Cheatsheet
PostgreSQL Streaming Replication CheatsheetPostgreSQL Streaming Replication Cheatsheet
PostgreSQL Streaming Replication Cheatsheet
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
 
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
 
The Accidental DBA
The Accidental DBAThe Accidental DBA
The Accidental DBA
 
PostgreSQL Extensions: A deeper look
PostgreSQL Extensions:  A deeper lookPostgreSQL Extensions:  A deeper look
PostgreSQL Extensions: A deeper look
 
High Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniHigh Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando Patroni
 
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte DataProblems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
Problems with PostgreSQL on Multi-core Systems with MultiTerabyte Data
 
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Replication in 10  Minutes - SCALEPostgreSQL Replication in 10  Minutes - SCALE
PostgreSQL Replication in 10 Minutes - SCALE
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized World
 
PostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized WorldPostgreSQL High Availability in a Containerized World
PostgreSQL High Availability in a Containerized World
 
PostgreSQL Hangout Parameter Tuning
PostgreSQL Hangout Parameter TuningPostgreSQL Hangout Parameter Tuning
PostgreSQL Hangout Parameter Tuning
 
Shootout at the AWS Corral
Shootout at the AWS CorralShootout at the AWS Corral
Shootout at the AWS Corral
 
Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer
 
pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)
pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)
pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuning
 
Shootout at the PAAS Corral
Shootout at the PAAS CorralShootout at the PAAS Corral
Shootout at the PAAS Corral
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs
 
Percona Toolkit for Effective MySQL Administration
Percona Toolkit for Effective MySQL AdministrationPercona Toolkit for Effective MySQL Administration
Percona Toolkit for Effective MySQL Administration
 
PostgreSQL and RAM usage
PostgreSQL and RAM usagePostgreSQL and RAM usage
PostgreSQL and RAM usage
 

Destacado

Postgres in Amazon RDS
Postgres in Amazon RDSPostgres in Amazon RDS
Postgres in Amazon RDSDenish Patel
 
PostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability ImprovementsPostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability ImprovementsPGConf APAC
 
Postgres in Production - Best Practices 2014
Postgres in Production - Best Practices 2014Postgres in Production - Best Practices 2014
Postgres in Production - Best Practices 2014EDB
 
NoSQL - Neue Ansätze zur Verwaltung unstrukturierter Daten
NoSQL - Neue Ansätze zur Verwaltung unstrukturierter DatenNoSQL - Neue Ansätze zur Verwaltung unstrukturierter Daten
NoSQL - Neue Ansätze zur Verwaltung unstrukturierter DatenMartin Junghanns
 
Top 10 database optimization tips
Top 10 database optimization tipsTop 10 database optimization tips
Top 10 database optimization tipsraviwriter
 
What Ops Can Learn From Design
What Ops Can Learn From DesignWhat Ops Can Learn From Design
What Ops Can Learn From DesignRobert Treat
 
Scaling With Postgres
Scaling With PostgresScaling With Postgres
Scaling With PostgresRobert Treat
 
Intro to pl/PHP Oscon2007
Intro to pl/PHP Oscon2007Intro to pl/PHP Oscon2007
Intro to pl/PHP Oscon2007Robert Treat
 
A Guide To PostgreSQL 9.0
A Guide To PostgreSQL 9.0A Guide To PostgreSQL 9.0
A Guide To PostgreSQL 9.0Robert Treat
 
Database Scalability Patterns
Database Scalability PatternsDatabase Scalability Patterns
Database Scalability PatternsRobert Treat
 
PostgreSQL9.3 Switchover/Switchback
PostgreSQL9.3 Switchover/SwitchbackPostgreSQL9.3 Switchover/Switchback
PostgreSQL9.3 Switchover/SwitchbackVibhor Kumar
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL AdministrationCommand Prompt., Inc
 
PostgreSQL Hangout Replication Features v9.4
PostgreSQL Hangout Replication Features v9.4PostgreSQL Hangout Replication Features v9.4
PostgreSQL Hangout Replication Features v9.4Ashnikbiz
 
Postgres Relevance: Guidepost to the Future
Postgres Relevance: Guidepost to the Future Postgres Relevance: Guidepost to the Future
Postgres Relevance: Guidepost to the Future EDB
 
Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)
Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)
Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)Masao Fujii
 
Streaming huge databases using logical decoding
Streaming huge databases using logical decodingStreaming huge databases using logical decoding
Streaming huge databases using logical decodingAlexander Shulgin
 
Enterprise PostgreSQL - EDB's answer to conventional Databases
Enterprise PostgreSQL - EDB's answer to conventional DatabasesEnterprise PostgreSQL - EDB's answer to conventional Databases
Enterprise PostgreSQL - EDB's answer to conventional DatabasesAshnikbiz
 
Less Alarming Alerts - SRECon 2016
Less Alarming Alerts - SRECon 2016 Less Alarming Alerts - SRECon 2016
Less Alarming Alerts - SRECon 2016 Robert Treat
 

Destacado (20)

PostgreSQL Replication Tutorial
PostgreSQL Replication TutorialPostgreSQL Replication Tutorial
PostgreSQL Replication Tutorial
 
Postgres in Amazon RDS
Postgres in Amazon RDSPostgres in Amazon RDS
Postgres in Amazon RDS
 
Scaling postgres
Scaling postgresScaling postgres
Scaling postgres
 
PostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability ImprovementsPostgreSQL 9.6 Performance-Scalability Improvements
PostgreSQL 9.6 Performance-Scalability Improvements
 
Postgres in Production - Best Practices 2014
Postgres in Production - Best Practices 2014Postgres in Production - Best Practices 2014
Postgres in Production - Best Practices 2014
 
NoSQL - Neue Ansätze zur Verwaltung unstrukturierter Daten
NoSQL - Neue Ansätze zur Verwaltung unstrukturierter DatenNoSQL - Neue Ansätze zur Verwaltung unstrukturierter Daten
NoSQL - Neue Ansätze zur Verwaltung unstrukturierter Daten
 
Top 10 database optimization tips
Top 10 database optimization tipsTop 10 database optimization tips
Top 10 database optimization tips
 
What Ops Can Learn From Design
What Ops Can Learn From DesignWhat Ops Can Learn From Design
What Ops Can Learn From Design
 
Scaling With Postgres
Scaling With PostgresScaling With Postgres
Scaling With Postgres
 
Intro to pl/PHP Oscon2007
Intro to pl/PHP Oscon2007Intro to pl/PHP Oscon2007
Intro to pl/PHP Oscon2007
 
A Guide To PostgreSQL 9.0
A Guide To PostgreSQL 9.0A Guide To PostgreSQL 9.0
A Guide To PostgreSQL 9.0
 
Database Scalability Patterns
Database Scalability PatternsDatabase Scalability Patterns
Database Scalability Patterns
 
PostgreSQL9.3 Switchover/Switchback
PostgreSQL9.3 Switchover/SwitchbackPostgreSQL9.3 Switchover/Switchback
PostgreSQL9.3 Switchover/Switchback
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
 
PostgreSQL Hangout Replication Features v9.4
PostgreSQL Hangout Replication Features v9.4PostgreSQL Hangout Replication Features v9.4
PostgreSQL Hangout Replication Features v9.4
 
Postgres Relevance: Guidepost to the Future
Postgres Relevance: Guidepost to the Future Postgres Relevance: Guidepost to the Future
Postgres Relevance: Guidepost to the Future
 
Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)
Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)
Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)
 
Streaming huge databases using logical decoding
Streaming huge databases using logical decodingStreaming huge databases using logical decoding
Streaming huge databases using logical decoding
 
Enterprise PostgreSQL - EDB's answer to conventional Databases
Enterprise PostgreSQL - EDB's answer to conventional DatabasesEnterprise PostgreSQL - EDB's answer to conventional Databases
Enterprise PostgreSQL - EDB's answer to conventional Databases
 
Less Alarming Alerts - SRECon 2016
Less Alarming Alerts - SRECon 2016 Less Alarming Alerts - SRECon 2016
Less Alarming Alerts - SRECon 2016
 

Similar a 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)Denish Patel
 
configuring a warm standby, the easy way
configuring a warm standby, the easy wayconfiguring a warm standby, the easy way
configuring a warm standby, the easy wayCommand Prompt., Inc
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOpsОмские ИТ-субботники
 
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
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with PuppetKris Buytaert
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with PuppetKris Buytaert
 
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
 
Replication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorReplication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorCommand Prompt., Inc
 
2011 384 hackworth_ppt
2011 384 hackworth_ppt2011 384 hackworth_ppt
2011 384 hackworth_pptmaclean liu
 
Backing up Wikipedia Databases
Backing up Wikipedia DatabasesBacking up Wikipedia Databases
Backing up Wikipedia DatabasesJaime Crespo
 
Docker 0.11 at MaxCDN meetup in Los Angeles
Docker 0.11 at MaxCDN meetup in Los AngelesDocker 0.11 at MaxCDN meetup in Los Angeles
Docker 0.11 at MaxCDN meetup in Los AngelesJérôme Petazzoni
 
Pro PostgreSQL, OSCon 2008
Pro PostgreSQL, OSCon 2008Pro PostgreSQL, OSCon 2008
Pro PostgreSQL, OSCon 2008Robert Treat
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpen Gurukul
 
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Herokuronnywang_tw
 
Challenges when building high profile editorial sites
Challenges when building high profile editorial sitesChallenges when building high profile editorial sites
Challenges when building high profile editorial sitesYann Malet
 

Similar a Out of the box replication in postgres 9.4 (20)

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)
 
configuring a warm standby, the easy way
configuring a warm standby, the easy wayconfiguring a warm standby, the easy way
configuring a warm standby, the easy way
 
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
 
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
 
Pitr Made Easy
Pitr Made EasyPitr Made Easy
Pitr Made Easy
 
Automating complex infrastructures with Puppet
Automating complex infrastructures with PuppetAutomating complex infrastructures with Puppet
Automating complex infrastructures with Puppet
 
Automating Complex Setups with Puppet
Automating Complex Setups with PuppetAutomating Complex Setups with Puppet
Automating Complex Setups with Puppet
 
9.1 Grand Tour
9.1 Grand Tour9.1 Grand Tour
9.1 Grand Tour
 
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
 
Docker, c'est bonheur !
Docker, c'est bonheur !Docker, c'est bonheur !
Docker, c'est bonheur !
 
Go replicator
Go replicatorGo replicator
Go replicator
 
Replication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorReplication using PostgreSQL Replicator
Replication using PostgreSQL Replicator
 
2011 384 hackworth_ppt
2011 384 hackworth_ppt2011 384 hackworth_ppt
2011 384 hackworth_ppt
 
Backing up Wikipedia Databases
Backing up Wikipedia DatabasesBacking up Wikipedia Databases
Backing up Wikipedia Databases
 
Docker 0.11 at MaxCDN meetup in Los Angeles
Docker 0.11 at MaxCDN meetup in Los AngelesDocker 0.11 at MaxCDN meetup in Los Angeles
Docker 0.11 at MaxCDN meetup in Los Angeles
 
Pro PostgreSQL, OSCon 2008
Pro PostgreSQL, OSCon 2008Pro PostgreSQL, OSCon 2008
Pro PostgreSQL, OSCon 2008
 
OpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQLOpenGurukul : Database : PostgreSQL
OpenGurukul : Database : PostgreSQL
 
Go Replicator
Go ReplicatorGo Replicator
Go Replicator
 
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
 
Challenges when building high profile editorial sites
Challenges when building high profile editorial sitesChallenges when building high profile editorial sites
Challenges when building high profile editorial sites
 

Más de 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
 
Choosing the "D" , Lightning talk
Choosing the "D" , Lightning talkChoosing the "D" , Lightning talk
Choosing the "D" , Lightning talkDenish Patel
 
Two Elephants Inthe Room
Two Elephants Inthe RoomTwo Elephants Inthe Room
Two Elephants Inthe RoomDenish Patel
 
Deploying Maximum HA Architecture With PostgreSQL
Deploying Maximum HA Architecture With PostgreSQLDeploying Maximum HA Architecture With PostgreSQL
Deploying Maximum HA Architecture With PostgreSQLDenish Patel
 
Deploying Maximum HA Architecture With PostgreSQL
Deploying Maximum HA Architecture With PostgreSQLDeploying Maximum HA Architecture With PostgreSQL
Deploying Maximum HA Architecture With PostgreSQLDenish Patel
 
P90 X Your Database!!
P90 X Your Database!!P90 X Your Database!!
P90 X Your Database!!Denish Patel
 
Achieving Pci Compliace
Achieving Pci CompliaceAchieving Pci Compliace
Achieving Pci CompliaceDenish Patel
 
Using SQL Standards? Database SQL comparition
Using SQL Standards? Database SQL comparitionUsing SQL Standards? Database SQL comparition
Using SQL Standards? Database SQL comparitionDenish Patel
 
Oracle10g New Features I
Oracle10g New Features IOracle10g New Features I
Oracle10g New Features IDenish Patel
 
Yet Another Replication Tool: RubyRep
Yet Another Replication Tool: RubyRepYet Another Replication Tool: RubyRep
Yet Another Replication Tool: RubyRepDenish Patel
 

Más de Denish Patel (11)

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)
 
Choosing the "D" , Lightning talk
Choosing the "D" , Lightning talkChoosing the "D" , Lightning talk
Choosing the "D" , Lightning talk
 
Two Elephants Inthe Room
Two Elephants Inthe RoomTwo Elephants Inthe Room
Two Elephants Inthe Room
 
Deploying Maximum HA Architecture With PostgreSQL
Deploying Maximum HA Architecture With PostgreSQLDeploying Maximum HA Architecture With PostgreSQL
Deploying Maximum HA Architecture With PostgreSQL
 
Deploying Maximum HA Architecture With PostgreSQL
Deploying Maximum HA Architecture With PostgreSQLDeploying Maximum HA Architecture With PostgreSQL
Deploying Maximum HA Architecture With PostgreSQL
 
P90 X Your Database!!
P90 X Your Database!!P90 X Your Database!!
P90 X Your Database!!
 
Achieving Pci Compliace
Achieving Pci CompliaceAchieving Pci Compliace
Achieving Pci Compliace
 
Using SQL Standards? Database SQL comparition
Using SQL Standards? Database SQL comparitionUsing SQL Standards? Database SQL comparition
Using SQL Standards? Database SQL comparition
 
Oracle10g New Features I
Oracle10g New Features IOracle10g New Features I
Oracle10g New Features I
 
Yet Another Replication Tool: RubyRep
Yet Another Replication Tool: RubyRepYet Another Replication Tool: RubyRep
Yet Another Replication Tool: RubyRep
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
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.pdfOrbitshub
 
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 WorkerThousandEyes
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
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 2024The Digital Insurer
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
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 FresherRemote DBA Services
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
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 TerraformAndrey Devyatkin
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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 AmsterdamUiPathCommunity
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 

Último (20)

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
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
 
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
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Out of the box replication in postgres 9.4

  • 1. / Out of the Box Replication In Postgres 9.4 Denish Patel Lead Database Architect
  • 2. Who am I ? •  Database Architect with OmniTI for last 8+ years •  Expertise in PostgreSQL , Oracle, MySQL, NoSQL •  Contact : denish@omniti.com •  Twitter: @DenishPatel •  Blog: http://www.pateldenish.com •  Providing Solutions for business problems to deliver •  Scalability •  Reliability •  High Availability •  Security We are hiring!! Apply @ l42.org/lg 1
  • 3. Agenda ! What is WAL? ! Postgres Replication History ! How you setup replication now? ! What’s missing ? ! Why replication slots? ! Demo I’m NOT going to discuss … ! SLONY or other 3rd party replication tools ! 3rd party replication management tools 2
  • 4. WAL - Write Ahead Log • Roll-forward recovery aka REDO • flushed to disk to guarantee commit durability • sequential writes • lower cost than flushing page cache • Allows us to do cool things • Crash recovery • Binary backups • Point-In Time Recovery • Replication 3
  • 5. WAL Internals (Basic) • Automatically enabled; no action required • Make sure to have enough space on server • Stored under pg_xlog directory • Normally, 16MB in size " --with-wal-segsize config option at build • Each segment is divided into pages (8 kB page) " --with-wal-blocksize config option at build • Segment name starts with.. 000000010000000000000000 4
  • 6. What is logged? select * from pg_settings where name='wal_level'; name | wal_level setting | hot_standby unit | category | Write-Ahead Log / Settings short_desc | Set the level of information written to the WAL. extra_desc | context | postmaster vartype | enum source | configuration file min_val | max_val | enumvals | { minimal, archive, hot_standby, logical } boot_val | minimal reset_val | hot_standby sourcefile | /var/lib/pgsql/9.4/data/postgresql.auto.conf sourceline | 4 5
  • 7. What’s NOT logged? Almost everything is replicated, but... ! unlogged tables (As name suggests) ! temporary tables ! hash indexes? (generally don’t use?) 6
  • 8. Postgres Replication History Postgres 7.0: WAL Postgres 8.0: PITR (Point-In-Time-Recovery) Postgres 8.2: pg_standby Postgres 9.0: Hot_standby, Streaming replication Postgres 9.1: pg_basebackup, Synchronous replication Postgres 9.2: Cascading Replication Postgres 9.3: Standby can switch timeline to follow new master Postgres 9.4: Replication Slots , Logical decoding 7
  • 9. Basic Steps to Setting up Replication initdb 8
  • 11. pg_hba.conf #TYPE DATABASE USER ADDRESS METHOD host replication replication 10.0.0.1/32 md5 10
  • 13. Create replication user CREATE ROLE replication WITH LOGIN REPLICATION; password replication 12
  • 14. Take Backup ! Take file system level backups ! What tools you are using for backups? 13
  • 15. Recovery.conf primary_conninfo = 'host=primaryhost user=replication password=replication' standby_mode = on 14
  • 17. Not done yet! Have you configured archiving? 16
  • 18. Don’t forget about this setting? wal_keep_segments 17
  • 19. Setup archiving . . . ! postgresql.conf archive_mode = on archive_command = 'cp %p /some/where/%f' 18
  • 21. Archiving Options ! local or remote copy ! Scp ! Rsync ! NFS ! pg_archivecleanup 20
  • 22. What if you have more standby machines? archive_command = 'rsync %p standby1::pg/%f && rsync %p standby2::pg/%f' archive_command = 'echo standby1 standby2 ... | xargs -d" " -I{} -n1 -P0 -r rsync %p {}::pg/%f' 21
  • 24. What about fsync? ! fsync capabilities ! cp: no ! dd: GNU coreutils ! SSH: OpenSSH 6.5 sftp-server (Jan 2014) ! rsync: patch or wrapper ! NFS: Supported 23
  • 25. Postgres 9.4 ; Enter Replication Slots 24
  • 27. Create Slot SELECT * FROM pg_create_physical_replication_slot('name'); 26
  • 28. Primary knows the status of standbys select * from pg_replication_slots ; slot_name |plugin |slot_type |datoid|database|active|xmin|catalog_xmin|restart_lsn ------------+--------+-----------+--------+----------+--------+------+--------------+--- standby1 | | physical | | | t | | |0/21000058 standby2 | | physical | | | t | | |0/21000058 standby3 | | physical | | | t | | |0/21000058 27
  • 30. Replication slots benefits ! Keep necessary WAL files ! Each standby can have different WAL apply status ! Single access control setup ! fsync on receiving side 29
  • 31. pg_basebackup pg_basebackup -h primaryhost -U replication -D $PGDATA -X stream –P –v -R 30
  • 32. How about archiving? ! Meet pg_receivexlog ! (Available since Postgers 9.1!) pg_receivexlog -D archivedir --slot archivingslot -h primaryhost -U replication ! -- synchronous option in 9.5 31
  • 33. Postgres 9.4 – Out of the Box Replication Are you ready to setup replication without any external tools? 1.  pg_basebackup 2. streaming with Replication Slots 3. pg_receivexlog 32
  • 34. Tutorial – Let’s bring up VM! ! Google Drive: https://drive.google.com/open? id=0BxnXwkT5PRBdeVByQVYySkhIemc ! Login: pgtraining/pgcon ! pgtraining user has sudo access ! You can access terminal on the desktop ! Internet should be working within VM ! Copy/paste should work between VM and Host ! Take snapshot along the process so you can rollback easily 33
  • 35. Installing Postgres ! Remove Postgres 8.4 version sudo yum erase postgresql.* ! Setup yum repo for your desired version sudo yum install http://yum.postgresql.org/9.4/redhat/rhel-6- x86_64/pgdg-redhat94-9.4-1.noarch.rpm ! Install PostgreSQL 9.4 & Contrib modules sudo yum install postgresql94-server postgresql94-contrib ! Create postgres cluster & initial automatic startup sudo service postgresql-9.4 initdb sudo chkconfig postgresql-9.4 on sudo service postgresql-9.4 start 34
  • 36. Create Role and Database ! Become postgres system user sudo su - postgres ! Log into database using psql (? to see all available commands) ! Create a role & database for yourself CREATE ROLE pgtraining WITH LOGIN SUPERUSER; CREATE DATABASE pgtraining; ! You can login as pgtraining user (psql –U pgtraining –d pgtraining) ! Create replication role for later CREATE ROLE replication WITH LOGIN REPLICATION; ! Set password (”replication”) password replication 35
  • 37. Configure pg_hba.conf ! http://www.postgresql.org/docs/9.4/static/auth-pg- hba-conf.html ! Find location of hba_file postgres=# show hba_file; ! Add following entry for replication user ! Try to avoid trust authentication ! [pgtraining@localhost ~]$ sudo vi /var/lib/pgsql/9.4/ data/pg_hba.conf host replication replication 127.0.0.1/32 md5 36
  • 38. Prepare Primary DB server alter system set wal_level = hot_standby; alter system set archive_mode=on; alter system set max_replication_slots=8; alter system set archive_timeout = 60; alter system set max_wal_senders = 8; alter system set wal_keep_segments=100; alter system set logging_collector=on; 37
  • 39. Restart Primary DB server ! Restart database sudo service postgresql-9.4 restart ! Verify settings psql=# show max_wal_senders; 38
  • 40. Create replication slot SELECT * FROM pg_create_physical_replication_slot('standby1'); 39
  • 41. Let’s take backup sudo su - postgres pg_basebackup -h 127.0.0.1 -U replication -D /var/ lib/pgsql/9.4/slave -R -Xs -P -v 40
  • 42. Prepare standby db server … cd /var/lib/pgsql/9.4/slave ! Edit Standby postgresql.conf file port = 5433 hot_standby = on ! Edit Standby recovery.conf file standby_mode = 'on' primary_conninfo = 'user=replication password=replication host=127.0.0.1 port=5432' primary_slot_name='standby1' trigger_file = '/var/lib/pgsql/9.4/slave/finish.recovery' recovery_target_timeline='latest' 41
  • 43. Configure Standby with init ! Copy existing init file sudo cp /etc/init.d/postgresql-9.4 /etc/init.d/postgresql-9.4-5433 ! Edit config file to change (as root): PGDATA=/var/lib/pgsql/9.4/slave PGLOG=/var/lib/pgsql/9.4/pgstartup-5433.log PGUPLOG=/var/lib/pgsql/$PGMAJORVERSION/ pgupgrade-5433.log ! Register service, start up slave sudo chkconfig postgresql-9.4-5433 on sudo service postgresql-9.4-5433 start 42
  • 44. Status: pg_stat_replication pgtraining=# x pgtraining=# select * from pg_stat_replication; -[ RECORD 1 ]----+------------------------------ pid | 3260 usesysid | 24576 usename | replication application_name | walreceiver client_addr | 127.0.0.1 client_hostname | client_port | 53206 backend_start | 2015-06-08 14:47:50.057326-04 backend_xmin | state | streaming sent_location | 0/240000B8 write_location | 0/240000B8 flush_location | 0/240000B8 replay_location | 0/240000B8 sync_priority | 0 sync_state | async 43
  • 45. Status : pg_replication_slots pgtraining=# select * from pg_replication_slots; -[ RECORD 1 ]+----------- slot_name | standby1 plugin | slot_type | physical datoid | database | active | t xmin | catalog_xmin | restart_lsn | 0/270000EC 44
  • 46. What about archiving? ! Create slot for archiving: SELECT * FROM pg_create_physical_replication_slot('archiver1'); ! Create archive directory mkdir /var/lib/pgsql/9.4/archive ! Start archiving process in background /usr/pgsql-9.4/bin/pg_receivexlog -h 127.0.0.1 -p 5432 -U replication –S 'archiver1' -n -v -D /var/lib/pgsql/9.4/ archive ! Put under init.d for continuous run ! Switch xlog : primary_db_sever# select pg_switch_xlog(); 45
  • 47. Monitoring ! Monitor Disk space ! Monitor slave lag select pg_xlog_location_diff(sent_location, write_location) AS byte_lag from pg_stat_replication where application_name='pg_receivexlog'; ! Monitor WAL archive process select pg_xlog_location_diff(sent_location, write_location) AS byte_lag from pg_stat_replication where application_name='walreceiver'; 46
  • 48. Monitoring • Number of pg_xlogs on master • Monitor pg_recievexlog process • Make sure archive location has new files • pg_basebackup log files for successful backup… look for “pg_basebackup: base backup completed” 47
  • 49. Thanks to…. ! OmniTI for travel sponsorships ! Pgcon conference committee ! Peter Eisentraut ! You!! 48