SlideShare a Scribd company logo
1 of 33
Download to read offline
1
Evolution of FaultEvolution of Fault
Tolerance inTolerance in
156398, MSc156398, MSc
@@
18 April 2016 Tallinn18 April 2016 Tallinn
PostgreSQLPostgreSQL
Gulcin YildirimGulcin Yildirim
IAF0530IAF0530 Tallinn University of TechnologyTallinn University of Technology
2
Overview of PostgreSQL Database
PostgreSQL Fault Tolerance: WAL
What is Replication?
Replication Methods for PostgreSQL
Physical Replication
Streaming Replication and WAL
Managing Timeline Issues: pg_rewind
Trigger-based Replication: Londiste, Slony
Logical Decoding : BDR and pglogical
AgendaAgenda
3
PostgreSQL in a nutshell (9.5)PostgreSQL in a nutshell (9.5)
Advanced open source db system
SQL standards compliance up to SQL:2011
Supports different data models: relational, document (JSON and
XML), and key/value (hstore extension)
Highly extensible
Fully ACID-compliant (atomicity, consistency, isolation, durability)
Allows physical and logical replication
Built-in physical and logical backup solution
Synchronous and asynchronous transactions
PITR (Point-in-time Recovery)
MVCC (Multiversion concurrency control)
4
PostgreSQL is robust!PostgreSQL is robust!
All actions on the database are performed within transactions, protected
by a transaction log that will perform automatic crash recovery in case
of software failure.
Databases may be optionally created with data block checksums to help
diagnose hardware faults. Multiple backup mechanisms exist, with full
and detailed PITR, in case of the need for detailed recovery. A variety of
diagnostic tools are available.
Database replication is supported natively.
Synchronous Replication can provide greater than "5 Nines" (99.999
percent) availability and data protection, if properly configured and
managed.
5
WAL Write-ahead LogWAL Write-ahead Log
The WAL consists of a series of binary files written to the pg_xlog
subdirectory of the PostgreSQL data directory.
Each change made to the database is recorded first in WAL, hence the
name "write-ahead" log, as a synonym of "transaction log". When a
transaction commits, the default—and safe—behaviour is to force the
WAL records to disk.
Should PostgreSQL crash, the WAL will be replayed, which returns the
database to the point of the last committed transaction, and thus ensures
the durability of any database changes.
6
Transaction? Commit?Transaction? Commit?
Database changes themselves aren't written to disk at transaction commit.
Those changes are written to disk sometime later by the background writer on a
well-tuned server. (WAL)
Transactions are a fundamental concept of all database systems. The
essential point of a transaction is that it bundles multiple steps into a
single, all-or-nothing operation.
The intermediate states between the steps are not visible to other
concurrent transactions, and if some failure occurs that prevents the
transaction from completing, then none of the steps affect the database at
all. ( PostgreSQL does not support dirty-reads. )
7
CheckpointCheckpoint
Crash recovery replays the WAL, but from what point does it start to recover?
Recovery starts from points in the WAL known as checkpoints. The
duration of crash recovery depends on the number of changes in the
transaction log since the last checkpoint. A checkpoint is a known safe
starting point for recovery, since it guarantees that all the previous
changes to the database have already been written to disk.
A checkpoint can be either immediate or scheduled. Immediate
checkpoints are triggered by some action of a superuser, such as the
CHECKPOINT command or other; scheduled checkpoints are decided
automatically by PostgreSQL.
8
PostgreSQL ReplicationPostgreSQL Replication
Database replication is the term we use to describe the technology used
to maintain a copy of a set of data on a remote system.
9
Postgres Replication HistoryPostgres Replication History
PostgreSQL 7.x (~2000)
Replication should not be part of core Postgres
Londiste - Slony (trigger based logical replication)
PostgreSQL 8.0 (2005)
Point-In-Time Recovery (WAL)
PostgreSQL 9.0 (2010)
Streaming Replication (physical)
PostgreSQL 9.4 (2014)
Logical Decoding (changeset extraction)
10
Physical ReplicationPhysical Replication
11
Physical ReplicationPhysical Replication
The existing replication is more properly known as Physical Streaming
Replication since we are streaming a series of physical changes from one
node to another. That means that when we insert a row into a table we
generate change records for the insert plus all of the index entries.
When we VACUUM a table we also generate change records.
Also, Physical Streaming Replication records all changes at the
byte/block level, making it very hard to do anything other than just
replay everything.
12
Physical ReplicationPhysical Replication
WAL over network from master to standby
Sending files: scp, rsync, ftp
Streaming changes: using internal
protocol (sender and receiver processes)
13
Standby ModesStandby Modes
Warm Standby
Can be activated immediately, but cannot perform
useful work until activated
Hot Standby
Node is already active
Read-only queries only
Multi-Master
All nodes can perform read/write work
14
Warm StandbyWarm Standby
Warm Standby
15
Hot StandbyHot Standby
Hot Standby
16
WAL LevelWAL Level
minimal ---------------------->
replica ----------------------->
logical ------------------------>
Suitable ForSuitable For
crash recovery
physical replication
file-based archiving
logical replication
WAL and ReplicationWAL and Replication
17
Failover and SwitchoverFailover and Switchover
In single-master replication, if the master dies, one of the standbys must
take its place ( promotion ). Otherwise, we will not be able to accept new
write transactions. Thus, the term designations, master and standby, are
just roles that any node can take at some point. To move the master role to
another node, we perform a procedure named Switchover.
If the master dies and does not recover, then the more severe role change
is known as a Failover. In many ways, these can be similar, but it helps to
use different terms for each event.
18
TimelinesTimelines
TL1
TL2
Master (Old master)
Standby (New master)
Failover
There are outstanding changes in the old master
Timeline increase represents new history of changes
Changes from the old timeline can't be replayed
on the servers that switched to new timeline
The old master can't follow the new master
19
TimelinesTimelines
TL1
TL2
Master (Old master)
Standby (New master)
Switchover
There are no outstanding changes in the old master
Timeline increase represents new history of changes
The old master can become standby for the new
master
20
pg_rewind (9.5)pg_rewind (9.5)
TL1
TL2
Master (Old master)
Standby (New master)
Outstanding changes are removed using data from
the new master
The old master can follow the new master
21
Synchronous commitSynchronous commit
By default, PostgreSQL implements asynchronous replication, where
data is streamed out whenever convenient for the server. As we've seen
this can mean data loss in case of failover. It's possible to ask Postgres to
require one (or more) standbys to acknowledge replication of the data
prior to commit, this is called synchronous replication ( synchronous
commit ).
With synchronous replication, the replication delay directly affects the
elapsed time of transactions on the master. With asynchronous
replication, the master may continue at full speed.
Synchronous replication guarantees that data is written to at least two
nodes before the user or application is told that a transaction has
committed.
22
Synchronous commitSynchronous commit
The user can select the commit mode of each transaction, so that it
is possible to have both synchronous and asynchronous commit
transactions running concurrently.
This allows flexible trade-offs between performance and certainty
of transaction durability.
23
Logical ReplicationLogical Replication
24
Logical ReplicationLogical Replication
Unlike physical replication which captures changes to the
raw data on disk, the logical replication captures the logical
changes to the individual records in database and replicates
those.
This allows for more complex replication topology than
master and standby and also allows for partial replication of
the database (selective replication) .
The logical records work across major releases, so we can
use this to upgrade from one release to another.
There are two basic approaches to logical replication, the
trigger-based and the changeset extraction (called logical
decoding in PostgreSQL).
25
Trigger-based ReplicationTrigger-based Replication
26
Triggered-based ReplicationTriggered-based Replication
Slony (~2004), Londiste (~2007)
Predates the physical replication (as a result of the "no
replication in core philosophy")
Uses triggers to capture the changes to individual table
Increases the amount of work needed to be done for each
write
Use table(s) as queue
Duplicates all writes
27
Logical Decoding a.k.a.Logical Decoding a.k.a.
Changeset ExtractionChangeset Extraction
Extracts information from Write-Ahead Log into logical changes
(INSERT/UPDATE/DELETE)
Per row and commit ordered
No write amplification
C API for output plugin
No DDL
SQL Interface
Streaming Interface
28
Logical Streaming ReplicationLogical Streaming Replication
Build on top of logical decoding
Uses same transport mechanism as streaming replication
(sender & apply)
Allows for synchronous commit
Currently available as extensions: BDR and pglogical
Better performant than trigger-based replications
29
pglogicalpglogical
Publish / Subscribe model
Multiple upstream (publisher) servers into a single subscriber
Replicates transactions in commit order
Selective Replication
Online Upgrade
Data Transport
Data integration
Streaming changes to analytical database
Master configuration data management
...
Optionally synchronous (mix)
30
BDR Bi-directional ReplicationBDR Bi-directional Replication
The project is used for feeding logical replication
development in PostgreSQL
Multi-master
Asynchronous
Optimistic conflict detection (after commit)
Does not prevent concurrent writes
Conflict resolution:
Happens automatically
Last update wins by default
Custom resolution triggers
Eventually consistent (cluster)
31
BDR Bi-Directional ReplicationBDR Bi-Directional Replication
Bi-directional Replication
32
Thank you!Thank you!
33
ReferencesReferences
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
PostgreSQL 9 High Availability Cookbook
PostgreSQL Replication
PostgreSQL Documentation - High Availability, Load Balancing and
Replication
BDR Documentation
PostgreSQL 9 Administration Cookbook - Second Edition
Why Logical Replication?
pglogical
Performance limits of logical replication solutions
Streaming replication slots in PostgreSQL 9.4
Failover slots for PostgreSQL
Continuous Archiving and Point-in-Time Recovery (PITR)
pg_rewind Nordic PGDay presentation by Heikki Linnakangas

More Related Content

Viewers also liked

Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016Gulcin Yildirim Jelinek
 
PGconf India 2017 - Closing Note
PGconf India 2017 - Closing NotePGconf India 2017 - Closing Note
PGconf India 2017 - Closing NotePavan Deolasee
 
LUG-BG - Kostadin Slavkov - PostgreSQL 10
LUG-BG - Kostadin Slavkov - PostgreSQL 10LUG-BG - Kostadin Slavkov - PostgreSQL 10
LUG-BG - Kostadin Slavkov - PostgreSQL 10Marian Marinov
 
Scaling PostgreSQL with Skytools
Scaling PostgreSQL with SkytoolsScaling PostgreSQL with Skytools
Scaling PostgreSQL with SkytoolsGavin Roy
 
Londiste Replication system for PostgreSQL
Londiste Replication system for PostgreSQLLondiste Replication system for PostgreSQL
Londiste Replication system for PostgreSQLelliando dias
 
2014.10.15 Сергей Бурладян, Avito.ru
2014.10.15 Сергей Бурладян, Avito.ru2014.10.15 Сергей Бурладян, Avito.ru
2014.10.15 Сергей Бурладян, Avito.ruNikolay Samokhvalov
 
10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQLPostgreSQL-Consulting
 
Monitoreo tunning postgresql_2011
Monitoreo tunning postgresql_2011Monitoreo tunning postgresql_2011
Monitoreo tunning postgresql_2011Lennin Caro
 
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
 
Entrepreneurship Reflective Learning Diary
Entrepreneurship Reflective Learning DiaryEntrepreneurship Reflective Learning Diary
Entrepreneurship Reflective Learning DiaryGulcin Yildirim Jelinek
 
Go Faster With Native Compilation
Go Faster With Native CompilationGo Faster With Native Compilation
Go Faster With Native CompilationPGConf APAC
 
Replication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorReplication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorCommand Prompt., Inc
 
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
 
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
 
(Ab)using 4d Indexing
(Ab)using 4d Indexing(Ab)using 4d Indexing
(Ab)using 4d IndexingPGConf APAC
 

Viewers also liked (20)

Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
Managing PostgreSQL with Ansible - FOSDEM PGDay 2016
 
PGconf India 2017 - Closing Note
PGconf India 2017 - Closing NotePGconf India 2017 - Closing Note
PGconf India 2017 - Closing Note
 
LUG-BG - Kostadin Slavkov - PostgreSQL 10
LUG-BG - Kostadin Slavkov - PostgreSQL 10LUG-BG - Kostadin Slavkov - PostgreSQL 10
LUG-BG - Kostadin Slavkov - PostgreSQL 10
 
Scaling PostgreSQL with Skytools
Scaling PostgreSQL with SkytoolsScaling PostgreSQL with Skytools
Scaling PostgreSQL with Skytools
 
Londiste Replication system for PostgreSQL
Londiste Replication system for PostgreSQLLondiste Replication system for PostgreSQL
Londiste Replication system for PostgreSQL
 
2014.10.15 Сергей Бурладян, Avito.ru
2014.10.15 Сергей Бурладян, Avito.ru2014.10.15 Сергей Бурладян, Avito.ru
2014.10.15 Сергей Бурладян, Avito.ru
 
10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL
 
Monitoreo tunning postgresql_2011
Monitoreo tunning postgresql_2011Monitoreo tunning postgresql_2011
Monitoreo tunning postgresql_2011
 
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
 
Entrepreneurship Reflective Learning Diary
Entrepreneurship Reflective Learning DiaryEntrepreneurship Reflective Learning Diary
Entrepreneurship Reflective Learning Diary
 
Go Faster With Native Compilation
Go Faster With Native CompilationGo Faster With Native Compilation
Go Faster With Native Compilation
 
Pg migrator
Pg migratorPg migrator
Pg migrator
 
Replication using PostgreSQL Replicator
Replication using PostgreSQL ReplicatorReplication using PostgreSQL Replicator
Replication using PostgreSQL Replicator
 
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
 
Go replicator
Go replicatorGo replicator
Go replicator
 
Backup and-recovery2
Backup and-recovery2Backup and-recovery2
Backup and-recovery2
 
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
 
(Ab)using 4d Indexing
(Ab)using 4d Indexing(Ab)using 4d Indexing
(Ab)using 4d Indexing
 

Recently uploaded

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 

Recently uploaded (20)

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 

Evolution of Fault Tolerance in PostgreSQL

  • 1. 1 Evolution of FaultEvolution of Fault Tolerance inTolerance in 156398, MSc156398, MSc @@ 18 April 2016 Tallinn18 April 2016 Tallinn PostgreSQLPostgreSQL Gulcin YildirimGulcin Yildirim IAF0530IAF0530 Tallinn University of TechnologyTallinn University of Technology
  • 2. 2 Overview of PostgreSQL Database PostgreSQL Fault Tolerance: WAL What is Replication? Replication Methods for PostgreSQL Physical Replication Streaming Replication and WAL Managing Timeline Issues: pg_rewind Trigger-based Replication: Londiste, Slony Logical Decoding : BDR and pglogical AgendaAgenda
  • 3. 3 PostgreSQL in a nutshell (9.5)PostgreSQL in a nutshell (9.5) Advanced open source db system SQL standards compliance up to SQL:2011 Supports different data models: relational, document (JSON and XML), and key/value (hstore extension) Highly extensible Fully ACID-compliant (atomicity, consistency, isolation, durability) Allows physical and logical replication Built-in physical and logical backup solution Synchronous and asynchronous transactions PITR (Point-in-time Recovery) MVCC (Multiversion concurrency control)
  • 4. 4 PostgreSQL is robust!PostgreSQL is robust! All actions on the database are performed within transactions, protected by a transaction log that will perform automatic crash recovery in case of software failure. Databases may be optionally created with data block checksums to help diagnose hardware faults. Multiple backup mechanisms exist, with full and detailed PITR, in case of the need for detailed recovery. A variety of diagnostic tools are available. Database replication is supported natively. Synchronous Replication can provide greater than "5 Nines" (99.999 percent) availability and data protection, if properly configured and managed.
  • 5. 5 WAL Write-ahead LogWAL Write-ahead Log The WAL consists of a series of binary files written to the pg_xlog subdirectory of the PostgreSQL data directory. Each change made to the database is recorded first in WAL, hence the name "write-ahead" log, as a synonym of "transaction log". When a transaction commits, the default—and safe—behaviour is to force the WAL records to disk. Should PostgreSQL crash, the WAL will be replayed, which returns the database to the point of the last committed transaction, and thus ensures the durability of any database changes.
  • 6. 6 Transaction? Commit?Transaction? Commit? Database changes themselves aren't written to disk at transaction commit. Those changes are written to disk sometime later by the background writer on a well-tuned server. (WAL) Transactions are a fundamental concept of all database systems. The essential point of a transaction is that it bundles multiple steps into a single, all-or-nothing operation. The intermediate states between the steps are not visible to other concurrent transactions, and if some failure occurs that prevents the transaction from completing, then none of the steps affect the database at all. ( PostgreSQL does not support dirty-reads. )
  • 7. 7 CheckpointCheckpoint Crash recovery replays the WAL, but from what point does it start to recover? Recovery starts from points in the WAL known as checkpoints. The duration of crash recovery depends on the number of changes in the transaction log since the last checkpoint. A checkpoint is a known safe starting point for recovery, since it guarantees that all the previous changes to the database have already been written to disk. A checkpoint can be either immediate or scheduled. Immediate checkpoints are triggered by some action of a superuser, such as the CHECKPOINT command or other; scheduled checkpoints are decided automatically by PostgreSQL.
  • 8. 8 PostgreSQL ReplicationPostgreSQL Replication Database replication is the term we use to describe the technology used to maintain a copy of a set of data on a remote system.
  • 9. 9 Postgres Replication HistoryPostgres Replication History PostgreSQL 7.x (~2000) Replication should not be part of core Postgres Londiste - Slony (trigger based logical replication) PostgreSQL 8.0 (2005) Point-In-Time Recovery (WAL) PostgreSQL 9.0 (2010) Streaming Replication (physical) PostgreSQL 9.4 (2014) Logical Decoding (changeset extraction)
  • 11. 11 Physical ReplicationPhysical Replication The existing replication is more properly known as Physical Streaming Replication since we are streaming a series of physical changes from one node to another. That means that when we insert a row into a table we generate change records for the insert plus all of the index entries. When we VACUUM a table we also generate change records. Also, Physical Streaming Replication records all changes at the byte/block level, making it very hard to do anything other than just replay everything.
  • 12. 12 Physical ReplicationPhysical Replication WAL over network from master to standby Sending files: scp, rsync, ftp Streaming changes: using internal protocol (sender and receiver processes)
  • 13. 13 Standby ModesStandby Modes Warm Standby Can be activated immediately, but cannot perform useful work until activated Hot Standby Node is already active Read-only queries only Multi-Master All nodes can perform read/write work
  • 16. 16 WAL LevelWAL Level minimal ----------------------> replica -----------------------> logical ------------------------> Suitable ForSuitable For crash recovery physical replication file-based archiving logical replication WAL and ReplicationWAL and Replication
  • 17. 17 Failover and SwitchoverFailover and Switchover In single-master replication, if the master dies, one of the standbys must take its place ( promotion ). Otherwise, we will not be able to accept new write transactions. Thus, the term designations, master and standby, are just roles that any node can take at some point. To move the master role to another node, we perform a procedure named Switchover. If the master dies and does not recover, then the more severe role change is known as a Failover. In many ways, these can be similar, but it helps to use different terms for each event.
  • 18. 18 TimelinesTimelines TL1 TL2 Master (Old master) Standby (New master) Failover There are outstanding changes in the old master Timeline increase represents new history of changes Changes from the old timeline can't be replayed on the servers that switched to new timeline The old master can't follow the new master
  • 19. 19 TimelinesTimelines TL1 TL2 Master (Old master) Standby (New master) Switchover There are no outstanding changes in the old master Timeline increase represents new history of changes The old master can become standby for the new master
  • 20. 20 pg_rewind (9.5)pg_rewind (9.5) TL1 TL2 Master (Old master) Standby (New master) Outstanding changes are removed using data from the new master The old master can follow the new master
  • 21. 21 Synchronous commitSynchronous commit By default, PostgreSQL implements asynchronous replication, where data is streamed out whenever convenient for the server. As we've seen this can mean data loss in case of failover. It's possible to ask Postgres to require one (or more) standbys to acknowledge replication of the data prior to commit, this is called synchronous replication ( synchronous commit ). With synchronous replication, the replication delay directly affects the elapsed time of transactions on the master. With asynchronous replication, the master may continue at full speed. Synchronous replication guarantees that data is written to at least two nodes before the user or application is told that a transaction has committed.
  • 22. 22 Synchronous commitSynchronous commit The user can select the commit mode of each transaction, so that it is possible to have both synchronous and asynchronous commit transactions running concurrently. This allows flexible trade-offs between performance and certainty of transaction durability.
  • 24. 24 Logical ReplicationLogical Replication Unlike physical replication which captures changes to the raw data on disk, the logical replication captures the logical changes to the individual records in database and replicates those. This allows for more complex replication topology than master and standby and also allows for partial replication of the database (selective replication) . The logical records work across major releases, so we can use this to upgrade from one release to another. There are two basic approaches to logical replication, the trigger-based and the changeset extraction (called logical decoding in PostgreSQL).
  • 26. 26 Triggered-based ReplicationTriggered-based Replication Slony (~2004), Londiste (~2007) Predates the physical replication (as a result of the "no replication in core philosophy") Uses triggers to capture the changes to individual table Increases the amount of work needed to be done for each write Use table(s) as queue Duplicates all writes
  • 27. 27 Logical Decoding a.k.a.Logical Decoding a.k.a. Changeset ExtractionChangeset Extraction Extracts information from Write-Ahead Log into logical changes (INSERT/UPDATE/DELETE) Per row and commit ordered No write amplification C API for output plugin No DDL SQL Interface Streaming Interface
  • 28. 28 Logical Streaming ReplicationLogical Streaming Replication Build on top of logical decoding Uses same transport mechanism as streaming replication (sender & apply) Allows for synchronous commit Currently available as extensions: BDR and pglogical Better performant than trigger-based replications
  • 29. 29 pglogicalpglogical Publish / Subscribe model Multiple upstream (publisher) servers into a single subscriber Replicates transactions in commit order Selective Replication Online Upgrade Data Transport Data integration Streaming changes to analytical database Master configuration data management ... Optionally synchronous (mix)
  • 30. 30 BDR Bi-directional ReplicationBDR Bi-directional Replication The project is used for feeding logical replication development in PostgreSQL Multi-master Asynchronous Optimistic conflict detection (after commit) Does not prevent concurrent writes Conflict resolution: Happens automatically Last update wins by default Custom resolution triggers Eventually consistent (cluster)
  • 31. 31 BDR Bi-Directional ReplicationBDR Bi-Directional Replication Bi-directional Replication
  • 33. 33 ReferencesReferences 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. PostgreSQL 9 High Availability Cookbook PostgreSQL Replication PostgreSQL Documentation - High Availability, Load Balancing and Replication BDR Documentation PostgreSQL 9 Administration Cookbook - Second Edition Why Logical Replication? pglogical Performance limits of logical replication solutions Streaming replication slots in PostgreSQL 9.4 Failover slots for PostgreSQL Continuous Archiving and Point-in-Time Recovery (PITR) pg_rewind Nordic PGDay presentation by Heikki Linnakangas