SlideShare a Scribd company logo
Built-in Physical and Logical
Replication in Postgresql
Speaker
Fırat Güleç
- Company
Hepsiexpress
- Now
Infrastructure & Database Manager
Member of Postgresql Europe
Contributing to Open Source Community
- Next Talks
Swiss PGDay 2019, June 28th, 2019
Austria PGDay 2019, September 6th, 2019
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.3
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.3
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.3
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 is not possible
2- 32-bit to a 64-bit system will not work.
pg_wal
WAL
Database Physical
File based
from 8.3
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?
readwrite read
pg_wal
WAL
Archieve
directory
Database Physical
File based
from 8.3
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
sync10.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 AEmployee
What is Logical Replication?
Master Slave
Streaming replication
Master Slave
Recovery Mode
Create index
Create table
Drop table
Create function
Insert
Delete
SelectHot Standby
SelectWarm 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 9.6
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 SlaveStreaming
Replication
Cascading
Replication
Slave A
Slave B
Publication 2
Publication 1
Subscription 2
Master
Subscription 1
Pub 3
Slave C
Subs 3Users 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 1Pub 1
Surname
DB B
Address
Pub 2Sub 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 = logical1.
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 database12.
Pg_hba.conf host all repluser 10.90.82.31/0 md5
Connected to db with postgres c database21.
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 ReplicationStreaming 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/
Thank you
Fırat Güleç

More Related Content

What's hot

PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuning
elliando dias
 
Troubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming ReplicationTroubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming Replication
Alexey Lesovsky
 
PGConf.ASIA 2017 Logical Replication Internals (English)
PGConf.ASIA 2017 Logical Replication Internals (English)PGConf.ASIA 2017 Logical Replication Internals (English)
PGConf.ASIA 2017 Logical Replication Internals (English)
Noriyoshi Shinoda
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
EDB
 
Postgresql Database Administration- Day3
Postgresql Database Administration- Day3Postgresql Database Administration- Day3
Postgresql Database Administration- Day3
PoguttuezhiniVP
 
PGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRest
PGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRestPGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRest
PGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRest
PGDay.Amsterdam
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
PostgresOpen
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System Administrators
Command Prompt., Inc
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep Internal
EXEM
 
Linux Profiling at Netflix
Linux Profiling at NetflixLinux Profiling at Netflix
Linux Profiling at Netflix
Brendan Gregg
 
Webinar: PostgreSQL continuous backup and PITR with Barman
Webinar: PostgreSQL continuous backup and PITR with BarmanWebinar: PostgreSQL continuous backup and PITR with Barman
Webinar: PostgreSQL continuous backup and PITR with Barman
Gabriele Bartolini
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs
PGConf APAC
 
Tame the small files problem and optimize data layout for streaming ingestion...
Tame the small files problem and optimize data layout for streaming ingestion...Tame the small files problem and optimize data layout for streaming ingestion...
Tame the small files problem and optimize data layout for streaming ingestion...
Flink Forward
 
PostGreSQL Performance Tuning
PostGreSQL Performance TuningPostGreSQL Performance Tuning
PostGreSQL Performance Tuning
Maven Logix
 
PostgreSQL Streaming Replication Cheatsheet
PostgreSQL Streaming Replication CheatsheetPostgreSQL Streaming Replication Cheatsheet
PostgreSQL Streaming Replication Cheatsheet
Alexey Lesovsky
 
PostgreSQL : Introduction
PostgreSQL : IntroductionPostgreSQL : Introduction
PostgreSQL : Introduction
Open Source School
 
Security Best Practices for your Postgres Deployment
Security Best Practices for your Postgres DeploymentSecurity Best Practices for your Postgres Deployment
Security Best Practices for your Postgres Deployment
PGConf APAC
 
Postgresql Database Administration Basic - Day1
Postgresql  Database Administration Basic  - Day1Postgresql  Database Administration Basic  - Day1
Postgresql Database Administration Basic - Day1
PoguttuezhiniVP
 
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and FanoutOpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
Saju Madhavan
 
