mirror of
https://github.com/postgres/postgres.git
synced 2025-04-27 22:56:53 +03:00
Make pg_restore usage examples more useful: illustrate restoring into
both the same database name and a different one.
This commit is contained in:
parent
50271fc9b3
commit
81b0b06462
@ -1,4 +1,4 @@
|
|||||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.63 2006/10/14 23:07:22 tgl Exp $ -->
|
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.64 2006/11/26 18:11:11 tgl Exp $ -->
|
||||||
|
|
||||||
<refentry id="APP-PGRESTORE">
|
<refentry id="APP-PGRESTORE">
|
||||||
<refmeta>
|
<refmeta>
|
||||||
@ -580,34 +580,54 @@ CREATE DATABASE foo WITH TEMPLATE template0;
|
|||||||
<title>Examples</title>
|
<title>Examples</title>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
To dump a database called <literal>mydb</> to a <filename>tar</filename>
|
Assume we have dumped a database called <literal>mydb</> into a
|
||||||
file:
|
custom-format dump file:
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>$</prompt> <userinput>pg_dump -Ft mydb > db.tar</userinput>
|
<prompt>$</prompt> <userinput>pg_dump -Fc mydb > db.dump</userinput>
|
||||||
</screen>
|
</screen>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
To reload this dump into an
|
To drop the database and recreate it from the dump:
|
||||||
existing database called <literal>newdb</>:
|
|
||||||
|
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>$</prompt> <userinput>pg_restore -d newdb db.tar</userinput>
|
<prompt>$</prompt> <userinput>dropdb mydb</userinput>
|
||||||
|
<prompt>$</prompt> <userinput>pg_restore -C -d postgres db.dump</userinput>
|
||||||
</screen>
|
</screen>
|
||||||
|
|
||||||
|
The database named in the <option>-d</> switch can be any database existing
|
||||||
|
in the cluster; <application>pg_restore</> only uses it to issue the
|
||||||
|
<command>CREATE DATABASE</> command for <literal>mydb</>. With
|
||||||
|
<option>-C</>, data is always restored into the database name that appears
|
||||||
|
in the dump file.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
To reload the dump into a new database called <literal>newdb</>:
|
||||||
|
|
||||||
|
<screen>
|
||||||
|
<prompt>$</prompt> <userinput>createdb -T template0 newdb</userinput>
|
||||||
|
<prompt>$</prompt> <userinput>pg_restore -d newdb db.dump</userinput>
|
||||||
|
</screen>
|
||||||
|
|
||||||
|
Notice we don't use <option>-C</>, and instead connect directly to the
|
||||||
|
database to be restored into. Also note that we clone the new database
|
||||||
|
from <literal>template0</> not <literal>template1</>, to ensure it is
|
||||||
|
initially empty.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
To reorder database items, it is first necessary to dump the table of
|
To reorder database items, it is first necessary to dump the table of
|
||||||
contents of the archive:
|
contents of the archive:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>$</prompt> <userinput>pg_restore -l archive.file > archive.list</userinput>
|
<prompt>$</prompt> <userinput>pg_restore -l db.dump > db.list</userinput>
|
||||||
</screen>
|
</screen>
|
||||||
The listing file consists of a header and one line for each item, e.g.,
|
The listing file consists of a header and one line for each item, e.g.,
|
||||||
<programlisting>
|
<programlisting>
|
||||||
;
|
;
|
||||||
; Archive created at Fri Jul 28 22:28:36 2000
|
; Archive created at Fri Jul 28 22:28:36 2000
|
||||||
; dbname: birds
|
; dbname: mydb
|
||||||
; TOC Entries: 74
|
; TOC Entries: 74
|
||||||
; Compression: 0
|
; Compression: 0
|
||||||
; Dump Version: 1.4-0
|
; Dump Version: 1.4-0
|
||||||
@ -645,7 +665,7 @@ CREATE DATABASE foo WITH TEMPLATE template0;
|
|||||||
could be used as input to <application>pg_restore</application> and would only restore
|
could be used as input to <application>pg_restore</application> and would only restore
|
||||||
items 10 and 6, in that order:
|
items 10 and 6, in that order:
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>$</prompt> <userinput>pg_restore -L archive.list archive.file</userinput>
|
<prompt>$</prompt> <userinput>pg_restore -L db.list db.dump</userinput>
|
||||||
</screen>
|
</screen>
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user