SlideShare a Scribd company logo
1 of 51
Built-in Physical and Logical
Replication in Postgresql
Fırat Güleç
- Company
Hepsiexpress
- Now
Infrastructure & Database Manager
PostgreSQL Consulting
Member of Postgresql Europe
Contributing to Open Source Community
Agenda
• What is Replication?
• Why do we need Replication?
• How many replication layers do we have?
• Understanding milestones of built-in Database Physical Replication.
• What is the purpose of replication? and How to rescue system in case of failover?
• What is Streaming Replication and what is its advantages? Async vs Sync, Hot standby etc.
• How to configurate Master and Standby Servers? And What is the most important parameters?
Example of topoloji.
• What is Cascading Replication and how to configurate it? Live Demo on Terminal.
• Quorum Commit for Sync Replication etc.
• What is Logical Replication coming with PostgreSQL 10? And What is its advantages?
• What is the purpose of Logical replication?
• How to set up Logical Replication and What are its benefits?
• Limitations of Logical Replication
• Logical Replication vs Physical Replication in detail.
• 10 Questions quiz and giving some gifts to participants according to their success.
What is Replication?
Master Slave
Slave
Slave
Slave
Slave
Slave
Slave
Slave
Slave
Replication Layers
Application
Database logical
Database physical
Operating System
Hardware
SAN
NAS
DRBD
Streaming Replication
Logical Replication
Slony
Londiste
Pgpool II
Bucardo
High Availability, Load Balancing, and
Replication Feature Matrix
https://www.postgresql.org/docs/11/different-replication-solutions.html
Pyhsical Replication
The purpose of Streaming Replication?
High availability
App Server
Client
Master Slave
The purpose of Streaming Replication?
Load Balancing
App Server
Client
Master Slave
%50 %50
Database Physical Replication Milestones
File based
from 8
Streaming
Replication
9.0
Synchronous
since 9.1
Quorum
commit since
10.0
Architecture of Streaming Replication
Master Slave
WAL
WAL
sender
WAL
receiver
WAL Record
16 MB
pg_wal
WAL
Archieve
directory
Database Physical
File based
from 8
Streaming
Replication
9.0
Synchronous
since 9.1
Quorum
commit since
10.0
File based Replication from Postgresql 8.3
Master Slave
WAL
WAL
sender
WAL
receiver
WAL Record
16 MB
pg_wal
WAL
Archieve
directory
WAL 16 MB
Database Physical
File based
from 8
Streaming
Replication
9.0
Synchronous
since 9.1
Quorum
commit since
10.0
Streaming Replication
Master Slave
WAL
WAL
sender
WAL
receiver
WAL Record
16 MB
pg_wal
WAL
Archieve
directory
Record-based log shipping
The primary and standby servers so that they are as similar as possible
1- Major PostgreSQL release levels should be same
2- 32-bit to a 64-bit system will not work.
pg_wal
WAL
Database Physical
File based
from 8
Streaming
Replication
9.0
Synchronous
since 9.1
Quorum
commit since
10.0
Streaming Replication
Master Slave
WAL
WAL
sender
WAL
receiver
WAL Record
16 MB
1- Async vs Sync
2- Hot Standby or Warm
Standby?
read
write read
pg_wal
WAL
Archieve
directory
Database Physical
File based
from 8
Streaming
Replication
9.0
Synchronous
since 9.1
Quorum
commit since
10.0
Quorum Commit for Sync Replication
• 10.0: Quorum Commit
Master Slave 2
Slave 3
Slave 1
sync
10.0synchronous_standby_names ANY 2 (s1, s2, s3)
sync
sync
10.0synchronous_standby_names FIRST 2 (s1, s2, s3)
6 Steps for Streaming Replication
Master Slave
1. Replica user is created
2. Configuration for Master
3. Authentication
4. Configuration for Slave
5. Synchronization
6. Create Recovery.conf
Hot Standy - postgresql.conf
• wal_level  determines how much information is written
wal_level=‘minimal’
wal_level=‘replica’
wal_level=‘logical’
max_wal_senders
• max_wal_senders= specifies the maximum
number of concurrent connections
Master
Slave
Slave
Slave
wal_keep_segments
wal_keep_segments
Master Slave
WAL WAL
WAL
sender
WAL
receiver
WAL Record
16 MB
pg_wal
WAL
Archieve
directory
1-Replication User for Master
• sudo -u postgres psql
Next, create a new user and role with the following command:
• postgres=#CREATE USER replica REPLICATION LOGIN ENCRYPTED
PASSWORD ‘*******';
postgres=#du
• You should see the following output:
2-Hot Standby Configuration for Master
in postgresql.conf
• wal_level=replica
• wal_keep_segment=20
• max_wal_sender=3
• archieve_mode=on
• archive_command = 'test ! -f /var/lib/postgresql/pg_log_archive/%f
&& cp %p /var/lib/postgresql/pg_log_archive/%f'
3-pg_hba.conf configuration for Master
For authentication:
host replication replica 10.90.82.61/32 md5
4-Hot standy configuration for slave
In Postgresql.conf
• hot standby=on
Below configuration in case of fail over
• archive_mode = on
• archive_command = 'test ! -f /var/lib/postgresql/pg_log_archive/%f && cp
%p /var/lib/postgresql/pg_log_archive/%f‘
• wal_keep_segment=20
• max_wal_sender=3
5-Syncronize Data from Master Server to
Slave Server
On the slave server, stop the postgresql service:
• sudo systemctl stop postgresql and move existing data folder.
• pg_basebackup -h 10.90.82.31 -D /var/lib/postgresql/11/main/ -P -U
replica --wal-method=fetch
Master Slave
Transfering……
Data file directory
/var/lib/postgresql/11/main
10.90.82.31 10.90.82.61
6-Recovery.conf file on standby
Datafile Directory/var/lib/postgresql/11/main
Test Replication
Commandpsql -x -c "select * from pg_stat_replication;"
Streaming Replication is DONE
Cascading Postgresql Replication
Master
Slave
Slave
Slave
Slave
Slave
Slave
Upstream Slaves
Downstream Slaves
Replication
Cascading
Replicaiton
hot_standby=on
Syncronization
1.
2.
3.
async
4. recovery.conf
max_standby_archive_delay for standby
Logical Replication
Logical replication
Master Slave
Streaming replication
Master Slave
DB A
DB B
DB A
DB B
DB A
DB B
DB A
Employee
What is Logical Replication?
Master Slave
Streaming replication
Master Slave
Recovery Mode
Create index
Create table
Drop table
Create function
Insert
Delete
Select
Hot Standby
Select
Warm Standby
New Instance
Create index
Create table
Drop table
Create function
Insert
Delete
Select
What is Logical Replication?
Logical replication
Master Slave
Streaming replication
Master Slave
PostgreSQL 9.5 PostgreSQL 9.5
PostgreSQL 11 PostgreSQL 12
PostgreSQL 10
PostgreSQL 10
PostgreSQL 11
What is Logical Replication?
Logical replication
Expected use cases of Logical replication
Streaming replication Client
1. High availability 2. Load Balancing
Master Standby
1. Analytical Purpose
Master A
Master B
DB C
2. Sharing a subnet of database
Expected use cases of Logical replication
Streaming replication Client
1. High availability 2. Load Balancing
Master Standby
Master A Master B
3. Online Upgrade
PostgreSQL 10 PostgreSQL 11
App
Dump
Schema
Logical Replication
Logical replication
Master Slave
Streaming replication
Master Slave
WAL
sender
WAL
receiver
WAL Streaming
WAL
sender
Publication Subscription
Apply
Worker
WAL
WAL
Decoding
Decoded message Logical
Replication
Launcher
triggers
Architecture
What is Publication & Subscription?
Streaming replication
Master
Slave Slave
Streaming
Replication
Cascading
Replication
Slave A
Slave B
Publication 2
Publication 1
Subscription 2
Master
Subscription 1
Pub 3
Slave C
Subs 3
Users Name
Users Name Surname
Async vs Sync
Logical replication
Logical
Replication Slot 1
Logical
Replication Slot 2
Logical replication
Streaming replication
Master
Slave Slave
Streaming
Replication
Cascading
Replication
DB A
Sub 1
Pub 1
Surname
DB B
Address
Pub 2
Sub 2
Logical replication
Streaming replication
Master
Slave Slave
Streaming
Replication
Cascading
Replication
Server A
Surname
Server B
Surname
Bi directional replication not allowed
Logical Replication Limitations in 11.0
• does not replicate schema and DDL
• does not replicate sequences
• does not replicate Large Objects
• Replication is only possible from base tables to base tables
Logical replication with PostgreSQL 11
Master
10.90.82.30
wal_level = logical
1.
3.
WAL
6.
Publication 1
repluser
CREATE TABLE user (user_name text PRIMARY KEY, full_name text);
CREATE PUBLICATION Publication1 for table user;
4.
CREATE ROLE repluser WITH LOGIN PASSWORD 'admin123' REPLICATION ;
user
GRANT SELECT ON public.delivery TO repluser;
GRANT USAGE ON SCHEMA public TO repluser;
5.
7.
Slave
10.90.82.31
Connected to db with postgres c database1
2.
Pg_hba.conf host all repluser 10.90.82.31/0 md5
Connected to db with postgres c database2
1.
2.
CREATE SUBSCRIPTION Subscribe1 CONNECTION
'host=10.90.82.31 dbname=database1 user=repluser
password=admin123' PUBLICATION Publication 1 ;
Subscribe1
CREATE TABLE user (user_name text PRIMARY KEY,
full_name text);
user
3.
Logical Replication is DONE
Topology(Logical & Pyhsical Replication)
App Server
Client
Master Slave
read
write read
Slave
Cascading Replication
Streaming Replication
read
Reporting Server
Slave
Logical Replication
Analytical purposes
App Server
read
write
CPU & Memory
Monitoring on Terminal
1- pg_stat_replication
2- pg_replication_slots
3- pg_publication_tables
1- pg_subscription
2- pg_stat_subscription
3- pg_subscription_rel
Master Slave(Logical) Slave(Physical)
1- pg_stat_wal_receiver
https://kahoot.it/
With an innovative service approach,
We are shaping delivery and transportation system in
Turkey
www.hepsiexpress.com
Hepsiexpress & Horizon 2020
ISA: Innovative logistics
Solutions and data
framework for the on-
demand economy
We are looking for partners!
2018
Applications
Focus Areas for New
Projects
• Logistics Research & Innovation
• Route Optimisation
• Natural Language Processing
• Open Source Softwares
Thank you
Fırat Güleç

