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>26.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 26. High Availability, Load Balancing, and Replication" /><link rel="next" href="warm-standby.html" title="26.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">26.1. Comparison of Different Solutions</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="high-availability.html" title="Chapter 26. High Availability, Load Balancing, and Replication">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="high-availability.html" title="Chapter 26. High Availability, Load Balancing, and Replication">Up</a></td><th width="60%" align="center">Chapter 26. High Availability, Load Balancing, and Replication</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="warm-standby.html" title="26.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">26.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 one
4 copy of the database. It uses a single disk array that is shared by
5 multiple servers. If the main database server fails, the standby server
6 is able to mount and start the database as though it were recovering from
7 a database crash. This allows rapid failover with no data loss.
9 Shared hardware functionality is common in network storage devices.
10 Using a network file system is also possible, though care must be
11 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="18.2.2.1. NFS">Section 18.2.2.1</a>). One significant limitation of this
12 method is that if the shared disk array fails or becomes corrupt, the
13 primary and standby servers are both nonfunctional. Another issue is
14 that the standby server should never access the shared storage while
15 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 system
18 replication, where all changes to a file system are mirrored to a file
19 system residing on another computer. The only restriction is that
20 the mirroring must be done in a way that ensures the standby server
21 has a consistent copy of the file system — specifically, writes
22 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 solution
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 a
27 stream of write-ahead log (<acronym class="acronym">WAL</acronym>)
28 records. If the main server fails, the standby contains
29 almost all of the data of the main server, and can be quickly
30 made the new primary database server. This can be synchronous or
31 asynchronous and can only be done for the entire database server.
33 A standby server can be implemented using file-based log shipping
34 (<a class="xref" href="warm-standby.html" title="26.2. Log-Shipping Standby Servers">Section 26.2</a>) or streaming replication (see
35 <a class="xref" href="warm-standby.html#STREAMING-REPLICATION" title="26.2.5. Streaming Replication">Section 26.2.5</a>), or a combination of both. For
36 information on hot standby, see <a class="xref" href="hot-standby.html" title="26.4. Hot Standby">Section 26.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 data
39 modifications to another server. <span class="productname">PostgreSQL</span>
40 logical replication constructs a stream of logical data modifications
41 from the WAL. Logical replication allows replication of data changes on
42 a per-table basis. In addition, a server that is publishing its own
43 changes can also subscribe to changes from another server, allowing data
44 to flow in multiple directions. For more information on logical
45 replication, see <a class="xref" href="logical-replication.html" title="Chapter 29. Logical Replication">Chapter 29</a>. Through the
46 logical decoding interface (<a class="xref" href="logicaldecoding.html" title="Chapter 47. Logical Decoding">Chapter 47</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 modification
50 queries to a designated primary server. Operating on a per-table basis,
51 the primary server sends data changes (typically) asynchronously to the
52 standby servers. Standby servers can answer queries while the primary is
53 running, and may allow some local data changes or write activity. This
54 form of replication is often used for offloading large analytical or data
57 <span class="productname">Slony-I</span> is an example of this type of
58 replication, with per-table granularity, and support for multiple standby
59 servers. Because it updates the standby server asynchronously (in
60 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 intercepts
63 every SQL query and sends it to one or all servers. Each server
64 operates independently. Read-write queries must be sent to all servers,
65 so that every server receives any changes. But read-only queries can be
66 sent to just one server, allowing the read workload to be distributed
69 If queries are simply broadcast unmodified, functions like
70 <code class="function">random()</code>, <code class="function">CURRENT_TIMESTAMP</code>, and
71 sequences can have different values on different servers.
72 This is because each server operates independently, and because
73 SQL queries are broadcast rather than actual data changes. If
74 this is unacceptable, either the middleware or the application
75 must determine such values from a single source and then use those
76 values in write queries. Care must also be taken that all
77 transactions either commit or abort on all servers, perhaps
78 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 slow
84 communication links, like laptops or
85 remote servers, keeping data consistent among servers is a
86 challenge. Using asynchronous multimaster replication, each
87 server works independently, and periodically communicates with
88 the other servers to identify conflicting transactions. The
89 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 accept
93 write requests, and modified data is transmitted from the
94 original server to every other server before each transaction
95 commits. Heavy write activity can cause excessive locking and
96 commit delays, leading to poor performance. Read requests can
97 be sent to any server. Some implementations use shared disk
98 to reduce the communication overhead. Synchronous multimaster
99 replication is best for mostly read workloads, though its big
100 advantage is that any server can accept write requests —
101 there is no need to partition workloads between primary and
102 standby servers, and because the data changes are sent from one
103 server to another, there is no problem with non-deterministic
104 functions like <code class="function">random()</code>.
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 26.1. High Availability, Load Balancing, and Replication Feature Matrix">Table 26.1</a> summarizes
111 the capabilities of the various solutions listed above.
112 </p><div class="table" id="HIGH-AVAILABILITY-MATRIX"><p class="title"><strong>Table 26.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 can
116 be modified by only one server. For example, data can be
117 partitioned by offices, e.g., London and Paris, with a server
118 in each office. If queries combining London and Paris data
119 are necessary, an application can query both servers, or
120 primary/standby replication can be used to keep a read-only copy
121 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 multiple
124 queries, but none allow a single query to use multiple servers to
125 complete faster. This solution allows multiple servers to work
126 concurrently on a single query. It is usually accomplished by
127 splitting the data among servers and having each server execute its
128 part of the query and return results to a central server where they
129 are combined and returned to the user. This can be implemented using the
130 <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 have
134 taken <span class="productname">PostgreSQL</span> and created commercial
135 closed-source solutions with unique failover, replication, and load
136 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 26. High Availability, Load Balancing, and Replication">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="high-availability.html" title="Chapter 26. High Availability, Load Balancing, and Replication">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="warm-standby.html" title="26.2. Log-Shipping Standby Servers">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 26. High Availability, Load Balancing, and Replication </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 26.2. Log-Shipping Standby Servers</td></tr></table></div></body></html>