Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > 977b9e43ddbf791a68788d984b14383d > files > 21

postgresql9.3-docs-9.3.9-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>pg_dump</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 9.3.9 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="PostgreSQL Client Applications"
HREF="reference-client.html"><LINK
REL="PREVIOUS"
TITLE="pg_config"
HREF="app-pgconfig.html"><LINK
REL="NEXT"
TITLE="pg_dumpall"
HREF="app-pg-dumpall.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="2015-06-13T20:07:22"></HEAD
><BODY
CLASS="REFENTRY"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.3.9 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="pg_config"
HREF="app-pgconfig.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="reference-client.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="pg_dumpall"
HREF="app-pg-dumpall.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="APP-PGDUMP"
></A
>pg_dump</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN84800"
></A
><H2
>Name</H2
>pg_dump&nbsp;--&nbsp;   extract a <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> database into a script file or other archive file
  </DIV
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN84806"
></A
><H2
>Synopsis</H2
><P
><TT
CLASS="COMMAND"
>pg_dump</TT
> [<TT
CLASS="REPLACEABLE"
><I
>connection-option</I
></TT
>...] [<TT
CLASS="REPLACEABLE"
><I
>option</I
></TT
>...] [<TT
CLASS="REPLACEABLE"
><I
>dbname</I
></TT
>]</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="PG-DUMP-DESCRIPTION"
></A
><H2
>   Description
  </H2
><P
>   <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> is a utility for backing up a
   <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> database. It makes consistent
   backups even if the database is being used concurrently.
   <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> does not block other users
   accessing the database (readers or writers).
  </P
><P
>   Dumps can be output in script or archive file formats. Script
   dumps are plain-text files containing the SQL commands required
   to reconstruct the database to the state it was in at the time it was
   saved. To restore from such a script, feed it to <A
HREF="app-psql.html"
><SPAN
CLASS="APPLICATION"
>psql</SPAN
></A
>. Script files
   can be used to reconstruct the database even on other machines and
   other architectures; with some modifications, even on other SQL
   database products.
  </P
><P
>   The alternative archive file formats must be used with
   <A
HREF="app-pgrestore.html"
>pg_restore</A
> to rebuild the database.  They
   allow <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> to be selective about
   what is restored, or even to reorder the items prior to being
   restored.
   The archive file formats are designed to be portable across
   architectures.
  </P
><P
>   When used with one of the archive file formats and combined with
   <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
>,
   <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> provides a flexible archival and
   transfer mechanism. <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> can be used to
   backup an entire database, then <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
>
   can be used to examine the archive and/or select which parts of the
   database are to be restored. The most flexible output file formats are
   the <SPAN
CLASS="QUOTE"
>"custom"</SPAN
> format (<TT
CLASS="OPTION"
>-Fc</TT
>) and the
   <SPAN
CLASS="QUOTE"
>"directory"</SPAN
> format(<TT
CLASS="OPTION"
>-Fd</TT
>). They allow
   for selection and reordering of all archived items, support parallel
   restoration, and are compressed by default. The <SPAN
CLASS="QUOTE"
>"directory"</SPAN
>
   format is the only format that supports parallel dumps.
  </P
><P
>   While running <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
>, one should examine the
   output for any warnings (printed on standard error), especially in
   light of the limitations listed below.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="PG-DUMP-OPTIONS"
></A
><H2
>Options</H2
><P
>    The following command-line options control the content and
    format of the output.

    <P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="REPLACEABLE"
><I
>dbname</I
></TT
></DT
><DD
><P
>        Specifies the name of the database to be dumped.  If this is
        not specified, the environment variable
        <TT
CLASS="ENVAR"
>PGDATABASE</TT
> is used.  If that is not set, the
        user name specified for the connection is used.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-a</TT
><BR><TT
CLASS="OPTION"
>--data-only</TT
></DT
><DD
><P
>        Dump only the data, not the schema (data definitions).
        Table data, large objects, and sequence values are dumped.
       </P
><P
>        This option is similar to, but for historical reasons not identical
        to, specifying <TT
CLASS="OPTION"
>--section=data</TT
>.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-b</TT
><BR><TT
CLASS="OPTION"
>--blobs</TT
></DT
><DD
><P
>        Include large objects in the dump.  This is the default behavior
        except when <TT
CLASS="OPTION"
>--schema</TT
>, <TT
CLASS="OPTION"
>--table</TT
>, or
        <TT
CLASS="OPTION"
>--schema-only</TT
> is specified, so the <TT
CLASS="OPTION"
>-b</TT
>
        switch is only useful to add large objects to selective dumps.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-c</TT
><BR><TT
CLASS="OPTION"
>--clean</TT
></DT
><DD
><P
>        Output commands to clean (drop)
        database objects prior to outputting the commands for creating them.
        (Restore might generate some harmless error messages, if any objects
        were not present in the destination database.)
       </P
><P
>        This option is only meaningful for the plain-text format.  For
        the archive formats, you can specify the option when you
        call <TT
CLASS="COMMAND"
>pg_restore</TT
>.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-C</TT
><BR><TT
CLASS="OPTION"
>--create</TT
></DT
><DD
><P
>        Begin the output with a command to create the
        database itself and reconnect to the created database.  (With a
        script of this form, it doesn't matter which database in the
        destination installation you connect to before running the script.)
        If <TT
CLASS="OPTION"
>--clean</TT
> is also specified, the script drops and
        recreates the target database before reconnecting to it.
       </P