More Related Content

Similar to Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptx

Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Michael Renner
 
Tsm7.1 seminar Stavanger
Tsm7.1 seminar StavangerTsm7.1 seminar Stavanger
Tsm7.1 seminar StavangerSolv AS
 
Real-time Big Data Analytics Engine using Impala
Real-time Big Data Analytics Engine using ImpalaReal-time Big Data Analytics Engine using Impala
Real-time Big Data Analytics Engine using ImpalaJason Shih
 
SRV407 Deep Dive on Amazon Aurora
SRV407 Deep Dive on Amazon AuroraSRV407 Deep Dive on Amazon Aurora
SRV407 Deep Dive on Amazon AuroraAmazon Web Services
 
MySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisationMySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisationMark Swarbrick
 
Product Update: EDB Postgres Platform 2017
Product Update: EDB Postgres Platform 2017Product Update: EDB Postgres Platform 2017
Product Update: EDB Postgres Platform 2017EDB
 
Tips and Tricks for Operating Apache Kafka
Tips and Tricks for Operating Apache KafkaTips and Tricks for Operating Apache Kafka
Tips and Tricks for Operating Apache KafkaAll Things Open
 
Managing Oracle Enterprise Manager Cloud Control 12c with Oracle Clusterware
Managing Oracle Enterprise Manager Cloud Control 12c with Oracle ClusterwareManaging Oracle Enterprise Manager Cloud Control 12c with Oracle Clusterware
Managing Oracle Enterprise Manager Cloud Control 12c with Oracle ClusterwareLeighton Nelson
 
