SlideShare a Scribd company logo
PostgreSQL Replication/HA Methods
Aakash M
DBRE, Mydbops
January 30, 2021
Mydbops Database Meetup -8
Database Reliability Engineer
Interest in PostgreSQL and MySQL
Active Blogger
Aakash M
About Me
Database
Consulting
Services
Managed
Database
Services
Focuses on Top Opensource database MySQL,
MongoDB and PostgreSQL ON Premises and Cloud
Mydbops Services
End of Life on February 11, 2021
Current Major Release is 13
AWS - March 16, 2021
PostgreSQL 9.5
Modes of Replication
Replication
Agenda
Replication Types
How to achieve HA
Replication
Continuous copying of data changes from one database server to another.
What is Replication?
Application
Changes
Replicate
Database Servers
High Availabilty
Why do we need it?
Application
S
Q
L
Database Servers
Load Balancing
Why do we need it?
Application
S
Q
L
Database Servers
S
Q
L
50%
50%
Terminologies
Terminologies
Write Ahead Log (WAL)
Every transactions -> Transaction Log
Each statement creates a new WAL record
Each WAL record contains a bunch of records
16MB by default
pg_xlog/pg_wal
WAL Records
WAL File
Terminologies
Write Ahead Log (WAL)
Crash Recovery
Point-In-Time-Recovery(PITR)
Replication
Terminologies
Primary Server / Master
Direct Writes
Application Primary Server
Writes
Terminologies
Standby / Secondary Server
Following up the primary and applying the changes
Application
Primary Server
Writes
Secondary Server
Terminologies
Warm / Hot Standby Server
Standby
Warm Standby Hot Standby
Failover
Switching to the backup server(standby) when the primary server is not available
Terminologies
Application
S
Q
L
Primary Server Standby Server
Replication Modes
Replication Modes
Replication Modes
Synchronous
Replication
Asynchronous
Replication
Asynchronous Replication
Transaction complete - considering only the primary server
Never consider its replicas
Can be out of sync
Asynchronous Replication
Time
Secondary - II
Secondary - I
Primary
Replication Lag
Replication Lag
Ins/Upd/Del
X Y Z
Asynchronous Replication
No Additional Overhead
Chances for dataloss
Synchronous Replication
Transaction Complete - when changes have been replicated to the replicas.
Replicas should be available all the time
Replicas will be in sync
Synchronous Replication
Time
Secondary - II
Secondary - I
Primary
Ins/Upd/Del
X
Synchronous Replication
No data loss
Additional Overhead
Types of Replication
Types of Replication
Replication
Physical Logical
Log Shipping
Streaming
Replication
Publisher
Subscriber
Physical Vs Logical Replication
Physical Replication
Primary - at offset 11 of disk page 5 of relation 14312, add a row with hex value
0x234...
Secondaries - at offset 11 of disk page 5 of relation 14312, add a row with hex
value 0x234...
Disk Block Level changes made by PostgreSQL
An exact copy of the Primary
Example:
Physical Vs Logical Replication
Logical Replication
Primary - INSERT INTO test1 VALUES (now());
Secondaries - INSERT INTO test1 VALUES (2021-01-31);
Data getting in and is replicated
Example:
Physical Replication
Log Shipping
Streaming Replication
Physical Replication - Log Shipping
PostgreSQL 8.2
Replication based on the archival
archive_command on the primary
restore_command on the standby
File Based
Physical Replication - Log Shipping
pgxlog/
pg_wal
2920514960194996
NFS / Archive Server
Primary Server Standby Server
Archive Command
Restore Command
WAL File
Physical Replication - Log Shipping
No direct connection
No replication user
Replica always be in lag
No support for synchronous mode
Physical Replication - Streaming Replication
PostgreSQL 9.0
Stream WAL files to the standbys
primary_conninfo in recovery.conf
Block Based
Physical Replication - Streaming Replication
WAL Receiver - on Standbys
Startup - on Standbys
WAL Sender - on Primary
Physical Replication - Streaming Replication
Start Connection
primary_conninfo
Authentication
Password Response
Authentication Done
Identify System
and start to
stream WAL
System Identified and
send WAL files
Standby
WAL Receiver
Primary
WAL Sender
Physical Replication - Streaming Replication
Primary Server Secondary Server
WAL Records
WAL Records
WAL Records
WAL Receiver
WAL Sender
Physical Replication - Streaming Replication
Replication Lag can be reduced
Supports Synchronous Replication
Used for Failover
Requires direct connection
Requires DB user
Physical Replication - Streaming Replication / Log Shipping
Same PostgreSQL Version
Same Architecture
Entire Dataset
No writes are possible
Logical Replication - Publisher/Subscriber Model
table - t1 and t2 on database test
Connection Details
PostgreSQL 10
Publication - Source Server
Publisher
Subscription - Destination Server
Subsciber
Logical Replication - Publisher/Subscriber Model
WAL Sender - Publisher
Logical Replication Launcher - Subscriber
Logical Replication - Publisher/Subscriber Model
Source/Publisher Destination/Subscriber
WAL Records WAL Sender Logical Replication
Launcher
Publication
Decoding
Logical
Messages
Subscriber
Logical Replication - Publisher/Subscriber Model
Granularity in replicating data
can write on the destination
Replicate across different versions
DDL is not supported
Not for failover
Physical / Logical
How to achieve HA
How to achieve HA
Application
Primary Server
Writes
Secondary Servers
Reads
How to achieve HA
Application
Primary Server
Writes
Secondary Servers
Reads
High Availability
Frameworks
High Availability Frameworks
Patroni
Repmgr
PAF
pgpool -II
High Availability Frameworks - Patroni
ETCD Server
Secondary Servers
Primary Server
Patroni
Patroni
Patroni
High Availability Frameworks - Patroni
Continuous Monitoring
Automatic Failover
Easy to add or remove the node
Join back the node
Support manual switchover too
Scheduling maintenance
Points to Note
Test the tool for auto-failover
Load Balancing
Frequent DR activity
Maintain Backups
Proper Monitoring
Reach Us : Info@mydbops.com
Thank You