><P
>        This option is only meaningful for the plain-text format.  For
        the archive formats, you can specify the option when you
        call <TT
CLASS="COMMAND"
>pg_restore</TT
>.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-E <TT
CLASS="REPLACEABLE"
><I
>encoding</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--encoding=<TT
CLASS="REPLACEABLE"
><I
>encoding</I
></TT
></TT
></DT
><DD
><P
>        Create the dump in the specified character set encoding. By default,
        the dump is created in the database encoding.  (Another way to get the
        same result is to set the <TT
CLASS="ENVAR"
>PGCLIENTENCODING</TT
> environment
        variable to the desired dump encoding.)
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-f <TT
CLASS="REPLACEABLE"
><I
>file</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--file=<TT
CLASS="REPLACEABLE"
><I
>file</I
></TT
></TT
></DT
><DD
><P
>        Send output to the specified file. This parameter can be omitted for
        file based output formats, in which case the standard output is used.
        It must be given for the directory output format however, where it
        specifies the target directory instead of a file. In this case the
        directory is created by <TT
CLASS="COMMAND"
>pg_dump</TT
> and must not exist
        before.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-F <TT
CLASS="REPLACEABLE"
><I
>format</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--format=<TT
CLASS="REPLACEABLE"
><I
>format</I
></TT
></TT
></DT
><DD
><P
>        Selects the format of the output.
        <TT
CLASS="REPLACEABLE"
><I
>format</I
></TT
> can be one of the following:

       <P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="LITERAL"
>p</TT
><BR><TT
CLASS="LITERAL"
>plain</TT
></DT
><DD
><P
>           Output a plain-text <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> script file (the default).
          </P
></DD
><DT
><TT
CLASS="LITERAL"
>c</TT
><BR><TT
CLASS="LITERAL"
>custom</TT
></DT
><DD
><P
>           Output a custom-format archive suitable for input into
           <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
>.
           Together with the directory output format, this is the most flexible
           output format in that it allows manual selection and reordering of
           archived items during restore. This format is also compressed by
           default.
          </P
></DD
><DT
><TT
CLASS="LITERAL"
>d</TT
><BR><TT
CLASS="LITERAL"
>directory</TT
></DT
><DD
><P
>           Output a directory-format archive suitable for input into
           <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
>. This will create a directory
           with one file for each table and blob being dumped, plus a
           so-called Table of Contents file describing the dumped objects in a
           machine-readable format that <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
>
           can read. A directory format archive can be manipulated with
           standard Unix tools; for example, files in an uncompressed archive
           can be compressed with the <SPAN
CLASS="APPLICATION"
>gzip</SPAN
> tool.
           This format is compressed by default and also supports parallel
           dumps.
          </P
></DD
><DT
><TT
CLASS="LITERAL"
>t</TT
><BR><TT
CLASS="LITERAL"
>tar</TT
></DT
><DD
><P
>           Output a <TT
CLASS="COMMAND"
>tar</TT
>-format archive suitable for input
           into <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
>. The tar-format is
           compatible with the directory-format; extracting a tar-format
           archive produces a valid directory-format archive.
           However, the tar-format does not support compression and has a
           limit of 8 GB on the size of individual tables. Also, the relative
           order of table data items cannot be changed during restore.
          </P
></DD
></DL
></DIV
><P></P
></DD
><DT
><TT
CLASS="OPTION"
>-i</TT
><BR><TT
CLASS="OPTION"
>--ignore-version</TT
></DT
><DD
><P
>        A deprecated option that is now ignored.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-j <TT
CLASS="REPLACEABLE"
><I
>njobs</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--jobs=<TT
CLASS="REPLACEABLE"
><I
>njobs</I
></TT
></TT
></DT
><DD
><P
>        Run the dump in parallel by dumping <TT
CLASS="REPLACEABLE"
><I
>njobs</I
></TT
>
        tables simultaneously. This option reduces the time of the dump but it also
        increases the load on the database server. You can only use this option with the
        directory output format because this is the only output format where multiple processes
        can write their data at the same time.
       </P
><P
><SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> will open <TT
CLASS="REPLACEABLE"
><I
>njobs</I
></TT
>
        + 1 connections to the database, so make sure your <A
HREF="runtime-config-connection.html#GUC-MAX-CONNECTIONS"
>max_connections</A
>
        setting is high enough to accommodate all connections.
       </P
><P
>        Requesting exclusive locks on database objects while running a parallel dump could
        cause the dump to fail. The reason is that the <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> master process
        requests shared locks on the objects that the worker processes are going to dump later
        in order to
        make sure that nobody deletes them and makes them go away while the dump is running.
        If another client then requests an exclusive lock on a table, that lock will not be
        granted but will be queued waiting for the shared lock of the master process to be
        released.. Consequently any other access to the table will not be granted either and
        will queue after the exclusive lock request. This includes the worker process trying
        to dump the table. Without any precautions this would be a classic deadlock situation.
        To detect this conflict, the <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> worker process requests another
        shared lock using the <TT
CLASS="LITERAL"
>NOWAIT</TT
> option. If the worker process is not granted
        this shared lock, somebody else must have requested an exclusive lock in the meantime
        and there is no way to continue with the dump, so <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> has no choice
        but to abort the dump.
       </P
><P
>        For a consistent backup, the database server needs to support synchronized snapshots,
        a feature that was introduced in <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> 9.2. With this
        feature, database clients can ensure they see the same data set even though they use
        different connections. <TT
