]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/pg_dumpall.sgml
9a891cd1fb34ede32d53118fee2bfdb8831634ca
[postgresql] / doc / src / sgml / ref / pg_dumpall.sgml
1 <!--
2 $PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.46 2004/07/19 21:39:46 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    Thus, <application>pg_dumpall</application> is an integrated
48    solution for backing up your databases.  But note a limitation:
49    it cannot dump <quote>large objects</quote>, since
50    <application>pg_dump</application> cannot dump such objects into
51    text files.  If you have databases containing large objects,
52    they should be dumped using one of <application>pg_dump</application>'s
53    non-text output modes.
54   </para>
55
56   <para>
57    Since <application>pg_dumpall</application> reads tables from all
58    databases you will most likely have to connect as a database
59    superuser in order to produce a complete dump.  Also you will need
60    superuser privileges to execute the saved script in order to be
61    allowed to add users and groups, and to create databases.
62   </para>
63
64   <para>
65    The SQL script will be written to the standard output.  Shell
66    operators should be used to redirect it into a file.
67   </para>
68
69   <para>
70   <application>pg_dumpall</application> needs to connect several
71   times to the <productname>PostgreSQL</productname> server and might be asking for
72   a password each time. It is convenient to have a
73   <filename>$HOME/.pgpass</> file in such cases.
74   </para>
75
76  </refsect1>
77
78  <refsect1>
79   <title>Options</title>
80
81    <para>
82     The following command-line options are used to control the content and
83     format of the output.
84
85     <variablelist>
86      <varlistentry>
87       <term><option>-a</></term>
88       <term><option>--data-only</></term>
89       <listitem>
90        <para>
91         Dump only the data, not the schema (data definitions).
92        </para>
93       </listitem>
94      </varlistentry>
95
96      <varlistentry>
97       <term><option>-c</option></term>
98       <term><option>--clean</option></term>
99       <listitem>
100        <para>
101         Include SQL commands to clean (drop) the databases before
102         recreating them.
103        </para>
104       </listitem>
105      </varlistentry>
106
107      <varlistentry>
108       <term><option>-d</option></term>
109       <term><option>--inserts</option></term>
110       <listitem>
111        <para>
112         Dump data as <command>INSERT</command> commands (rather
113         than <command>COPY</command>). This will make restoration very
114         slow, but it makes the output more portable to other SQL database
115         management systems.
116        </para>
117       </listitem>
118      </varlistentry>
119
120      <varlistentry>
121       <term><option>-D</option></term>
122       <term><option>--column-inserts</option></term>
123       <term><option>--attribute-inserts</option></term>
124       <listitem>
125        <para>
126         Dump data as <command>INSERT</command> commands with explicit
127         column names (<literal>INSERT INTO
128         <replaceable>table</replaceable>
129         (<replaceable>column</replaceable>, ...) VALUES
130         ...</literal>).  This will make restoration very slow,
131         but it is necessary if you desire to rearrange column ordering.
132        </para>
133       </listitem>
134      </varlistentry>
135
136      <varlistentry>
137       <term><option>-g</option></term>
138       <term><option>--globals-only</option></term>
139       <listitem>
140        <para>
141         Dump only global objects (users and groups), no databases.
142        </para>
143       </listitem>
144      </varlistentry>
145
146      <varlistentry>
147       <term><option>-i</></term>
148       <term><option>--ignore-version</></term>
149       <listitem>
150        <para>
151         Ignore version mismatch between
152         <application>pg_dumpall</application> and the database server.
153        </para>
154
155        <para>
156         <application>pg_dumpall</application> can handle databases
157         from previous releases of <productname>PostgreSQL</>, but very
158         old versions are not supported anymore (currently prior to
159         7.0).  Use this option if you need to override the version
160         check (and if <application>pg_dumpall</application> then
161         fails, don't say you weren't warned).
162        </para>
163       </listitem>
164      </varlistentry>
165
166      <varlistentry>
167       <term><option>-o</></term>
168       <term><option>--oids</></term>
169       <listitem>
170        <para>
171         Dump object identifiers (<acronym>OID</acronym>s) for every
172         table.  Use this option if your application references the OID
173         columns in some way (e.g., in a foreign key constraint).
174         Otherwise, this option should not be used.
175        </para>
176       </listitem>
177      </varlistentry>
178
179      <varlistentry>
180       <term><option>-O</></term>
181       <term><option>--no-owner</option></term>
182       <listitem>
183        <para>
184         Do not output commands to set
185         ownership of objects to match the original database.
186         By default, <application>pg_dumpall</application> issues
187         <command>SET SESSION AUTHORIZATION</command>
188         statements to set ownership of created schema elements.
189         These statements
190         will fail when the script is run unless it is started by a superuser
191         (or the same user that owns all of the objects in the script).
192         To make a script that can be restored by any user, but will give
193         that user ownership of all the objects, specify <option>-O</>.
194        </para>
195       </listitem>
196      </varlistentry>
197
198      <varlistentry>
199       <term><option>-s</option></term>
200       <term><option>--schema-only</option></term>
201       <listitem>
202        <para>
203         Dump only the schema (data definitions), no data.
204        </para>
205       </listitem>
206      </varlistentry>
207
208      <varlistentry>
209       <term><option>-S <replaceable class="parameter">username</replaceable></option></term>
210       <term><option>--superuser=<replaceable class="parameter">username</replaceable></option></term>
211       <listitem>
212        <para>
213         Specify the superuser user name to use when disabling triggers.
214         This is only relevant if <option>--disable-triggers</> is used.
215         (Usually, it's better to leave this out, and instead start the
216         resulting script as superuser.)
217        </para>
218       </listitem>
219      </varlistentry>
220
221      <varlistentry>
222       <term><option>-v</></term>
223       <term><option>--verbose</></term>
224       <listitem>
225        <para>
226         Specifies verbose mode.  This will cause
227         <application>pg_dumpall</application> to output start/stop
228         times to the dump file, and progress messages to standard error.
229         It will also enable verbose output in <application>pg_dump</>.
230        </para>
231       </listitem>
232      </varlistentry>
233
234      <varlistentry>
235       <term><option>-x</></term>
236       <term><option>--no-privileges</></term>
237       <term><option>--no-acl</></term>
238       <listitem>
239        <para>
240         Prevent dumping of access privileges (grant/revoke commands).
241        </para>
242       </listitem>
243      </varlistentry>
244
245      <varlistentry>
246       <term><option>-X disable-dollar-quoting</></term>
247       <term><option>--disable-dollar-quoting</></term>
248       <listitem>
249        <para>
250         This option disables the use of dollar quoting for function bodies,
251         and forces them to be quoted using SQL standard string syntax.
252        </para>
253      </listitem>
254     </varlistentry>
255
256      <varlistentry>
257       <term><option>-X disable-triggers</></term>
258       <term><option>--disable-triggers</></term>
259       <listitem>
260        <para>
261         This option is only relevant when creating a data-only dump.
262         It instructs <application>pg_dumpall</application> to include commands
263         to temporarily disable triggers on the target tables while
264         the data is reloaded.  Use this if you have referential
265         integrity checks or other triggers on the tables that you
266         do not want to invoke during data reload.
267        </para>
268
269        <para>
270         Presently, the commands emitted for <option>--disable-triggers</>
271         must be done as superuser.  So, you should also specify
272         a superuser name with <option>-S</>, or preferably be careful to
273         start the resulting script as a superuser.
274        </para>
275       </listitem>
276      </varlistentry>
277
278      <varlistentry>
279       <term><option>-X use-set-session-authorization</></term>
280       <term><option>--use-set-session-authorization</></term>
281       <listitem>
282        <para>
283         Output SQL standard SET SESSION AUTHORIZATION commands instead
284         of OWNER TO commands.  This makes the dump more standards compatible,
285         but depending on the history of the objects in the dump, may not
286         restore properly.
287        </para>
288       </listitem>
289      </varlistentry>
290
291     </variablelist>
292    </para>
293
294   <para>
295    The following command-line options control the database connection parameters.
296
297    <variablelist>
298      <varlistentry>
299       <term>-h <replaceable>host</replaceable></term>
300       <listitem>
301        <para>
302         Specifies the host name of the machine on which the database
303         server is running.  If the value begins with a slash, it is
304         used as the directory for the Unix domain socket.  The default
305         is taken from the <envar>PGHOST</envar> environment variable,
306         if set, else a Unix domain socket connection is attempted.
307        </para>
308       </listitem>
309      </varlistentry>
310
311      <varlistentry>
312       <term>-p <replaceable>port</replaceable></term>
313       <listitem>
314        <para>
315         Specifies the TCP port or local Unix domain socket file
316         extension on which the server is listening for connections.
317         Defaults to the <envar>PGPORT</envar> environment variable, if
318         set, or a compiled-in default.
319        </para>
320       </listitem>
321      </varlistentry>
322
323      <varlistentry>
324       <term>-U <replaceable>username</replaceable></term>
325       <listitem>
326        <para>
327         Connect as the given user.
328        </para>
329       </listitem>
330      </varlistentry>
331
332      <varlistentry>
333       <term>-W</term>
334       <listitem>
335        <para>
336         Force a password prompt.  This should happen automatically if
337         the server requires password authentication.
338        </para>
339       </listitem>
340      </varlistentry>
341    </variablelist>
342   </para>
343  </refsect1>
344
345
346  <refsect1>
347   <title>Environment</title>
348
349   <variablelist>
350    <varlistentry>
351     <term><envar>PGHOST</envar></term>
352     <term><envar>PGPORT</envar></term>
353     <term><envar>PGUSER</envar></term>
354
355     <listitem>
356      <para>
357       Default connection parameters
358      </para>
359     </listitem>
360    </varlistentry>
361   </variablelist>
362  </refsect1>
363
364
365  <refsect1>
366   <title>Notes</title>
367
368   <para>
369    Since <application>pg_dumpall</application> calls
370    <application>pg_dump</application> internally, some diagnostic
371    messages will refer to <application>pg_dump</application>.
372   </para>
373
374   <para>
375    Once restored, it is wise to run <command>ANALYZE</> on each
376    database so the optimizer has useful statistics. You
377    can also run <command>vacuumdb -a -z</> to analyze all
378    databases.
379   </para>
380
381  </refsect1>
382
383
384  <refsect1 id="app-pg-dumpall-ex">
385   <title>Examples</title>
386   <para>
387    To dump all databases:
388
389 <screen>
390 <prompt>$</prompt> <userinput>pg_dumpall &gt; db.out</userinput>
391 </screen>
392   </para>
393
394   <para>
395    To reload this database use, for example:
396 <screen>
397 <prompt>$</prompt> <userinput>psql -f db.out template1</userinput>
398 </screen>
399    (It is not important to which database you connect here since the
400    script file created by <application>pg_dumpall</application> will
401    contain the appropriate commands to create and connect to the saved
402    databases.)
403   </para>
404  </refsect1>
405
406  <refsect1>
407   <title>See Also</title>
408
409   <para>
410     <xref linkend="app-pgdump">.  Check there for details on possible
411     error conditions.
412   </para>
413  </refsect1>   
414
415 </refentry>
416
417 <!-- Keep this comment at the end of the file
418 Local variables:
419 mode: sgml
420 sgml-omittag:nil
421 sgml-shorttag:t
422 sgml-minimize-attributes:nil
423 sgml-always-quote-attributes:t
424 sgml-indent-step:1
425 sgml-indent-data:t
426 sgml-parent-document:nil
427 sgml-default-dtd-file:"../reference.ced"
428 sgml-exposed-tags:nil
429 sgml-local-catalogs:"/usr/lib/sgml/catalog"
430 sgml-local-ecat-files:nil
431 End:
432 -->