SlideShare a Scribd company logo
Multi-Master Replication Using Slony
Who Am I? Jim Mlodgenski Co-organizer of NYCPUG
Founder of Cirrus Technologies
Former Chief Architect of EnterpriseDB
What is Mult-Master? Multiple phyiscal servers in a cluster allow for the updating of data Increases Availability
Increases performance Most noticable over a WAN
CAP Theorem The theory put forth by Brewer that only 2 of the 3 are possible in a distributed system C onsistency
A vailability
P artition Tolerance
Sync vs. Async Synchronous All transactions applied to all server before a success is returned to the client Simpler to design and architect
At the expense of performance
Sync vs. Async Asynchronous A transaction is applied to a single server before a success is returned to the client About the same performance as a single server
Need to deal with conflict resolution
Existing Solutions Bucardo
PgPool
RubyRep
Bucardo Asynchronous multi-master, master-slave, event based replication solution Used in several production deployments
Limited to 2 masters
PgPool Synchronous statement based, multi-master replication solution Much more than a replication solution
Need to deal with Nondeterministic functions
RubyRep Asynchronous multi-master, event based replication solution Not a PostgreSQL only solution
Limited to 2 masters
What is Slony? Asynchronous master-slave, event based replication solution Proven production use cases
Cascading replication
Retail Store Problem Corporate HQ controls the pricing
The stores  control the daily sales information
Retail Store Problem The information pushed down for HQ is exactly what Slony is good at The tables controlled at HQ replicates to the many stores
The tables at the stores are read-only
Retail Store Problem A single replication set can control this May need to cascade if there are many stores slonik <<_EOF_ cluster name = HQ; node 1 admin conninfo = 'dbname=hq'; node 2 admin conninfo = 'dbname=store1'; node 3 admin conninfo = 'dbname=store2'; node 4 admin conninfo = 'dbname=store3'; node 5 admin conninfo = 'dbname=store4'; node 6 admin conninfo = 'dbname=store5'; init cluster ( id=1, comment = 'HQ Node'); create set (id=1, origin=1, comment='All HQ tables'); set add table (set id=1, origin=1, id=1, fully qualified name = 'public.items', comment='items table'); set add table (set id=1, origin=1, id=2, fully qualified name = 'public.prices', comment='prices table'); store node (id=2, comment = 'Store1 node', event node=1); store path (server = 1, client = 2, conninfo='dbname=hq'); store path (server = 2, client = 1, conninfo='dbname=store1'); ...
Retail Store Problem Replicating all of the stores data to HQ is the challenge Use table inheritance

More Related Content

ODP
Scaling PostgreSQL With GridSQL
PDF
Scaling PostreSQL with Stado
PDF
ClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEO
PDF
Webinar slides: MORE secrets of ClickHouse Query Performance. By Robert Hodge...
PDF
How to teach an elephant to rock'n'roll
PDF
Spark SQL Adaptive Execution Unleashes The Power of Cluster in Large Scale wi...
PDF
ClickHouse Deep Dive, by Aleksei Milovidov
PDF
MariaDB and Clickhouse Percona Live 2019 talk
Scaling PostgreSQL With GridSQL
Scaling PostreSQL with Stado
ClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEO
Webinar slides: MORE secrets of ClickHouse Query Performance. By Robert Hodge...
How to teach an elephant to rock'n'roll
Spark SQL Adaptive Execution Unleashes The Power of Cluster in Large Scale wi...
ClickHouse Deep Dive, by Aleksei Milovidov
MariaDB and Clickhouse Percona Live 2019 talk

What's hot (20)