Cost Effectively Run Multiple Oracle Database Copies at Scale
Cost Effectively Run Multiple Oracle Database Copies at Scale Cost Effectively Run Multiple Oracle Database Copies at Scale
Cost Effectively Run Multiple Oracle Database Copies at Scale NetApp
 
SQL Server Alwayson for SharePoint HA/DR Step by Step Guide
SQL Server Alwayson for SharePoint HA/DR Step by Step GuideSQL Server Alwayson for SharePoint HA/DR Step by Step Guide
SQL Server Alwayson for SharePoint HA/DR Step by Step GuideLars Platzdasch
 
Streaming replication in practice
Streaming replication in practiceStreaming replication in practice
Streaming replication in practiceAlexey Lesovsky
 
Best Practices with PostgreSQL on Solaris
Best Practices with PostgreSQL on SolarisBest Practices with PostgreSQL on Solaris
Best Practices with PostgreSQL on SolarisJignesh Shah
 
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...BIOVIA
 
Oracle database 12c intro
Oracle database 12c introOracle database 12c intro
Oracle database 12c intropasalapudi
 
0396 oracle-goldengate-12c-tutorial
0396 oracle-goldengate-12c-tutorial0396 oracle-goldengate-12c-tutorial
0396 oracle-goldengate-12c-tutorialKlausePaulino
 
ProxySQL for MySQL
ProxySQL for MySQLProxySQL for MySQL
ProxySQL for MySQLMydbops
 
SQL AlwaysON for SharePoint HA/DR on Azure Global Azure Bootcamp 2017 Eisenac...
SQL AlwaysON for SharePoint HA/DR on Azure Global Azure Bootcamp 2017 Eisenac...SQL AlwaysON for SharePoint HA/DR on Azure Global Azure Bootcamp 2017 Eisenac...
SQL AlwaysON for SharePoint HA/DR on Azure Global Azure Bootcamp 2017 Eisenac...Lars Platzdasch
 