More Related Content

PDF
Deep dive into PostgreSQL statistics.
PDF
PostgreSQL replication
PDF
High Availability PostgreSQL with Zalando Patroni
PDF
PostgreSQL WAL for DBAs
PDF
Solving PostgreSQL wicked problems
PPTX
515689311-Postgresql-DBA-Architecture.pptx
PDF
PostgreSQL and RAM usage
ODP
OpenGurukul : Database : PostgreSQL
Deep dive into PostgreSQL statistics.
PostgreSQL replication
High Availability PostgreSQL with Zalando Patroni
PostgreSQL WAL for DBAs
Solving PostgreSQL wicked problems
515689311-Postgresql-DBA-Architecture.pptx
PostgreSQL and RAM usage
OpenGurukul : Database : PostgreSQL

What's hot (20)

PDF
PostgreSQL HA
PPTX
PostgreSQL Database Slides
PDF
Backup and-recovery2
PDF
Linux tuning to improve PostgreSQL performance
PDF
Postgresql database administration volume 1
ODP
PostgreSQL Administration for System Administrators
PDF
PostgreSQL High Availability in a Containerized World
PDF
Mastering PostgreSQL Administration
PPTX
Postgresql Database Administration Basic - Day1
PPTX
Getting started with postgresql
PDF
MongoDB WiredTiger Internals
PDF
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
PPTX
Introduction to MongoDB
PPTX
Mongodb basics and architecture
PDF
PostgreSQL : Introduction
ZIP
NoSQL databases
PDF
Introduction to Docker Compose
PPTX
MongoDB presentation
PDF
PostgreSQL Tutorial For Beginners | Edureka
PDF
Maxscale switchover, failover, and auto rejoin
PostgreSQL HA
PostgreSQL Database Slides
Backup and-recovery2
Linux tuning to improve PostgreSQL performance
Postgresql database administration volume 1
PostgreSQL Administration for System Administrators
PostgreSQL High Availability in a Containerized World
Mastering PostgreSQL Administration
Postgresql Database Administration Basic - Day1
Getting started with postgresql
MongoDB WiredTiger Internals
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Introduction to MongoDB
Mongodb basics and architecture
PostgreSQL : Introduction
NoSQL databases
Introduction to Docker Compose
MongoDB presentation
PostgreSQL Tutorial For Beginners | Edureka
Maxscale switchover, failover, and auto rejoin
Ad

Similar to PostgreSQL Replication High Availability Methods (20)

PPTX
Built in physical and logical replication in postgresql-Firat Gulec
PDF
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
 
PDF
How to Replicate PostgreSQL Database
PPTX
PG_Phsycal_logical_study_Replication.pptx
PPTX
Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptx
PDF
The Magic of Hot Streaming Replication, Bruce Momjian
PDF
Postgres Vienna DB Meetup 2014
PDF
PostgreSQL Sharding and HA: Theory and Practice (PGConf.ASIA 2017)
PPTX
StreSd332g_ReplADSSAon_aerasd333333.pptx
PDF
Streaming replication in practice
PDF
Out of the Box Replication in Postgres 9.4(pgconfsf)
PDF
Replication in PostgreSQL tutorial given in Postgres Conference 2019
PPTX
Postgresql_Replication.pptx
PPTX
PostgreSQL Hangout Replication Features v9.4
PDF
PostgreSQL replication
PDF
Managing replication of PostgreSQL, Simon Riggs
PDF
PGConf APAC 2018: PostgreSQL 10 - Replication goes Logical
PDF
Out of the box replication in postgres 9.4(pg confus)
PDF
Out of the Box Replication in Postgres 9.4(PgConfUS)
PDF
PostgreSQL Replication Tutorial
Built in physical and logical replication in postgresql-Firat Gulec
Die 10 besten PostgreSQL-Replikationsstrategien für Ihr Unternehmen
 
