Sophie

Sophie

distrib > Mandriva > current > i586 > media > main-updates > by-pkgid > fc62ce67f262cdcd253dc7f849ce3223 > files > 252

postgresql8.4-docs-8.4.12-0.1mdv2010.2.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>High Availability, Load Balancing, and Replication</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 8.4.12 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Server Administration"
HREF="admin.html"><LINK
REL="PREVIOUS"
TITLE="Migration Between Releases"
HREF="migration.html"><LINK
REL="NEXT"
TITLE="Monitoring Database Activity"
HREF="monitoring.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2012-05-31T23:30:11"></HEAD
><BODY
CLASS="CHAPTER"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
>PostgreSQL 8.4.12 Documentation</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="migration.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="backup.html"
>Fast Backward</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="monitoring.html"
>Fast Forward</A
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="monitoring.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="CHAPTER"
><H1
><A
NAME="HIGH-AVAILABILITY"
></A
>Chapter 25. High Availability, Load Balancing, and Replication</H1
><A
NAME="AEN31298"
></A
><A
NAME="AEN31300"
></A
><A
NAME="AEN31302"
></A
><A
NAME="AEN31304"
></A
><A
NAME="AEN31306"
></A
><A
NAME="AEN31308"
></A
><P
>  Database servers can work together to allow a second server to
  take over quickly if the primary server fails (high
  availability), or to allow several computers to serve the same
  data (load balancing).  Ideally, database servers could work
  together seamlessly.  Web servers serving static web pages can
  be combined quite easily by merely load-balancing web requests
  to multiple machines.  In fact, read-only database servers can
  be combined relatively easily too.  Unfortunately, most database
  servers have a read/write mix of requests, and read/write servers
  are much harder to combine.  This is because though read-only
  data needs to be placed on each server only once, a write to any
  server has to be propagated to all servers so that future read
  requests to those servers return consistent results.
 </P
><P
>  This synchronization problem is the fundamental difficulty for
  servers working together.  Because there is no single solution
  that eliminates the impact of the sync problem for all use cases,
  there are multiple solutions.  Each solution addresses this
  problem in a different way, and minimizes its impact for a specific
  workload.
 </P
><P
>  Some solutions deal with synchronization by allowing only one
  server to modify the data.  Servers that can modify data are
  called read/write or "master" servers.  Servers that can reply
  to read-only queries are called "slave" servers.  Servers that
  cannot be accessed until they are changed to master servers are
  called "standby" servers.
 </P
><P
>  Some solutions are synchronous,
  meaning that a data-modifying transaction is not considered
  committed until all servers have committed the transaction.  This
  guarantees that a failover will not lose any data and that all
  load-balanced servers will return consistent results no matter
  which server is queried. In contrast, asynchronous solutions allow some
  delay between the time of a commit and its propagation to the other servers,
  opening the possibility that some transactions might be lost in
  the switch to a backup server, and that load balanced servers
  might return slightly stale results.  Asynchronous communication
  is used when synchronous would be too slow.
 </P
><P
>  Solutions can also be categorized by their granularity.  Some solutions
  can deal only with an entire database server, while others allow control
  at the per-table or per-database level.
 </P
><P
>  Performance must be considered in any choice.  There is usually a
  trade-off between functionality and
  performance.  For example, a full synchronous solution over a slow
  network might cut performance by more than half, while an asynchronous
  one might have a minimal performance impact.
 </P
><P
>  The remainder of this section outlines various failover, replication,
  and load balancing solutions.  A <A
HREF="http://www.postgres-r.org/documentation/terms"
TARGET="_top"
>glossary</A
> is
  also available.
 </P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Shared Disk Failover</DT
><DD
><P
>     Shared disk failover avoids synchronization overhead by having only one
     copy of the database.  It uses a single disk array that is shared by
     multiple servers.  If the main database server fails, the standby server
     is able to mount and start the database as though it was recovering from
     a database crash.  This allows rapid failover with no data loss.
    </P
><P
>     Shared hardware functionality is common in network storage devices.
     Using a network file system is also possible, though care must be
     taken that the file system has full <ACRONYM
