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 conļ¬gured and
managed.
5
WAL Write-ahead LogWAL Write-ahead Log
The WAL consists of a series of binary ļ¬les written to the pg_xlog
subdirectory of the PostgreSQL data directory.
Each change made to the database is recorded ļ¬rst 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 ļ¬les: 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
ļ¬le-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 ļ¬‚exible 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 ampliļ¬cation
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 conļ¬guration 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 conļ¬‚ict detection (after commit)
Does not prevent concurrent writes
Conļ¬‚ict 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
Ā 
A Practical Multi-Tenant Cluster
A Practical Multi-Tenant ClusterA Practical Multi-Tenant Cluster
A Practical Multi-Tenant ClusterCommand 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

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
Ā 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
Ā 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
Ā 
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
Ā 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
Ā 
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
Ā 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
Ā 
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 SERVICE9953056974 Low Rate Call Girls In Saket, Delhi NCR
Ā 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
Ā 
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
Ā 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
Ā 
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
Ā 
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
Ā 
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...Steffen Staab
Ā 
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
Ā 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
Ā 
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
Ā 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanā€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanā€™s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanā€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanā€™s ...OnePlan Solutions
Ā 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
Ā 

Recently uploaded (20)

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
Ā 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
Ā 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
Ā 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
Ā 
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
Ā 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.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
Ā 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
Ā 
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
Ā 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Ā 
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...
Ā 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Ā 
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
Ā 
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
Ā 
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data SpacesĀ - and Epistemic Querying of RDF-...
Ā 
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 ...
Ā 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
Ā 
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
Ā 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanā€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanā€™s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanā€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanā€™s ...
Ā 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
Ā 

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 conļ¬gured and managed.
  • 5. 5 WAL Write-ahead LogWAL Write-ahead Log The WAL consists of a series of binary ļ¬les written to the pg_xlog subdirectory of the PostgreSQL data directory. Each change made to the database is recorded ļ¬rst 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 ļ¬les: 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 ļ¬le-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 ļ¬‚exible 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 ampliļ¬cation 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 conļ¬guration 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 conļ¬‚ict detection (after commit) Does not prevent concurrent writes Conļ¬‚ict 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