Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > media > main-testing > by-pkgid > bab02a23fa9f3df8d66a9a3231b50245 > files > 23

postgresql8.3-docs-8.3.6-2mdv2008.1.x86_64.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>pg_restore</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.3.6 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="PostgreSQL Client Applications"
HREF="reference-client.html"><LINK
REL="PREVIOUS"
TITLE="pg_dumpall"
HREF="app-pg-dumpall.html"><LINK
REL="NEXT"
TITLE="psql"
HREF="app-psql.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-02-03T04:34:16"></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"
>PostgreSQL 8.3.6 Documentation</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="app-pg-dumpall.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="app-pg-dumpall.html"
>Fast Backward</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="app-psql.html"
>Fast Forward</A
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="app-psql.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="APP-PGRESTORE"
></A
>pg_restore</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN63722"
></A
><H2
>Name</H2
>pg_restore&nbsp;--&nbsp;   restore a <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> database from an
   archive file created by <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
>
  </DIV
><A
NAME="AEN63727"
></A
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN63729"
></A
><H2
>Synopsis</H2
><P
><TT
CLASS="COMMAND"
>pg_restore</TT
> [<TT
CLASS="REPLACEABLE"
><I
>option</I
></TT
>...] [<TT
CLASS="REPLACEABLE"
><I
>filename</I
></TT
>]</P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="APP-PGRESTORE-DESCRIPTION"
></A
><H2
>Description</H2
><P
>   <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> is a utility for restoring a
   <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> database from an archive
   created by <A
HREF="app-pgdump.html"
>pg_dump</A
> in one of the non-plain-text
   formats.  It will issue the commands necessary to reconstruct the
   database to the state it was in at the time it was saved.  The
   archive files also 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 files are designed to be
   portable across architectures.
  </P
><P
>   <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> can operate in two modes.
   If a database name is specified, the archive is restored directly into
   the database.  Otherwise, a script containing the SQL
   commands necessary to rebuild the database is created and written
   to a file or standard output.  The script output is equivalent to
   the plain text output format of <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
>.
   Some of the options controlling the output are therefore analogous to
   <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
> options.
  </P
><P
>   Obviously, <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> cannot restore information
   that is not present in the archive file.  For instance, if the
   archive was made using the <SPAN
CLASS="QUOTE"
>"dump data as
   <TT
CLASS="COMMAND"
>INSERT</TT
> commands"</SPAN
> option,
   <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> will not be able to load the data
   using <TT
CLASS="COMMAND"
>COPY</TT
> statements.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="APP-PGRESTORE-OPTIONS"
></A
><H2
>Options</H2
><P
>    <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> accepts the following command
    line arguments.

    <P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="REPLACEABLE"
><I
>filename</I
></TT
></DT
><DD
><P
>       Specifies the location of the archive file to be restored.
       If not specified, the standard input is used.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-a</TT
><BR><TT
CLASS="OPTION"
>--data-only</TT
></DT
><DD
><P
>        Restore only the data, not the schema (data definitions).
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-c</TT
><BR><TT
CLASS="OPTION"
>--clean</TT
></DT
><DD
><P
>        Clean (drop) database objects before recreating them.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-C</TT
><BR><TT
CLASS="OPTION"
>--create</TT
></DT
><DD
><P
>        Create the database before restoring into it.  (When this
        option is used, the database named with <TT
CLASS="OPTION"
>-d</TT
> is
        used only to issue the initial <TT
CLASS="COMMAND"
>CREATE DATABASE</TT
>
        command.  All data is restored into the database name that
        appears in the archive.)
       </P
></DD
><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
>        Connect to database <TT
CLASS="REPLACEABLE"
><I
>dbname</I
></TT
> and restore directly
        into the database.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-e</TT
><BR><TT
CLASS="OPTION"
>--exit-on-error</TT
></DT
><DD
><P
>        Exit if an error is encountered while sending SQL commands to
        the database. The default is to continue and to display a count of 
        errors at the end of the restoration.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-f <TT
