SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
Demystifying Postgres Logical
Replication
Emanuel Calvo
April 2017
Percona Live 2017 - Santa Clara
Who am I?
●Data Engineer / 3manuek.com
●Currently working as a Remote DBA at Percona.
●Worked at PalominoDB, 2ndQuadrant, 8kdata, iMedicare,
Pythian among others.
●Being oscillating between MySQL, Postgres, Oracle and other
data solutions.
Agenda
• The path of replication in Postgres
• Streaming Replication and Logical Replication
• Replication flow for MySQL DBAs
• Feature capabilities
• Postgres Logical Replication for MySQL DBAs
• What can be done with this
• Limitations
• Elements
• Conflicts
• Monitoring
The path of replication in Postgres
• Streaming replication incorporated in 9.0.
• Cascading streaming replication introduced in 9.2.
• Switch timeline added in 9.3.
• Logical Decoding added in 9.4.
• More support to LD added in 9.6.
• Postgres 10 Logical replication natively supported.
Streaming and logical replication
• Streaming replication is a byte-by-byte replication, the whole
instance (all databases) are replicated.
• Logical replication is supported through pglogical for +9.4
• Natively supported in the next Postgres release.
Replication flow for MySQL DBAs
• MySQL
• Engine log + Binlog -> byte encoded -> bingo stream ->
binlog apply
• Cross-engine Events are append to the binlog (unless
skipped sql_log_bin)
• Slaves filter using do%
• Row_format: Replicates the change or the complete
statement
• Postgres
• WAL -> Logical Decoding/output_plugin -> logical log ->
sender -> receiver & apply
• Filtering is done at publisher
• Closer to row based replication
Feature capabilities
●LR replicates data objects based upon their replication
identity (generally a primary key).
●Destination server is writable. Different indexes and security
definition.
●Cross-version support
●Event-based filtering
●Less write amplification than streaming replication
●Publications can have several subscriptions
What can be achieved with LR?
●Storage flexibility through replicating smaller sets (even
partitioned tables)
●Flexible topology
●Minimum server load compared with trigger based solutions
●Allows parallel streaming across publishers
●Migrations and upgrades
●Multi source replication for consolidation
●Data distribution
●Flexible replication chains
●Data transformation
Limitations
●Can’t stream over to the same host (subscription will get
locked).
●Tables must have the same full qualified name between
publication and subscription.
●Subscriptions can have more columns or different order but
the types and column names must match between P/S.
●Database superuser is needed for P/S creation.
Elements
• Logical Decoding
• Replication Slots
• Output plugin
• Exported Snapshot
• Publication
• Subscription
[Logical] Replication Slots
• Keep track of the replication.
• Each replica stream has one in the origin for tracking
consuming changes.
• Locations are explicitly in LSN (log sequence number).
• catalog_xmin is the transaction number
• Slots are placed in the origin.
Example [Logical] Replication Slots
Output Plugin
• Converts WAL records entries into custom output
• Internal plugin name is pgoutput.
• For testing Logical Decoding capabilities, test_decoding.
Exported snapshot
• Sharing visibility between transactions by exporting the current
snapshot of the transaction.
• This is used for the initial COPY.
• Can be used to query outside a transaction but sharing its
visibility.
Publication
• Publications can have more than one subscriber.
• Tables added to the publication must be declared with
REPLICA IDENTITY. Otherwise subsequent operations will fail.
Subscription
• Subscriptions receive changes through replication slots.
• More than one replication slot may needed for the initial data
copy.
• Initial COPY data is done by pg_dump.
• The session_replication_role is set to replica in order to
manage triggers on tables as expected.
• DDL of replicated tables must previously exist.
• If creating a replication slot, it will use the name of the
subscriber, so beware as slots are in the origin (you will need to
specify different subscription names across subscribers).
Basic definition
CREATE PUBLICATION P_main_P0 FOR TABLE main_shard0
WITH (NOPUBLISH DELETE);
CREATE SUBSCRIPTION S_main_P0
CONNECTION 'port=7777 user=postgres dbname=master'
PUBLICATION P_main_P0 WITH (CREATE SLOT, COPY DATA);
NOTE: Slot name will be the subscription name in the
publisher
LR is suitable for:
Conflicts
• Any violation in constraints stops replication.
• UPDATE and DELETE operations on missing data will be
skipped.
• Transaction can be omitted using
pg_replication_origin_advance(subscriber_name + position).
sql_skip_counter *cough*.
• Current position can be seen at pg_replication_origin_status at
subscriber.
• Showcase LR conflict
• Showcase publication with many subscribers
REPLICA IDENTITY
• Which identity is used for conflict resolution:
REPLICA IDENTITY { DEFAULT | USING INDEX
index_name | FULL | NOTHING }
Monitoring
• Publisher:
select * from pg_replication_slots;
• Subscribers:
postgres=# select * from pg_replication_origin;
roident | roname
---------+----------
1 | pg_16394
(1 row)
postgres=# select * from pg_replication_origin_status;
local_id | external_id | remote_lsn | local_lsn
----------+-------------+------------+-----------
1 | pg_16394 | 0/0 | 0/15E0E80
Monitoring — cont.
• Subscribers:
select * from pg_stat_subscription where subname = 's_queue';"
percona
-[ RECORD 1 ]---------+------------------------------
subid | 16418
subname | s_queue
pid | 5293
relid |
received_lsn | 0/1678E98
last_msg_send_time | 2017-04-25 19:25:15.858439+00
last_msg_receipt_time | 2017-04-25 19:25:15.858475+00
latest_end_lsn | 0/1678E98
latest_end_time | 2017-04-25 19:25:15.858439+00
Minimun configuration
wal_level = logical #minimal, replica, or
logical
Max_wal_senders = 10
Wal_keep_segments # don’t use it if slots
Max_replication_slots =10
#max_worker_processes = 8
# Subscribers
#max_logical_replication_workers = 4
# taken from max_worker_processes
#max_sync_workers_per_subscription = 2
# taken from max_logical_replication_workers
Functions related
• pg_create_logical_replication_slot
• pg_drop_replication_slot
Consuming (get) /Seeing(peek) changes (will fail with pgoutput,
but this works with other logical decoding plugins, probably a
bug):
• pg_logical_slot_peek_changes
• pg_logical_slot_get_changes
• pg_logical_slot_get_binary_changes
• pg_logical_slot_peek_binary_changes
Partitions and Logical Replication
pglogical
• Extension, providing similar capabilities as the future native
implementation
• Additional flexibility, by allowing row filtering
• Manageable through functions
• It allows define Replication Sets
• Supports Synchronous commit
• Logical Decoding over WAL
• Stream is in commit order
• For versions over 9.4
• On subscriber it executes triggers as ENABLE REPLICA (basic
transformation).
BDR
• Bi-directional replication.
• Currently is a fork, intended to be an extension on 9.6
• Allows master-master replication up to 48 nodes (or more).
• Conflict detection
• Selective replication
RDS test_decoding support
• A basic and premature implementation is on RDS by using
test_decoding
• Not much documented in RDS documentation, but functional.
Reference links
●Upcoming postgres 10 features by Robert Hass
●Logical Replication and Partitioning features by me
●First insights by Robert Hass
●RDS test_decoding support
QA
Welcome to