CLASS="COMMAND"
>pg_dump -j</TT
> uses multiple database
        connections; it connects to the database once with the master process and
        once again for each worker job. Without the synchronized snapshot feature, the
        different worker jobs wouldn't be guaranteed to see the same data in each connection,
        which could lead to an inconsistent backup.
       </P
><P
>        If you want to run a parallel dump of a pre-9.2 server, you need to make sure that the
        database content doesn't change from between the time the master connects to the
        database until the last worker job has connected to the database. The easiest way to
        do this is to halt any data modifying processes (DDL and DML) accessing the database
        before starting the backup. You also need to specify the
        <TT
CLASS="OPTION"
>--no-synchronized-snapshots</TT
> parameter when running
        <TT
CLASS="COMMAND"
>pg_dump -j</TT
> against a pre-9.2 <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>
        server.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-n <TT
CLASS="REPLACEABLE"
><I
>schema</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--schema=<TT
CLASS="REPLACEABLE"
><I
>schema</I
></TT
></TT
></DT
><DD
><P
>        Dump only schemas matching <TT
CLASS="REPLACEABLE"
><I
>schema</I
></TT
>; this selects both the
        schema itself, and all its contained objects.  When this option is
        not specified, all non-system schemas in the target database will be
        dumped.  Multiple schemas can be
        selected by writing multiple <TT
CLASS="OPTION"
>-n</TT
> switches.  Also, the
        <TT
CLASS="REPLACEABLE"
><I
>schema</I
></TT
> parameter is
        interpreted as a pattern according to the same rules used by
        <SPAN
CLASS="APPLICATION"
>psql</SPAN
>'s <TT
CLASS="LITERAL"
>\d</TT
> commands (see <A
HREF="app-psql.html#APP-PSQL-PATTERNS"
><I
>Patterns</I
></A
>),
        so multiple schemas can also be selected by writing wildcard characters
        in the pattern.  When using wildcards, be careful to quote the pattern
        if needed to prevent the shell from expanding the wildcards;  see
        <A
HREF="app-pgdump.html#PG-DUMP-EXAMPLES"
><I
>Examples</I
></A
>.
       </P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>         When <TT
CLASS="OPTION"
>-n</TT
> is specified, <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
>
         makes no attempt to dump any other database objects that the selected
         schema(s) might depend upon. Therefore, there is no guarantee
         that the results of a specific-schema dump can be successfully
         restored by themselves into a clean database.
        </P
></BLOCKQUOTE
></DIV
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>         Non-schema objects such as blobs are not dumped when <TT
CLASS="OPTION"
>-n</TT
> is
         specified.  You can add blobs back to the dump with the
         <TT
CLASS="OPTION"
>--blobs</TT
> switch.
        </P
></BLOCKQUOTE
></DIV
></DD
><DT
><TT
CLASS="OPTION"
>-N <TT
CLASS="REPLACEABLE"
><I
>schema</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--exclude-schema=<TT
CLASS="REPLACEABLE"
><I
>schema</I
></TT
></TT
></DT
><DD
><P
>        Do not dump any schemas matching the <TT
CLASS="REPLACEABLE"
><I
>schema</I
></TT
> pattern.  The pattern is
        interpreted according to the same rules as for <TT
CLASS="OPTION"
>-n</TT
>.
        <TT
CLASS="OPTION"
>-N</TT
> can be given more than once to exclude schemas
        matching any of several patterns.
       </P
><P
>        When both <TT
CLASS="OPTION"
>-n</TT
> and <TT
CLASS="OPTION"
>-N</TT
> are given, the behavior
        is to dump just the schemas that match at least one <TT
CLASS="OPTION"
>-n</TT
>
        switch but no <TT
CLASS="OPTION"
>-N</TT
> switches.  If <TT
CLASS="OPTION"
>-N</TT
> appears
        without <TT
CLASS="OPTION"
>-n</TT
>, then schemas matching <TT
CLASS="OPTION"
>-N</TT
> are
        excluded from what is otherwise a normal dump.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-o</TT
><BR><TT
CLASS="OPTION"
>--oids</TT
></DT
><DD
><P
>        Dump object identifiers (<ACRONYM
CLASS="ACRONYM"
>OID</ACRONYM
>s) as part of the
        data for every table.  Use this option if your application references
        the <ACRONYM
CLASS="ACRONYM"
>OID</ACRONYM
>
        columns in some way (e.g., in a foreign key constraint).
        Otherwise, this option should not be used.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-O</TT
><BR><TT
CLASS="OPTION"
>--no-owner</TT
></DT
><DD
><P
>        Do not output commands to set
        ownership of objects to match the original database.
        By default, <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> issues
        <TT
CLASS="COMMAND"
>ALTER OWNER</TT
> or
        <TT
CLASS="COMMAND"
>SET SESSION AUTHORIZATION</TT
>
        statements to set ownership of created database objects.
        These statements
        will fail when the script is run unless it is started by a superuser
        (or the same user that owns all of the objects in the script).
        To make a script that can be restored by any user, but will give
        that user ownership of all the objects, specify <TT
CLASS="OPTION"
>-O</TT
>.
       </P
><P
>        This option is only meaningful for the plain-text format.  For
        the archive formats, you can specify the option when you
        call <TT
CLASS="COMMAND"
>pg_restore</TT
>.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-R</TT
><BR><TT
CLASS="OPTION"
>--no-reconnect</TT
></DT
><DD
><P
>        This option is obsolete but still accepted for backwards
        compatibility.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-s</TT