How to Replicate PostgreSQL Database
PG_Phsycal_logical_study_Replication.pptx
Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptx
The Magic of Hot Streaming Replication, Bruce Momjian
Postgres Vienna DB Meetup 2014
PostgreSQL Sharding and HA: Theory and Practice (PGConf.ASIA 2017)
StreSd332g_ReplADSSAon_aerasd333333.pptx
Streaming replication in practice
Out of the Box Replication in Postgres 9.4(pgconfsf)
Replication in PostgreSQL tutorial given in Postgres Conference 2019
Postgresql_Replication.pptx
PostgreSQL Hangout Replication Features v9.4
PostgreSQL replication
Managing replication of PostgreSQL, Simon Riggs
PGConf APAC 2018: PostgreSQL 10 - Replication goes Logical
Out of the box replication in postgres 9.4(pg confus)
Out of the Box Replication in Postgres 9.4(PgConfUS)
PostgreSQL Replication Tutorial
Ad

More from Mydbops (20)

PDF
Scaling TiDB for Large-Scale Application
PDF
AWS MySQL Showdown - RDS vs RDS Multi AZ vs Aurora vs Serverless - Mydbops...
PDF
Mastering Vector Search with MongoDB Atlas - Manosh Malai - Mydbops MyWebinar 39
PDF
Migration Journey To TiDB - Kabilesh PR - Mydbops MyWebinar 38
PDF
AWS Blue Green Deployment for Databases - Mydbops
PDF
What's New In MySQL 8.4 LTS Mydbops MyWebinar Edition 36
PDF
What's New in PostgreSQL 17? - Mydbops MyWebinar Edition 35
PDF
What's New in MongoDB 8.0 - Mydbops MyWebinar Edition 34
PDF
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
PDF
Read/Write Splitting using MySQL Router - Mydbops Meetup16
PDF
TiDB - From Data to Discovery: Exploring the Intersection of Distributed Dat...
PDF
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
PDF
Demystifying Real time Analytics with TiDB
PDF
Must Know Postgres Extension for DBA and Developer during Migration
PDF
Efficient MySQL Indexing and what's new in MySQL Explain
PDF
Scale your database traffic with Read & Write split using MySQL Router
PDF
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
PDF
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
PDF
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
PDF
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...
Scaling TiDB for Large-Scale Application
AWS MySQL Showdown - RDS vs RDS Multi AZ vs Aurora vs Serverless - Mydbops...
Mastering Vector Search with MongoDB Atlas - Manosh Malai - Mydbops MyWebinar 39
Migration Journey To TiDB - Kabilesh PR - Mydbops MyWebinar 38
AWS Blue Green Deployment for Databases - Mydbops
What's New In MySQL 8.4 LTS Mydbops MyWebinar Edition 36
What's New in PostgreSQL 17? - Mydbops MyWebinar Edition 35
What's New in MongoDB 8.0 - Mydbops MyWebinar Edition 34
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Read/Write Splitting using MySQL Router - Mydbops Meetup16
TiDB - From Data to Discovery: Exploring the Intersection of Distributed Dat...
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
Demystifying Real time Analytics with TiDB
Must Know Postgres Extension for DBA and Developer during Migration
Efficient MySQL Indexing and what's new in MySQL Explain
Scale your database traffic with Read & Write split using MySQL Router
PostgreSQL Schema Changes with pg-osc - Mydbops @ PGConf India 2024
Choosing the Right Database: Exploring MySQL Alternatives for Modern Applicat...
Mastering Aurora PostgreSQL Clusters for Disaster Recovery
Navigating Transactions: ACID Complexity in Modern Databases- Mydbops Open So...

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Encapsulation theory and applications.pdf
PPTX
Cloud computing and distributed systems.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Empathic Computing: Creating Shared Understanding
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Approach and Philosophy of On baking technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
cuic standard and advanced reporting.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Encapsulation theory and applications.pdf
Cloud computing and distributed systems.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
A Presentation on Artificial Intelligence
Chapter 3 Spatial Domain Image Processing.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation_ Review paper, used for researhc scholars
Empathic Computing: Creating Shared Understanding
Network Security Unit 5.pdf for BCA BBA.
Understanding_Digital_Forensics_Presentation.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Approach and Philosophy of On baking technology
Dropbox Q2 2025 Financial Results & Investor Presentation
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Reach Out and Touch Someone: Haptics and Empathic Computing

PostgreSQL Replication High Availability Methods