2018 MuellerStephanPGDay
2018 MuellerStephanPGDay
Using RepMgr
Stephan Müller
Introduction
Postgres high availability options
Write ahead log and streaming replication
Built-in tools
Cluster management with RepMgr
Configuration and usage
Automatic failover with RepMgrD
Backup and Recovery with BarMan
Configuration and usage
Hardware
SAN
Transparent to OS and postgres
Fails spectacularly
Operating system
Distributed Replicated Block Device (DRDB)
SAN in Software
Database physical
WAL based: Log shipping (≥ v 8.3)
WAL based: Streaming replication (≥ v 9.0)
Database logical
PGDay.ch’18: Harald Armin Massa → 11:00
FOSDEM’18: Magnus Hagander
App-in-db
Slony-I (trigger based)
Application
Introduction: Postgres Write Ahead Log
Built-in
Easy to set up
Hard to break
Easy monitoring: All or nothing
SELECT ∗ FROM pg stat replication;
pid | 20841
usename | repmgr
application name | db02 remote server
backend xmin | 294106915
state | streaming OK
sent location | 83E/ F92947F0
write location | 83E/ F92947F0 in memory
flush location | 83E/ F92947F0 on disk
replay location | 83E/ F92947B8 applied to db
sync state | async
[...]
Streaming Replication: Easy Setup
Prepare primary:
postgres . conf
listen addresses = ’ 192.168.0.10 ’
max wal senders ≥ #nodes + 2
wal level = replica
wal log hints = on for pg rewind
Special user:
CREATE ROLE r e p u s e r WITH REPLICATION
Adjust hba.conf
Allow repmgr user to connect to its db, local and remotely
Prepare repmgr.conf
node id = 1
node name = db01 dont use role names
c o n n i n f o = ’ h o s t=db01 . o l m e r o . ch
u s e r=repmgr
dbname=repmgr ’
RepMgr Usage: Start a Cluster
Executes a basebackup
p g b a s e b a c k u p −h node1 −U repmgr −X s t r e a m
Prepares recovery.conf
RepMgr Usage: Adding Nodes to Your Cluster (cont)
recovery.conf:
s t a n d b y m o d e = ’ on ’
recovery target timeline = ’ latest ’
p r i m a r y c o n n i n f o = ’ h o s t = db01.olmero.ch
u s e r = repmgr
a p p l i c a t i o n n a m e = db02 ’
r e s t o r e c o m m a n d = ’ / u s r / b i n / barman−wal−r e s t o r e
barman o l m e r o %f %p ’
Promote a standby:
Make sure your old primary is dead and will stay dead
Choose a standby and run
repmgr s t a n d b y promote
Calls service promote command from repmgr.conf
Change the upstream node for your other standbys
repmgr s t a n d b y f o l l o w
STONITH in software
Eventually call repmgr standby promote
In doubt, leave it out
BarMan: Backup and Recovery Manager
https://www.pgbarman.org/
Developed by 2ndQuadrant, written in Python 2
Packaged for most distributions
dnf install barman
dnf install barman−cli (on your postges nodes)
Physical backups
Fast recovery
Point In Time Recovery (PITR)
No logical backups
Onsite and offsite backups possible
Restore functionality
BarMan: Overview
/ d a t a 1 / barman / o l m e r o / w a l s :
[...]
0000002 E0000084B / all wal segments
0000002 E0000084C /
0000002 E0000084D /
0000002E . h i s t o r y
BarMan: Configuration
Everything in barman.conf
[ olmero ]
c o n n i n f o = host=db01.olmero.ch user=barman
dbname=postgres
s t r e a m i n g c o n n i n f o = host=db01.olmero.ch user=barman
s t r e a m i n g a r c h i v e r = on ; stream wals
s l o t n a m e = barman01 ; use a replication slot