><BR><TT
CLASS="OPTION"
>--schema-only</TT
></DT
><DD
><P
>        Dump only the object definitions (schema), not data.
       </P
><P
>        This option is the inverse of <TT
CLASS="OPTION"
>--data-only</TT
>.
        It is similar to, but for historical reasons not identical to,
        specifying
        <TT
CLASS="OPTION"
>--section=pre-data --section=post-data</TT
>.
       </P
><P
>        (Do not confuse this with the <TT
CLASS="OPTION"
>--schema</TT
> option, which
        uses the word <SPAN
CLASS="QUOTE"
>"schema"</SPAN
> in a different meaning.)
       </P
><P
>        To exclude table data for only a subset of tables in the database,
        see <TT
CLASS="OPTION"
>--exclude-table-data</TT
>.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-S <TT
CLASS="REPLACEABLE"
><I
>username</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--superuser=<TT
CLASS="REPLACEABLE"
><I
>username</I
></TT
></TT
></DT
><DD
><P
>        Specify the superuser user name to use when disabling triggers.
        This is relevant only if <TT
CLASS="OPTION"
>--disable-triggers</TT
> is used.
        (Usually, it's better to leave this out, and instead start the
        resulting script as superuser.)
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-t <TT
CLASS="REPLACEABLE"
><I
>table</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--table=<TT
CLASS="REPLACEABLE"
><I
>table</I
></TT
></TT
></DT
><DD
><P
>        Dump only tables (or views or sequences or foreign tables) matching
        <TT
CLASS="REPLACEABLE"
><I
>table</I
></TT
>.  Multiple tables
        can be selected by writing multiple <TT
CLASS="OPTION"
>-t</TT
> switches.  Also, the
        <TT
CLASS="REPLACEABLE"
><I
>table</I
></TT
> parameter is
        interpreted as a pattern according to the same rules used by
        <SPAN
CLASS="APPLICATION"
>psql</SPAN
>'s <TT
CLASS="LITERAL"
>\d</TT
> commands (see <A
HREF="app-psql.html#APP-PSQL-PATTERNS"
><I
>Patterns</I
></A
>),
        so multiple tables can also be selected by writing wildcard characters
        in the pattern.  When using wildcards, be careful to quote the pattern
        if needed to prevent the shell from expanding the wildcards;  see
        <A
HREF="app-pgdump.html#PG-DUMP-EXAMPLES"
><I
>Examples</I
></A
>.
       </P
><P
>        The <TT
CLASS="OPTION"
>-n</TT
> and <TT
CLASS="OPTION"
>-N</TT
> switches have no effect when
        <TT
CLASS="OPTION"
>-t</TT
> is used, because tables selected by <TT
CLASS="OPTION"
>-t</TT
> will
        be dumped regardless of those switches, and non-table objects will not
        be dumped.
       </P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>         When <TT
CLASS="OPTION"
>-t</TT
> is specified, <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
>
         makes no attempt to dump any other database objects that the selected
         table(s) might depend upon. Therefore, there is no guarantee
         that the results of a specific-table dump can be successfully
         restored by themselves into a clean database.
        </P
></BLOCKQUOTE
></DIV
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>         The behavior of the <TT
CLASS="OPTION"
>-t</TT
> switch is not entirely upward
         compatible with pre-8.2 <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>
         versions.  Formerly, writing <TT
CLASS="LITERAL"
>-t tab</TT
> would dump all
         tables named <TT
CLASS="LITERAL"
>tab</TT
>, but now it just dumps whichever one
         is visible in your default search path.  To get the old behavior
         you can write <TT
CLASS="LITERAL"
>-t '*.tab'</TT
>.  Also, you must write something
         like <TT
CLASS="LITERAL"
>-t sch.tab</TT
> to select a table in a particular schema,
         rather than the old locution of <TT
CLASS="LITERAL"
>-n sch -t tab</TT
>.
        </P
></BLOCKQUOTE
></DIV
></DD
><DT
><TT
CLASS="OPTION"
>-T <TT
CLASS="REPLACEABLE"
><I
>table</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--exclude-table=<TT
CLASS="REPLACEABLE"
><I
>table</I
></TT
></TT
></DT
><DD
><P
>        Do not dump any tables matching the <TT
CLASS="REPLACEABLE"
><I
>table</I
></TT
> pattern.  The pattern is
        interpreted according to the same rules as for <TT
CLASS="OPTION"
>-t</TT
>.
        <TT
CLASS="OPTION"
>-T</TT
> can be given more than once to exclude tables
        matching any of several patterns.
       </P
><P
>        When both <TT
CLASS="OPTION"
>-t</TT
> and <TT
CLASS="OPTION"
>-T</TT
> are given, the behavior
        is to dump just the tables that match at least one <TT
CLASS="OPTION"
>-t</TT
>
        switch but no <TT
CLASS="OPTION"
>-T</TT
> switches.  If <TT
CLASS="OPTION"
>-T</TT
> appears
        without <TT
CLASS="OPTION"
>-t</TT
>, then tables matching <TT
CLASS="OPTION"
>-T</TT
> are
        excluded from what is otherwise a normal dump.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-v</TT
><BR><TT
CLASS="OPTION"
>--verbose</TT
></DT
><DD
><P
>        Specifies verbose mode.  This will cause
        <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> to output detailed object
        comments and start/stop times to the dump file, and progress
        messages to standard error.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-V</TT