Backup and-recovery2
Backup and-recovery2Backup and-recovery2
Backup and-recovery2
Command Prompt., Inc
 

What's hot (20)

PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuning
 
Troubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming ReplicationTroubleshooting PostgreSQL Streaming Replication
Troubleshooting PostgreSQL Streaming Replication
 
PGConf.ASIA 2017 Logical Replication Internals (English)
PGConf.ASIA 2017 Logical Replication Internals (English)PGConf.ASIA 2017 Logical Replication Internals (English)
PGConf.ASIA 2017 Logical Replication Internals (English)
 
Mastering PostgreSQL Administration
Mastering PostgreSQL AdministrationMastering PostgreSQL Administration
Mastering PostgreSQL Administration
 
Postgresql Database Administration- Day3
Postgresql Database Administration- Day3Postgresql Database Administration- Day3
Postgresql Database Administration- Day3
 
PGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRest
PGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRestPGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRest
PGDay.Amsterdam 2018 - Stefan Fercot - Save your data with pgBackRest
 
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres OpenKevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
Kevin Kempter PostgreSQL Backup and Recovery Methods @ Postgres Open
 
PostgreSQL Administration for System Administrators
PostgreSQL Administration for System AdministratorsPostgreSQL Administration for System Administrators
PostgreSQL Administration for System Administrators
 
PostgreSQL Deep Internal
PostgreSQL Deep InternalPostgreSQL Deep Internal
PostgreSQL Deep Internal
 
Linux Profiling at Netflix
Linux Profiling at NetflixLinux Profiling at Netflix
Linux Profiling at Netflix
 
Webinar: PostgreSQL continuous backup and PITR with Barman
Webinar: PostgreSQL continuous backup and PITR with BarmanWebinar: PostgreSQL continuous backup and PITR with Barman
Webinar: PostgreSQL continuous backup and PITR with Barman
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs
 
Tame the small files problem and optimize data layout for streaming ingestion...
Tame the small files problem and optimize data layout for streaming ingestion...Tame the small files problem and optimize data layout for streaming ingestion...
Tame the small files problem and optimize data layout for streaming ingestion...
 
PostGreSQL Performance Tuning
PostGreSQL Performance TuningPostGreSQL Performance Tuning
PostGreSQL Performance Tuning
 
PostgreSQL Streaming Replication Cheatsheet
PostgreSQL Streaming Replication CheatsheetPostgreSQL Streaming Replication Cheatsheet
PostgreSQL Streaming Replication Cheatsheet
 
PostgreSQL : Introduction
PostgreSQL : IntroductionPostgreSQL : Introduction
PostgreSQL : Introduction
 
Security Best Practices for your Postgres Deployment
Security Best Practices for your Postgres DeploymentSecurity Best Practices for your Postgres Deployment
Security Best Practices for your Postgres Deployment
 
Postgresql Database Administration Basic - Day1
Postgresql  Database Administration Basic  - Day1Postgresql  Database Administration Basic  - Day1
Postgresql Database Administration Basic - Day1
 
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and FanoutOpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
OpenStack Oslo Messaging RPC API Tutorial Demo Call, Cast and Fanout
 
Backup and-recovery2
Backup and-recovery2Backup and-recovery2
Backup and-recovery2
 

Similar to Built in physical and logical replication in postgresql-Firat Gulec

Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptx
Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptxBuilt-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptx
Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptx
nadirpervez2
 
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Command Prompt., Inc
 
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
Lars Platzdasch
 
SRV407 Deep Dive on Amazon Aurora
SRV407 Deep Dive on Amazon AuroraSRV407 Deep Dive on Amazon Aurora
SRV407 Deep Dive on Amazon Aurora
Amazon Web Services
 