Similar to Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptx (20)

Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014
 
Tsm7.1 seminar Stavanger
Tsm7.1 seminar StavangerTsm7.1 seminar Stavanger
Tsm7.1 seminar Stavanger
 
Real-time Big Data Analytics Engine using Impala
Real-time Big Data Analytics Engine using ImpalaReal-time Big Data Analytics Engine using Impala
Real-time Big Data Analytics Engine using Impala
 
SRV407 Deep Dive on Amazon Aurora
SRV407 Deep Dive on Amazon AuroraSRV407 Deep Dive on Amazon Aurora
SRV407 Deep Dive on Amazon Aurora
 
MySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisationMySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisation
 
Product Update: EDB Postgres Platform 2017
Product Update: EDB Postgres Platform 2017Product Update: EDB Postgres Platform 2017
Product Update: EDB Postgres Platform 2017
 
Tips and Tricks for Operating Apache Kafka
Tips and Tricks for Operating Apache KafkaTips and Tricks for Operating Apache Kafka
Tips and Tricks for Operating Apache Kafka
 
PostgreSQL : Introduction
PostgreSQL : IntroductionPostgreSQL : Introduction
PostgreSQL : Introduction
 
Managing Oracle Enterprise Manager Cloud Control 12c with Oracle Clusterware
Managing Oracle Enterprise Manager Cloud Control 12c with Oracle ClusterwareManaging Oracle Enterprise Manager Cloud Control 12c with Oracle Clusterware
Managing Oracle Enterprise Manager Cloud Control 12c with Oracle Clusterware
 
Cost Effectively Run Multiple Oracle Database Copies at Scale
Cost Effectively Run Multiple Oracle Database Copies at Scale Cost Effectively Run Multiple Oracle Database Copies at Scale
Cost Effectively Run Multiple Oracle Database Copies at Scale
 
SQL Server vs Postgres
SQL Server vs PostgresSQL Server vs Postgres
SQL Server vs Postgres
 
SQL Server Alwayson for SharePoint HA/DR Step by Step Guide
SQL Server Alwayson for SharePoint HA/DR Step by Step GuideSQL Server Alwayson for SharePoint HA/DR Step by Step Guide
SQL Server Alwayson for SharePoint HA/DR Step by Step Guide
 
RMAN – The Pocket Knife of a DBA
RMAN – The Pocket Knife of a DBA RMAN – The Pocket Knife of a DBA
RMAN – The Pocket Knife of a DBA
 
Streaming replication in practice
Streaming replication in practiceStreaming replication in practice
Streaming replication in practice
 
Best Practices with PostgreSQL on Solaris
Best Practices with PostgreSQL on SolarisBest Practices with PostgreSQL on Solaris
Best Practices with PostgreSQL on Solaris
 
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...
(ATS4-PLAT01) Core Architecture Changes in AEP 9.0 and their Impact on Admini...
 
Oracle database 12c intro
Oracle database 12c introOracle database 12c intro
Oracle database 12c intro
 
0396 oracle-goldengate-12c-tutorial
0396 oracle-goldengate-12c-tutorial0396 oracle-goldengate-12c-tutorial
0396 oracle-goldengate-12c-tutorial
 
ProxySQL for MySQL
ProxySQL for MySQLProxySQL for MySQL
ProxySQL for MySQL
 
SQL AlwaysON for SharePoint HA/DR on Azure Global Azure Bootcamp 2017 Eisenac...
SQL AlwaysON for SharePoint HA/DR on Azure Global Azure Bootcamp 2017 Eisenac...SQL AlwaysON for SharePoint HA/DR on Azure Global Azure Bootcamp 2017 Eisenac...
SQL AlwaysON for SharePoint HA/DR on Azure Global Azure Bootcamp 2017 Eisenac...
 

Recently uploaded

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 

