Home Explore Blog CI



postgresql

25th chunk of `doc/src/sgml/ref/pg_dump.sgml`
4cee232bc840105856912c942ca272209656268ee75602e800000001000008ae
 enabled by the subscriber if the subscription
   had been originally created with <literal>two_phase = true</literal> option.
  </para>

  <para>
   It is generally recommended to use the <option>-X</option>
   (<option>--no-psqlrc</option>) option when restoring a database from a
   plain-text <application>pg_dump</application> script to ensure a clean
   restore process and prevent potential conflicts with
   non-default <application>psql</application> configurations.
  </para>
 </refsect1>

 <refsect1 id="pg-dump-examples" xreflabel="Examples">
  <title>Examples</title>

  <para>
   To dump a database called <literal>mydb</literal> into an SQL-script file:
<screen>
<prompt>$</prompt> <userinput>pg_dump mydb &gt; db.sql</userinput>
</screen>
  </para>

  <para>
   To reload such a script into a (freshly created) database named
   <literal>newdb</literal>:

<screen>
<prompt>$</prompt> <userinput>psql -X -d newdb -f db.sql</userinput>
</screen>
  </para>

  <para>
   To dump a database into a custom-format archive file:

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

  <para>
   To dump a database into a directory-format archive:

<screen>
<prompt>$</prompt> <userinput>pg_dump -Fd mydb -f dumpdir</userinput>
</screen>
  </para>

  <para>
   To dump a database into a directory-format archive in parallel with
   5 worker jobs:

<screen>
<prompt>$</prompt> <userinput>pg_dump -Fd mydb -j 5 -f dumpdir</userinput>
</screen>
  </para>

  <para>
   To reload an archive file into a (freshly created) database named
   <literal>newdb</literal>:

<screen>
<prompt>$</prompt> <userinput>pg_restore -d newdb db.dump</userinput>
</screen>
  </para>

  <para>
   To reload an archive file into the same database it was dumped from,
   discarding the current contents of that database:

<screen>
<prompt>$</prompt> <userinput>pg_restore -d postgres --clean --create db.dump</userinput>
</screen>
  </para>

  <para>
   To dump a single table named <literal>mytab</literal>:

<screen>
<prompt>$</prompt> <userinput>pg_dump -t mytab mydb &gt; db.sql</userinput>
</screen>
  </para>

  <para>
   To dump all tables whose names start with <literal>emp</literal>

Title: pg_dump Usage Examples: Dumping and Restoring Databases
Summary
This section provides examples of using pg_dump and pg_restore for various scenarios. These include dumping a database to an SQL script, reloading the script into a new database, dumping to custom or directory-format archives, performing parallel dumps, reloading archives, and selectively dumping a single table or tables matching a pattern.