><BR><TT
CLASS="OPTION"
>--version</TT
></DT
><DD
><P
>       Print the <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> version and exit.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-x</TT
><BR><TT
CLASS="OPTION"
>--no-privileges</TT
><BR><TT
CLASS="OPTION"
>--no-acl</TT
></DT
><DD
><P
>        Prevent dumping of access privileges (grant/revoke commands).
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-Z <TT
CLASS="REPLACEABLE"
><I
>0..9</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--compress=<TT
CLASS="REPLACEABLE"
><I
>0..9</I
></TT
></TT
></DT
><DD
><P
>        Specify the compression level to use.  Zero means no compression.
        For the custom archive format, this specifies compression of
        individual table-data segments, and the default is to compress
        at a moderate level.
        For plain text output, setting a nonzero compression level causes
        the entire output file to be compressed, as though it had been
        fed through <SPAN
CLASS="APPLICATION"
>gzip</SPAN
>; but the default is not to compress.
        The tar archive format currently does not support compression at all.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--binary-upgrade</TT
></DT
><DD
><P
>        This option is for use by in-place upgrade utilities.  Its use
        for other purposes is not recommended or supported.  The
        behavior of the option may change in future releases without
        notice.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--column-inserts</TT
><BR><TT
CLASS="OPTION"
>--attribute-inserts</TT
></DT
><DD
><P
>        Dump data as <TT
CLASS="COMMAND"
>INSERT</TT
> commands with explicit
        column names (<TT
CLASS="LITERAL"
>INSERT INTO
        <TT
CLASS="REPLACEABLE"
><I
>table</I
></TT
>
        (<TT
CLASS="REPLACEABLE"
><I
>column</I
></TT
>, ...) VALUES
        ...</TT
>).  This will make restoration very slow; it is mainly
        useful for making dumps that can be loaded into
        non-<SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> databases.
        However, since this option generates a separate command for each row,
        an error in reloading a row causes only that row to be lost rather
        than the entire table contents.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--disable-dollar-quoting</TT
></DT
><DD
><P
>        This option disables the use of dollar quoting for function bodies,
        and forces them to be quoted using SQL standard string syntax.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--disable-triggers</TT
></DT
><DD
><P
>        This option is relevant only when creating a data-only dump.
        It instructs <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> to include commands
        to temporarily disable triggers on the target tables while
        the data is reloaded.  Use this if you have referential
        integrity checks or other triggers on the tables that you
        do not want to invoke during data reload.
       </P
><P
>        Presently, the commands emitted for <TT
CLASS="OPTION"
>--disable-triggers</TT
>
        must be done as superuser.  So, you should also specify
        a superuser name with <TT
CLASS="OPTION"
>-S</TT
>, or preferably be careful to
        start the resulting script as a superuser.
       </P
><P
>        This option is only meaningful for the plain-text format.  For
        the archive formats, you can specify the option when you
        call <TT
CLASS="COMMAND"
>pg_restore</TT
>.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--exclude-table-data=<TT
CLASS="REPLACEABLE"
><I
>table</I
></TT
></TT
></DT
><DD
><P
>        Do not dump data for any tables matching the <TT
CLASS="REPLACEABLE"
><I
>table</I
></TT
> pattern. The pattern is
        interpreted according to the same rules as for <TT
CLASS="OPTION"
>-t</TT
>.
        <TT
CLASS="OPTION"
>--exclude-table-data</TT
> can be given more than once to
        exclude tables matching any of several patterns. This option is
        useful when you need the definition of a particular table even
        though you do not need the data in it.
       </P
><P
>        To exclude data for all tables in the database, see <TT
CLASS="OPTION"
>--schema-only</TT
>.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--inserts</TT
></DT
><DD
><P
>        Dump data as <TT
CLASS="COMMAND"
>INSERT</TT
> commands (rather
        than <TT
CLASS="COMMAND"
>COPY</TT
>).  This will make restoration very slow;
        it is mainly useful for making dumps that can be loaded into
        non-<SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> databases.
        However, since this option generates a separate command for each row,
        an error in reloading a row causes only that row to be lost rather
        than the entire table contents.
        Note that
        the restore might fail altogether if you have rearranged column order.
        The <TT
CLASS="OPTION"
>--column-inserts</TT
> option is safe against column
        order changes, though even slower.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--lock-wait-timeout=<TT
CLASS="REPLACEABLE"
><I
>timeout</I
></TT
></TT
></DT
><DD
><P
>        Do not wait forever to acquire shared table locks at the beginning of
        the dump. Instead fail if unable to lock a table within the specified
        <TT
CLASS="REPLACEABLE"
><I
>timeout</I
></TT
>. The timeout may be
        specified in any of the formats accepted by <TT
CLASS="COMMAND"
>SET
        statement_timeout</TT
>.  (Allowed values vary depending on the server
        version you are dumping from, but an integer number of milliseconds
        is accepted by all versions since 7.3.  This option is ignored when
        dumping from a pre-7.3 server.)
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--no-security-labels</TT
></DT
><DD
><P
>        Do not dump security labels.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--no-synchronized-snapshots</TT
></DT
><DD
><P
>        This option allows running <TT
CLASS="COMMAND"
>pg_dump -j</TT
> against a pre-9.2
        server, see the documentation of the <TT
CLASS="OPTION"
>-j</TT
> parameter
        for more details.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--no-tablespaces</TT
></DT
><DD
><P
>        Do not output commands to select tablespaces.
        With this option, all objects will be created in whichever
        tablespace is the default during restore.
       </P
