Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
81b0b064
Commit
81b0b064
authored
18 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Make pg_restore usage examples more useful: illustrate restoring into
both the same database name and a different one.
parent
50271fc9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/src/sgml/ref/pg_restore.sgml
+30
-10
30 additions, 10 deletions
doc/src/sgml/ref/pg_restore.sgml
with
30 additions
and
10 deletions
doc/src/sgml/ref/pg_restore.sgml
+
30
−
10
View file @
81b0b064
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.6
3
2006/1
0/14 23:07:22
tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.6
4
2006/1
1/26 18:11:11
tgl Exp $ -->
<refentry id="APP-PGRESTORE">
<refmeta>
...
...
@@ -580,34 +580,54 @@ CREATE DATABASE foo WITH TEMPLATE template0;
<title>Examples</title>
<para>
To
dump a database called <literal>mydb</> to a
<filename>tar</filename>
file:
Assume we have
dump
ed
a database called <literal>mydb</>
in
to a
custom-format dump
file:
<screen>
<prompt>$</prompt> <userinput>pg_dump -F
t
mydb > db.
tar
</userinput>
<prompt>$</prompt> <userinput>pg_dump -F
c
mydb > db.
dump
</userinput>
</screen>
</para>
<para>
To reload this dump into an
existing database called <literal>newdb</>:
To drop the database and recreate it from the dump:
<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>
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>
To reorder database items, it is first necessary to dump the table of
contents of the archive:
<screen>
<prompt>$</prompt> <userinput>pg_restore -l
archive.file > archive
.list</userinput>
<prompt>$</prompt> <userinput>pg_restore -l
db.dump > db
.list</userinput>
</screen>
The listing file consists of a header and one line for each item, e.g.,
<programlisting>
;
; Archive created at Fri Jul 28 22:28:36 2000
; dbname:
birds
; dbname:
mydb
; TOC Entries: 74
; Compression: 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
items 10 and 6, in that order:
<screen>
<prompt>$</prompt> <userinput>pg_restore -L
archive.list archive.file
</userinput>
<prompt>$</prompt> <userinput>pg_restore -L
db.list db.dump
</userinput>
</screen>
</para>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment