<!--
doc/src/sgml/ref/pg_restore.sgml
PostgreSQL documentation
-->
<refentry id="app-pgrestore">
<indexterm zone="app-pgrestore">
<primary>pg_restore</primary>
</indexterm>
<refmeta>
<refentrytitle><application>pg_restore</application></refentrytitle>
<manvolnum>1</manvolnum>
<refmiscinfo>Application</refmiscinfo>
</refmeta>
<refnamediv>
<refname>pg_restore</refname>
<refpurpose>
restore a <productname>PostgreSQL</productname> database or cluster
from an archive created by <application>pg_dump</application> or
<application>pg_dumpall</application>
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<cmdsynopsis>
<command>pg_restore</command>
<arg rep="repeat"><replaceable>connection-option</replaceable></arg>
<arg rep="repeat"><replaceable>option</replaceable></arg>
<arg choice="opt"><replaceable>filename</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1 id="app-pgrestore-description">
<title>Description</title>
<para>
<application>pg_restore</application> is a utility for restoring a
<productname>PostgreSQL</productname> database or cluster from an archive
created by <xref linkend="app-pgdump"/> or
<xref linkend="app-pg-dumpall"/> in one of the non-plain-text
formats. It will issue the commands necessary to reconstruct the
database or cluster to the state it was in at the time it was saved. The
archives also allow <application>pg_restore</application> to
be selective about what is restored, or even to reorder the items
prior to being restored. The archive formats are designed to be
portable across architectures.
</para>
<para>
<application>pg_restore</application> can operate in two modes.
If a database name is specified, <application>pg_restore</application>
connects to that database and restores archive contents directly into
the database.
When restoring from a dump made by <application>pg_dumpall</application>,
each database will be created and then the restoration will be run in that
database.
Otherwise, when a database name is not specified, a script containing the SQL
commands necessary to rebuild the database or cluster is created and written
to a file or standard output. This script output is equivalent to
the plain text output format of <application>pg_dump</application> or
<application>pg_dumpall</application>.
Some of the options controlling the output are therefore analogous to
<application>pg_dump</application> options.
</para>
<para>
Obviously, <application>pg_restore</application> cannot restore information
that is not present in the archive file. For instance, if the
archive was made using the <quote>dump data as
<command>INSERT</command> commands</quote> option,
<application>pg_restore</application> will not be able to load the data
using <command>COPY</command> statements.
</para>
</refsect1>
<refsect1 id="app-pgrestore-options">
<title>Options</title>
<para>
<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>