><P
>        This option is only meaningful for the plain-text format.  For
        the archive formats, you can specify the option when you
        call <TT
CLASS="COMMAND"
>pg_restore</TT
>.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--no-unlogged-table-data</TT
></DT
><DD
><P
>        Do not dump the contents of unlogged tables.  This option has no
        effect on whether or not the table definitions (schema) are dumped;
        it only suppresses dumping the table data. Data in unlogged tables
        is always excluded when dumping from a standby server.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--quote-all-identifiers</TT
></DT
><DD
><P
>        Force quoting of all identifiers.  This may be useful when dumping a
        database for migration to a future version that may have introduced
        additional keywords.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--section=<TT
CLASS="REPLACEABLE"
><I
>sectionname</I
></TT
></TT
></DT
><DD
><P
>          Only dump the named section. The section name can be
          <TT
CLASS="OPTION"
>pre-data</TT
>, <TT
CLASS="OPTION"
>data</TT
>, or <TT
CLASS="OPTION"
>post-data</TT
>.
          This option can be specified more than once to select multiple
          sections. The default is to dump all sections.
         </P
><P
>          The data section contains actual table data, large-object
          contents, and sequence values.
          Post-data items include definitions of indexes, triggers, rules,
          and constraints other than validated check constraints.
          Pre-data items include all other data definition items.
         </P
></DD
><DT
><TT
CLASS="OPTION"
>--serializable-deferrable</TT
></DT
><DD
><P
>        Use a <TT
CLASS="LITERAL"
>serializable</TT
> transaction for the dump, to
        ensure that the snapshot used is consistent with later database
        states; but do this by waiting for a point in the transaction stream
        at which no anomalies can be present, so that there isn't a risk of
        the dump failing or causing other transactions to roll back with a
        <TT
CLASS="LITERAL"
>serialization_failure</TT
>.  See <A
HREF="mvcc.html"
>Chapter 13</A
>
        for more information about transaction isolation and concurrency
        control.
       </P
><P
>        This option is not beneficial for a dump which is intended only for
        disaster recovery.  It could be useful for a dump used to load a
        copy of the database for reporting or other read-only load sharing
        while the original database continues to be updated.  Without it the
        dump may reflect a state which is not consistent with any serial
        execution of the transactions eventually committed.  For example, if
        batch processing techniques are used, a batch may show as closed in
        the dump without all of the items which are in the batch appearing.
       </P
><P
>        This option will make no difference if there are no read-write
        transactions active when pg_dump is started.  If read-write
        transactions are active, the start of the dump may be delayed for an
        indeterminate length of time.  Once running, performance with or
        without the switch is the same.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--use-set-session-authorization</TT
></DT
><DD
><P
>        Output SQL-standard <TT
CLASS="COMMAND"
>SET SESSION AUTHORIZATION</TT
> commands
        instead of <TT
CLASS="COMMAND"
>ALTER OWNER</TT
> commands to determine object
        ownership.  This makes the dump more standards-compatible, but
        depending on the history of the objects in the dump, might not restore
        properly.  Also, a dump using <TT
CLASS="COMMAND"
>SET SESSION AUTHORIZATION</TT
>
        will certainly require superuser privileges to restore correctly,
        whereas <TT
CLASS="COMMAND"
>ALTER OWNER</TT
> requires lesser privileges.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-?</TT
><BR><TT
CLASS="OPTION"
>--help</TT
></DT
><DD
><P
>       Show help about <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> command line
       arguments, and exit.
       </P
></DD
></DL
></DIV
><P>
   </P
><P
>    The following command-line options control the database connection parameters.

    <P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="OPTION"
>-d <TT
CLASS="REPLACEABLE"
><I
>dbname</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--dbname=<TT
CLASS="REPLACEABLE"
><I
>dbname</I
></TT
></TT
></DT
><DD
><P
>       Specifies the name of the database to connect to. This is
       equivalent to specifying <TT
CLASS="REPLACEABLE"
><I
>dbname</I
></TT
> as the first non-option
       argument on the command line.
      </P
><P
>       If this parameter contains an <TT
CLASS="SYMBOL"
>=</TT
> sign or starts
       with a valid <ACRONYM
CLASS="ACRONYM"
>URI</ACRONYM
> prefix
       (<TT
CLASS="LITERAL"
>postgresql://</TT
>
       or <TT
CLASS="LITERAL"
>postgres://</TT
>), it is treated as a
       <TT
CLASS="PARAMETER"
>conninfo</TT
> string. See <A
HREF="libpq-connect.html"
>Section 31.1</A
> for more information.
      </P
></DD
><DT
><TT
CLASS="OPTION"
>-h <TT
CLASS="REPLACEABLE"
><I
>host</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--host=<TT
CLASS="REPLACEABLE"
><I
>host</I
></TT
></TT
></DT
><DD
><P
>        Specifies the host name of the machine on which the server is
        running.  If the value begins with a slash, it is used as the
        directory for the Unix domain socket. The default is taken
        from the <TT
CLASS="ENVAR"
>PGHOST</TT
> environment variable, if set,
        else a Unix domain socket connection is attempted.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-p <TT
CLASS="REPLACEABLE"
><I
>port</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--port=<TT
CLASS="REPLACEABLE"
><I
>port</I
></TT
></TT
></DT
><DD
><P
>        Specifies the TCP port or local Unix domain socket file
        extension on which the server is listening for connections.
        Defaults to the <TT
CLASS="ENVAR"
>PGPORT</TT
> environment variable, if
        set, or a compiled-in default.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-U <TT