CLASS="REPLACEABLE"
><I
>filename</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--file=<TT
CLASS="REPLACEABLE"
><I
>filename</I
></TT
></TT
></DT
><DD
><P
>        Specify output file for generated script, or for the listing
        when used with <TT
CLASS="OPTION"
>-l</TT
>. Default is the standard
        output.
       </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
>        Specify format of the archive.  It is not necessary to specify
        the format, since <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> will
        determine the format automatically. If specified, it can be
        one of the following:

       <P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="LITERAL"
>t</TT
><BR><TT
CLASS="LITERAL"
>tar</TT
></DT
><DD
><P
>           The archive is a <TT
CLASS="COMMAND"
>tar</TT
> archive. Using this
           archive format allows reordering and/or exclusion of schema
           elements at the time the database is restored. It is also
           possible to limit which data is reloaded at restore time.
          </P
></DD
><DT
><TT
CLASS="LITERAL"
>c</TT
><BR><TT
CLASS="LITERAL"
>custom</TT
></DT
><DD
><P
>           The archive is in the custom format of
           <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
>. This is the most
           flexible format in that it allows reordering of data load
           as well as schema elements.  This format is also compressed
           by default.
          </P
></DD
></DL
></DIV
><P>
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-i</TT
><BR><TT
CLASS="OPTION"
>--ignore-version</TT
></DT
><DD
><P
>        Ignore database version checks.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-I <TT
CLASS="REPLACEABLE"
><I
>index</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--index=<TT
CLASS="REPLACEABLE"
><I
>index</I
></TT
></TT
></DT
><DD
><P
>        Restore definition of named index only.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-l</TT
><BR><TT
CLASS="OPTION"
>--list</TT
></DT
><DD
><P
>        List the contents of the archive. The output of this operation
        can be used with the <TT
CLASS="OPTION"
>-L</TT
> option to restrict
        and reorder the items that are restored.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-L <TT
CLASS="REPLACEABLE"
><I
>list-file</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--use-list=<TT
CLASS="REPLACEABLE"
><I
>list-file</I
></TT
></TT
></DT
><DD
><P
>        Restore elements in <TT
CLASS="REPLACEABLE"
><I
>        list-file</I
></TT
> only, and in the
        order they appear in the file. Lines can be moved and can also
        be commented out by placing a <TT
CLASS="LITERAL"
>;</TT
> at the
        start of the line.  (See below for examples.)
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-n <TT
CLASS="REPLACEABLE"
><I
>namespace</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--schema=<TT
CLASS="REPLACEABLE"
><I
>schema</I
></TT
></TT
></DT
><DD
><P
>        Restore only objects that are in the named schema.  This can be
        combined with the <TT
CLASS="OPTION"
>-t</TT
> option to restore just a
        specific table.
       </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_restore</SPAN
> issues
        <TT
CLASS="COMMAND"
>ALTER OWNER</TT
> or 
        <TT
CLASS="COMMAND"
>SET SESSION AUTHORIZATION</TT
>
        statements to set ownership of created schema elements.
        These statements will fail unless the initial connection to the
        database is made by a superuser
        (or the same user that owns all of the objects in the script).
        With <TT
CLASS="OPTION"
>-O</TT
>, any user name can be used for the
        initial connection, and this user will own all the created objects.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-P <TT
CLASS="REPLACEABLE"
><I
>function-name(argtype [, ...])</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--function=<TT
CLASS="REPLACEABLE"
><I
>function-name(argtype [, ...])</I
></TT
></TT
></DT
><DD
><P
>        Restore the named function only.  Be careful to spell the function
        name and arguments exactly as they appear in the dump file's table
        of contents.
       </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