CLASS="ACRONYM"
>POSIX</ACRONYM
> behavior (see <A
HREF="creating-cluster.html#CREATING-CLUSTER-NFS"
>Section 17.2.1</A
>).  One significant limitation of this
     method is that if the shared disk array fails or becomes corrupt, the
     primary and standby servers are both nonfunctional.  Another issue is
     that the standby server should never access the shared storage while
     the primary server is running.
    </P
></DD
><DT
>File System (Block-Device) Replication</DT
><DD
><P
>     A modified version of shared hardware functionality is file system
     replication, where all changes to a file system are mirrored to a file
     system residing on another computer.  The only restriction is that
     the mirroring must be done in a way that ensures the standby server
     has a consistent copy of the file system &mdash; specifically, writes
     to the standby must be done in the same order as those on the master.
     <SPAN
CLASS="PRODUCTNAME"
>DRBD</SPAN
> is a popular file system replication solution
     for Linux.
    </P
></DD
><DT
>Warm Standby Using Point-In-Time Recovery (<ACRONYM
CLASS="ACRONYM"
>PITR</ACRONYM
>)</DT
><DD
><P
>     A warm standby server (see <A
HREF="warm-standby.html"
>Section 24.4</A
>) can
     be kept current by reading a stream of write-ahead log (<ACRONYM
CLASS="ACRONYM"
>WAL</ACRONYM
>)
     records.  If the main server fails, the warm standby contains
     almost all of the data of the main server, and can be quickly
     made the new master database server.  This is asynchronous and
     can only be done for the entire database server.
    </P
></DD
><DT
>Master-Slave Replication</DT
><DD
><P
>     A master-slave replication setup sends all data modification
     queries to the master server.  The master server asynchronously
     sends data changes to the slave server.  The slave can answer
     read-only queries while the master server is running.  The
     slave server is ideal for data warehouse queries.
    </P
><P
>     <SPAN
CLASS="PRODUCTNAME"
>Slony-I</SPAN
> is an example of this type of replication, with per-table
     granularity, and support for multiple slaves.  Because it
     updates the slave server asynchronously (in batches), there is
     possible data loss during fail over.
    </P
></DD
><DT
>Statement-Based Replication Middleware</DT
><DD
><P
>     With statement-based replication middleware, a program intercepts
     every SQL query and sends it to one or all servers.  Each server
     operates independently.  Read-write queries are sent to all servers,
     while read-only queries can be sent to just one server, allowing
     the read workload to be distributed.
    </P
><P
>     If queries are simply broadcast unmodified, functions like
     <CODE
