SlideShare a Scribd company logo
1 of 32
© 2ndQuadrant 2016
Logical replication
with pglogical
Moving the same old data around in new
and exciting ways
© 2ndQuadrant 2016
pglogical
It's row-oriented replication
Really, that's pretty much it. The rest is
details.
Done now?
© 2ndQuadrant 2016
pglogical
Open source – PostgreSQL license
Submitted to 9.6
Generic, re-usable, no custom PostgreSQL
© 2ndQuadrant 2016
Architectures
●
Standalone (no replication)
●
Physical replication (block level)
●
Logical replication (row level)
© 2ndQuadrant 2016
Standalone PostgreSQL
Client
Heap
&
Indexes
WAL
PostgreSQL master
Parser/Executor
Client
© 2ndQuadrant 2016
Physical replica & hot standby
Client
Heap
&
Indexes
WAL
PostgreSQL master
Parser/Executor
Client
WALSender
PostgreSQL replica / hot standby
Heap
&
Indexes
WAL
WALReceiver
Parser/Executor
Client
Client
© 2ndQuadrant 2016
Confused yet?
© 2ndQuadrant 2016
“Physical” replication
Copies everything:
●
Every database
●
VACUUM
●
Index updates
●
….
© 2ndQuadrant 2016
“Physical” replication
Fast to apply changes to replicas.
Bandwidth-hungry.
All-or-nothing.
Hot standby limitations
© 2ndQuadrant 2016
Logical decoding
Client
WAL
PostgreSQL master
Parser/Executor
Client
WALSender
Logical decoding
Decoding plugin
????
© 2ndQuadrant 2016
Logical decoding
Collects just row values
No VACUUM traffic, index updates, etc
Can generate text-format values for
replication to other Pg versions etc
© 2ndQuadrant 2016
Logical decoding
●
Useful for logical replication
●
… but not just replication
●
Intrusion detection
●
Search
●
Messages buses
●
….
© 2ndQuadrant 2016
Many logical decoding plugins
●
pglogical_output
●
BDR output plugin
●
The demo test_decoding to stream SQL
●
decoder_raw and receiver_raw to stream and apply SQL
●
github.com/ildus/decoder_json and github.com/leptonix/decoding-json to
stream JSON
●
github.com/xstevens/decoderbufs to stream as protocol buffers
●
github.com/confluentinc/bottledwater-pg to stream to Kafka
●
….?
© 2ndQuadrant 2016
pglogical_output
Make it easy and generic:
Both json & fast native proto
Selective replication, metadata, etc
Use it without writing a bunch of C
© 2ndQuadrant 2016
Logical replication
Selective – just the DBs/tables you want
More flexible standby with read/write
tables, no query cancels
Not just 1:1 – sharding, data gather, ...
© 2ndQuadrant 2016
Pglogical
Client
WAL
PostgreSQL master
Parser/Executor
Client
WALSender
Logical decoding
pglogical_output
Client
Client
PostgreSQL logical replica
WAL
Parser/Executor
Client
Client
Pglogical
downstream
© 2ndQuadrant 2016
Pglogical: now
Selective replication
Crash safe
Downstream replica writeable
No query cancels on downstream
Efficient COPY-like apply process
No-downtime cross-version upgrade
© 2ndQuadrant 2016
Pglogical: performance now
© 2ndQuadrant 2016
Pglogical: future
Filter rows by WHERE clause
Logical and Physical Failover
Continuous ETL, transform
Continuous Data Warehouse ingestion
Automatic DDL replication
….
© 2ndQuadrant 2016
Sending data to apps
Take json or native output from
pglogical_output
Proxy it to the app with a script
Ingest it into the app
© 2ndQuadrant 2016
Decoding to apps
Client
WAL
PostgreSQL master
Parser/Executor
Client
WALSender
Logical decoding
Decoding plugin
● Apache Solr
● ElasticSearch
● AWS SNS
● Azure Notifcations
● Apache Camel
● Kafka
● Mule ESB
● MySQL
…..Proxy
&
Converter
© 2ndQuadrant 2016
Demo: solr
Take json or native output
Proxy it
Ingest it
© 2ndQuadrant 2016
Demo: solr
The code is simple but not brief enough to list here.
https://gist.github.com/ringerc/f74a12e430866ccd9227
© 2ndQuadrant 2016
Demo: solr
The process:
• Make a normal psycopg2 connection
• Create a replication with pg_create_logical_replication_slot slot
if it doesn't exist
• Loop over pg_logical_slot_get_changes to fetch the change stream
• Accumulate a whole transaction's worth of rows
• Transform the JSON from each call into something Solr will understand
• Send the transaction to Solr over http
© 2ndQuadrant 2016
Initial database state
No good way to send rows already in the
database when we set up decoding.
Workaround:
COPY (SELECT row_to_json(x)
FROM my_table x) TO stdout
© 2ndQuadrant 2016
Initial state
Ugly? Very. Plenty of room for improvement.
© 2ndQuadrant 2016
pglogical pitfalls
●
Unused slots can fill pg_xlog
●
DDL isn't replicated yet
●
Serial streaming of big xacts causes latency
●
Big xacts need extra disk space
●
Sequences not replicated yet
© 2ndQuadrant 2016
Using pglogical
I won't repeat the docs.
Yes, there are docs.
The pglogical_output protocol is documented
too, for app devs.
© 2ndQuadrant 2016
Slots: a public service announcement
Replication slots prevent the server from
removing still-needed WAL from pg_xlog.
An abandoned, unused slot can cause
pg_xlog to fill up and your server to stop.
Unused logical slots also create bloat in the
catalogs.
© 2ndQuadrant 2016
Slots: a public service announcement
Add pg_replication_slots replay lag to
your monitoring and alerting system. Use
pg_xlog_location_diff(...)
You'll already have alerts on pg_xlog disk
space, of course. Right?
Just like you regularly test your backups.
© 2ndQuadrant 2016
Questions?
© 2ndQuadrant 2016
Questions?
Q: Can pglogical be used to receive data from non-PostgreSQL sources and stream it into
PostgreSQL?
A: Not yet but there's room to support it in the design of the receiver. Good idea.
Q: Can I replicate to non-PostgreSQL databases?
A: No, and the pglogical downstream isn't designed to do that. You could use the
pglogical_output plugin to provide the data extraction and streaming facilities you need to send
data to your own downstream though.