Recently uploaded (20)

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 

Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptx

  • 1. Built-in Physical and Logical Replication in Postgresql
  • 2. Fırat Güleç - Company Hepsiexpress - Now Infrastructure & Database Manager PostgreSQL Consulting Member of Postgresql Europe Contributing to Open Source Community
  • 3. Agenda • What is Replication? • Why do we need Replication? • How many replication layers do we have? • Understanding milestones of built-in Database Physical Replication. • What is the purpose of replication? and How to rescue system in case of failover? • What is Streaming Replication and what is its advantages? Async vs Sync, Hot standby etc. • How to configurate Master and Standby Servers? And What is the most important parameters? Example of topoloji. • What is Cascading Replication and how to configurate it? Live Demo on Terminal. • Quorum Commit for Sync Replication etc. • What is Logical Replication coming with PostgreSQL 10? And What is its advantages? • What is the purpose of Logical replication? • How to set up Logical Replication and What are its benefits? • Limitations of Logical Replication • Logical Replication vs Physical Replication in detail. • 10 Questions quiz and giving some gifts to participants according to their success.
  • 4. What is Replication? Master Slave Slave Slave Slave Slave Slave Slave Slave Slave
  • 5. Replication Layers Application Database logical Database physical Operating System Hardware SAN NAS DRBD Streaming Replication Logical Replication Slony Londiste Pgpool II Bucardo
  • 6. High Availability, Load Balancing, and Replication Feature Matrix https://www.postgresql.org/docs/11/different-replication-solutions.html
  • 8. The purpose of Streaming Replication? High availability App Server Client Master Slave
  • 9. The purpose of Streaming Replication? Load Balancing App Server Client Master Slave %50 %50
  • 10. Database Physical Replication Milestones File based from 8 Streaming Replication 9.0 Synchronous since 9.1 Quorum commit since 10.0
  • 11. Architecture of Streaming Replication Master Slave WAL WAL sender WAL receiver WAL Record 16 MB pg_wal WAL Archieve directory
  • 12. Database Physical File based from 8 Streaming Replication 9.0 Synchronous since 9.1 Quorum commit since 10.0
  • 13. File based Replication from Postgresql 8.3 Master Slave WAL WAL sender WAL receiver WAL Record 16 MB pg_wal WAL Archieve directory WAL 16 MB
  • 14. Database Physical File based from 8 Streaming Replication 9.0 Synchronous since 9.1 Quorum commit since 10.0
  • 15. Streaming Replication Master Slave WAL WAL sender WAL receiver WAL Record 16 MB pg_wal WAL Archieve directory Record-based log shipping The primary and standby servers so that they are as similar as possible 1- Major PostgreSQL release levels should be same 2- 32-bit to a 64-bit system will not work. pg_wal WAL
  • 16. Database Physical File based from 8 Streaming Replication 9.0 Synchronous since 9.1 Quorum commit since 10.0
  • 17. Streaming Replication Master Slave WAL WAL sender WAL receiver WAL Record 16 MB 1- Async vs Sync 2- Hot Standby or Warm Standby? read write read pg_wal WAL Archieve directory
  • 18. Database Physical File based from 8 Streaming Replication 9.0 Synchronous since 9.1 Quorum commit since 10.0
  • 19. Quorum Commit for Sync Replication • 10.0: Quorum Commit Master Slave 2 Slave 3 Slave 1 sync 10.0synchronous_standby_names ANY 2 (s1, s2, s3) sync sync 10.0synchronous_standby_names FIRST 2 (s1, s2, s3)
  • 20. 6 Steps for Streaming Replication Master Slave 1. Replica user is created 2. Configuration for Master 3. Authentication 4. Configuration for Slave 5. Synchronization 6. Create Recovery.conf
  • 21. Hot Standy - postgresql.conf • wal_level  determines how much information is written wal_level=‘minimal’ wal_level=‘replica’ wal_level=‘logical’
  • 22. max_wal_senders • max_wal_senders= specifies the maximum number of concurrent connections Master Slave Slave Slave
  • 24. wal_keep_segments Master Slave WAL WAL WAL sender WAL receiver WAL Record 16 MB pg_wal WAL Archieve directory
  • 25. 1-Replication User for Master • sudo -u postgres psql Next, create a new user and role with the following command: • postgres=#CREATE USER replica REPLICATION LOGIN ENCRYPTED PASSWORD ‘*******'; postgres=#du • You should see the following output:
  • 26. 2-Hot Standby Configuration for Master in postgresql.conf • wal_level=replica • wal_keep_segment=20 • max_wal_sender=3 • archieve_mode=on • archive_command = 'test ! -f /var/lib/postgresql/pg_log_archive/%f && cp %p /var/lib/postgresql/pg_log_archive/%f'
  • 27. 3-pg_hba.conf configuration for Master For authentication: host replication replica 10.90.82.61/32 md5
  • 28. 4-Hot standy configuration for slave In Postgresql.conf • hot standby=on Below configuration in case of fail over • archive_mode = on • archive_command = 'test ! -f /var/lib/postgresql/pg_log_archive/%f && cp %p /var/lib/postgresql/pg_log_archive/%f‘ • wal_keep_segment=20 • max_wal_sender=3
  • 29. 5-Syncronize Data from Master Server to Slave Server On the slave server, stop the postgresql service: • sudo systemctl stop postgresql and move existing data folder. • pg_basebackup -h 10.90.82.31 -D /var/lib/postgresql/11/main/ -P -U replica --wal-method=fetch Master Slave Transfering…… Data file directory /var/lib/postgresql/11/main 10.90.82.31 10.90.82.61
  • 30. 6-Recovery.conf file on standby Datafile Directory/var/lib/postgresql/11/main
  • 31. Test Replication Commandpsql -x -c "select * from pg_stat_replication;" Streaming Replication is DONE
  • 32. Cascading Postgresql Replication Master Slave Slave Slave Slave Slave Slave Upstream Slaves Downstream Slaves Replication Cascading Replicaiton hot_standby=on Syncronization 1. 2. 3. async 4. recovery.conf
  • 35. Logical replication Master Slave Streaming replication Master Slave DB A DB B DB A DB B DB A DB B DB A Employee What is Logical Replication?
  • 36. Master Slave Streaming replication Master Slave Recovery Mode Create index Create table Drop table Create function Insert Delete Select Hot Standby Select Warm Standby New Instance Create index Create table Drop table Create function Insert Delete Select What is Logical Replication? Logical replication
  • 37. Master Slave Streaming replication Master Slave PostgreSQL 9.5 PostgreSQL 9.5 PostgreSQL 11 PostgreSQL 12 PostgreSQL 10 PostgreSQL 10 PostgreSQL 11 What is Logical Replication? Logical replication
  • 38. Expected use cases of Logical replication Streaming replication Client 1. High availability 2. Load Balancing Master Standby 1. Analytical Purpose Master A Master B DB C 2. Sharing a subnet of database
  • 39. Expected use cases of Logical replication Streaming replication Client 1. High availability 2. Load Balancing Master Standby Master A Master B 3. Online Upgrade PostgreSQL 10 PostgreSQL 11 App Dump Schema Logical Replication
  • 40. Logical replication Master Slave Streaming replication Master Slave WAL sender WAL receiver WAL Streaming WAL sender Publication Subscription Apply Worker WAL WAL Decoding Decoded message Logical Replication Launcher triggers Architecture
  • 41. What is Publication & Subscription? Streaming replication Master Slave Slave Streaming Replication Cascading Replication Slave A Slave B Publication 2 Publication 1 Subscription 2 Master Subscription 1 Pub 3 Slave C Subs 3 Users Name Users Name Surname Async vs Sync Logical replication Logical Replication Slot 1 Logical Replication Slot 2
  • 42. Logical replication Streaming replication Master Slave Slave Streaming Replication Cascading Replication DB A Sub 1 Pub 1 Surname DB B Address Pub 2 Sub 2
  • 43. Logical replication Streaming replication Master Slave Slave Streaming Replication Cascading Replication Server A Surname Server B Surname Bi directional replication not allowed
  • 44. Logical Replication Limitations in 11.0 • does not replicate schema and DDL • does not replicate sequences • does not replicate Large Objects • Replication is only possible from base tables to base tables
  • 45. Logical replication with PostgreSQL 11 Master 10.90.82.30 wal_level = logical 1. 3. WAL 6. Publication 1 repluser CREATE TABLE user (user_name text PRIMARY KEY, full_name text); CREATE PUBLICATION Publication1 for table user; 4. CREATE ROLE repluser WITH LOGIN PASSWORD 'admin123' REPLICATION ; user GRANT SELECT ON public.delivery TO repluser; GRANT USAGE ON SCHEMA public TO repluser; 5. 7. Slave 10.90.82.31 Connected to db with postgres c database1 2. Pg_hba.conf host all repluser 10.90.82.31/0 md5 Connected to db with postgres c database2 1. 2. CREATE SUBSCRIPTION Subscribe1 CONNECTION 'host=10.90.82.31 dbname=database1 user=repluser password=admin123' PUBLICATION Publication 1 ; Subscribe1 CREATE TABLE user (user_name text PRIMARY KEY, full_name text); user 3. Logical Replication is DONE
  • 46. Topology(Logical & Pyhsical Replication) App Server Client Master Slave read write read Slave Cascading Replication Streaming Replication read Reporting Server Slave Logical Replication Analytical purposes App Server read write CPU & Memory
  • 47. Monitoring on Terminal 1- pg_stat_replication 2- pg_replication_slots 3- pg_publication_tables 1- pg_subscription 2- pg_stat_subscription 3- pg_subscription_rel Master Slave(Logical) Slave(Physical) 1- pg_stat_wal_receiver
  • 49. With an innovative service approach, We are shaping delivery and transportation system in Turkey www.hepsiexpress.com
  • 50. Hepsiexpress & Horizon 2020 ISA: Innovative logistics Solutions and data framework for the on- demand economy We are looking for partners! 2018 Applications Focus Areas for New Projects • Logistics Research & Innovation • Route Optimisation • Natural Language Processing • Open Source Softwares

