Home Explore Blog CI



postgresql

15th chunk of `doc/src/sgml/ref/pg_restore.sgml`
b806bded6fc3d0c9496eee526195350710c9d2df97e63a6700000001000009c6
 to duplicate definitions
   of the added objects.  To make an empty database without any local
   additions, copy from <literal>template0</literal> not <literal>template1</literal>, for example:
<programlisting>
CREATE DATABASE foo WITH TEMPLATE template0;
</programlisting>
  </para>

  <para>
   The limitations of <application>pg_restore</application> are detailed below.

   <itemizedlist>
    <listitem>
     <para>
      When restoring data to a pre-existing table and the option
      <option>--disable-triggers</option> is used,
      <application>pg_restore</application> 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.
     </para>
    </listitem>

    <listitem>
     <para><application>pg_restore</application> cannot restore large objects
      selectively;  for instance, only those for a specific table.  If
      an archive contains large objects, then all large objects will be
      restored, or none of them if they are excluded via <option>-L</option>,
      <option>-t</option>, or other options.
     </para>
    </listitem>

   </itemizedlist>
  </para>

  <para>
   See also the <xref linkend="app-pgdump"/> documentation for details on
   limitations of <application>pg_dump</application>.
  </para>

  <para>
   By default, <command>pg_restore</command> will restore optimizer statistics
   if included in the dump file.  If not all statistics were restored, it may
   be useful to run <command>ANALYZE</command> on each restored table so the
   optimizer has useful statistics; see <xref
   linkend="vacuum-for-statistics"/> and <xref linkend="autovacuum"/> for more
   information.
  </para>

 </refsect1>


 <refsect1 id="app-pgrestore-examples">
  <title>Examples</title>

  <para>
   Assume we have dumped a database called <literal>mydb</literal> into a
   custom-format dump file:

<screen>
<prompt>$</prompt> <userinput>pg_dump -Fc mydb &gt; db.dump</userinput>
</screen>
  </para>

  <para>
   To drop the database and recreate it from the dump:

<screen>
<prompt>$</prompt> <userinput>dropdb mydb</userinput>
<prompt>$</prompt> <userinput>pg_restore -C -d postgres db.dump</userinput>
</screen>

   The database named in the <option>-d</option> switch can be any database existing
   in the cluster; <application>pg_restore</application> only uses it

Title: pg_restore: Notes and Examples
Summary
This section further elaborates on pg_restore's notes and limitations, including restoring to an empty database, trigger management during restoration, and the handling of large objects. It recommends analyzing restored tables to update optimizer statistics. Additionally, it provides examples of using pg_restore to drop and recreate a database from a dump file.