Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
different-replication-solutions.html137 linesDownload Raw Back to html
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>27.1. Comparison of Different Solutions</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="high-availability.html" title="Chapter 27. High Availability, Load Balancing, and Replication" /><link rel="next" href="warm-standby.html" title="27.2. Log-Shipping Standby Servers" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">27.1. Comparison of Different Solutions</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="high-availability.html" title="Chapter 27. High Availability, Load Balancing, and Replication">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="high-availability.html" title="Chapter 27. High Availability, Load Balancing, and Replication">Up</a></td><th width="60%" align="center">Chapter 27. High Availability, Load Balancing, and Replication</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="warm-standby.html" title="27.2. Log-Shipping Standby Servers">Next</a></td></tr></table><hr /></div><div class="sect1" id="DIFFERENT-REPLICATION-SOLUTIONS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">27.1. Comparison of Different Solutions <a href="#DIFFERENT-REPLICATION-SOLUTIONS" class="id_link">#</a></h2></div></div></div><div class="variablelist"><dl class="variablelist"><dt><span class="term">Shared Disk Failover</span></dt><dd><p>3     Shared disk failover avoids synchronization overhead by having only one4     copy of the database.  It uses a single disk array that is shared by5     multiple servers.  If the main database server fails, the standby server6     is able to mount and start the database as though it were recovering from7     a database crash.  This allows rapid failover with no data loss.8    </p><p>9     Shared hardware functionality is common in network storage devices.10     Using a network file system is also possible, though care must be11     taken that the file system has full <acronym class="acronym">POSIX</acronym> behavior (see <a class="xref" href="creating-cluster.html#CREATING-CLUSTER-NFS" title="19.2.2.1. NFS">Section 19.2.2.1</a>).  One significant limitation of this12     method is that if the shared disk array fails or becomes corrupt, the13     primary and standby servers are both nonfunctional.  Another issue is14     that the standby server should never access the shared storage while15     the primary server is running.16    </p></dd><dt><span class="term">File System (Block Device) Replication</span></dt><dd><p>17     A modified version of shared hardware functionality is file system18     replication, where all changes to a file system are mirrored to a file19     system residing on another computer.  The only restriction is that20     the mirroring must be done in a way that ensures the standby server21     has a consistent copy of the file system — specifically, writes22     to the standby must be done in the same order as those on the primary.23     <span class="productname">DRBD</span> is a popular file system replication solution24     for Linux.25    </p></dd><dt><span class="term">Write-Ahead Log Shipping</span></dt><dd><p>26     Warm and hot standby servers can be kept current by reading a27     stream of write-ahead log (<acronym class="acronym">WAL</acronym>)28     records.  If the main server fails, the standby contains29     almost all of the data of the main server, and can be quickly30     made the new primary database server.  This can be synchronous or31     asynchronous and can only be done for the entire database server.32    </p><p>33     A standby server can be implemented using file-based log shipping34     (<a class="xref" href="warm-standby.html" title="27.2. Log-Shipping Standby Servers">Section 27.2</a>) or streaming replication (see35     <a class="xref" href="warm-standby.html#STREAMING-REPLICATION" title="27.2.5. Streaming Replication">Section 27.2.5</a>), or a combination of both. For36     information on hot standby, see <a class="xref" href="hot-standby.html" title="27.4. Hot Standby">Section 27.4</a>.37    </p></dd><dt><span class="term">Logical Replication</span></dt><dd><p>38     Logical replication allows a database server to send a stream of data39     modifications to another server.  <span class="productname">PostgreSQL</span>40     logical replication constructs a stream of logical data modifications41     from the WAL.  Logical replication allows replication of data changes on42     a per-table basis.  In addition, a server that is publishing its own43     changes can also subscribe to changes from another server, allowing data44     to flow in multiple directions.  For more information on logical45     replication, see <a class="xref" href="logical-replication.html" title="Chapter 31. Logical Replication">Chapter 31</a>.  Through the46     logical decoding interface (<a class="xref" href="logicaldecoding.html" title="Chapter 49. Logical Decoding">Chapter 49</a>),47     third-party extensions can also provide similar functionality.48    </p></dd><dt><span class="term">Trigger-Based Primary-Standby Replication</span></dt><dd><p>49     A trigger-based replication setup typically funnels data modification50     queries to a designated primary server. Operating on a per-table basis,51     the primary server sends data changes (typically) asynchronously to the52     standby servers.  Standby servers can answer queries while the primary is53     running, and may allow some local data changes or write activity.  This54     form of replication is often used for offloading large analytical or data55     warehouse queries.56    </p><p>57     <span class="productname">Slony-I</span> is an example of this type of58     replication, with per-table granularity, and support for multiple standby59     servers.  Because it updates the standby server asynchronously (in60     batches), there is possible data loss during fail over.61    </p></dd><dt><span class="term">SQL-Based Replication Middleware</span></dt><dd><p>62     With SQL-based replication middleware, a program intercepts63     every SQL query and sends it to one or all servers.  Each server64     operates independently.  Read-write queries must be sent to all servers,65     so that every server receives any changes.  But read-only queries can be66     sent to just one server, allowing the read workload to be distributed67     among them.68    </p><p>69     If queries are simply broadcast unmodified, functions like70     <code class="function">random()</code>, <code class="function">CURRENT_TIMESTAMP</code>, and71     sequences can have different values on different servers.72     This is because each server operates independently, and because73     SQL queries are broadcast rather than actual data changes.  If74     this is unacceptable, either the middleware or the application75     must determine such values from a single source and then use those76     values in write queries.  Care must also be taken that all77     transactions either commit or abort on all servers, perhaps78     using two-phase commit (<a class="xref" href="sql-prepare-transaction.html" title="PREPARE TRANSACTION"><span class="refentrytitle">PREPARE TRANSACTION</span></a>79     and <a class="xref" href="sql-commit-prepared.html" title="COMMIT PREPARED"><span class="refentrytitle">COMMIT PREPARED</span></a>).80     <span class="productname">Pgpool-II</span> and <span class="productname">Continuent Tungsten</span>81     are examples of this type of replication.82    </p></dd><dt><span class="term">Asynchronous Multimaster Replication</span></dt><dd><p>83     For servers that are not regularly connected or have slow84     communication links, like laptops or85     remote servers, keeping data consistent among servers is a86     challenge.  Using asynchronous multimaster replication, each87     server works independently, and periodically communicates with88     the other servers to identify conflicting transactions.  The89     conflicts can be resolved by users or conflict resolution rules.90     Bucardo is an example of this type of replication.91    </p></dd><dt><span class="term">Synchronous Multimaster Replication</span></dt><dd><p>92     In synchronous multimaster replication, each server can accept93     write requests, and modified data is transmitted from the94     original server to every other server before each transaction95     commits.  Heavy write activity can cause excessive locking and96     commit delays, leading to poor performance.  Read requests can97     be sent to any server.  Some implementations use shared disk98     to reduce the communication overhead.  Synchronous multimaster99     replication is best for mostly read workloads, though its big100     advantage is that any server can accept write requests —101     there is no need to partition workloads between primary and102     standby servers, and because the data changes are sent from one103     server to another, there is no problem with non-deterministic104     functions like <code class="function">random()</code>.105    </p><p>106     <span class="productname">PostgreSQL</span> does not offer this type of replication,107     though <span class="productname">PostgreSQL</span> two-phase commit (<a class="xref" href="sql-prepare-transaction.html" title="PREPARE TRANSACTION"><span class="refentrytitle">PREPARE TRANSACTION</span></a> and <a class="xref" href="sql-commit-prepared.html" title="COMMIT PREPARED"><span class="refentrytitle">COMMIT PREPARED</span></a>)108     can be used to implement this in application code or middleware.109    </p></dd></dl></div><p>110  <a class="xref" href="different-replication-solutions.html#HIGH-AVAILABILITY-MATRIX" title="Table 27.1. High Availability, Load Balancing, and Replication Feature Matrix">Table 27.1</a> summarizes111  the capabilities of the various solutions listed above.112 </p><div class="table" id="HIGH-AVAILABILITY-MATRIX"><p class="title"><strong>Table 27.1. High Availability, Load Balancing, and Replication Feature Matrix</strong></p><div class="table-contents"><table class="table" summary="High Availability, Load Balancing, and Replication Feature Matrix" border="1"><colgroup><col class="col1" /><col class="col2" /><col class="col3" /><col class="col4" /><col class="col5" /><col class="col6" /><col class="col7" /><col class="col8" /><col class="col9" /></colgroup><thead><tr><th>Feature</th><th>Shared Disk</th><th>File System Repl.</th><th>Write-Ahead Log Shipping</th><th>Logical Repl.</th><th>Trigger-​Based Repl.</th><th>SQL Repl. Middle-ware</th><th>Async. MM Repl.</th><th>Sync. MM Repl.</th></tr></thead><tbody><tr><td>Popular examples</td><td align="center">NAS</td><td align="center">DRBD</td><td align="center">built-in streaming repl.</td><td align="center">built-in logical repl., pglogical</td><td align="center">Londiste, Slony</td><td align="center">pgpool-II</td><td align="center">Bucardo</td><td align="center"> </td></tr><tr><td>Comm. method</td><td align="center">shared disk</td><td align="center">disk blocks</td><td align="center">WAL</td><td align="center">logical decoding</td><td align="center">table rows</td><td align="center">SQL</td><td align="center">table rows</td><td align="center">table rows and row locks</td></tr><tr><td>No special hardware required</td><td align="center"> </td><td align="center">•</td><td align="center">•</td><td align="center">•</td><td align="center">•</td><td align="center">•</td><td align="center">•</td><td align="center">•</td></tr><tr><td>Allows multiple primary servers</td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center">•</td><td align="center"> </td><td align="center">•</td><td align="center">•</td><td align="center">•</td></tr><tr><td>No overhead on primary</td><td align="center">•</td><td align="center"> </td><td align="center">•</td><td align="center">•</td><td align="center"> </td><td align="center">•</td><td align="center"> </td><td align="center"> </td></tr><tr><td>No waiting for multiple servers</td><td align="center">•</td><td align="center"> </td><td align="center">with sync off</td><td align="center">with sync off</td><td align="center">•</td><td align="center"> </td><td align="center">•</td><td align="center"> </td></tr><tr><td>Primary failure will never lose data</td><td align="center">•</td><td align="center">•</td><td align="center">with sync on</td><td align="center">with sync on</td><td align="center"> </td><td align="center">•</td><td align="center"> </td><td align="center">•</td></tr><tr><td>Replicas accept read-only queries</td><td align="center"> </td><td align="center"> </td><td align="center">with hot standby</td><td align="center">•</td><td align="center">•</td><td align="center">•</td><td align="center">•</td><td align="center">•</td></tr><tr><td>Per-table granularity</td><td align="center"> </td><td align="center"> </td><td align="center"> </td><td align="center">•</td><td align="center">•</td><td align="center"> </td><td align="center">•</td><td align="center">•</td></tr><tr><td>No conflict resolution necessary</td><td align="center">•</td><td align="center">•</td><td align="center">•</td><td align="center"> </td><td align="center">•</td><td align="center">•</td><td align="center"> </td><td align="center">•</td></tr></tbody></table></div></div><br class="table-break" /><p>113  There are a few solutions that do not fit into the above categories:114 </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">Data Partitioning</span></dt><dd><p>115     Data partitioning splits tables into data sets.  Each set can116     be modified by only one server.  For example, data can be117     partitioned by offices, e.g., London and Paris, with a server118     in each office.  If queries combining London and Paris data119     are necessary, an application can query both servers, or120     primary/standby replication can be used to keep a read-only copy121     of the other office's data on each server.122    </p></dd><dt><span class="term">Multiple-Server Parallel Query Execution</span></dt><dd><p>123     Many of the above solutions allow multiple servers to handle multiple124     queries, but none allow a single query to use multiple servers to125     complete faster.  This solution allows multiple servers to work126     concurrently on a single query.  It is usually accomplished by127     splitting the data among servers and having each server execute its128     part of the query and return results to a central server where they129     are combined and returned to the user. This can be implemented using the130     <span class="productname">PL/Proxy</span> tool set.131    </p></dd></dl></div><p>132   It should also be noted that because <span class="productname">PostgreSQL</span>133   is open source and easily extended, a number of companies have134   taken <span class="productname">PostgreSQL</span> and created commercial135   closed-source solutions with unique failover, replication, and load136   balancing capabilities.  These are not discussed here.137  </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="high-availability.html" title="Chapter 27. High Availability, Load Balancing, and Replication">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="high-availability.html" title="Chapter 27. High Availability, Load Balancing, and Replication">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="warm-standby.html" title="27.2. Log-Shipping Standby Servers">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 27. High Availability, Load Balancing, and Replication </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 27.2. Log-Shipping Standby Servers</td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai