|
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 $ --> |
2 | 2 |
|
3 | 3 | <refentry id="APP-PGRESTORE">
|
4 | 4 | <refmeta>
|
@@ -580,34 +580,54 @@ CREATE DATABASE foo WITH TEMPLATE template0;
|
580 | 580 | <title>Examples</title>
|
581 | 581 |
|
582 | 582 | <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: |
585 | 585 |
|
586 | 586 | <screen>
|
587 |
| -<prompt>$</prompt> <userinput>pg_dump -Ft mydb > db.tar</userinput> |
| 587 | +<prompt>$</prompt> <userinput>pg_dump -Fc mydb > db.dump</userinput> |
588 | 588 | </screen>
|
589 | 589 | </para>
|
590 | 590 |
|
591 | 591 | <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: |
594 | 593 |
|
595 | 594 | <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> |
597 | 597 | </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. |
598 | 618 | </para>
|
599 | 619 |
|
600 | 620 | <para>
|
601 | 621 | To reorder database items, it is first necessary to dump the table of
|
602 | 622 | contents of the archive:
|
603 | 623 | <screen>
|
604 |
| -<prompt>$</prompt> <userinput>pg_restore -l archive.file > archive.list</userinput> |
| 624 | +<prompt>$</prompt> <userinput>pg_restore -l db.dump > db.list</userinput> |
605 | 625 | </screen>
|
606 | 626 | The listing file consists of a header and one line for each item, e.g.,
|
607 | 627 | <programlisting>
|
608 | 628 | ;
|
609 | 629 | ; Archive created at Fri Jul 28 22:28:36 2000
|
610 |
| -; dbname: birds |
| 630 | +; dbname: mydb |
611 | 631 | ; TOC Entries: 74
|
612 | 632 | ; Compression: 0
|
613 | 633 | ; Dump Version: 1.4-0
|
@@ -645,7 +665,7 @@ CREATE DATABASE foo WITH TEMPLATE template0;
|
645 | 665 | could be used as input to <application>pg_restore</application> and would only restore
|
646 | 666 | items 10 and 6, in that order:
|
647 | 667 | <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> |
649 | 669 | </screen>
|
650 | 670 | </para>
|
651 | 671 |
|
|
0 commit comments