Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 81b0b06

Browse files
committed
Make pg_restore usage examples more useful: illustrate restoring into
both the same database name and a different one.
1 parent 50271fc commit 81b0b06

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

doc/src/sgml/ref/pg_restore.sgml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.63 2006/10/14 23:07:22 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.64 2006/11/26 18:11:11 tgl Exp $ -->
22

33
<refentry id="APP-PGRESTORE">
44
<refmeta>
@@ -580,34 +580,54 @@ CREATE DATABASE foo WITH TEMPLATE template0;
580580
<title>Examples</title>
581581

582582
<para>
583-
To dump a database called <literal>mydb</> to a <filename>tar</filename>
584-
file:
583+
Assume we have dumped a database called <literal>mydb</> into a
584+
custom-format dump file:
585585

586586
<screen>
587-
<prompt>$</prompt> <userinput>pg_dump -Ft mydb &gt; db.tar</userinput>
587+
<prompt>$</prompt> <userinput>pg_dump -Fc mydb &gt; db.dump</userinput>
588588
</screen>
589589
</para>
590590

591591
<para>
592-
To reload this dump into an
593-
existing database called <literal>newdb</>:
592+
To drop the database and recreate it from the dump:
594593

595594
<screen>
596-
<prompt>$</prompt> <userinput>pg_restore -d newdb db.tar</userinput>
595+
<prompt>$</prompt> <userinput>dropdb mydb</userinput>
596+
<prompt>$</prompt> <userinput>pg_restore -C -d postgres db.dump</userinput>
597597
</screen>
598+
599+
The database named in the <option>-d</> switch can be any database existing
600+
in the cluster; <application>pg_restore</> only uses it to issue the
601+
<command>CREATE DATABASE</> command for <literal>mydb</>. With
602+
<option>-C</>, data is always restored into the database name that appears
603+
in the dump file.
604+
</para>
605+
606+
<para>
607+
To reload the dump into a new database called <literal>newdb</>:
608+
609+
<screen>
610+
<prompt>$</prompt> <userinput>createdb -T template0 newdb</userinput>
611+
<prompt>$</prompt> <userinput>pg_restore -d newdb db.dump</userinput>
612+
</screen>
613+
614+
Notice we don't use <option>-C</>, and instead connect directly to the
615+
database to be restored into. Also note that we clone the new database
616+
from <literal>template0</> not <literal>template1</>, to ensure it is
617+
initially empty.
598618
</para>
599619

600620
<para>
601621
To reorder database items, it is first necessary to dump the table of
602622
contents of the archive:
603623
<screen>
604-
<prompt>$</prompt> <userinput>pg_restore -l archive.file &gt; archive.list</userinput>
624+
<prompt>$</prompt> <userinput>pg_restore -l db.dump &gt; db.list</userinput>
605625
</screen>
606626
The listing file consists of a header and one line for each item, e.g.,
607627
<programlisting>
608628
;
609629
; Archive created at Fri Jul 28 22:28:36 2000
610-
; dbname: birds
630+
; dbname: mydb
611631
; TOC Entries: 74
612632
; Compression: 0
613633
; Dump Version: 1.4-0
@@ -645,7 +665,7 @@ CREATE DATABASE foo WITH TEMPLATE template0;
645665
could be used as input to <application>pg_restore</application> and would only restore
646666
items 10 and 6, in that order:
647667
<screen>
648-
<prompt>$</prompt> <userinput>pg_restore -L archive.list archive.file</userinput>
668+
<prompt>$</prompt> <userinput>pg_restore -L db.list db.dump</userinput>
649669
</screen>
650670
</para>
651671

0 commit comments

Comments
 (0)