Más contenido relacionado

La actualidad más candente

Meet Spilo, Zalando’s HIGH-AVAILABLE POSTGRESQL CLUSTER - Feike Steenbergen
Meet Spilo, Zalando’s HIGH-AVAILABLE POSTGRESQL CLUSTER - Feike SteenbergenMeet Spilo, Zalando’s HIGH-AVAILABLE POSTGRESQL CLUSTER - Feike Steenbergen
Meet Spilo, Zalando’s HIGH-AVAILABLE POSTGRESQL CLUSTER - Feike Steenbergen
distributed matters
 

La actualidad más candente (20)

PostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability MethodsPostgreSQL Replication High Availability Methods
PostgreSQL Replication High Availability Methods
 
Lessons PostgreSQL learned from commercial databases, and didn’t
Lessons PostgreSQL learned from commercial databases, and didn’tLessons PostgreSQL learned from commercial databases, and didn’t
Lessons PostgreSQL learned from commercial databases, and didn’t
 
Toro DB- Open-source, MongoDB-compatible database, built on top of PostgreSQL
Toro DB- Open-source, MongoDB-compatible database,  built on top of PostgreSQLToro DB- Open-source, MongoDB-compatible database,  built on top of PostgreSQL
Toro DB- Open-source, MongoDB-compatible database, built on top of PostgreSQL
 