More Related Content

What's hot

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
 

What's hot (20)

Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
 
PostgreSQL- An Introduction
PostgreSQL- An IntroductionPostgreSQL- An Introduction
PostgreSQL- An Introduction
 
Tuning Autovacuum in Postgresql
Tuning Autovacuum in PostgresqlTuning Autovacuum in Postgresql
Tuning Autovacuum in Postgresql
 
Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.Deep dive into PostgreSQL statistics.
Deep dive into PostgreSQL statistics.
 
Automate DBA Tasks With Ansible
Automate DBA Tasks With AnsibleAutomate DBA Tasks With Ansible
Automate DBA Tasks With Ansible
 
PostgreSQL Extensions: A deeper look
PostgreSQL Extensions:  A deeper lookPostgreSQL Extensions:  A deeper look
PostgreSQL Extensions: A deeper look
 
Patroni - HA PostgreSQL made easy
Patroni - HA PostgreSQL made easyPatroni - HA PostgreSQL made easy
Patroni - HA PostgreSQL made easy
 
PostgreSQL replication
PostgreSQL replicationPostgreSQL replication
PostgreSQL replication
 
What is new in PostgreSQL 14?
What is new in PostgreSQL 14?What is new in PostgreSQL 14?
What is new in PostgreSQL 14?
 
High Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando PatroniHigh Availability PostgreSQL with Zalando Patroni
High Availability PostgreSQL with Zalando Patroni
 
Postgre sql best_practices
Postgre sql best_practicesPostgre sql best_practices
Postgre sql best_practices
 
Advanced backup methods (Postgres@CERN)
Advanced backup methods (Postgres@CERN)Advanced backup methods (Postgres@CERN)
Advanced backup methods (Postgres@CERN)
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
 
Streaming replication in practice
Streaming replication in practiceStreaming replication in practice
Streaming replication in practice
 
Looking ahead at PostgreSQL 15
Looking ahead at PostgreSQL 15Looking ahead at PostgreSQL 15
Looking ahead at PostgreSQL 15
 
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)
 
Why we love pgpool-II and why we hate it!
Why we love pgpool-II and why we hate it!Why we love pgpool-II and why we hate it!
Why we love pgpool-II and why we hate it!
 
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
 