Experiences building a distributed shared log on RADOS - Noah Watkins
Experiences building a distributed shared log on RADOS - Noah WatkinsExperiences building a distributed shared log on RADOS - Noah Watkins
Experiences building a distributed shared log on RADOS - Noah Watkins
Ceph Community
 
2012 scale replication
2012 scale replication2012 scale replication
2012 scale replication
sqlhjalp
 
Tales from the four-comma club: Managing Kafka as a service at Salesforce | L...
Tales from the four-comma club: Managing Kafka as a service at Salesforce | L...Tales from the four-comma club: Managing Kafka as a service at Salesforce | L...
Tales from the four-comma club: Managing Kafka as a service at Salesforce | L...
HostedbyConfluent
 
Load Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - SlidesLoad Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - Slides
Severalnines
 
2012 replication
2012 replication2012 replication
2012 replication
sqlhjalp
 
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
 
GraphConnect Europe 2016 - Moving Graphs to Production at Scale - Ian Robinson
GraphConnect Europe 2016 - Moving Graphs to Production at Scale - Ian RobinsonGraphConnect Europe 2016 - Moving Graphs to Production at Scale - Ian Robinson
GraphConnect Europe 2016 - Moving Graphs to Production at Scale - Ian Robinson
Neo4j
 
Database High Availability Using SHADOW Systems
Database High Availability Using SHADOW SystemsDatabase High Availability Using SHADOW Systems
Database High Availability Using SHADOW Systems
Jaemyung Kim
 
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
 
Using Kubernetes to deliver a “serverless” service
Using Kubernetes to deliver a “serverless” serviceUsing Kubernetes to deliver a “serverless” service
Using Kubernetes to deliver a “serverless” service
DoKC
 
Amazon Aurora: Under the Hood
Amazon Aurora: Under the HoodAmazon Aurora: Under the Hood
Amazon Aurora: Under the Hood
Amazon Web Services
 
Implementing SharePoint on Azure, Lessons Learnt from a Real World Project
Implementing SharePoint on Azure, Lessons Learnt from a Real World ProjectImplementing SharePoint on Azure, Lessons Learnt from a Real World Project
Implementing SharePoint on Azure, Lessons Learnt from a Real World Project
K.Mohamed Faizal
 
Postgresql 9.0 HA at LOADAYS 2012
Postgresql 9.0 HA at LOADAYS 2012Postgresql 9.0 HA at LOADAYS 2012
Postgresql 9.0 HA at LOADAYS 2012
Julien Pivotto
 
Технологии работы с дисковыми хранилищами и файловыми системами Windows Serve...
Технологии работы с дисковыми хранилищами и файловыми системами Windows Serve...Технологии работы с дисковыми хранилищами и файловыми системами Windows Serve...
Технологии работы с дисковыми хранилищами и файловыми системами Windows Serve...
Виталий Стародубцев
 
Introduction to Apache Kafka- Part 1
Introduction to Apache Kafka- Part 1Introduction to Apache Kafka- Part 1
Introduction to Apache Kafka- Part 1
Knoldus Inc.
 
11g R2
11g R211g R2
11g R2
afa reg
 

Similar to Built in physical and logical replication in postgresql-Firat Gulec (20)

Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptx
Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptxBuilt-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptx
Built-in-Physical-and-Logical-Replication-in-Postgresql-Firat-Gulec.pptx
 
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
Building tungsten-clusters-with-postgre sql-hot-standby-and-streaming-replica...
 
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
 
SRV407 Deep Dive on Amazon Aurora
SRV407 Deep Dive on Amazon AuroraSRV407 Deep Dive on Amazon Aurora
SRV407 Deep Dive on Amazon Aurora
 
Experiences building a distributed shared log on RADOS - Noah Watkins
Experiences building a distributed shared log on RADOS - Noah WatkinsExperiences building a distributed shared log on RADOS - Noah Watkins
Experiences building a distributed shared log on RADOS - Noah Watkins
 
2012 scale replication
2012 scale replication2012 scale replication
2012 scale replication
 
