]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/pg_dumpall.sgml
0a3b44c48ab620789bea0477ebf50e42e86a30a4
[postgresql] / doc / src / sgml / ref / pg_dumpall.sgml
1 <!--
2 $PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.61 2007/01/25 02:46:33 momjian Exp $
3 PostgreSQL documentation
4 -->
5
6 <refentry id="APP-PG-DUMPALL">
7  <refmeta>
8   <refentrytitle id="APP-PG-DUMPALL-TITLE"><application>pg_dumpall</application></refentrytitle>
9   <manvolnum>1</manvolnum>
10   <refmiscinfo>Application</refmiscinfo>
11  </refmeta>
12
13  <refnamediv>
14   <refname>pg_dumpall</refname>
15   <refpurpose>extract a <productname>PostgreSQL</productname> database cluster into a script file</refpurpose>
16  </refnamediv>
17
18  <indexterm zone="app-pg-dumpall">
19   <primary>pg_dumpall</primary>
20  </indexterm>
21
22  <refsynopsisdiv>
23   <cmdsynopsis>
24    <command>pg_dumpall</command>
25    <arg rep="repeat"><replaceable>option</replaceable></arg>
26   </cmdsynopsis>
27  </refsynopsisdiv>
28
29  <refsect1 id="app-pg-dumpall-description">
30   <title>Description</title>
31
32   <para>
33    <application>pg_dumpall</application> is a utility for writing out
34    (<quote>dumping</quote>) all <productname>PostgreSQL</> databases
35    of a cluster into one script file.  The script file contains
36    <acronym>SQL</acronym> commands that can be used as input to <xref
37    linkend="app-psql"> to restore the databases.  It does this by
38    calling <xref linkend="app-pgdump"> for each database in a cluster.
39    <application>pg_dumpall</application> also dumps global objects
40    that are common to all databases.
41    (<application>pg_dump</application> does not save these objects.)
42    This currently includes information about database users and
43    groups, and access permissions that apply to databases as a whole.
44   </para>
45
46   <para>
47    Since <application>pg_dumpall</application> reads tables from all
48    databases you will most likely have to connect as a database
49    superuser in order to produce a complete dump.  Also you will need
50    superuser privileges to execute the saved script in order to be
51    allowed to add users and groups, and to create databases.
52   </para>
53
54   <para>
55    The SQL script will be written to the standard output.  Shell
56    operators should be used to redirect it into a file.
57   </para>
58
59   <para>
60   <application>pg_dumpall</application> needs to connect several
61   times to the <productname>PostgreSQL</productname> server (once per
62   database).  If you use password authentication it is likely to ask for
63   a password each time. It is convenient to have a
64   <filename>~/.pgpass</> file in such cases. See <xref
65   linkend="libpq-pgpass"> for more information.
66   </para>
67
68  </refsect1>
69
70  <refsect1>
71   <title>Options</title>
72
73    <para>
74     The following command-line options control the content and
75     format of the output.
76
77     <variablelist>
78      <varlistentry>
79       <term><option>-a</></term>
80       <term><option>--data-only</></term>
81       <listitem>
82        <para>
83         Dump only the data, not the schema (data definitions).
84        </para>
85       </listitem>
86      </varlistentry>
87
88      <varlistentry>
89       <term><option>-c</option></term>
90       <term><option>--clean</option></term>
91       <listitem>
92        <para>
93         Include SQL commands to clean (drop) databases before
94         recreating them.  <command>DROP</> commands for roles and
95         tablespaces are added as well.
96        </para>
97       </listitem>
98      </varlistentry>
99
100      <varlistentry>
101       <term><option>-d</option></term>
102       <term><option>--inserts</option></term>
103       <listitem>
104        <para>
105         Dump data as <command>INSERT</command> commands (rather
106         than <command>COPY</command>).  This will make restoration very slow;
107         it is mainly useful for making dumps that can be loaded into
108         non-<productname>PostgreSQL</productname> databases.  Note that
109         the restore may fail altogether if you have rearranged column order.
110         The <option>-D</option> option is safer, though even slower.
111        </para>
112       </listitem>
113      </varlistentry>
114
115      <varlistentry>
116       <term><option>-D</option></term>
117       <term><option>--column-inserts</option></term>
118       <term><option>--attribute-inserts</option></term>
119       <listitem>
120        <para>
121         Dump data as <command>INSERT</command> commands with explicit
122         column names (<literal>INSERT INTO
123         <replaceable>table</replaceable>
124         (<replaceable>column</replaceable>, ...) VALUES
125         ...</literal>).  This will make restoration very slow; it is mainly
126         useful for making dumps that can be loaded into
127         non-<productname>PostgreSQL</productname> databases.
128        </para>
129       </listitem>
130      </varlistentry>
131
132      <varlistentry>
133       <term><option>-g</option></term>
134       <term><option>--globals-only</option></term>
135       <listitem>
136        <para>
137         Dump only global objects (roles and tablespaces), no databases.
138        </para>
139       </listitem>
140      </varlistentry>
141
142      <varlistentry>
143       <term><option>-i</></term>
144       <term><option>--ignore-version</></term>
145       <listitem>
146        <para>
147         Ignore version mismatch between
148         <application>pg_dumpall</application> and the database server.
149        </para>
150
151        <para>
152         <application>pg_dumpall</application> can handle databases
153         from previous releases of <productname>PostgreSQL</>, but very
154         old versions are not supported anymore (currently prior to
155         7.0).  Use this option if you need to override the version
156         check (and if <application>pg_dumpall</application> then
157         fails, don't say you weren't warned).
158        </para>
159       </listitem>
160      </varlistentry>
161
162      <varlistentry>
163       <term><option>-o</></term>
164       <term><option>--oids</></term>
165       <listitem>
166        <para>
167         Dump object identifiers (<acronym>OID</acronym>s) as part of the
168         data for every table.  Use this option if your application references
169         the <acronym>OID</>
170         columns in some way (e.g., in a foreign key constraint).
171         Otherwise, this option should not be used.
172        </para>
173       </listitem>
174      </varlistentry>
175
176      <varlistentry>
177       <term><option>-O</></term>
178       <term><option>--no-owner</option></term>
179       <listitem>
180        <para>
181         Do not output commands to set
182         ownership of objects to match the original database.
183         By default, <application>pg_dumpall</application> issues
184         <command>ALTER OWNER</> or 
185         <command>SET SESSION AUTHORIZATION</command>
186         statements to set ownership of created schema elements.
187         These statements
188         will fail when the script is run unless it is started by a superuser
189         (or the same user that owns all of the objects in the script).
190         To make a script that can be restored by any user, but will give
191         that user ownership of all the objects, specify <option>-O</>.
192        </para>
193       </listitem>
194      </varlistentry>
195
196      <varlistentry>
197       <term><option>-r</option></term>
198       <term><option>--roles-only</option></term>
199       <listitem>
200        <para>
201         Dump only roles, no databases or tablespaces.
202        </para>
203       </listitem>
204      </varlistentry>
205
206      <varlistentry>
207       <term><option>-s</option></term>
208       <term><option>--schema-only</option></term>
209       <listitem>
210        <para>
211         Dump only the object definitions (schema), not data.
212        </para>
213       </listitem>
214      </varlistentry>
215
216      <varlistentry>
217       <term><option>-S <replaceable class="parameter">username</replaceable></option></term>
218       <term><option>--superuser=<replaceable class="parameter">username</replaceable></option></term>
219       <listitem>
220        <para>
221         Specify the superuser user name to use when disabling triggers.
222         This is only relevant if <option>--disable-triggers</> is used.
223         (Usually, it's better to leave this out, and instead start the
224         resulting script as superuser.)
225        </para>
226       </listitem>
227      </varlistentry>
228
229      <varlistentry>
230       <term><option>-t</option></term>
231       <term><option>--tablespaces-only</option></term>
232       <listitem>
233        <para>
234         Dump only tablespaces, no databases or roles.
235        </para>
236       </listitem>
237      </varlistentry>
238
239      <varlistentry>
240       <term><option>-v</></term>
241       <term><option>--verbose</></term>
242       <listitem>
243        <para>
244         Specifies verbose mode.  This will cause
245         <application>pg_dumpall</application> to output start/stop
246         times to the dump file, and progress messages to standard error.
247         It will also enable verbose output in <application>pg_dump</>.
248        </para>
249       </listitem>
250      </varlistentry>
251
252      <varlistentry>
253       <term><option>-x</></term>
254       <term><option>--no-privileges</></term>
255       <term><option>--no-acl</></term>
256       <listitem>
257        <para>
258         Prevent dumping of access privileges (grant/revoke commands).
259        </para>
260       </listitem>
261      </varlistentry>
262
263      <varlistentry>
264       <term><option>--disable-dollar-quoting</></term>
265       <listitem>
266        <para>
267         This option disables the use of dollar quoting for function bodies,
268         and forces them to be quoted using SQL standard string syntax.
269        </para>
270      </listitem>
271     </varlistentry>
272
273      <varlistentry>
274       <term><option>--disable-triggers</></term>
275       <listitem>
276        <para>
277         This option is only relevant when creating a data-only dump.
278         It instructs <application>pg_dumpall</application> to include commands
279         to temporarily disable triggers on the target tables while
280         the data is reloaded.  Use this if you have referential
281         integrity checks or other triggers on the tables that you
282         do not want to invoke during data reload.
283        </para>
284
285        <para>
286         Presently, the commands emitted for <option>--disable-triggers</>
287         must be done as superuser.  So, you should also specify
288         a superuser name with <option>-S</>, or preferably be careful to
289         start the resulting script as a superuser.
290        </para>
291       </listitem>
292      </varlistentry>
293
294      <varlistentry>
295       <term><option>--use-set-session-authorization</></term>
296       <listitem>
297        <para>
298         Output SQL-standard <command>SET SESSION AUTHORIZATION</> commands
299         instead of <command>ALTER OWNER</> commands to determine object
300         ownership.  This makes the dump more standards compatible, but
301         depending on the history of the objects in the dump, may not restore
302         properly.
303        </para>
304       </listitem>
305      </varlistentry>
306
307     </variablelist>
308    </para>
309
310   <para>
311    The following command-line options control the database connection parameters.
312
313    <variablelist>
314      <varlistentry>
315       <term>-h <replaceable>host</replaceable></term>
316       <term>--host=<replaceable>host</replaceable></term>
317       <listitem>
318        <para>
319         Specifies the host name of the machine on which the database
320         server is running.  If the value begins with a slash, it is
321         used as the directory for the Unix domain socket.  The default
322         is taken from the <envar>PGHOST</envar> environment variable,
323         if set, else a Unix domain socket connection is attempted.
324        </para>
325       </listitem>
326      </varlistentry>
327          
328      <varlistentry>
329       <term>-l <replaceable>dbname</replaceable></term>
330       <term>--database=<replaceable>dbname</replaceable></term>
331       <listitem>
332        <para>
333          Specifies the name of the database to connect to to dump global
334          objects and discover what other databases should be dumped. If
335          not specified, the <quote>postgres</quote> database will be used,
336          and if that does not exist, <quote>template1</quote> will be used.
337        </para>
338       </listitem>
339      </varlistentry>
340
341      <varlistentry>
342       <term>-p <replaceable>port</replaceable></term>
343       <term>--port=<replaceable>port</replaceable></term>
344       <listitem>
345        <para>
346         Specifies the TCP port or local Unix domain socket file
347         extension on which the server is listening for connections.
348         Defaults to the <envar>PGPORT</envar> environment variable, if
349         set, or a compiled-in default.
350        </para>
351       </listitem>
352      </varlistentry>
353
354      <varlistentry>
355       <term>-U <replaceable>username</replaceable></term>
356       <term>--username=<replaceable>username</replaceable></term>
357       <listitem>
358        <para>
359         Connect as the given user.
360        </para>
361       </listitem>
362      </varlistentry>
363
364      <varlistentry>
365       <term>-W</term>
366             <term>--password</term>
367       <listitem>
368        <para>
369         Force a password prompt.  This should happen automatically if
370         the server requires password authentication.
371        </para>
372       </listitem>
373      </varlistentry>
374    </variablelist>
375   </para>
376  </refsect1>
377
378
379  <refsect1>
380   <title>Environment</title>
381
382   <variablelist>
383    <varlistentry>
384     <term><envar>PGHOST</envar></term>
385     <term><envar>PGPORT</envar></term>
386     <term><envar>PGUSER</envar></term>
387
388     <listitem>
389      <para>
390       Default connection parameters
391      </para>
392     </listitem>
393    </varlistentry>
394   </variablelist>
395  </refsect1>
396
397
398  <refsect1>
399   <title>Notes</title>
400
401   <para>
402    Since <application>pg_dumpall</application> calls
403    <application>pg_dump</application> internally, some diagnostic
404    messages will refer to <application>pg_dump</application>.
405   </para>
406
407   <para>
408    Once restored, it is wise to run <command>ANALYZE</> on each
409    database so the optimizer has useful statistics. You
410    can also run <command>vacuumdb -a -z</> to analyze all
411    databases.
412   </para>
413
414   <para>
415    <application>pg_dumpall</application> requires all needed
416    tablespace directories to exist before the restore or
417    database creation will fail for databases in non-default
418    locations.
419   </para>
420
421  </refsect1>
422
423
424  <refsect1 id="app-pg-dumpall-ex">
425   <title>Examples</title>
426   <para>
427    To dump all databases:
428
429 <screen>
430 <prompt>$</prompt> <userinput>pg_dumpall &gt; db.out</userinput>
431 </screen>
432   </para>
433
434   <para>
435    To reload this database use, for example:
436 <screen>
437 <prompt>$</prompt> <userinput>psql -f db.out postgres</userinput>
438 </screen>
439    (It is not important to which database you connect here since the
440    script file created by <application>pg_dumpall</application> will
441    contain the appropriate commands to create and connect to the saved
442    databases.)
443   </para>
444  </refsect1>
445
446  <refsect1>
447   <title>See Also</title>
448
449   <para>
450     <xref linkend="app-pgdump">.  Check there for details on possible
451     error conditions.  Also see supported environment variables
452     (<xref linkend="libpq-envars">).
453   </para>
454  </refsect1>   
455
456 </refentry>