PostgreSQL HA
PostgreSQL   HAPostgreSQL   HA
PostgreSQL HA
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs
 
Countdown to PostgreSQL v9.5 - Foriegn Tables can be part of Inheritance Tree
Countdown to PostgreSQL v9.5 - Foriegn Tables can be part of Inheritance Tree Countdown to PostgreSQL v9.5 - Foriegn Tables can be part of Inheritance Tree
Countdown to PostgreSQL v9.5 - Foriegn Tables can be part of Inheritance Tree
 
HBaseCon2017 Removable singularity: a story of HBase upgrade in Pinterest
HBaseCon2017 Removable singularity: a story of HBase upgrade in PinterestHBaseCon2017 Removable singularity: a story of HBase upgrade in Pinterest
HBaseCon2017 Removable singularity: a story of HBase upgrade in Pinterest
 
High Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniHigh Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando Patroni
 
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
 
PostgreSQL Enterprise Class Features and Capabilities
PostgreSQL Enterprise Class Features and CapabilitiesPostgreSQL Enterprise Class Features and Capabilities
PostgreSQL Enterprise Class Features and Capabilities
 
hbaseconasia2017: hbase-2.0.0
hbaseconasia2017: hbase-2.0.0hbaseconasia2017: hbase-2.0.0
hbaseconasia2017: hbase-2.0.0
 
What's New In PostgreSQL 9.4
What's New In PostgreSQL 9.4What's New In PostgreSQL 9.4
What's New In PostgreSQL 9.4
 
How We Made Scylla Maintenance Easier, Safer and Faster
How We Made Scylla Maintenance Easier, Safer and FasterHow We Made Scylla Maintenance Easier, Safer and Faster
How We Made Scylla Maintenance Easier, Safer and Faster
 
Meet Spilo, Zalando’s HIGH-AVAILABLE POSTGRESQL CLUSTER - Feike Steenbergen
Meet Spilo, Zalando’s HIGH-AVAILABLE POSTGRESQL CLUSTER - Feike SteenbergenMeet Spilo, Zalando’s HIGH-AVAILABLE POSTGRESQL CLUSTER - Feike Steenbergen
Meet Spilo, Zalando’s HIGH-AVAILABLE POSTGRESQL CLUSTER - Feike Steenbergen
 
PostgreSQL on AWS: Tips & Tricks (and horror stories)
PostgreSQL on AWS: Tips & Tricks (and horror stories)PostgreSQL on AWS: Tips & Tricks (and horror stories)
PostgreSQL on AWS: Tips & Tricks (and horror stories)
 
Elephants in the Cloud
Elephants in the CloudElephants in the Cloud
Elephants in the Cloud
 
PostgreSQL Hangout Parameter Tuning
PostgreSQL Hangout Parameter TuningPostgreSQL Hangout Parameter Tuning
PostgreSQL Hangout Parameter Tuning
 
Query Parallelism in PostgreSQL: What's coming next?
Query Parallelism in PostgreSQL: What's coming next?Query Parallelism in PostgreSQL: What's coming next?
Query Parallelism in PostgreSQL: What's coming next?
 
Creating a Benchmarking Infrastructure That Just Works
Creating a Benchmarking Infrastructure That Just WorksCreating a Benchmarking Infrastructure That Just Works
Creating a Benchmarking Infrastructure That Just Works
 
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
 

Similar a Demystifying postgres logical replication percona live sc

NoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
NoCOUG_201411_Patel_Managing_a_Large_OLTP_DatabaseNoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
NoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
Paresh Patel
 
Buytaert kris my_sql-pacemaker
Buytaert kris my_sql-pacemakerBuytaert kris my_sql-pacemaker
Buytaert kris my_sql-pacemaker
kuchinskaya
 

Similar a Demystifying postgres logical replication percona live sc (20)