Editor's Notes

  1. Servers that can modify data are called read/write, master or primary servers. Servers that track changes in the master are called standby or slave servers. A standby server that cannot be connected to until it is promoted to a master server is called a warm standby server, and one that can accept connections and serves read-only queries is called a hot standby server. This can be used to reduce the number of direct connections to the master and also to minimize inter-site bandwidth overheads.
  2. The amount of data loss is proportional to the replication delay at the time of failover. When requesting synchronous replication, each commit of a write transaction will wait until confirmation is received that the commit has been written to the transaction log on disk of both the primary and standby server. The only possibility that data can be lost is if both the primary and the standby suffer crashes at the same time. This can provide a much higher level of durability, though only if the sysadmin is cautious about the placement and management of the two servers. Waiting for confirmation increases the user's confidence that the changes will not be lost in the event of server crashes but it also necessarily increases the response time for the requesting transaction. The minimum wait time is the roundtrip time between primary to standby. Read only transactions and transaction rollbacks need not wait for replies from standby servers. Subtransaction commits do not wait for responses from standby servers, only top-level commits. Long running actions such as data loading or index building do not wait until the very final commit message. All two-phase commit actions require commit waits, including both prepare and commit.
  3. Streaming replication allows a standby server to stay more up-to-date than is possible with file-based log shipping. The standby connects to the primary, which streams WAL records to the standby as they're generated, without waiting for the WAL file to be filled.
  4. The amount of data loss is proportional to the replication delay at the time of failover. When requesting synchronous replication, each commit of a write transaction will wait until confirmation is received that the commit has been written to the transaction log on disk of both the primary and standby server. The only possibility that data can be lost is if both the primary and the standby suffer crashes at the same time. This can provide a much higher level of durability, though only if the sysadmin is cautious about the placement and management of the two servers. Waiting for confirmation increases the user's confidence that the changes will not be lost in the event of server crashes but it also necessarily increases the response time for the requesting transaction. The minimum wait time is the roundtrip time between primary to standby. Read only transactions and transaction rollbacks need not wait for replies from standby servers. Subtransaction commits do not wait for responses from standby servers, only top-level commits. Long running actions such as data loading or index building do not wait until the very final commit message. All two-phase commit actions require commit waits, including both prepare and commit.
  5. Streaming replication is asynchronous by default (see Section 26.2.8), in which case there is a small delay between committing a transaction in the primary and the changes becoming visible in the standby. This delay is however much smaller than with file-based log shipping, typically under one second assuming the standby is powerful enough to keep up with the load. With streaming replication, archive_timeout is not required to reduce the data loss window. The amount of data loss is proportional to the replication delay at the time of failover. When requesting synchronous replication, each commit of a write transaction will wait until confirmation is received that the commit has been written to the transaction log on disk of both the primary and standby server. The only possibility that data can be lost is if both the primary and the standby suffer crashes at the same time. This can provide a much higher level of durability, though only if the sysadmin is cautious about the placement and management of the two servers. Waiting for confirmation increases the user's confidence that the changes will not be lost in the event of server crashes but it also necessarily increases the response time for the requesting transaction. The minimum wait time is the roundtrip time between primary to standby. Read only transactions and transaction rollbacks need not wait for replies from standby servers. Subtransaction commits do not wait for responses from standby servers, only top-level commits. Long running actions such as data loading or index building do not wait until the very final commit message. All two-phase commit actions require commit waits, including both prepare and commit.
  6. Traditionally, only one server could act as a synchronous standby. This has changed. In PostgreSQL 10.0, the community has introduced quorum COMMITs. The idea is actually quite simple. Suppose you want five out of seven servers to confirm a transaction before the master returns a COMMIT. This is exactly what a quorum COMMIT does. It gives the developers and administrators a chance to define what COMMIT does in a more fine-grained way.
  7. Create replication user in Master Configuration for Master configuration for authentication Configuration for Slave Syncronize Data from Master Server to Slave Create recovery.conf file
  8. -minimal : only information needed to recover from a crash or an immediate shutdown -replica : enough data to support WAL archiving and replication -logical : enough information to support logical decoding.
  9. Specifies the maximum number of concurrent connections from standby servers or streaming base backup clients (i.e., the maximum number of simultaneously running WAL sender processes). The default is 10. The value 0 means replication is disabled. WAL sender processes count towards the total number of connections, so this parameter's value must be less than max_connections minus superuser_reserved_connections. Abrupt streaming client disconnection might leave an orphaned connection slot behind until a timeout is reached, so this parameter should be set slightly higher than the maximum number of expected clients so disconnected clients can immediately reconnect. This parameter can only be set at server start. Also, wal_level must be set to replica or higher to allow connections from standby servers.
  10. Specifies the minimum number of past log file segments kept in the pg_xlog directory, in case a standby server needs to fetch them for streaming replication. 
  11. Specifies the minimum number of past log file segments kept in the pg_wal directory, in case a standby server needs to fetch them for streaming replication. Each segment is normally 16 megabytes. If a standby server connected to the sending server falls behind by more than wal_keep_segments segments, the sending server might remove a WAL segment still needed by the standby, in which case the replication connection will be terminated. Downstream connections will also eventually fail as a result. (However, the standby server can recover by fetching the segment from archive, if WAL archiving is in use.)
  12. The write-ahead log files are collected at the end of the backup. Therefore, it is necessary for the wal_keep_segments parameter to be set high enough that the log is not removed before the end of the backup. If the log has been rotated when it's time to transfer it, the backup will fail and be unusable.
  13. which tells PostgreSQL how to retrieve archived WAL file segments
  14. The cascading replication feature allows a standby server to accept replication connections and stream WAL records to other standbys, acting as a relay. This can be used to reduce the number of direct connections to the master and also to minimize inter-site bandwidth overheads. A standby acting as both a receiver and a sender is known as a cascading standby. Standbys that are more directly connected to the master are known as upstream servers, while those standby servers further away are downstream servers. Cascading replication does not place limits on the number or arrangement of downstream servers, though each standby connects to only one upstream server which eventually links to a single master/primary server.
  15. When Hot Standby is active, this parameter determines how long the standby server should wait before canceling standby queries that conflict with about-to-be-applied WAL entries, as described in Section 26.5.2. max_standby_archive_delay applies when WAL data is being read from WAL archive (and is therefore not current). The default is 30 seconds. Units are milliseconds if not specified. A value of -1 allows the standby to wait forever for conflicting queries to complete. This parameter can only be set in the postgresql.conf file or on the server command line.
  16. Why we need to Logical replication? As we are moving out from physical replication, we are getting into Logical Replication
  17. Why we need to Logical replication? As we are moving out from physical replication, we are getting into Logical Replication
  18. 1- Each publication exists in only one database. 2- Publications may currently only contain tables.  3- Objects must be added explicitly, except when a publication is created for ALL TABLES. Every publication can have multiple subscribers. In the context of logical replication, a slot represents a stream of changes that can be replayed to a client in the order they were made on the origin server. Each slot streams a sequence of changes from a single database. A logical replication slot knows nothing about the state of the receiver(s). It's even possible to have multiple different receivers using the same slot at different times; they'll just get the changes following on from when the last receiver stopped consuming them. Only one receiver may consume changes from a slot at any given time.
  19. 1- Each publication exists in only one database. 2- Publications may currently only contain tables.  3- Objects must be added explicitly, except when a publication is created for ALL TABLES.
  20. 1- Each publication exists in only one database. 2- Publications may currently only contain tables.  3- Objects must be added explicitly, except when a publication is created for ALL TABLES.
  21. Sequence data is not replicated. The data in serial or identity columns backed by sequences will of course be replicated as part of the table, but the sequence itself would still show the start value on the subscriber.   If the subscriber is used as a read-only database, then this should typically not be a problem. If, however, some kind of switchover or failover to the subscriber database is intended, then the sequences would need to be updated to the latest values, either by copying the current data from the publisher (perhaps using pg_dump) or by determining a sufficiently high value from the tables themselves. hat is, the tables on the publication and on the subscription side must be normal tables, not views, materialized views, partition root tables, or foreign tables
  22. In logical level, the same information is logged as with replica, plus information needed to allow extracting logical change sets from the WAL. Using a level of logical will increase the WAL volume, particularly if many tables are configured for REPLICA IDENTITY FULL and many UPDATE and DELETE statements are executed. Publications can choose to limit the changes they produce to any combination of INSERT, UPDATE, DELETE, and TRUNCATE, similar to how triggers are fired by particular event types. By default, all operation types are replicated. Columns of a table are also matched by name. A different order of columns in the target table is allowed, but the column types have to match. 
  23. Şirkket olarak vizyonumuz avrupa birliği projelerinde de yer almak.
  24. ISA project will provide value for city stakeholders of the on-demand economy in four case study areas, Barcelona, Istanbul, Maribor and Vienna, by guiding them in the design, implementation, modelling, assessment and uptake of innovative logistics solutions addressing shared, connected and low emission pick-up and delivery services. It was our first H2020 project which was rejected in early stage. We are willing to be a part of H2020 projects. If you are looking for partners please contact with me.