PDF
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
PDF
Your first ClickHouse data warehouse
PDF
ClickHouse Materialized Views: The Magic Continues
PDF
ClickHouse and the Magic of Materialized Views, By Robert Hodges and Altinity...
PDF
ClickHouse Unleashed 2020: Our Favorite New Features for Your Analytical Appl...
PDF
Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...
PDF
Webinar: Secrets of ClickHouse Query Performance, by Robert Hodges
PDF
Creating Beautiful Dashboards with Grafana and ClickHouse
PDF
Webinar slides: Adding Fast Analytics to MySQL Applications with Clickhouse
PDF
PostgreSQL: Data analysis and analytics
PDF
Oracle Join Methods and 12c Adaptive Plans
PDF
ClickHouse Features for Advanced Users, by Aleksei Milovidov
PPTX
Managing a 14 TB reporting datawarehouse with postgresql
PDF
Altinity Quickstart for ClickHouse
ODP
Performance Tuning
PDF
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
PDF
Table partitioning in PostgreSQL + Rails
PDF
Percona xtra db cluster(pxc) non blocking operations, what you need to know t...
PDF
Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10
PDF
Dangerous on ClickHouse in 30 minutes, by Robert Hodges, Altinity CEO
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
Your first ClickHouse data warehouse
ClickHouse Materialized Views: The Magic Continues
ClickHouse and the Magic of Materialized Views, By Robert Hodges and Altinity...
ClickHouse Unleashed 2020: Our Favorite New Features for Your Analytical Appl...
Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...
Webinar: Secrets of ClickHouse Query Performance, by Robert Hodges
Creating Beautiful Dashboards with Grafana and ClickHouse
Webinar slides: Adding Fast Analytics to MySQL Applications with Clickhouse
PostgreSQL: Data analysis and analytics
Oracle Join Methods and 12c Adaptive Plans
ClickHouse Features for Advanced Users, by Aleksei Milovidov
Managing a 14 TB reporting datawarehouse with postgresql
Altinity Quickstart for ClickHouse
Performance Tuning
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
Table partitioning in PostgreSQL + Rails
Percona xtra db cluster(pxc) non blocking operations, what you need to know t...
Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10
Dangerous on ClickHouse in 30 minutes, by Robert Hodges, Altinity CEO
Ad

Similar to Multi-Master Replication with Slony (20)

PPTX
SCALE 15x Minimizing PostgreSQL Major Version Upgrade Downtime
PDF
Getting Started with PL/Proxy
PDF
Five data models for sharding and which is right | PGConf.ASIA 2018 | Craig K...
PDF
Five Data Models for Sharding | Nordic PGDay 2018 | Craig Kerstiens
PPTX
Megastore by Google
PDF
Massively Distributed Backups at Facebook Scale - Shlomo Priymak, Facebook - ...
PDF
PostgreSQL Replication
PDF
What Every Developer Should Know About Database Scalability
PDF
MySQL Conference 2011 -- The Secret Sauce of Sharding -- Ryan Thiessen
PDF
Dublin Meetup: Cassandra anti patterns
PPT
Growing Data Analytics at Etsy (Cristopher Bohn)
PDF
Postgres Vision 2018: Five Sharding Data Models
 
PDF
Asynchronous Replication for PostgreSQL Slony
PPTX
Distribution Models.pptxgdfgdfgdfgfdgdfg
PDF
Updating and Scheduling of Streaming Web Services in Data Warehouses
PDF
Scaling Databases On The Cloud
PDF
Scaing databases on the cloud
PPSX
Dbms presentation
PDF
Vienna Feb 2015: Cassandra: How it works and what it's good for!
PPTX
UNIT II (1).pptx
SCALE 15x Minimizing PostgreSQL Major Version Upgrade Downtime
Getting Started with PL/Proxy
Five data models for sharding and which is right | PGConf.ASIA 2018 | Craig K...
Five Data Models for Sharding | Nordic PGDay 2018 | Craig Kerstiens
Megastore by Google
Massively Distributed Backups at Facebook Scale - Shlomo Priymak, Facebook - ...
PostgreSQL Replication
What Every Developer Should Know About Database Scalability
MySQL Conference 2011 -- The Secret Sauce of Sharding -- Ryan Thiessen
Dublin Meetup: Cassandra anti patterns
Growing Data Analytics at Etsy (Cristopher Bohn)
Postgres Vision 2018: Five Sharding Data Models
 
Asynchronous Replication for PostgreSQL Slony
Distribution Models.pptxgdfgdfgdfgfdgdfg
Updating and Scheduling of Streaming Web Services in Data Warehouses
Scaling Databases On The Cloud
Scaing databases on the cloud
Dbms presentation
Vienna Feb 2015: Cassandra: How it works and what it's good for!
UNIT II (1).pptx
Ad

More from Jim Mlodgenski (10)

