|
1 |
| -<!-- $PostgreSQL: pgsql/doc/src/sgml/failover.sgml,v 1.7 2006/11/1618:25:58 momjian Exp $ --> |
| 1 | +<!-- $PostgreSQL: pgsql/doc/src/sgml/failover.sgml,v 1.8 2006/11/1621:43:33 momjian Exp $ --> |
2 | 2 |
|
3 | 3 | <chapter id="failover">
|
4 | 4 | <title>Failover, Replication, Load Balancing, and Clustering Options</title>
|
|
76 | 76 | and load balancing solutions.
|
77 | 77 | </para>
|
78 | 78 |
|
79 |
| - <sect1 id="shared-disk-failover"> |
80 |
| - <title>Shared Disk Failover</title> |
81 |
| - |
82 |
| - <para> |
83 |
| - Shared disk failover avoids synchronization overhead by having only one |
84 |
| - copy of the database. It uses a single disk array that is shared by |
85 |
| - multiple servers. If the main database server fails, the backup server |
86 |
| - is able to mount and start the database as though it was recovering from |
87 |
| - a database crash. This allows rapid failover with no data loss. |
88 |
| - </para> |
89 |
| - |
90 |
| - <para> |
91 |
| - Shared hardware functionality is common in network storage devices. One |
92 |
| - significant limitation of this method is that if the shared disk array |
93 |
| - fails or becomes corrupt, the primary and backup servers are both |
94 |
| - nonfunctional. |
95 |
| - </para> |
96 |
| - </sect1> |
97 |
| - |
98 |
| - <sect1 id="warm-standby-using-point-in-time-recovery"> |
99 |
| - <title>Warm Standby Using Point-In-Time Recovery</title> |
100 |
| - |
101 |
| - <para> |
102 |
| - A warm standby server (see <xref linkend="warm-standby">) can |
103 |
| - be kept current by reading a stream of write-ahead log (WAL) |
104 |
| - records. If the main server fails, the warm standby contains |
105 |
| - almost all of the data of the main server, and can be quickly |
106 |
| - made the new master database server. This is asynchronous and |
107 |
| - can only be done for the entire database server. |
108 |
| - </para> |
109 |
| - </sect1> |
110 |
| - |
111 |
| - <sect1 id="continuously-running-replication-server"> |
112 |
| - <title>Continuously Running Replication Server</title> |
113 |
| - |
114 |
| - <para> |
115 |
| - A continuously running replication server allows the backup server to |
116 |
| - answer read-only queries while the master server is running. It |
117 |
| - receives a continuous stream of write activity from the master server. |
118 |
| - Because the backup server can be used for read-only database requests, |
119 |
| - it is ideal for data warehouse queries. |
120 |
| - </para> |
121 |
| - |
122 |
| - <para> |
123 |
| - Slony-I is an example of this type of replication, with per-table |
124 |
| - granularity. It updates the backup server in batches, so the replication |
125 |
| - is asynchronous and might lose data during a fail over. |
126 |
| - </para> |
127 |
| - </sect1> |
128 |
| - |
129 |
| - <sect1 id="data-partitioning"> |
130 |
| - <title>Data Partitioning</title> |
131 |
| - |
132 |
| - <para> |
133 |
| - Data partitioning splits tables into data sets. Each set can |
134 |
| - be modified by only one server. For example, data can be |
135 |
| - partitioned by offices, e.g. London and Paris. While London |
136 |
| - and Paris servers have all data records, only London can modify |
137 |
| - London records, and Paris can only modify Paris records. This |
138 |
| - is similar to section <xref |
139 |
| - linkend="continuously-running-replication-server"> above, except |
140 |
| - that instead of having a read/write server and a read-only server, |
141 |
| - each server has a read/write data set and a read-only data |
142 |
| - set. |
143 |
| - </para> |
144 |
| - |
145 |
| - <para> |
146 |
| - Such partitioning provides both failover and load balancing. Failover |
147 |
| - is achieved because the data resides on both servers, and this is an |
148 |
| - ideal way to enable failover if the servers share a slow communication |
149 |
| - channel. Load balancing is possible because read requests can go to any |
150 |
| - of the servers, and write requests are split among the servers. Of |
151 |
| - course, the communication to keep all the servers up-to-date adds |
152 |
| - overhead, so ideally the write load should be low, or localized as in |
153 |
| - the London/Paris example above. |
154 |
| - </para> |
155 |
| - |
156 |
| - <para> |
157 |
| - Data partitioning is usually handled by application code, though rules |
158 |
| - and triggers can be used to keep the read-only data sets current. Slony-I |
159 |
| - can also be used in such a setup. While Slony-I replicates only entire |
160 |
| - tables, London and Paris can be placed in separate tables, and |
161 |
| - inheritance can be used to access both tables using a single table name. |
162 |
| - </para> |
163 |
| - </sect1> |
164 |
| - |
165 |
| - <sect1 id="query-broadcast-load-balancing"> |
166 |
| - <title>Query Broadcast Load Balancing</title> |
167 |
| - |
168 |
| - <para> |
169 |
| - Query broadcast load balancing is accomplished by having a |
170 |
| - program intercept every SQL query and send it to all servers. |
171 |
| - This is unique because most replication solutions have the write |
172 |
| - server propagate its changes to the other servers. With query |
173 |
| - broadcasting, each server operates independently. Read-only |
174 |
| - queries can be sent to a single server because there is no need |
175 |
| - for all servers to process it. |
176 |
| - </para> |
177 |
| - |
178 |
| - <para> |
179 |
| - One limitation of this solution is that functions like |
180 |
| - <function>random()</>, <function>CURRENT_TIMESTAMP</>, and |
181 |
| - sequences can have different values on different servers. This |
182 |
| - is because each server operates independently, and because SQL |
183 |
| - queries are broadcast (and not actual modified rows). If this |
184 |
| - is unacceptable, applications must query such values from a |
185 |
| - single server and then use those values in write queries. Also, |
186 |
| - care must be taken that all transactions either commit or abort |
187 |
| - on all servers Pgpool is an example of this type of replication. |
188 |
| - </para> |
189 |
| - </sect1> |
190 |
| - |
191 |
| - <sect1 id="clustering-for-load-balancing"> |
192 |
| - <title>Clustering For Load Balancing</title> |
193 |
| - |
194 |
| - <para> |
195 |
| - In clustering, each server can accept write requests, and modified |
196 |
| - data is transmitted from the original server to every other |
197 |
| - server before each transaction commits. Heavy write activity |
198 |
| - can cause excessive locking, leading to poor performance. In |
199 |
| - fact, write performance is often worse than that of a single |
200 |
| - server. Read requests can be sent to any server. Clustering |
201 |
| - is best for mostly read workloads, though its big advantage is |
202 |
| - that any server can accept write requests — there is no need |
203 |
| - to partition workloads between read/write and read-only servers. |
204 |
| - </para> |
205 |
| - |
206 |
| - <para> |
207 |
| - Clustering is implemented by <productname>Oracle</> in their |
208 |
| - <productname><acronym>RAC</></> product. <productname>PostgreSQL</> |
209 |
| - does not offer this type of load balancing, though |
210 |
| - <productname>PostgreSQL</> two-phase commit (<xref |
211 |
| - linkend="sql-prepare-transaction" |
212 |
| - endterm="sql-prepare-transaction-title"> and <xref |
213 |
| - linkend="sql-commit-prepared" endterm="sql-commit-prepared-title">) |
214 |
| - can be used to implement this in application code or middleware. |
215 |
| - </para> |
216 |
| - </sect1> |
217 |
| - |
218 |
| - <sect1 id="clustering-for-parallel-query-execution"> |
219 |
| - <title>Clustering For Parallel Query Execution</title> |
220 |
| - |
221 |
| - <para> |
222 |
| - This allows multiple servers to work concurrently on a single |
223 |
| - query. One possible way this could work is for the data to be |
224 |
| - split among servers and for each server to execute its part of |
225 |
| - the query and results sent to a central server to be combined |
226 |
| - and returned to the user. There currently is no |
227 |
| - <productname>PostgreSQL</> open source solution for this. |
228 |
| - </para> |
229 |
| - </sect1> |
230 |
| - |
231 |
| - <sect1 id="commercial-solutions"> |
232 |
| - <title>Commercial Solutions</title> |
233 |
| - |
234 |
| - <para> |
235 |
| - Because <productname>PostgreSQL</> is open source and easily |
236 |
| - extended, a number of companies have taken <productname>PostgreSQL</> |
237 |
| - and created commercial closed-source solutions with unique |
238 |
| - failover, replication, and load balancing capabilities. |
239 |
| - </para> |
240 |
| - </sect1> |
| 79 | + <variablelist> |
| 80 | + |
| 81 | + <varlistentry> |
| 82 | + <term>Shared Disk Failover</term> |
| 83 | + <listitem> |
| 84 | + |
| 85 | + <para> |
| 86 | + Shared disk failover avoids synchronization overhead by having only one |
| 87 | + copy of the database. It uses a single disk array that is shared by |
| 88 | + multiple servers. If the main database server fails, the backup server |
| 89 | + is able to mount and start the database as though it was recovering from |
| 90 | + a database crash. This allows rapid failover with no data loss. |
| 91 | + </para> |
| 92 | + |
| 93 | + <para> |
| 94 | + Shared hardware functionality is common in network storage devices. One |
| 95 | + significant limitation of this method is that if the shared disk array |
| 96 | + fails or becomes corrupt, the primary and backup servers are both |
| 97 | + nonfunctional. |
| 98 | + </para> |
| 99 | + </listitem> |
| 100 | + </varlistentry> |
| 101 | + |
| 102 | + <varlistentry> |
| 103 | + <term>Warm Standby Using Point-In-Time Recovery</term> |
| 104 | + <listitem> |
| 105 | + |
| 106 | + <para> |
| 107 | + A warm standby server (see <xref linkend="warm-standby">) can |
| 108 | + be kept current by reading a stream of write-ahead log (WAL) |
| 109 | + records. If the main server fails, the warm standby contains |
| 110 | + almost all of the data of the main server, and can be quickly |
| 111 | + made the new master database server. This is asynchronous and |
| 112 | + can only be done for the entire database server. |
| 113 | + </para> |
| 114 | + </listitem> |
| 115 | + </varlistentry> |
| 116 | + |
| 117 | + <varlistentry> |
| 118 | + <term>Continuously Running Replication Server</term> |
| 119 | + <listitem> |
| 120 | + |
| 121 | + <para> |
| 122 | + A continuously running replication server allows the backup server to |
| 123 | + answer read-only queries while the master server is running. It |
| 124 | + receives a continuous stream of write activity from the master server. |
| 125 | + Because the backup server can be used for read-only database requests, |
| 126 | + it is ideal for data warehouse queries. |
| 127 | + </para> |
| 128 | + |
| 129 | + <para> |
| 130 | + Slony-I is an example of this type of replication, with per-table |
| 131 | + granularity. It updates the backup server in batches, so the replication |
| 132 | + is asynchronous and might lose data during a fail over. |
| 133 | + </para> |
| 134 | + </listitem> |
| 135 | + </varlistentry> |
| 136 | + |
| 137 | + <varlistentry> |
| 138 | + <term>Data Partitioning</term> |
| 139 | + <listitem> |
| 140 | + |
| 141 | + <para> |
| 142 | + Data partitioning splits tables into data sets. Each set can |
| 143 | + be modified by only one server. For example, data can be |
| 144 | + partitioned by offices, e.g. London and Paris. While London |
| 145 | + and Paris servers have all data records, only London can modify |
| 146 | + London records, and Paris can only modify Paris records. This |
| 147 | + is similar to the "Continuously Running Replication Server" |
| 148 | + item above, except that instead of having a read/write server |
| 149 | + and a read-only server, each server has a read/write data set |
| 150 | + and a read-only data set. |
| 151 | + </para> |
| 152 | + |
| 153 | + <para> |
| 154 | + Such partitioning provides both failover and load balancing. Failover |
| 155 | + is achieved because the data resides on both servers, and this is an |
| 156 | + ideal way to enable failover if the servers share a slow communication |
| 157 | + channel. Load balancing is possible because read requests can go to any |
| 158 | + of the servers, and write requests are split among the servers. Of |
| 159 | + course, the communication to keep all the servers up-to-date adds |
| 160 | + overhead, so ideally the write load should be low, or localized as in |
| 161 | + the London/Paris example above. |
| 162 | + </para> |
| 163 | + |
| 164 | + <para> |
| 165 | + Data partitioning is usually handled by application code, though rules |
| 166 | + and triggers can be used to keep the read-only data sets current. Slony-I |
| 167 | + can also be used in such a setup. While Slony-I replicates only entire |
| 168 | + tables, London and Paris can be placed in separate tables, and |
| 169 | + inheritance can be used to access both tables using a single table name. |
| 170 | + </para> |
| 171 | + </listitem> |
| 172 | + </varlistentry> |
| 173 | + |
| 174 | + <varlistentry> |
| 175 | + <term>Query Broadcast Load Balancing</term> |
| 176 | + <listitem> |
| 177 | + |
| 178 | + <para> |
| 179 | + Query broadcast load balancing is accomplished by having a |
| 180 | + program intercept every SQL query and send it to all servers. |
| 181 | + This is unique because most replication solutions have the write |
| 182 | + server propagate its changes to the other servers. With query |
| 183 | + broadcasting, each server operates independently. Read-only |
| 184 | + queries can be sent to a single server because there is no need |
| 185 | + for all servers to process it. |
| 186 | + </para> |
| 187 | + |
| 188 | + <para> |
| 189 | + One limitation of this solution is that functions like |
| 190 | + <function>random()</>, <function>CURRENT_TIMESTAMP</>, and |
| 191 | + sequences can have different values on different servers. This |
| 192 | + is because each server operates independently, and because SQL |
| 193 | + queries are broadcast (and not actual modified rows). If this |
| 194 | + is unacceptable, applications must query such values from a |
| 195 | + single server and then use those values in write queries. Also, |
| 196 | + care must be taken that all transactions either commit or abort |
| 197 | + on all servers Pgpool is an example of this type of replication. |
| 198 | + </para> |
| 199 | + </listitem> |
| 200 | + </varlistentry> |
| 201 | + |
| 202 | + <varlistentry> |
| 203 | + <term>Clustering For Load Balancing</term> |
| 204 | + <listitem> |
| 205 | + |
| 206 | + <para> |
| 207 | + In clustering, each server can accept write requests, and modified |
| 208 | + data is transmitted from the original server to every other |
| 209 | + server before each transaction commits. Heavy write activity |
| 210 | + can cause excessive locking, leading to poor performance. In |
| 211 | + fact, write performance is often worse than that of a single |
| 212 | + server. Read requests can be sent to any server. Clustering |
| 213 | + is best for mostly read workloads, though its big advantage is |
| 214 | + that any server can accept write requests — there is no need |
| 215 | + to partition workloads between read/write and read-only servers. |
| 216 | + </para> |
| 217 | + |
| 218 | + <para> |
| 219 | + Clustering is implemented by <productname>Oracle</> in their |
| 220 | + <productname><acronym>RAC</></> product. <productname>PostgreSQL</> |
| 221 | + does not offer this type of load balancing, though |
| 222 | + <productname>PostgreSQL</> two-phase commit (<xref |
| 223 | + linkend="sql-prepare-transaction" |
| 224 | + endterm="sql-prepare-transaction-title"> and <xref |
| 225 | + linkend="sql-commit-prepared" endterm="sql-commit-prepared-title">) |
| 226 | + can be used to implement this in application code or middleware. |
| 227 | + </para> |
| 228 | + </listitem> |
| 229 | + </varlistentry> |
| 230 | + |
| 231 | + <varlistentry> |
| 232 | + <term>Clustering For Parallel Query Execution</term> |
| 233 | + <listitem> |
| 234 | + |
| 235 | + <para> |
| 236 | + This allows multiple servers to work concurrently on a single |
| 237 | + query. One possible way this could work is for the data to be |
| 238 | + split among servers and for each server to execute its part of |
| 239 | + the query and results sent to a central server to be combined |
| 240 | + and returned to the user. There currently is no |
| 241 | + <productname>PostgreSQL</> open source solution for this. |
| 242 | + </para> |
| 243 | + </listitem> |
| 244 | + </varlistentry> |
| 245 | + |
| 246 | + <varlistentry> |
| 247 | + <term>Commercial Solutions</term> |
| 248 | + <listitem> |
| 249 | + |
| 250 | + <para> |
| 251 | + Because <productname>PostgreSQL</> is open source and easily |
| 252 | + extended, a number of companies have taken <productname>PostgreSQL</> |
| 253 | + and created commercial closed-source solutions with unique |
| 254 | + failover, replication, and load balancing capabilities. |
| 255 | + </para> |
| 256 | + </listitem> |
| 257 | + </varlistentry> |
| 258 | + |
| 259 | + </variablelist> |
241 | 260 |
|
242 | 261 | </chapter>
|