Optimizing Presto Connector on Cloud Storage
Optimizing Presto Connector on Cloud StorageOptimizing Presto Connector on Cloud Storage
Optimizing Presto Connector on Cloud Storage
 
[Altibase] 12 replication part5 (optimization and monitoring)
[Altibase] 12 replication part5 (optimization and monitoring)[Altibase] 12 replication part5 (optimization and monitoring)
[Altibase] 12 replication part5 (optimization and monitoring)
 
NoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
NoCOUG_201411_Patel_Managing_a_Large_OLTP_DatabaseNoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
NoCOUG_201411_Patel_Managing_a_Large_OLTP_Database
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_features
 
Neo4j 4.1 overview
Neo4j 4.1 overviewNeo4j 4.1 overview
Neo4j 4.1 overview
 
Multi-Tenancy Kafka cluster for LINE services with 250 billion daily messages
Multi-Tenancy Kafka cluster for LINE services with 250 billion daily messagesMulti-Tenancy Kafka cluster for LINE services with 250 billion daily messages
Multi-Tenancy Kafka cluster for LINE services with 250 billion daily messages
 
PostgreSQL 9.5 - Major Features
PostgreSQL 9.5 - Major FeaturesPostgreSQL 9.5 - Major Features
PostgreSQL 9.5 - Major Features
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
 
Real World Storage in Treasure Data
Real World Storage in Treasure DataReal World Storage in Treasure Data
Real World Storage in Treasure Data
 
Making Postgres Central in Your Data Center
Making Postgres Central in Your Data CenterMaking Postgres Central in Your Data Center
Making Postgres Central in Your Data Center
 
Intro to Apache Apex - Next Gen Platform for Ingest and Transform
Intro to Apache Apex - Next Gen Platform for Ingest and TransformIntro to Apache Apex - Next Gen Platform for Ingest and Transform
Intro to Apache Apex - Next Gen Platform for Ingest and Transform
 
GLOC 2014 NEOOUG - Oracle Database 12c New Features
GLOC 2014 NEOOUG - Oracle Database 12c New FeaturesGLOC 2014 NEOOUG - Oracle Database 12c New Features
GLOC 2014 NEOOUG - Oracle Database 12c New Features
 
Buytaert kris my_sql-pacemaker
Buytaert kris my_sql-pacemakerBuytaert kris my_sql-pacemaker
Buytaert kris my_sql-pacemaker
 
Unifying Messaging, Queueing & Light Weight Compute Using Apache Pulsar
Unifying Messaging, Queueing & Light Weight Compute Using Apache PulsarUnifying Messaging, Queueing & Light Weight Compute Using Apache Pulsar
Unifying Messaging, Queueing & Light Weight Compute Using Apache Pulsar
 
Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014
 
MySQL database replication
MySQL database replicationMySQL database replication
MySQL database replication
 
Improve your SQL workload with observability
Improve your SQL workload with observabilityImprove your SQL workload with observability
Improve your SQL workload with observability
 
Exploring the replication in MongoDB
Exploring the replication in MongoDBExploring the replication in MongoDB
Exploring the replication in MongoDB
 
Migrate from Oracle to Aurora PostgreSQL: Best Practices, Design Patterns, & ...
Migrate from Oracle to Aurora PostgreSQL: Best Practices, Design Patterns, & ...Migrate from Oracle to Aurora PostgreSQL: Best Practices, Design Patterns, & ...
Migrate from Oracle to Aurora PostgreSQL: Best Practices, Design Patterns, & ...
 

Más de Emanuel Calvo (9)

Open Source SQL Databases
Open Source SQL DatabasesOpen Source SQL Databases
Open Source SQL Databases
 
Pgbr 2013 fts
Pgbr 2013 ftsPgbr 2013 fts
Pgbr 2013 fts
 
Pgbr 2013 postgres on aws
Pgbr 2013   postgres on awsPgbr 2013   postgres on aws
Pgbr 2013 postgres on aws
 
PostgreSQL and Sphinx pgcon 2013
PostgreSQL and Sphinx   pgcon 2013PostgreSQL and Sphinx   pgcon 2013
PostgreSQL and Sphinx pgcon 2013
 