[pgday.Seoul 2022] PostgreSQL with Google Cloud
[pgday.Seoul 2022] PostgreSQL with Google Cloud[pgday.Seoul 2022] PostgreSQL with Google Cloud
[pgday.Seoul 2022] PostgreSQL with Google Cloud
 
Vacuum in PostgreSQL
Vacuum in PostgreSQLVacuum in PostgreSQL
Vacuum in PostgreSQL
 

Viewers also liked

Ryan Jarvinen Open Shift Talk @ Postgres Open 2013
Ryan Jarvinen Open Shift Talk @ Postgres Open 2013Ryan Jarvinen Open Shift Talk @ Postgres Open 2013
Ryan Jarvinen Open Shift Talk @ Postgres Open 2013
PostgresOpen
 
Gurjeet Singh - How Postgres is Different From (Better Tha) Your RDBMS @ Post...
Gurjeet Singh - How Postgres is Different From (Better Tha) Your RDBMS @ Post...Gurjeet Singh - How Postgres is Different From (Better Tha) Your RDBMS @ Post...
Gurjeet Singh - How Postgres is Different From (Better Tha) Your RDBMS @ Post...
PostgresOpen
 
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenBruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
PostgresOpen
 
David Keeney - SQL Database Server Requests from the Browser @ Postgres Open
David Keeney - SQL Database Server Requests from the Browser @ Postgres OpenDavid Keeney - SQL Database Server Requests from the Browser @ Postgres Open
David Keeney - SQL Database Server Requests from the Browser @ Postgres Open
PostgresOpen
 
Keith Fiske - When PostgreSQL Can't, You Can @ Postgres Open
Keith Fiske - When PostgreSQL Can't, You Can @ Postgres OpenKeith Fiske - When PostgreSQL Can't, You Can @ Postgres Open
Keith Fiske - When PostgreSQL Can't, You Can @ Postgres Open
PostgresOpen
 
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
 
Keith Paskett - Postgres on ZFS @ Postgres Open
Keith Paskett - Postgres on ZFS @ Postgres OpenKeith Paskett - Postgres on ZFS @ Postgres Open
Keith Paskett - Postgres on ZFS @ Postgres Open
PostgresOpen
 
Henrietta Dombrovskaya - A New Approach to Resolve Object-Relational Impedanc...
Henrietta Dombrovskaya - A New Approach to Resolve Object-Relational Impedanc...Henrietta Dombrovskaya - A New Approach to Resolve Object-Relational Impedanc...
Henrietta Dombrovskaya - A New Approach to Resolve Object-Relational Impedanc...
PostgresOpen
 

Viewers also liked (20)

Logical Replication in PostgreSQL - FLOSSUK 2016
Logical Replication in PostgreSQL - FLOSSUK 2016Logical Replication in PostgreSQL - FLOSSUK 2016
Logical Replication in PostgreSQL - FLOSSUK 2016
 
Islamabad PUG - 7th Meetup - performance tuning
Islamabad PUG - 7th Meetup - performance tuningIslamabad PUG - 7th Meetup - performance tuning
Islamabad PUG - 7th Meetup - performance tuning
 
Streaming huge databases using logical decoding
Streaming huge databases using logical decodingStreaming huge databases using logical decoding
Streaming huge databases using logical decoding
 
Gbroccolo pgconfeu2016 pgnfs
Gbroccolo pgconfeu2016 pgnfsGbroccolo pgconfeu2016 pgnfs
Gbroccolo pgconfeu2016 pgnfs
 
PostgreSQL replication from setup to advanced features.
 PostgreSQL replication from setup to advanced features. PostgreSQL replication from setup to advanced features.
PostgreSQL replication from setup to advanced features.
 
PostgreSQL performance improvements in 9.5 and 9.6
PostgreSQL performance improvements in 9.5 and 9.6PostgreSQL performance improvements in 9.5 and 9.6
PostgreSQL performance improvements in 9.5 and 9.6
 
On The Building Of A PostgreSQL Cluster
On The Building Of A PostgreSQL ClusterOn The Building Of A PostgreSQL Cluster
On The Building Of A PostgreSQL Cluster
 