PDF
Strategic autovacuum
PDF
Top 10 Mistakes When Migrating From Oracle to PostgreSQL
PDF
Oracle postgre sql-mirgration-top-10-mistakes
PDF
Profiling PL/pgSQL
PDF
Debugging Your PL/pgSQL Code
PDF
An Introduction To PostgreSQL Triggers
PDF
PostgreSQL Procedural Languages: Tips, Tricks and Gotchas
ODP
Introduction to PostgreSQL
ODP
Postgresql Federation
PPT
Leveraging Hadoop in your PostgreSQL Environment
Strategic autovacuum
Top 10 Mistakes When Migrating From Oracle to PostgreSQL
Oracle postgre sql-mirgration-top-10-mistakes
Profiling PL/pgSQL
Debugging Your PL/pgSQL Code
An Introduction To PostgreSQL Triggers
PostgreSQL Procedural Languages: Tips, Tricks and Gotchas
Introduction to PostgreSQL
Postgresql Federation
Leveraging Hadoop in your PostgreSQL Environment

Recently uploaded (20)

PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Electronic commerce courselecture one. Pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
KodekX | Application Modernization Development
PPT
Teaching material agriculture food technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Empathic Computing: Creating Shared Understanding
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
cuic standard and advanced reporting.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
Diabetes mellitus diagnosis method based random forest with bat algorithm
“AI and Expert System Decision Support & Business Intelligence Systems”
Network Security Unit 5.pdf for BCA BBA.
Electronic commerce courselecture one. Pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
20250228 LYD VKU AI Blended-Learning.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
KodekX | Application Modernization Development
Teaching material agriculture food technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Empathic Computing: Creating Shared Understanding
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
cuic standard and advanced reporting.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
NewMind AI Weekly Chronicles - August'25 Week I