PostgreSQL FTS Solutions FOSDEM 2013 - PGDAY
PostgreSQL FTS Solutions FOSDEM 2013 - PGDAYPostgreSQL FTS Solutions FOSDEM 2013 - PGDAY
PostgreSQL FTS Solutions FOSDEM 2013 - PGDAY
 
LSWC PostgreSQL 9.1 (2011)
LSWC PostgreSQL 9.1 (2011)LSWC PostgreSQL 9.1 (2011)
LSWC PostgreSQL 9.1 (2011)
 
Admon PG 1
Admon PG 1Admon PG 1
Admon PG 1
 
Monitoreo de MySQL y PostgreSQL con SQL
Monitoreo de MySQL y PostgreSQL con SQLMonitoreo de MySQL y PostgreSQL con SQL
Monitoreo de MySQL y PostgreSQL con SQL
 
Osol Pgsql
Osol PgsqlOsol Pgsql
Osol Pgsql
 

Último

Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
amitlee9823
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
AroojKhan71
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
shivangimorya083
 

Último (20)

Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptx
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptx
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 

Demystifying postgres logical replication percona live sc

  • 1. Demystifying Postgres Logical Replication Emanuel Calvo April 2017 Percona Live 2017 - Santa Clara
  • 2. Who am I? ●Data Engineer / 3manuek.com ●Currently working as a Remote DBA at Percona. ●Worked at PalominoDB, 2ndQuadrant, 8kdata, iMedicare, Pythian among others. ●Being oscillating between MySQL, Postgres, Oracle and other data solutions.
  • 3. Agenda • The path of replication in Postgres • Streaming Replication and Logical Replication • Replication flow for MySQL DBAs • Feature capabilities • Postgres Logical Replication for MySQL DBAs • What can be done with this • Limitations • Elements • Conflicts • Monitoring
  • 4. The path of replication in Postgres • Streaming replication incorporated in 9.0. • Cascading streaming replication introduced in 9.2. • Switch timeline added in 9.3. • Logical Decoding added in 9.4. • More support to LD added in 9.6. • Postgres 10 Logical replication natively supported.
  • 5. Streaming and logical replication • Streaming replication is a byte-by-byte replication, the whole instance (all databases) are replicated. • Logical replication is supported through pglogical for +9.4 • Natively supported in the next Postgres release.
  • 6. Replication flow for MySQL DBAs • MySQL • Engine log + Binlog -> byte encoded -> bingo stream -> binlog apply • Cross-engine Events are append to the binlog (unless skipped sql_log_bin) • Slaves filter using do% • Row_format: Replicates the change or the complete statement • Postgres • WAL -> Logical Decoding/output_plugin -> logical log -> sender -> receiver & apply • Filtering is done at publisher • Closer to row based replication
  • 7. Feature capabilities ●LR replicates data objects based upon their replication identity (generally a primary key). ●Destination server is writable. Different indexes and security definition. ●Cross-version support ●Event-based filtering ●Less write amplification than streaming replication ●Publications can have several subscriptions
  • 8. What can be achieved with LR? ●Storage flexibility through replicating smaller sets (even partitioned tables) ●Flexible topology ●Minimum server load compared with trigger based solutions ●Allows parallel streaming across publishers ●Migrations and upgrades ●Multi source replication for consolidation ●Data distribution ●Flexible replication chains ●Data transformation
  • 9. Limitations ●Can’t stream over to the same host (subscription will get locked). ●Tables must have the same full qualified name between publication and subscription. ●Subscriptions can have more columns or different order but the types and column names must match between P/S. ●Database superuser is needed for P/S creation.
  • 10. Elements • Logical Decoding • Replication Slots • Output plugin • Exported Snapshot • Publication • Subscription
  • 11. [Logical] Replication Slots • Keep track of the replication. • Each replica stream has one in the origin for tracking consuming changes. • Locations are explicitly in LSN (log sequence number). • catalog_xmin is the transaction number • Slots are placed in the origin.
  • 13. Output Plugin • Converts WAL records entries into custom output • Internal plugin name is pgoutput. • For testing Logical Decoding capabilities, test_decoding.
  • 14. Exported snapshot • Sharing visibility between transactions by exporting the current snapshot of the transaction. • This is used for the initial COPY. • Can be used to query outside a transaction but sharing its visibility.
  • 15. Publication • Publications can have more than one subscriber. • Tables added to the publication must be declared with REPLICA IDENTITY. Otherwise subsequent operations will fail.
  • 16. Subscription • Subscriptions receive changes through replication slots. • More than one replication slot may needed for the initial data copy. • Initial COPY data is done by pg_dump. • The session_replication_role is set to replica in order to manage triggers on tables as expected. • DDL of replicated tables must previously exist. • If creating a replication slot, it will use the name of the subscriber, so beware as slots are in the origin (you will need to specify different subscription names across subscribers).
  • 17.
  • 18. Basic definition CREATE PUBLICATION P_main_P0 FOR TABLE main_shard0 WITH (NOPUBLISH DELETE); CREATE SUBSCRIPTION S_main_P0 CONNECTION 'port=7777 user=postgres dbname=master' PUBLICATION P_main_P0 WITH (CREATE SLOT, COPY DATA); NOTE: Slot name will be the subscription name in the publisher
  • 20. Conflicts • Any violation in constraints stops replication. • UPDATE and DELETE operations on missing data will be skipped. • Transaction can be omitted using pg_replication_origin_advance(subscriber_name + position). sql_skip_counter *cough*. • Current position can be seen at pg_replication_origin_status at subscriber. • Showcase LR conflict • Showcase publication with many subscribers
  • 21. REPLICA IDENTITY • Which identity is used for conflict resolution: REPLICA IDENTITY { DEFAULT | USING INDEX index_name | FULL | NOTHING }
  • 22. Monitoring • Publisher: select * from pg_replication_slots; • Subscribers: postgres=# select * from pg_replication_origin; roident | roname ---------+---------- 1 | pg_16394 (1 row) postgres=# select * from pg_replication_origin_status; local_id | external_id | remote_lsn | local_lsn ----------+-------------+------------+----------- 1 | pg_16394 | 0/0 | 0/15E0E80
  • 23. Monitoring — cont. • Subscribers: select * from pg_stat_subscription where subname = 's_queue';" percona -[ RECORD 1 ]---------+------------------------------ subid | 16418 subname | s_queue pid | 5293 relid | received_lsn | 0/1678E98 last_msg_send_time | 2017-04-25 19:25:15.858439+00 last_msg_receipt_time | 2017-04-25 19:25:15.858475+00 latest_end_lsn | 0/1678E98 latest_end_time | 2017-04-25 19:25:15.858439+00
  • 24. Minimun configuration wal_level = logical #minimal, replica, or logical Max_wal_senders = 10 Wal_keep_segments # don’t use it if slots Max_replication_slots =10 #max_worker_processes = 8 # Subscribers #max_logical_replication_workers = 4 # taken from max_worker_processes #max_sync_workers_per_subscription = 2 # taken from max_logical_replication_workers
  • 25. Functions related • pg_create_logical_replication_slot • pg_drop_replication_slot Consuming (get) /Seeing(peek) changes (will fail with pgoutput, but this works with other logical decoding plugins, probably a bug): • pg_logical_slot_peek_changes • pg_logical_slot_get_changes • pg_logical_slot_get_binary_changes • pg_logical_slot_peek_binary_changes
  • 26. Partitions and Logical Replication
  • 27. pglogical • Extension, providing similar capabilities as the future native implementation • Additional flexibility, by allowing row filtering • Manageable through functions • It allows define Replication Sets • Supports Synchronous commit • Logical Decoding over WAL • Stream is in commit order • For versions over 9.4 • On subscriber it executes triggers as ENABLE REPLICA (basic transformation).
  • 28. BDR • Bi-directional replication. • Currently is a fork, intended to be an extension on 9.6 • Allows master-master replication up to 48 nodes (or more). • Conflict detection • Selective replication
  • 29. RDS test_decoding support • A basic and premature implementation is on RDS by using test_decoding • Not much documented in RDS documentation, but functional.
  • 30. Reference links ●Upcoming postgres 10 features by Robert Hass ●Logical Replication and Partitioning features by me ●First insights by Robert Hass ●RDS test_decoding support
  • 31. QA