1
- <!-- $PostgreSQL: pgsql/doc/src/sgml/backup.sgml,v 2.87 2006/09/19 15:18:41 neilc Exp $ -->
1
+ <!-- $PostgreSQL: pgsql/doc/src/sgml/backup.sgml,v 2.88 2006/09/19 19:04:51 neilc Exp $ -->
2
2
3
3
<chapter id="backup">
4
4
<title>Backup and Restore</title>
@@ -84,7 +84,7 @@ pg_dump <replaceable class="parameter">dbname</replaceable> > <replaceable cl
84
84
85
85
<important>
86
86
<para>
87
- When your database schema relies on OIDs (for instance as foreign
87
+ If your database schema relies on OIDs (for instance as foreign
88
88
keys) you must instruct <application>pg_dump</> to dump the OIDs
89
89
as well. To do this, use the <option>-o</option> command line
90
90
option.
@@ -105,30 +105,42 @@ psql <replaceable class="parameter">dbname</replaceable> < <replaceable class
105
105
you used as <replaceable class="parameter">outfile</replaceable>
106
106
for the <application>pg_dump</> command. The database <replaceable
107
107
class="parameter">dbname</replaceable> will not be created by this
108
- command, you must create it yourself from <literal>template0</> before executing
109
- <application>psql</> (e.g., with <literal>createdb -T template0
110
- <replaceable class="parameter">dbname</></literal>).
111
- <application>psql</> supports options similar to <application>pg_dump</>
112
- for controlling the database server location and the user name. See
113
- <xref linkend="app-psql">'s reference page for more information.
108
+ command, so you must create it yourself from <literal>template0</>
109
+ before executing <application>psql</> (e.g., with
110
+ <literal>createdb -T template0 <replaceable
111
+ class="parameter">dbname</></literal>). <application>psql</>
112
+ supports similar options to <application>pg_dump</> for specifying
113
+ the database server to connect to and the user name to use. See
114
+ the <xref linkend="app-psql"> reference page for more information.
114
115
</para>
115
116
116
117
<para>
117
- Not only must the target database already exist before starting to
118
- run the restore, but so must all the users who own objects in the
119
- dumped database or were granted permissions on the objects. If they
120
- do not, then the restore will fail to recreate the objects with the
121
- original ownership and/or permissions. (Sometimes this is what you want,
122
- but usually it is not.)
118
+ Before restoring a SQL dump, all the users who own objects or were
119
+ granted permissions on objects in the dumped database must already
120
+ exist. If they do not, then the restore will fail to recreate the
121
+ objects with the original ownership and/or permissions.
122
+ (Sometimes this is what you want, but usually it is not.)
123
123
</para>
124
124
125
125
<para>
126
- Once restored, it is wise to run <xref linkend="sql-analyze"
127
- endterm="sql-analyze-title"> on each database so the optimizer has
128
- useful statistics. An easy way to do this is to run
129
- <command>vacuumdb -a -z</> to
130
- <command>VACUUM ANALYZE</> all databases; this is equivalent to
131
- running <command>VACUUM ANALYZE</command> manually.
126
+ By default, the <application>psql</> script will continue to
127
+ execute after an SQL error is encountered. You may wish to use the
128
+ following command at the top of the script to alter that
129
+ behaviour and have <application>psql</application> exit with an
130
+ exit status of 3 if an SQL error occurs:
131
+ <programlisting>
132
+ \set ON_ERROR_STOP
133
+ </programlisting>
134
+ Either way, you will only have a partially restored
135
+ dump. Alternatively, you can specify that the whole dump should be
136
+ restored as a single transaction, so the restore is either fully
137
+ completed or fully rolled back. This mode can be specified by
138
+ passing the <option>-1</> or <option>--single-transaction</>
139
+ command-line options to <application>psql</>. When using this
140
+ mode, be aware that even the smallest of errors can rollback a
141
+ restore that has already run for many hours. However, that may
142
+ still be preferable to manually cleaning up a complex database
143
+ after a partially restored dump.
132
144
</para>
133
145
134
146
<para>
@@ -153,8 +165,13 @@ pg_dump -h <replaceable>host1</> <replaceable>dbname</> | psql -h <replaceable>h
153
165
</important>
154
166
155
167
<para>
156
- For advice on how to load large amounts of data into
157
- <productname>PostgreSQL</productname> efficiently, refer to <xref
168
+ After restoring a backup, it is wise to run <xref
169
+ linkend="sql-analyze" endterm="sql-analyze-title"> on each
170
+ database so the query optimizer has useful statistics. An easy way
171
+ to do this is to run <command>vacuumdb -a -z</>; this is
172
+ equivalent to running <command>VACUUM ANALYZE</> on each database
173
+ manually. For more advice on how to load large amounts of data
174
+ into <productname>PostgreSQL</> efficiently, refer to <xref
158
175
linkend="populate">.
159
176
</para>
160
177
</sect2>
0 commit comments