richard yen pg conf silicon valley 2019 - postgres conf · 2019-11-07 · next, try pglogical or...
TRANSCRIPT
![Page 1: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/1.jpg)
Choosing from the Many Flavors of PostgreSQL ReplicationRichard Yen
PG Conf Silicon Valley 2019
![Page 2: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/2.jpg)
DisclaimerThis is not an EDB talk!
![Page 3: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/3.jpg)
Why Replication?
• Because one copy is not enough!
• Fault-Tolerance
• Scalability
• Recoverability
• People want “real” data to work with
![Page 4: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/4.jpg)
Which one is for me?
• Streaming replication
• Logical replication
• Slony
• Bucardo
• Londiste
• DRBD
• Corosync
• 2ndQ BDR
• pg_shard
• pglogical
• Daffodil
• Mammoth
• Pgpool
• EDB Replication Server
• Spectral Core Replicator Pro
• And More!
![Page 5: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/5.jpg)
It all boils down to…Trigger-based | WAL-based
![Page 6: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/6.jpg)
Trigger-based Replication
• Relies on PostgreSQL’s trigger mechanism to log all DML into event/shadow tables
• Data from shadow tables ingested by another program and replayed to other nodes
• Very reliable: replicating production environments since 2003
![Page 7: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/7.jpg)
Trigger-based Replication
• Main players
• Slony — written in C
• Londiste — written in Python
• Bucardo — written in Perl
![Page 8: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/8.jpg)
Trigger-based Pros & Cons
• Select which tables to replicate
• Enables row-based/column-based replication
• Major-version upgrades
• Master-master replication (Bucardo only)
![Page 9: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/9.jpg)
Trigger-based Pros & Cons• Primary keys required
• Limited ability to replicate DDL
• Large object replication not available
• Trigger activity generates additional I/O
• Event tracking consumes network bandwidth
• Hard to scale up
• Infrastructure is brittle
![Page 10: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/10.jpg)
WAL-based Replication
• WAL files are the mechanism to recover from crashes
• WAL files can be used to replay DML on remote servers
• Streaming WAL activity effectively creates an up-to-date clone
![Page 11: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/11.jpg)
WAL-based Pros & Cons• It's fast
• Easy to set up
• Requires no additional software, I/O, bandwidth
• Exact replica provides assurance for backups
• Exact replica means all data types are supported
• Synchronous replication is possible
![Page 12: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/12.jpg)
WAL-based Pros & Cons• All or nothing
• No major version upgrades
• Query cancellations
• Storage impact on primary
• wal_keep_segments
• replication slots
![Page 13: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/13.jpg)
Middle Ground: Logical Replication
• Introduced in v. 10
• Based off Logical Decoding framework introduced in v. 9.4
• WAL files are reconstructed into SQL statements
• Paves the way to more granular replication filters
• Happy-medium
![Page 14: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/14.jpg)
Best of Both Worlds?• Like Trigger-based Replication:
• Still need uniqueness/PK
• DDL is not replicated
• Sequences are not replicated
• Like WAL-based Replication
• Still need to monitor storage impact
• Can’t create column-level filters (yet)
![Page 15: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/15.jpg)
Additional Gotchas
• WAL events are unrolled into individual SQL queries
• COPY statements are translated into INSERTs
• UPDATE on 1000 rows are translated into 1000 individual UPDATEs
• TRUNCATEs are replicated, but not cascaded
• Partitioned tables cannot be easily replicated
![Page 16: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/16.jpg)
Other options
• DRBD, Corosync, Windows Cluster
• Basically, mirrors a disk or other block-level device
• Doesn't support read-only standby
• Use cases for these are somewhat rare
• Use at your own discretion
![Page 17: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/17.jpg)
How do you choose?
![Page 18: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/18.jpg)
It all depends on your requirementsTolerances, privacy, etc.
![Page 19: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/19.jpg)
Process of Elimination
![Page 20: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/20.jpg)
Start with built-in Streaming Replication
• Super-simple to set up
• No additional software
• Best performance, least impact
• Good for most use-cases
![Page 21: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/21.jpg)
Streaming ReplicationX
![Page 22: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/22.jpg)
Next, try Logical Replication
• Pick and choose which tables to replicate
• WAL-based replication performance
• Zero-downtime major-version upgrades
• Only available in v. 10 and later
![Page 23: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/23.jpg)
Streaming Replication
Logical Replication
XX
![Page 24: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/24.jpg)
Next, try pglogical or EPRS
• Replication engines supporting Logical Decoding
• pglogical
• EnterpriseDB Postgres Replication Server 7 (EPRS7 — Limited Availability)
• Row-level and column-level filters
• Still WAL-based
![Page 25: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/25.jpg)
Streaming Replication
Logical Replication
pglogical | EPRS7
XXX
![Page 26: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/26.jpg)
Use a Trigger-based Solution
![Page 27: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/27.jpg)
Use a Trigger-based Solution
• But please upgrade soon!
• Impacts performance
• Often difficult to administration
• Logical Replication is the future
![Page 28: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/28.jpg)
RDS?Try Bucardo
![Page 29: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/29.jpg)
Multi-Master Replication?
![Page 30: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/30.jpg)
Multi-Master Replication?
• Holy Grail of replication solutions?
• First, ask yourself if you REALLY need it
• Consistency
• Performance
• Conflict Resolution
• Often, the other options are good enough?
![Page 31: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/31.jpg)
Multi-Master Replication• Trigger-based
• Bucardo
• XDB by EnterpriseDB
• WAL-based
• Bi-Directional Replication (BDR) by 2nd Quadrant
• requires a custom compile/installation of PG
• XDB/EPRS7 by EnterpriseDB
![Page 32: Richard Yen PG Conf Silicon Valley 2019 - Postgres Conf · 2019-11-07 · Next, try pglogical or EPRS • Replication engines supporting Logical Decoding • pglogical • EnterpriseDB](https://reader033.vdocuments.mx/reader033/viewer/2022053009/5f0ce9d07e708231d437c058/html5/thumbnails/32.jpg)
Q & A