CLASS="REPLACEABLE"
><I
>username</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--username=<TT
CLASS="REPLACEABLE"
><I
>username</I
></TT
></TT
></DT
><DD
><P
>        User name to connect as.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-w</TT
><BR><TT
CLASS="OPTION"
>--no-password</TT
></DT
><DD
><P
>        Never issue a password prompt.  If the server requires
        password authentication and a password is not available by
        other means such as a <TT
CLASS="FILENAME"
>.pgpass</TT
> file, the
        connection attempt will fail.  This option can be useful in
        batch jobs and scripts where no user is present to enter a
        password.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-W</TT
><BR><TT
CLASS="OPTION"
>--password</TT
></DT
><DD
><P
>        Force <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> to prompt for a
        password before connecting to a database.
       </P
><P
>        This option is never essential, since
        <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> will automatically prompt
        for a password if the server demands password authentication.
        However, <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> will waste a
        connection attempt finding out that the server wants a password.
        In some cases it is worth typing <TT
CLASS="OPTION"
>-W</TT
> to avoid the extra
        connection attempt.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--role=<TT
CLASS="REPLACEABLE"
><I
>rolename</I
></TT
></TT
></DT
><DD
><P
>        Specifies a role name to be used to create the dump.
        This option causes <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> to issue a
        <TT
CLASS="COMMAND"
>SET ROLE</TT
> <TT
CLASS="REPLACEABLE"
><I
>rolename</I
></TT
>
        command after connecting to the database. It is useful when the
        authenticated user (specified by <TT
CLASS="OPTION"
>-U</TT
>) lacks privileges
        needed by <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
>, but can switch to a role with
        the required rights.  Some installations have a policy against
        logging in directly as a superuser, and use of this option allows
        dumps to be made without violating the policy.
       </P
></DD
></DL
></DIV
><P>
   </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN85379"
></A
><H2
>Environment</H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="ENVAR"
>PGDATABASE</TT
><BR><TT
CLASS="ENVAR"
>PGHOST</TT
><BR><TT
CLASS="ENVAR"
>PGOPTIONS</TT
><BR><TT
CLASS="ENVAR"
>PGPORT</TT
><BR><TT
CLASS="ENVAR"
>PGUSER</TT
></DT
><DD
><P
>      Default connection parameters.
     </P
></DD
></DL
></DIV
><P
>   This utility, like most other <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> utilities,
   also uses the environment variables supported by <SPAN
CLASS="APPLICATION"
>libpq</SPAN
>
   (see <A
HREF="libpq-envars.html"
>Section 31.14</A
>).
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="APP-PGDUMP-DIAGNOSTICS"
></A
><H2
>Diagnostics</H2
><P
>   <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> internally executes
   <TT
CLASS="COMMAND"
>SELECT</TT
> statements. If you have problems running
   <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
>, make sure you are able to
   select information from the database using, for example, <A
HREF="app-psql.html"
><SPAN
CLASS="APPLICATION"
>psql</SPAN
></A
>.  Also, any default connection settings and environment
   variables used by the <SPAN
CLASS="APPLICATION"
>libpq</SPAN
> front-end
   library will apply.
  </P
><P
>   The database activity of <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> is
   normally collected by the statistics collector.  If this is
   undesirable, you can set parameter <TT
CLASS="VARNAME"
>track_counts</TT
>
   to false via <TT
CLASS="ENVAR"
>PGOPTIONS</TT
> or the <TT
CLASS="LITERAL"
>ALTER
   USER</TT
> command.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="PG-DUMP-NOTES"
></A
><H2
>Notes</H2
><P
>   If your database cluster has any local additions to the <TT
CLASS="LITERAL"
>template1</TT
> database,
   be careful to restore the output of <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> into a
   truly empty database; otherwise you are likely to get errors due to
   duplicate definitions of the added objects.  To make an empty database
   without any local additions, copy from <TT
CLASS="LITERAL"
>template0</TT
> not <TT
CLASS="LITERAL"
>template1</TT
>,
   for example:
</P><PRE
CLASS="PROGRAMLISTING"
>CREATE DATABASE foo WITH TEMPLATE template0;</PRE
><P>
  </P
><P
>   When a data-only dump is chosen and the option <TT
CLASS="OPTION"
>--disable-triggers</TT
>
   is used, <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> emits commands
   to disable triggers on user tables before inserting the data,
   and then commands to re-enable them after the data has been
   inserted.  If the restore is stopped in the middle, the system
   catalogs might be left in the wrong state.
  </P
><P
>   Members of tar archives are limited to a size less than 8 GB.
   (This is an inherent limitation of the tar file format.)  Therefore
   this format cannot be used if the textual representation of any one table
   exceeds that size.  The total size of a tar archive and any of the
   other output formats is not limited, except possibly by the
   operating system.
  </P
><P
>   The dump file produced by <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
>
   does not contain the statistics used by the optimizer to make
   query planning decisions.  Therefore, it is wise to run
   <TT
CLASS="COMMAND"
>ANALYZE</TT
> after restoring from a dump file
   to ensure optimal performance; see <A
HREF="routine-vacuuming.html#VACUUM-FOR-STATISTICS"
>Section 23.1.3</A
>
   and <A
HREF="routine-vacuuming.html#AUTOVACUUM"
>Section 23.1.6</A
> for more information.
   The dump file also does not
   contain any <TT
CLASS="COMMAND"
>ALTER DATABASE ... SET</TT
> commands;
   these settings are dumped by <A