Tales from the four-comma club: Managing Kafka as a service at Salesforce | L...
Tales from the four-comma club: Managing Kafka as a service at Salesforce | L...Tales from the four-comma club: Managing Kafka as a service at Salesforce | L...
Tales from the four-comma club: Managing Kafka as a service at Salesforce | L...
 
Load Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - SlidesLoad Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - Slides
 
2012 replication
2012 replication2012 replication
2012 replication
 
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
 
GraphConnect Europe 2016 - Moving Graphs to Production at Scale - Ian Robinson
GraphConnect Europe 2016 - Moving Graphs to Production at Scale - Ian RobinsonGraphConnect Europe 2016 - Moving Graphs to Production at Scale - Ian Robinson
GraphConnect Europe 2016 - Moving Graphs to Production at Scale - Ian Robinson
 
Database High Availability Using SHADOW Systems
Database High Availability Using SHADOW SystemsDatabase High Availability Using SHADOW Systems
Database High Availability Using SHADOW Systems
 
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...
 
Using Kubernetes to deliver a “serverless” service
Using Kubernetes to deliver a “serverless” serviceUsing Kubernetes to deliver a “serverless” service
Using Kubernetes to deliver a “serverless” service
 
Amazon Aurora: Under the Hood
Amazon Aurora: Under the HoodAmazon Aurora: Under the Hood
Amazon Aurora: Under the Hood
 
Implementing SharePoint on Azure, Lessons Learnt from a Real World Project
Implementing SharePoint on Azure, Lessons Learnt from a Real World ProjectImplementing SharePoint on Azure, Lessons Learnt from a Real World Project
Implementing SharePoint on Azure, Lessons Learnt from a Real World Project
 
Postgresql 9.0 HA at LOADAYS 2012
Postgresql 9.0 HA at LOADAYS 2012Postgresql 9.0 HA at LOADAYS 2012
Postgresql 9.0 HA at LOADAYS 2012
 
Технологии работы с дисковыми хранилищами и файловыми системами Windows Serve...
Технологии работы с дисковыми хранилищами и файловыми системами Windows Serve...Технологии работы с дисковыми хранилищами и файловыми системами Windows Serve...
Технологии работы с дисковыми хранилищами и файловыми системами Windows Serve...
 
Introduction to Apache Kafka- Part 1
Introduction to Apache Kafka- Part 1Introduction to Apache Kafka- Part 1
Introduction to Apache Kafka- Part 1
 
11g R2
11g R211g R2
11g R2
 

Recently uploaded

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 

Recently uploaded (20)

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 

Built in physical and logical replication in postgresql-Firat Gulec

  • 1. Built-in Physical and Logical Replication in Postgresql
  • 2. Speaker Fırat Güleç - Company Hepsiexpress - Now Infrastructure & Database Manager Member of Postgresql Europe Contributing to Open Source Community - Next Talks Swiss PGDay 2019, June 28th, 2019 Austria PGDay 2019, September 6th, 2019
  • 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.3 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.3 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.3 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 is not possible 2- 32-bit to a 64-bit system will not work. pg_wal WAL
  • 16. Database Physical File based from 8.3 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? readwrite read pg_wal WAL Archieve directory
  • 18. Database Physical File based from 8.3 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 sync10.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 AEmployee What is Logical Replication?
  • 36. Master Slave Streaming replication Master Slave Recovery Mode Create index Create table Drop table Create function Insert Delete SelectHot Standby SelectWarm 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 9.6 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 SlaveStreaming Replication Cascading Replication Slave A Slave B Publication 2 Publication 1 Subscription 2 Master Subscription 1 Pub 3 Slave C Subs 3Users 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 1Pub 1 Surname DB B Address Pub 2Sub 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 = logical1. 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 database12. Pg_hba.conf host all repluser 10.90.82.31/0 md5 Connected to db with postgres c database21. 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 ReplicationStreaming 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

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.