Multi-Master Replication with Slony

  • 2. Who Am I? Jim Mlodgenski Co-organizer of NYCPUG
  • 3. Founder of Cirrus Technologies
  • 4. Former Chief Architect of EnterpriseDB
  • 5. What is Mult-Master? Multiple phyiscal servers in a cluster allow for the updating of data Increases Availability
  • 6. Increases performance Most noticable over a WAN
  • 7. CAP Theorem The theory put forth by Brewer that only 2 of the 3 are possible in a distributed system C onsistency
  • 10. Sync vs. Async Synchronous All transactions applied to all server before a success is returned to the client Simpler to design and architect
  • 11. At the expense of performance
  • 12. Sync vs. Async Asynchronous A transaction is applied to a single server before a success is returned to the client About the same performance as a single server
  • 13. Need to deal with conflict resolution
  • 17. Bucardo Asynchronous multi-master, master-slave, event based replication solution Used in several production deployments
  • 18. Limited to 2 masters
  • 19. PgPool Synchronous statement based, multi-master replication solution Much more than a replication solution
  • 20. Need to deal with Nondeterministic functions
  • 21. RubyRep Asynchronous multi-master, event based replication solution Not a PostgreSQL only solution
  • 22. Limited to 2 masters
  • 23. What is Slony? Asynchronous master-slave, event based replication solution Proven production use cases
  • 25. Retail Store Problem Corporate HQ controls the pricing
  • 26. The stores control the daily sales information
  • 27. Retail Store Problem The information pushed down for HQ is exactly what Slony is good at The tables controlled at HQ replicates to the many stores
  • 28. The tables at the stores are read-only
  • 29. Retail Store Problem A single replication set can control this May need to cascade if there are many stores slonik <<_EOF_ cluster name = HQ; node 1 admin conninfo = 'dbname=hq'; node 2 admin conninfo = 'dbname=store1'; node 3 admin conninfo = 'dbname=store2'; node 4 admin conninfo = 'dbname=store3'; node 5 admin conninfo = 'dbname=store4'; node 6 admin conninfo = 'dbname=store5'; init cluster ( id=1, comment = 'HQ Node'); create set (id=1, origin=1, comment='All HQ tables'); set add table (set id=1, origin=1, id=1, fully qualified name = 'public.items', comment='items table'); set add table (set id=1, origin=1, id=2, fully qualified name = 'public.prices', comment='prices table'); store node (id=2, comment = 'Store1 node', event node=1); store path (server = 1, client = 2, conninfo='dbname=hq'); store path (server = 2, client = 1, conninfo='dbname=store1'); ...
  • 30. Retail Store Problem Replicating all of the stores data to HQ is the challenge Use table inheritance
  • 31. Retail Store Problem Each store has its one partition as well as the master partition The appropriate triggers or rules should be applied to keep the structure transparent to the application
  • 32. Retail Store Problem A replication set is needed for each store
  • 33. Cascading will be necessary with many stores slonik <<_EOF_ cluster name = Store1; node 1 admin conninfo = 'dbname=store1'; node 2 admin conninfo = 'dbname=hq'; init cluster ( id=1, comment = 'Store1 Node'); create set (id=1, origin=1, comment='All Store1 sales tables'); set add table (set id=1, origin=1, id=1, fully qualified name = 'public.sales_store1', comment='sales partition'); set add table (set id=1, origin=1, id=2, fully qualified name = 'public.sales_line_store1', comment='sales detail partition'); store node (id=2, comment = 'HQ node', event node=1); store path (server = 1, client = 2, conninfo='dbname=store1'); store path (server = 2, client = 1, conninfo='dbname=hq'); _EOF_
  • 34. Retail Store Problem Potential pitfalls Many replication set and many slon daemons running
  • 35. Need to deal with the complexity of table inheritance
  • 36. Regional Office Problem NY, London, Tokyo each control their own accounts
  • 37. All accounts need to be visible
  • 38. Changes to international accounts do occur
  • 39. Regional Office Problem Challenges Need to deal with conflict resolution
  • 40. Unique account identifier across all regions
  • 42. Regional Office Problem The application needs to deal with the account table as it is designed but we need additional fields SELECT *
  • 45. Regional Office Problem Create a table with the necessary origin
  • 46. Use a view to mask the field CREATE VIEW accounts AS
  • 50. Regional Office Problem Need a central broker to handle distribution of the changes One place for conflict resolution slonik <<_EOF_ cluster name = CENTRAL_BROKER; node 1 admin conninfo = 'dbname=london'; node 2 admin conninfo = 'dbname=newyork'; node 3 admin conninfo = 'dbname=tokyo'; init cluster ( id=1, comment = 'Central Broker'); create set (id=1, origin=1, comment='Account Table'); set add table (set id=1, origin=1, id=1, fully qualified name = 'public.accounts_tbl', comment='accounts table'); store node (id=2, comment = 'New York', event node=1); store path (server = 1, client = 2, conninfo='dbname=london'); store path (server = 2, client = 1, conninfo='dbname=newyork'); store node (id=3, comment = 'Tokyo', event node=1); store path (server = 1, client = 3, conninfo='dbname=london'); store path (server = 3, client = 1, conninfo='dbname=tokyo');
  • 51. Regional Office Problem Use table inheritance to handle the changes in the offices No account_id on the shadow tables
  • 52. Regional Office Problem Adding rules to the accounts view allows the transactions to occur on the shadow tables CREATE OR REPLACE RULE accounts_i AS ON INSERT TO accounts DO INSTEAD INSERT INTO accounts_shadow_newyork VALUES (NEW.account_no, NEW.account_name, NEW.amount, NEW.created_date, NEW.last_update, 'newyork')
  • 53. Regional Office Problem Replicate the local transactions to the central broker slonik <<_EOF_ cluster name = NEWYORK; node 1 admin conninfo = 'dbname=newyork'; node 2 admin conninfo = 'dbname=london'; init cluster ( id=1, comment = 'New York'); create set (id=1, origin=1, comment='Account Shadow Table'); set add table (set id=1, origin=1, id=1, fully qualified name = 'public.accounts_shadow_newyork'); store node (id=2, comment = 'New York', event node=1); store path (server = 1, client = 2, conninfo='dbname=newyork'); store path (server = 2, client = 1, conninfo='dbname=london'); _EOF_
  • 54. CREATE OR REPLACE FUNCTION accounts_shadow_trig() RETURNS trigger AS $BODY$ DECLARE existing_account_id integer; BEGIN -- Business Logic for First-In Wins SELECT account_id INTO existing_account_id FROM accounts_tbl WHERE account_no = NEW.account_no; IF FOUND THEN RAISE INFO 'Account % already exists. Ignoring new INSERT', NEW.account_no; ELSE INSERT INTO accounts_tbl VALUES (nextval('account_id_seq'), NEW.account_no, NEW.account_name, NEW.amount, NEW.created_date, NEW.last_update, NEW.origin_code); END IF; RETURN NEW; END; $BODY$ LANGUAGE plpgsql; Regional Office Problem Add the conflict resolution logic to the broker as triggers on the shadow tables
  • 55. Regional Office Problem Potential pitfalls Many moving parts to maintenance is a heavy burden
  • 56. Reliance on a central broker
  • 57. Moral of the Story Slony is extremely flexible
  • 59. Together you can do some strange and powerful things
  • 60. Don't use multi-master unless absolutely necessary
  • 61. Questions? Jim Mlodgenski Email: [email_address] Twitter: @jim_mlodgenski