HREF="app-pg-dumpall.html"
><SPAN
CLASS="APPLICATION"
>pg_dumpall</SPAN
></A
>,
   along with database users and other installation-wide settings.
  </P
><P
>   Because <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> is used to transfer data
   to newer versions of <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>, the output of
   <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> can be expected to load into
   <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> server versions newer than
   <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
>'s version.  <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> can also
   dump from <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> servers older than its own version.
   (Currently, servers back to version 7.0 are supported.)
   However, <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> cannot dump from
   <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> servers newer than its own major version;
   it will refuse to even try, rather than risk making an invalid dump.
   Also, it is not guaranteed that <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
>'s output can
   be loaded into a server of an older major version &mdash; not even if the
   dump was taken from a server of that version.  Loading a dump file
   into an older server may require manual editing of the dump file
   to remove syntax not understood by the older server.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="PG-DUMP-EXAMPLES"
></A
><H2
>Examples</H2
><P
>   To dump a database called <TT
CLASS="LITERAL"
>mydb</TT
> into a SQL-script file:
</P><PRE
CLASS="SCREEN"
><SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>pg_dump mydb &gt; db.sql</KBD
></PRE
><P>
  </P
><P
>   To reload such a script into a (freshly created) database named
   <TT
CLASS="LITERAL"
>newdb</TT
>:

</P><PRE
CLASS="SCREEN"
><SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>psql -d newdb -f db.sql</KBD
></PRE
><P>
  </P
><P
>   To dump a database into a custom-format archive file:

</P><PRE
CLASS="SCREEN"
><SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>pg_dump -Fc mydb &gt; db.dump</KBD
></PRE
><P>
  </P
><P
>   To dump a database into a directory-format archive:

</P><PRE
CLASS="SCREEN"
><SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>pg_dump -Fd mydb -f dumpdir</KBD
></PRE
><P>
  </P
><P
>   To dump a database into a directory-format archive in parallel with
   5 worker jobs:

</P><PRE
CLASS="SCREEN"
><SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>pg_dump -Fd mydb -j 5 -f dumpdir</KBD
></PRE
><P>
  </P
><P
>   To reload an archive file into a (freshly created) database named
   <TT
CLASS="LITERAL"
>newdb</TT
>:

</P><PRE
CLASS="SCREEN"
><SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>pg_restore -d newdb db.dump</KBD
></PRE
><P>
  </P
><P
>   To dump a single table named <TT
CLASS="LITERAL"
>mytab</TT
>:

</P><PRE
CLASS="SCREEN"
><SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>pg_dump -t mytab mydb &gt; db.sql</KBD
></PRE
><P>
  </P
><P
>   To dump all tables whose names start with <TT
CLASS="LITERAL"
>emp</TT
> in the
   <TT
CLASS="LITERAL"
>detroit</TT
> schema, except for the table named
   <TT
CLASS="LITERAL"
>employee_log</TT
>:

</P><PRE
CLASS="SCREEN"
><SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>pg_dump -t 'detroit.emp*' -T detroit.employee_log mydb &gt; db.sql</KBD
></PRE
><P>
  </P
><P
>   To dump all schemas whose names start with <TT
CLASS="LITERAL"
>east</TT
> or
   <TT
CLASS="LITERAL"
>west</TT
> and end in <TT
CLASS="LITERAL"
>gsm</TT
>, excluding any schemas whose
   names contain the word <TT
CLASS="LITERAL"
>test</TT
>:

</P><PRE
CLASS="SCREEN"
><SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>pg_dump -n 'east*gsm' -n 'west*gsm' -N '*test*' mydb &gt; db.sql</KBD
></PRE
><P>
  </P
><P
>   The same, using regular expression notation to consolidate the switches:

</P><PRE
CLASS="SCREEN"
><SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>pg_dump -n '(east|west)*gsm' -N '*test*' mydb &gt; db.sql</KBD
></PRE
><P>
  </P
><P
>   To dump all database objects except for tables whose names begin with
   <TT
CLASS="LITERAL"
>ts_</TT
>:

</P><PRE
CLASS="SCREEN"
><SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>pg_dump -T 'ts_*' mydb &gt; db.sql</KBD
></PRE
><P>
  </P
><P
>   To specify an upper-case or mixed-case name in <TT
CLASS="OPTION"
>-t</TT
> and related
   switches, you need to double-quote the name; else it will be folded to
   lower case (see <A
HREF="app-psql.html#APP-PSQL-PATTERNS"
><I
>Patterns</I
></A
>).  But
   double quotes are special to the shell, so in turn they must be quoted.
   Thus, to dump a single table with a mixed-case name, you need something
   like

</P><PRE
CLASS="SCREEN"
><SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>pg_dump -t "\"MixedCaseName\"" mydb &gt; mytab.sql</KBD
></PRE
><P></P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN85506"
></A
><H2
>See Also</H2
><A
HREF="app-pg-dumpall.html"
><SPAN
CLASS="APPLICATION"
>pg_dumpall</SPAN
></A
>, <A
HREF="app-pgrestore.html"
>pg_restore</A
>, <A
HREF="app-psql.html"
><SPAN
CLASS="APPLICATION"
>psql</SPAN
></A
></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="app-pgconfig.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="app-pg-dumpall.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>pg_config</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="reference-client.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><SPAN
CLASS="APPLICATION"
>pg_dumpall</SPAN
></TD
></TR
></TABLE
></DIV
></BODY
></HTML
>