>        Restore only the schema (data definitions), not the data (table
        contents).  Sequence current values will not be restored, either.
        (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
></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 only relevant if <TT
CLASS="OPTION"
>--disable-triggers</TT
> is used.
       </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
>        Restore definition and/or data of named table only.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-T <TT
CLASS="REPLACEABLE"
><I
>trigger</I
></TT
></TT
><BR><TT
CLASS="OPTION"
>--trigger=<TT
CLASS="REPLACEABLE"
><I
>trigger</I
></TT
></TT
></DT
><DD
><P
>        Restore named trigger only.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>-v</TT
><BR><TT
CLASS="OPTION"
>--verbose</TT
></DT
><DD
><P
>        Specifies verbose mode.
       </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 restoration of access privileges (grant/revoke commands).
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--disable-triggers</TT
></DT
><DD
><P
>        This option is only relevant when performing a data-only restore.
        It instructs <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> to execute 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 run <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> as a
        <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> superuser.
       </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.
       </P
></DD
><DT
><TT
CLASS="OPTION"
>--no-data-for-failed-tables</TT
></DT
><DD
><P
>        By default, table data is restored even if the creation command
        for the table failed (e.g., because it already exists).
        With this option, data for such a table is skipped.
        This behavior is useful if the target database already
        contains the desired table contents.  For example,
        auxiliary tables for <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> extensions
        such as <SPAN
CLASS="PRODUCTNAME"
>PostGIS</SPAN
> might already be loaded in
        the target database; specifying this option prevents duplicate
        or obsolete data from being loaded into them.
       </P
><P
>        This option is effective only when restoring directly into a
        database, not when producing SQL script output.
       </P
></DD
></DL
></DIV
><P>
   </P
><P
>    <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> also accepts
    the following command line arguments for connection parameters:

    <P
></P
></P><DIV
CLASS="VARIABLELIST"
><DL
><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"
>--password</TT
></DT
><DD
><P
>        Force <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> to prompt for a
        password before connecting to a database.  
       </P
><P
>        This option is never essential, since
        <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> will automatically prompt
        for a password if the server demands password authentication.
        However, <SPAN
CLASS="APPLICATION"
>pg_restore</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"
>-1</TT
><BR><TT
CLASS="OPTION"
>--single-transaction</TT
></DT
><DD
><P
>        Execute the restore as a single transaction (that is, wrap the
        emitted commands in <TT
CLASS="COMMAND"
>BEGIN</TT
>/<TT
CLASS="COMMAND"
>COMMIT</TT
>).  This
        ensures that either all the commands complete successfully, or no
        changes are applied. This option implies
        <TT
CLASS="OPTION"
>--exit-on-error</TT
>.
       </P
></DD
></DL
></DIV
><P>
   </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN64045"
></A
><H2
>Environment</H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="ENVAR"
>PGHOST</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 30.12</A
>).
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="APP-PGRESTORE-DIAGNOSTICS"
></A
><H2
>Diagnostics</H2
><P
>   When a direct database connection is specified using the
   <TT
CLASS="OPTION"
>-d</TT
> option, <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
>
   internally executes <ACRONYM
CLASS="ACRONYM"
>SQL</ACRONYM
> statements. If you have
   problems running <SPAN
CLASS="APPLICATION"
>pg_restore</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
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="APP-PGRESTORE-NOTES"
></A
><H2
>Notes</H2
><P
>   If your installation has any local additions to the
   <TT
CLASS="LITERAL"
>template1</TT
> database, be careful to load the output of
   <SPAN
CLASS="APPLICATION"
>pg_restore</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
>   The limitations of <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> are detailed below.

   <P
></P
></P><UL
><LI
><P
>      When restoring data to a pre-existing table and the option
      <TT
CLASS="OPTION"
>--disable-triggers</TT
> is used,
      <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> emits commands
      to disable triggers on user tables before inserting the data then emits 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
></LI
><LI
><P
>      <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> will not restore large objects for a single table. If
      an archive contains large objects, then all large objects will be restored.
     </P
></LI
></UL
><P>
  </P
><P
>   See also the <A
HREF="app-pgdump.html"
>pg_dump</A
> documentation for details on
   limitations of <SPAN
CLASS="APPLICATION"
>pg_dump</SPAN
>.
  </P