PostgresOpen 2013 A Comparison of PostgreSQL Encryption Options
PostgresOpen 2013 A Comparison of PostgreSQL Encryption OptionsPostgresOpen 2013 A Comparison of PostgreSQL Encryption Options
PostgresOpen 2013 A Comparison of PostgreSQL Encryption Options
 
PostgreSQL: вчера, сегодня, завтра, Олег Бартунов, Postgres Professional, Мо...
 PostgreSQL: вчера, сегодня, завтра, Олег Бартунов, Postgres Professional, Мо... PostgreSQL: вчера, сегодня, завтра, Олег Бартунов, Postgres Professional, Мо...
PostgreSQL: вчера, сегодня, завтра, Олег Бартунов, Postgres Professional, Мо...
 
Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)
Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)
Streaming Replication (Keynote @ PostgreSQL Conference 2009 Japan)
 
Enterprise PostgreSQL - EDB's answer to conventional Databases
Enterprise PostgreSQL - EDB's answer to conventional DatabasesEnterprise PostgreSQL - EDB's answer to conventional Databases
Enterprise PostgreSQL - EDB's answer to conventional Databases
 
Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2Adding replication protocol support for psycopg2
Adding replication protocol support for psycopg2
 
Ryan Jarvinen Open Shift Talk @ Postgres Open 2013
Ryan Jarvinen Open Shift Talk @ Postgres Open 2013Ryan Jarvinen Open Shift Talk @ Postgres Open 2013
Ryan Jarvinen Open Shift Talk @ Postgres Open 2013
 
Gurjeet Singh - How Postgres is Different From (Better Tha) Your RDBMS @ Post...
Gurjeet Singh - How Postgres is Different From (Better Tha) Your RDBMS @ Post...Gurjeet Singh - How Postgres is Different From (Better Tha) Your RDBMS @ Post...
Gurjeet Singh - How Postgres is Different From (Better Tha) Your RDBMS @ Post...
 
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres OpenBruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
Bruce Momjian - Inside PostgreSQL Shared Memory @ Postgres Open
 
David Keeney - SQL Database Server Requests from the Browser @ Postgres Open
David Keeney - SQL Database Server Requests from the Browser @ Postgres OpenDavid Keeney - SQL Database Server Requests from the Browser @ Postgres Open
David Keeney - SQL Database Server Requests from the Browser @ Postgres Open
 
Keith Fiske - When PostgreSQL Can't, You Can @ Postgres Open
Keith Fiske - When PostgreSQL Can't, You Can @ Postgres OpenKeith Fiske - When PostgreSQL Can't, You Can @ Postgres Open
Keith Fiske - When PostgreSQL Can't, You Can @ Postgres Open
 
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
 
Keith Paskett - Postgres on ZFS @ Postgres Open
Keith Paskett - Postgres on ZFS @ Postgres OpenKeith Paskett - Postgres on ZFS @ Postgres Open
Keith Paskett - Postgres on ZFS @ Postgres Open
 
Henrietta Dombrovskaya - A New Approach to Resolve Object-Relational Impedanc...
Henrietta Dombrovskaya - A New Approach to Resolve Object-Relational Impedanc...Henrietta Dombrovskaya - A New Approach to Resolve Object-Relational Impedanc...
Henrietta Dombrovskaya - A New Approach to Resolve Object-Relational Impedanc...
 

Similar to Logical replication with pglogical

Benchmarking for postgresql workloads in kubernetes
Benchmarking for postgresql workloads in kubernetesBenchmarking for postgresql workloads in kubernetes
Benchmarking for postgresql workloads in kubernetes
DoKC
 
The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL Stack
Sashko Stubailo
 

Similar to Logical replication with pglogical (20)

What's coming in Airflow 2.0? - NYC Apache Airflow Meetup
What's coming in Airflow 2.0? - NYC Apache Airflow MeetupWhat's coming in Airflow 2.0? - NYC Apache Airflow Meetup
What's coming in Airflow 2.0? - NYC Apache Airflow Meetup
 
GraphQL vs. (the) REST
GraphQL vs. (the) RESTGraphQL vs. (the) REST
GraphQL vs. (the) REST
 
Benchmarking for postgresql workloads in kubernetes
Benchmarking for postgresql workloads in kubernetesBenchmarking for postgresql workloads in kubernetes
Benchmarking for postgresql workloads in kubernetes
 