CLASS="FUNCTION"
>random()</CODE
>, <CODE
CLASS="FUNCTION"
>CURRENT_TIMESTAMP</CODE
>, and
     sequences would have different values on different servers.
     This is because each server operates independently, and because
     SQL queries are broadcast (and not actual modified rows).  If
     this is unacceptable, either the middleware or the application
     must query such values from a single server and then use those
     values in write queries.  Also, care must be taken that all
     transactions either commit or abort on all servers, perhaps
     using two-phase commit (<A
HREF="sql-prepare-transaction.html"
><I
>PREPARE TRANSACTION</I
></A
> and <A
HREF="sql-commit-prepared.html"
><I
>COMMIT PREPARED</I
></A
>.
     <SPAN
CLASS="PRODUCTNAME"
>Pgpool-II</SPAN
> and <SPAN
CLASS="PRODUCTNAME"
>Sequoia</SPAN
> are examples of
     this type of replication.
    </P
></DD
><DT
>Asynchronous Multimaster Replication</DT
><DD
><P
>     For servers that are not regularly connected, like laptops or
     remote servers, keeping data consistent among servers is a
     challenge.  Using asynchronous multimaster replication, each
     server works independently, and periodically communicates with
     the other servers to identify conflicting transactions.  The
     conflicts can be resolved by users or conflict resolution rules.
     Bucardo is an example of this type of replication.
    </P
></DD
><DT
>Synchronous Multimaster Replication</DT
><DD
><P
>     In synchronous multimaster replication, each server can accept
     write requests, and modified data is transmitted from the
     original server to every other server before each transaction
     commits.  Heavy write activity can cause excessive locking,
     leading to poor performance.  In fact, write performance is
     often worse than that of a single server.  Read requests can
     be sent to any server.  Some implementations use shared disk
     to reduce the communication overhead.  Synchronous multimaster
     replication is best for mostly read workloads, though its big
     advantage is that any server can accept write requests &mdash;
     there is no need to partition workloads between master and
     slave servers, and because the data changes are sent from one
     server to another, there is no problem with non-deterministic
     functions like <CODE
CLASS="FUNCTION"
>random()</CODE
>.
    </P
><P
>     <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> does not offer this type of replication,
     though <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> two-phase commit (<A
HREF="sql-prepare-transaction.html"
><I
>PREPARE TRANSACTION</I
></A
> and <A
HREF="sql-commit-prepared.html"
><I
>COMMIT PREPARED</I
></A
>)
     can be used to implement this in application code or middleware.
    </P
></DD
><DT
>Commercial Solutions</DT
><DD
><P
>     Because <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> is open source and easily
     extended, a number of companies have taken <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>
     and created commercial closed-source solutions with unique
     failover, replication, and load balancing capabilities.
    </P
></DD
></DL
></DIV
><P
>  <A
HREF="high-availability.html#HIGH-AVAILABILITY-MATRIX"
>Table 25-1</A
> summarizes
  the capabilities of the various solutions listed above.
 </P
><DIV
CLASS="TABLE"
><A
NAME="HIGH-AVAILABILITY-MATRIX"
></A
><P
><B
>Table 25-1. High Availability, Load Balancing, and Replication Feature Matrix</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><COL><COL><COL><COL><COL><THEAD
><TR
><TH
>Feature</TH
><TH
>Shared Disk Failover</TH
><TH
>File System Replication</TH
><TH
>Warm Standby Using PITR</TH
><TH
>Master-Slave Replication</TH
><TH
>Statement-Based Replication Middleware</TH
><TH
>Asynchronous Multimaster Replication</TH
><TH
>Synchronous Multimaster Replication</TH
></TR
></THEAD
><TBODY
><TR
><TD
>Most Common Implementation</TD
><TD
ALIGN="CENTER"
>NAS</TD
><TD
ALIGN="CENTER"
>DRBD</TD
><TD
ALIGN="CENTER"
>PITR</TD
><TD
ALIGN="CENTER"
>Slony</TD
><TD
ALIGN="CENTER"
>pgpool-II</TD
><TD
ALIGN="CENTER"
>Bucardo</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
></TR
><TR
><TD
>Communication Method</TD
><TD
ALIGN="CENTER"
>shared disk</TD
><TD
ALIGN="CENTER"
>disk blocks</TD
><TD
ALIGN="CENTER"
>WAL</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"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
></TR
><TR
><TD
>Allows multiple master servers</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
></TR
><TR
><TD
>No master server overhead</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
></TR
><TR
><TD
>No waiting for multiple servers</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
></TR
><TR
><TD
>Master failure will never lose data</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
></TR
><TR
><TD
>Slaves accept read-only queries</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
></TR
><TR
><TD
>Per-table granularity</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
></TR
><TR
><TD
>No conflict resolution necessary</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&nbsp;</TD
><TD
ALIGN="CENTER"
>&bull;</TD
></TR
></TBODY
></TABLE
></DIV
><P
>  There are a few solutions that do not fit into the above categories:
 </P
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
>Data Partitioning</DT
><DD
><P
>     Data partitioning splits tables into data sets.  Each set can
     be modified by only one server.  For example, data can be
     partitioned by offices, e.g., London and Paris, with a server
     in each office.  If queries combining London and Paris data
     are necessary, an application can query both servers, or
     master/slave replication can be used to keep a read-only copy
     of the other office's data on each server.
    </P
></DD
><DT
>Multiple-Server Parallel Query Execution</DT
><DD
><P
>     Many of the above solutions allow multiple servers to handle multiple
     queries, but none allow a single query to use multiple servers to
     complete faster.  This solution allows multiple servers to work
     concurrently on a single query.  It is usually accomplished by
     splitting the data among servers and having each server execute its
     part of the query and return results to a central server where they
     are combined and returned to the user.  <SPAN
CLASS="PRODUCTNAME"
>Pgpool-II</SPAN
>
     has this capability.  Also, this can be implemented using the
     <SPAN
CLASS="PRODUCTNAME"
>PL/Proxy</SPAN
> toolset.
    </P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="migration.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="monitoring.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Migration Between Releases</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="admin.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Monitoring Database Activity</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>