><P
>   Once restored, it is wise to run <TT
CLASS="COMMAND"
>ANALYZE</TT
> on each
   restored table so the optimizer has useful statistics.
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="APP-PGRESTORE-EXAMPLES"
></A
><H2
>Examples</H2
><P
>   Assume we have dumped a database called <TT
CLASS="LITERAL"
>mydb</TT
> into a
   custom-format dump 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 drop the database and recreate it from the dump:

</P><PRE
CLASS="SCREEN"
><SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>dropdb mydb</KBD
>
<SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>pg_restore -C -d postgres db.dump</KBD
></PRE
><P>

   The database named in the <TT
CLASS="OPTION"
>-d</TT
> switch can be any database existing
   in the cluster; <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> only uses it to issue the
   <TT
CLASS="COMMAND"
>CREATE DATABASE</TT
> command for <TT
CLASS="LITERAL"
>mydb</TT
>.  With
   <TT
CLASS="OPTION"
>-C</TT
>, data is always restored into the database name that appears
   in the dump file.
  </P
><P
>   To reload the dump into a new database called <TT
CLASS="LITERAL"
>newdb</TT
>:

</P><PRE
CLASS="SCREEN"
><SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>createdb -T template0 newdb</KBD
>
<SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>pg_restore -d newdb db.dump</KBD
></PRE
><P>

   Notice we don't use <TT
CLASS="OPTION"
>-C</TT
>, and instead connect directly to the
   database to be restored into.  Also note that we clone the new database
   from <TT
CLASS="LITERAL"
>template0</TT
> not <TT
CLASS="LITERAL"
>template1</TT
>, to ensure it is
   initially empty.
  </P
><P
>   To reorder database items, it is first necessary to dump the table of
   contents of the archive:
</P><PRE
CLASS="SCREEN"
><SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>pg_restore -l db.dump &gt; db.list</KBD
></PRE
><P>
   The listing file consists of a header and one line for each item, e.g.:
</P><PRE
CLASS="PROGRAMLISTING"
>;
; Archive created at Fri Jul 28 22:28:36 2000
;     dbname: mydb
;     TOC Entries: 74
;     Compression: 0
;     Dump Version: 1.4-0
;     Format: CUSTOM
;
;
; Selected TOC Entries:
;
2; 145344 TABLE species postgres
3; 145344 ACL species
4; 145359 TABLE nt_header postgres
5; 145359 ACL nt_header
6; 145402 TABLE species_records postgres
7; 145402 ACL species_records
8; 145416 TABLE ss_old postgres
9; 145416 ACL ss_old
10; 145433 TABLE map_resolutions postgres
11; 145433 ACL map_resolutions
12; 145443 TABLE hs_old postgres
13; 145443 ACL hs_old</PRE
><P>
   Semicolons start a comment, and the numbers at the start of lines refer to the
   internal archive ID assigned to each item.
  </P
><P
>   Lines in the file can be commented out, deleted, and reordered. For example:
</P><PRE
CLASS="PROGRAMLISTING"
>10; 145433 TABLE map_resolutions postgres
;2; 145344 TABLE species postgres
;4; 145359 TABLE nt_header postgres
6; 145402 TABLE species_records postgres
;8; 145416 TABLE ss_old postgres</PRE
><P>
   could be used as input to <SPAN
CLASS="APPLICATION"
>pg_restore</SPAN
> and would only restore
   items 10 and 6, in that order:
</P><PRE
CLASS="SCREEN"
><SAMP
CLASS="PROMPT"
>$</SAMP
> <KBD
CLASS="USERINPUT"
>pg_restore -L db.list db.dump</KBD
></PRE
><P>
  </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN64132"
></A
><H2
>See Also</H2
><A
HREF="app-pgdump.html"
>pg_dump</A
>, <A
HREF="app-pg-dumpall.html"
><SPAN
CLASS="APPLICATION"
>pg_dumpall</SPAN
></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-pg-dumpall.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-psql.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><SPAN
CLASS="APPLICATION"
>pg_dumpall</SPAN
></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"
>psql</SPAN
></TD
></TR
></TABLE
></DIV
></BODY
></HTML
>