Eko10 Workshop Opensource Database Auditing
Eko10  Workshop Opensource Database AuditingEko10  Workshop Opensource Database Auditing
Eko10 Workshop Opensource Database Auditing
 
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORINGEko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
 
Raising ux bar with offline first design
Raising ux bar with offline first designRaising ux bar with offline first design
Raising ux bar with offline first design
 
Retour d'expérience d'un environnement base de données multitenant
Retour d'expérience d'un environnement base de données multitenantRetour d'expérience d'un environnement base de données multitenant
Retour d'expérience d'un environnement base de données multitenant
 
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
 
OSMC 2023 | What’s new with Grafana Labs’s Open Source Observability stack by...
OSMC 2023 | What’s new with Grafana Labs’s Open Source Observability stack by...OSMC 2023 | What’s new with Grafana Labs’s Open Source Observability stack by...
OSMC 2023 | What’s new with Grafana Labs’s Open Source Observability stack by...
 
Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...
Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...
Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...
 
02 ai inference acceleration with components all in open hardware: opencapi a...
02 ai inference acceleration with components all in open hardware: opencapi a...02 ai inference acceleration with components all in open hardware: opencapi a...
02 ai inference acceleration with components all in open hardware: opencapi a...
 
Gobblin @ NerdWallet (Nov 2015)
Gobblin @ NerdWallet (Nov 2015)Gobblin @ NerdWallet (Nov 2015)
Gobblin @ NerdWallet (Nov 2015)
 
Kernel Recipes 2018 - Live (Kernel) Patching: status quo and status futurus -...
Kernel Recipes 2018 - Live (Kernel) Patching: status quo and status futurus -...Kernel Recipes 2018 - Live (Kernel) Patching: status quo and status futurus -...
Kernel Recipes 2018 - Live (Kernel) Patching: status quo and status futurus -...
 
Migration Spring PetClinic to Quarkus
Migration Spring PetClinic to QuarkusMigration Spring PetClinic to Quarkus
Migration Spring PetClinic to Quarkus
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Kotlin REST & GraphQL API
Kotlin REST & GraphQL APIKotlin REST & GraphQL API
Kotlin REST & GraphQL API
 
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything togetherSashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
 
The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL Stack
 
GraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherGraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits together
 
How easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performanceHow easy (or hard) it is to monitor your graph ql service performance
How easy (or hard) it is to monitor your graph ql service performance
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Logical replication with pglogical

  • 1. © 2ndQuadrant 2016 Logical replication with pglogical Moving the same old data around in new and exciting ways
  • 2. © 2ndQuadrant 2016 pglogical It's row-oriented replication Really, that's pretty much it. The rest is details. Done now?
  • 3. © 2ndQuadrant 2016 pglogical Open source – PostgreSQL license Submitted to 9.6 Generic, re-usable, no custom PostgreSQL
  • 4. © 2ndQuadrant 2016 Architectures ● Standalone (no replication) ● Physical replication (block level) ● Logical replication (row level)
  • 5. © 2ndQuadrant 2016 Standalone PostgreSQL Client Heap & Indexes WAL PostgreSQL master Parser/Executor Client
  • 6. © 2ndQuadrant 2016 Physical replica & hot standby Client Heap & Indexes WAL PostgreSQL master Parser/Executor Client WALSender PostgreSQL replica / hot standby Heap & Indexes WAL WALReceiver Parser/Executor Client Client
  • 8. © 2ndQuadrant 2016 “Physical” replication Copies everything: ● Every database ● VACUUM ● Index updates ● ….
  • 9. © 2ndQuadrant 2016 “Physical” replication Fast to apply changes to replicas. Bandwidth-hungry. All-or-nothing. Hot standby limitations
  • 10. © 2ndQuadrant 2016 Logical decoding Client WAL PostgreSQL master Parser/Executor Client WALSender Logical decoding Decoding plugin ????
  • 11. © 2ndQuadrant 2016 Logical decoding Collects just row values No VACUUM traffic, index updates, etc Can generate text-format values for replication to other Pg versions etc
  • 12. © 2ndQuadrant 2016 Logical decoding ● Useful for logical replication ● … but not just replication ● Intrusion detection ● Search ● Messages buses ● ….
  • 13. © 2ndQuadrant 2016 Many logical decoding plugins ● pglogical_output ● BDR output plugin ● The demo test_decoding to stream SQL ● decoder_raw and receiver_raw to stream and apply SQL ● github.com/ildus/decoder_json and github.com/leptonix/decoding-json to stream JSON ● github.com/xstevens/decoderbufs to stream as protocol buffers ● github.com/confluentinc/bottledwater-pg to stream to Kafka ● ….?
  • 14. © 2ndQuadrant 2016 pglogical_output Make it easy and generic: Both json & fast native proto Selective replication, metadata, etc Use it without writing a bunch of C
  • 15. © 2ndQuadrant 2016 Logical replication Selective – just the DBs/tables you want More flexible standby with read/write tables, no query cancels Not just 1:1 – sharding, data gather, ...
  • 16. © 2ndQuadrant 2016 Pglogical Client WAL PostgreSQL master Parser/Executor Client WALSender Logical decoding pglogical_output Client Client PostgreSQL logical replica WAL Parser/Executor Client Client Pglogical downstream
  • 17. © 2ndQuadrant 2016 Pglogical: now Selective replication Crash safe Downstream replica writeable No query cancels on downstream Efficient COPY-like apply process No-downtime cross-version upgrade
  • 19. © 2ndQuadrant 2016 Pglogical: future Filter rows by WHERE clause Logical and Physical Failover Continuous ETL, transform Continuous Data Warehouse ingestion Automatic DDL replication ….
  • 20. © 2ndQuadrant 2016 Sending data to apps Take json or native output from pglogical_output Proxy it to the app with a script Ingest it into the app
  • 21. © 2ndQuadrant 2016 Decoding to apps Client WAL PostgreSQL master Parser/Executor Client WALSender Logical decoding Decoding plugin ● Apache Solr ● ElasticSearch ● AWS SNS ● Azure Notifcations ● Apache Camel ● Kafka ● Mule ESB ● MySQL …..Proxy & Converter
  • 22. © 2ndQuadrant 2016 Demo: solr Take json or native output Proxy it Ingest it
  • 23. © 2ndQuadrant 2016 Demo: solr The code is simple but not brief enough to list here. https://gist.github.com/ringerc/f74a12e430866ccd9227
  • 24. © 2ndQuadrant 2016 Demo: solr The process: • Make a normal psycopg2 connection • Create a replication with pg_create_logical_replication_slot slot if it doesn't exist • Loop over pg_logical_slot_get_changes to fetch the change stream • Accumulate a whole transaction's worth of rows • Transform the JSON from each call into something Solr will understand • Send the transaction to Solr over http
  • 25. © 2ndQuadrant 2016 Initial database state No good way to send rows already in the database when we set up decoding. Workaround: COPY (SELECT row_to_json(x) FROM my_table x) TO stdout
  • 26. © 2ndQuadrant 2016 Initial state Ugly? Very. Plenty of room for improvement.
  • 27. © 2ndQuadrant 2016 pglogical pitfalls ● Unused slots can fill pg_xlog ● DDL isn't replicated yet ● Serial streaming of big xacts causes latency ● Big xacts need extra disk space ● Sequences not replicated yet
  • 28. © 2ndQuadrant 2016 Using pglogical I won't repeat the docs. Yes, there are docs. The pglogical_output protocol is documented too, for app devs.
  • 29. © 2ndQuadrant 2016 Slots: a public service announcement Replication slots prevent the server from removing still-needed WAL from pg_xlog. An abandoned, unused slot can cause pg_xlog to fill up and your server to stop. Unused logical slots also create bloat in the catalogs.
  • 30. © 2ndQuadrant 2016 Slots: a public service announcement Add pg_replication_slots replay lag to your monitoring and alerting system. Use pg_xlog_location_diff(...) You'll already have alerts on pg_xlog disk space, of course. Right? Just like you regularly test your backups.
  • 32. © 2ndQuadrant 2016 Questions? Q: Can pglogical be used to receive data from non-PostgreSQL sources and stream it into PostgreSQL? A: Not yet but there's room to support it in the design of the receiver. Good idea. Q: Can I replicate to non-PostgreSQL databases? A: No, and the pglogical downstream isn't designed to do that. You could use the pglogical_output plugin to provide the data extraction and streaming facilities you need to send data to your own downstream though.