Home Explore Blog CI



postgresql

2nd chunk of `doc/src/sgml/ref/pg_restore.sgml`
17e6cbab5c6123edbb8e372c963c2ac2f9516419c6ad80650000000100000fa9
   <application>pg_restore</application> accepts the following command
    line arguments.

    <variablelist>
     <varlistentry>
      <term><replaceable class="parameter">filename</replaceable></term>
      <listitem>
       <para>
       Specifies the location of the archive file (or directory, for a
       directory-format archive) to be restored.
       If not specified, the standard input is used.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-a</option></term>
      <term><option>--data-only</option></term>
      <listitem>
       <para>
        Restore only the data, not the schema (data definitions) or statistics.
        Table data, large objects, and sequence values are restored,
        if present in the archive.
       </para>

       <para>
        This option is similar to, but for historical reasons not identical
        to, specifying <option>--section=data</option>.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-c</option></term>
      <term><option>--clean</option></term>
      <listitem>
       <para>
        Before restoring database objects, issue commands
        to <command>DROP</command> all the objects that will be restored.
        This option is useful for overwriting an existing database.
        If any of the objects do not exist in the destination database,
        ignorable error messages will be reported,
        unless <option>--if-exists</option> is also specified.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-C</option></term>
      <term><option>--create</option></term>
      <listitem>
       <para>
        Create the database before restoring into it.
        If <option>--clean</option> is also specified, drop and
        recreate the target database before connecting to it.
       </para>

       <para>
        With <option>--create</option>, <application>pg_restore</application>
        also restores the database's comment if any, and any configuration
        variable settings that are specific to this database, that is,
        any <command>ALTER DATABASE ... SET ...</command>
        and <command>ALTER ROLE ... IN DATABASE ... SET ...</command>
        commands that mention this database.
        Access privileges for the database itself are also restored,
        unless <option>--no-acl</option> is specified.
        <option>--create</option> is required when restoring multiple databases
        from an archive created by <application>pg_dumpall</application>.
       </para>

       <para>
        When this option is used, the database named with <option>-d</option>
        is used only to issue the initial <command>DROP DATABASE</command> and
        <command>CREATE DATABASE</command> commands.  All data is restored into the
        database name that appears in the archive.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-d <replaceable class="parameter">dbname</replaceable></option></term>
      <term><option>--dbname=<replaceable class="parameter">dbname</replaceable></option></term>
      <listitem>
       <para>
        Connect to database <replaceable
        class="parameter">dbname</replaceable> and restore directly
        into the database.  The <replaceable>dbname</replaceable> can
        be a <link linkend="libpq-connstring">connection string</link>.
        If so, connection string parameters will override any conflicting
        command line options.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-e</option></term>
      <term><option>--exit-on-error</option></term>
      <listitem>
       <para>
        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.
       </para>
      </listitem>
     </varlistentry>

Title: pg_restore Options: Filename, Data-Only, Clean, Create, dbname, and Exit-on-Error
Summary
This section describes several command-line options for pg_restore. It includes options for specifying the archive filename, restoring only data, cleaning (dropping) objects before restoring, creating the database before restoring, connecting to a specific database (dbname), and exiting immediately upon encountering an error during the restoration process.