Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > a866202fe868538f89a755dbcabc378b > files > 204

postgresql8.2-docs-8.2.14-1mdv2010.0.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 and Load Balancing</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.2.14 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="2009-09-04T05:25:47"></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.2.14 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 24. High Availability and Load Balancing</H1
><A
NAME="AEN25444"
></A
><A
NAME="AEN25446"
></A
><A
NAME="AEN25448"
></A
><A
NAME="AEN25450"
></A
><A
NAME="AEN25452"
></A
><A
NAME="AEN25454"
></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 failover and load balancing 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 failover or load balancing
  choice.  There is usually a tradeoff 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.
 </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 POSIX behavior.
    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
><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.
    DRBD is a popular file system replication solution for Linux.
   </P
></DD
><DT
>Warm Standby Using Point-In-Time Recovery</DT
><DD
><P
>    A warm standby server (see <A
HREF="warm-standby.html"
>Section 23.4</A
>) can
    be kept current by reading a stream of write-ahead log (WAL)
    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
>    Slony-I 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
>.
    Pgpool and Sequoia are an example of this type of replication.
   </P
></DD
><DT
>Synchronous Multi-Master Replication</DT
><DD
><P
>    In synchronous multi-master 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 multi-master
    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
>Asynchronous Multi-Master 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 multi-master 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.
   </P
></DD
><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
>Multi-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.  This 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.  Pgpool-II has this capability.
   </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
></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
>