pg_dumpall.sgml 14.6 KB
Newer Older
1
<!--
2
$PostgreSQL: pgsql/doc/src/sgml/ref/pg_dumpall.sgml,v 1.64 2007/01/31 23:26:04 momjian Exp $
3
PostgreSQL documentation
4 5
-->

6
<refentry id="APP-PG-DUMPALL">
7
 <refmeta>
8 9
  <refentrytitle id="APP-PG-DUMPALL-TITLE"><application>pg_dumpall</application></refentrytitle>
  <manvolnum>1</manvolnum>
10 11
  <refmiscinfo>Application</refmiscinfo>
 </refmeta>
12

13
 <refnamediv>
14
  <refname>pg_dumpall</refname>
15
  <refpurpose>extract a <productname>PostgreSQL</productname> database cluster into a script file</refpurpose>
16 17
 </refnamediv>

P
Peter Eisentraut 已提交
18 19 20 21
 <indexterm zone="app-pg-dumpall">
  <primary>pg_dumpall</primary>
 </indexterm>

22 23 24
 <refsynopsisdiv>
  <cmdsynopsis>
   <command>pg_dumpall</command>
25
   <arg rep="repeat"><replaceable>option</replaceable></arg>
26 27
  </cmdsynopsis>
 </refsynopsisdiv>
28

29 30
 <refsect1 id="app-pg-dumpall-description">
  <title>Description</title>
31

32 33
  <para>
   <application>pg_dumpall</application> is a utility for writing out
B
Bruce Momjian 已提交
34 35 36 37 38 39 40
   (<quote>dumping</quote>) all <productname>PostgreSQL</> databases
   of a cluster into one script file.  The script file contains
   <acronym>SQL</acronym> commands that can be used as input to <xref
   linkend="app-psql"> to restore the databases.  It does this by
   calling <xref linkend="app-pgdump"> for each database in a cluster.
   <application>pg_dumpall</application> also dumps global objects
   that are common to all databases.
41
   (<application>pg_dump</application> does not save these objects.)
42 43
   This currently includes information about database users and
   groups, and access permissions that apply to databases as a whole.
44
  </para>
45

46 47 48 49
  <para>
   Since <application>pg_dumpall</application> reads tables from all
   databases you will most likely have to connect as a database
   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 52
   allowed to add users and groups, and to create databases.
  </para>
53

54
  <para>
B
Bruce Momjian 已提交
55
   The SQL script will be written to the standard output.  Shell
56 57
   operators should be used to redirect it into a file.
  </para>
58 59

  <para>
60
  <application>pg_dumpall</application> needs to connect several
T
Tom Lane 已提交
61 62
  times to the <productname>PostgreSQL</productname> server (once per
  database).  If you use password authentication it is likely to ask for
63
  a password each time. It is convenient to have a
64 65
  <filename>~/.pgpass</> file in such cases. See <xref
  linkend="libpq-pgpass"> for more information.
66 67
  </para>

B
Bruce Momjian 已提交
68 69 70 71
 </refsect1>

 <refsect1>
  <title>Options</title>
72

73
   <para>
T
Tom Lane 已提交
74
    The following command-line options control the content and
75
    format of the output.
B
Bruce Momjian 已提交
76

77
    <variablelist>
78 79 80 81 82
     <varlistentry>
      <term><option>-a</></term>
      <term><option>--data-only</></term>
      <listitem>
       <para>
T
Tom Lane 已提交
83
        Dump only the data, not the schema (data definitions).
84 85 86 87
       </para>
      </listitem>
     </varlistentry>

88
     <varlistentry>
89 90
      <term><option>-c</option></term>
      <term><option>--clean</option></term>
91 92
      <listitem>
       <para>
93 94 95
        Include SQL commands to clean (drop) databases before
        recreating them.  <command>DROP</> commands for roles and
        tablespaces are added as well.
96 97 98 99 100 101 102 103 104
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-d</option></term>
      <term><option>--inserts</option></term>
      <listitem>
       <para>
T
Tom Lane 已提交
105 106 107 108
        Dump data as <command>INSERT</command> commands (rather
        than <command>COPY</command>).  This will make restoration very slow;
        it is mainly useful for making dumps that can be loaded into
        non-<productname>PostgreSQL</productname> databases.  Note that
109
        the restore might fail altogether if you have rearranged column order.
T
Tom Lane 已提交
110
        The <option>-D</option> option is safer, though even slower.
111 112 113 114 115 116 117 118 119 120
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-D</option></term>
      <term><option>--column-inserts</option></term>
      <term><option>--attribute-inserts</option></term>
      <listitem>
       <para>
T
Tom Lane 已提交
121 122 123 124 125 126 127
        Dump data as <command>INSERT</command> commands with explicit
        column names (<literal>INSERT INTO
        <replaceable>table</replaceable>
        (<replaceable>column</replaceable>, ...) VALUES
        ...</literal>).  This will make restoration very slow; it is mainly
        useful for making dumps that can be loaded into
        non-<productname>PostgreSQL</productname> databases.
128 129 130
       </para>
      </listitem>
     </varlistentry>
131 132 133 134 135 136
	 
     <varlistentry>
      <term><option>-f <replaceable class="parameter">filename</replaceable></option></term>
      <term><option>--file=<replaceable class="parameter">filename</replaceable></option></term>
      <listitem>
       <para>
137 138
        Send output to the specified file.  If this is omitted, the
        standard output is used.
139 140 141
       </para>
      </listitem>
     </varlistentry>
142 143

     <varlistentry>
144 145
      <term><option>-g</option></term>
      <term><option>--globals-only</option></term>
146 147
      <listitem>
       <para>
148
        Dump only global objects (roles and tablespaces), no databases.
149 150 151 152 153 154 155 156 157 158 159
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-i</></term>
      <term><option>--ignore-version</></term>
      <listitem>
       <para>
        Ignore version mismatch between
        <application>pg_dumpall</application> and the database server.
160 161 162 163
       </para>

       <para>
        <application>pg_dumpall</application> can handle databases
B
Bruce Momjian 已提交
164 165 166 167 168
        from previous releases of <productname>PostgreSQL</>, but very
        old versions are not supported anymore (currently prior to
        7.0).  Use this option if you need to override the version
        check (and if <application>pg_dumpall</application> then
        fails, don't say you weren't warned).
169 170 171 172 173 174 175 176 177
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>-o</></term>
      <term><option>--oids</></term>
      <listitem>
       <para>
T
Tom Lane 已提交
178 179 180 181 182
        Dump object identifiers (<acronym>OID</acronym>s) as part of the
        data for every table.  Use this option if your application references
        the <acronym>OID</>
        columns in some way (e.g., in a foreign key constraint).
        Otherwise, this option should not be used.
183 184 185 186
       </para>
      </listitem>
     </varlistentry>

187 188 189 190 191 192
     <varlistentry>
      <term><option>-O</></term>
      <term><option>--no-owner</option></term>
      <listitem>
       <para>
        Do not output commands to set
T
Tom Lane 已提交
193 194 195 196 197 198 199 200 201 202
        ownership of objects to match the original database.
        By default, <application>pg_dumpall</application> issues
        <command>ALTER OWNER</> or 
        <command>SET SESSION AUTHORIZATION</command>
        statements to set ownership of created schema elements.
        These statements
        will fail when the script is run unless it is started by a superuser
        (or the same user that owns all of the objects in the script).
        To make a script that can be restored by any user, but will give
        that user ownership of all the objects, specify <option>-O</>.
203 204 205 206
       </para>
      </listitem>
     </varlistentry>

207 208 209 210 211 212 213 214 215 216
     <varlistentry>
      <term><option>-r</option></term>
      <term><option>--roles-only</option></term>
      <listitem>
       <para>
        Dump only roles, no databases or tablespaces.
       </para>
      </listitem>
     </varlistentry>

217 218 219 220 221
     <varlistentry>
      <term><option>-s</option></term>
      <term><option>--schema-only</option></term>
      <listitem>
       <para>
T
Tom Lane 已提交
222
        Dump only the object definitions (schema), not data.
223 224 225 226
       </para>
      </listitem>
     </varlistentry>

227 228 229 230 231 232
     <varlistentry>
      <term><option>-S <replaceable class="parameter">username</replaceable></option></term>
      <term><option>--superuser=<replaceable class="parameter">username</replaceable></option></term>
      <listitem>
       <para>
        Specify the superuser user name to use when disabling triggers.
T
Tom Lane 已提交
233 234 235
        This is only relevant if <option>--disable-triggers</> is used.
        (Usually, it's better to leave this out, and instead start the
        resulting script as superuser.)
236 237 238 239
       </para>
      </listitem>
     </varlistentry>

240 241 242 243 244 245 246 247 248 249
     <varlistentry>
      <term><option>-t</option></term>
      <term><option>--tablespaces-only</option></term>
      <listitem>
       <para>
        Dump only tablespaces, no databases or roles.
       </para>
      </listitem>
     </varlistentry>

250 251 252 253 254
     <varlistentry>
      <term><option>-v</></term>
      <term><option>--verbose</></term>
      <listitem>
       <para>
T
Tom Lane 已提交
255 256
        Specifies verbose mode.  This will cause
        <application>pg_dumpall</application> to output start/stop
257 258
        times to the dump file, and progress messages to standard error.
        It will also enable verbose output in <application>pg_dump</>.
259 260 261
       </para>
      </listitem>
     </varlistentry>
262 263 264 265 266 267 268

     <varlistentry>
      <term><option>-x</></term>
      <term><option>--no-privileges</></term>
      <term><option>--no-acl</></term>
      <listitem>
       <para>
T
Tom Lane 已提交
269
        Prevent dumping of access privileges (grant/revoke commands).
270 271 272
       </para>
      </listitem>
     </varlistentry>
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308

     <varlistentry>
      <term><option>--disable-dollar-quoting</></term>
      <listitem>
       <para>
        This option disables the use of dollar quoting for function bodies,
        and forces them to be quoted using SQL standard string syntax.
       </para>
     </listitem>
    </varlistentry>

     <varlistentry>
      <term><option>--disable-triggers</></term>
      <listitem>
       <para>
        This option is only relevant when creating a data-only dump.
        It instructs <application>pg_dumpall</application> to include commands
        to temporarily disable triggers on the target tables while
        the data is reloaded.  Use this if you have referential
        integrity checks or other triggers on the tables that you
        do not want to invoke during data reload.
       </para>

       <para>
        Presently, the commands emitted for <option>--disable-triggers</>
        must be done as superuser.  So, you should also specify
        a superuser name with <option>-S</>, or preferably be careful to
        start the resulting script as a superuser.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term><option>--use-set-session-authorization</></term>
      <listitem>
       <para>
309 310 311
        Output SQL-standard <command>SET SESSION AUTHORIZATION</> commands
        instead of <command>ALTER OWNER</> commands to determine object
        ownership.  This makes the dump more standards compatible, but
312
        depending on the history of the objects in the dump, might not restore
313
        properly.
314 315 316
       </para>
      </listitem>
     </varlistentry>
317

318 319 320 321 322 323 324 325 326
    </variablelist>
   </para>

  <para>
   The following command-line options control the database connection parameters.

   <variablelist>
     <varlistentry>
      <term>-h <replaceable>host</replaceable></term>
327
      <term>--host=<replaceable>host</replaceable></term>
328 329
      <listitem>
       <para>
T
Tom Lane 已提交
330 331 332 333 334
        Specifies the host name of the machine on which the database
        server is running.  If the value begins with a slash, it is
        used as the directory for the Unix domain socket.  The default
        is taken from the <envar>PGHOST</envar> environment variable,
        if set, else a Unix domain socket connection is attempted.
335 336 337
       </para>
      </listitem>
     </varlistentry>
338 339 340 341 342 343 344 345 346 347 348 349 350
	 
     <varlistentry>
      <term>-l <replaceable>dbname</replaceable></term>
      <term>--database=<replaceable>dbname</replaceable></term>
      <listitem>
       <para>
         Specifies the name of the database to connect to to dump global
         objects and discover what other databases should be dumped. If
         not specified, the <quote>postgres</quote> database will be used,
         and if that does not exist, <quote>template1</quote> will be used.
       </para>
      </listitem>
     </varlistentry>
351 352 353

     <varlistentry>
      <term>-p <replaceable>port</replaceable></term>
354
      <term>--port=<replaceable>port</replaceable></term>
355 356
      <listitem>
       <para>
T
Tom Lane 已提交
357 358 359 360
        Specifies the TCP port or local Unix domain socket file
        extension on which the server is listening for connections.
        Defaults to the <envar>PGPORT</envar> environment variable, if
        set, or a compiled-in default.
361 362 363 364 365 366
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term>-U <replaceable>username</replaceable></term>
367
      <term>--username=<replaceable>username</replaceable></term>
368 369
      <listitem>
       <para>
370
        Connect as the given user.
371 372 373 374 375 376
       </para>
      </listitem>
     </varlistentry>

     <varlistentry>
      <term>-W</term>
377
	    <term>--password</term>
378 379
      <listitem>
       <para>
380 381
        Force a password prompt.  This should happen automatically if
        the server requires password authentication.
382 383 384
       </para>
      </listitem>
     </varlistentry>
B
Bruce Momjian 已提交
385 386
   </variablelist>
  </para>
387
 </refsect1>
388

389 390 391 392 393 394 395 396 397 398 399 400

 <refsect1>
  <title>Environment</title>

  <variablelist>
   <varlistentry>
    <term><envar>PGHOST</envar></term>
    <term><envar>PGPORT</envar></term>
    <term><envar>PGUSER</envar></term>

    <listitem>
     <para>
401
      Default connection parameters
402 403 404 405 406 407 408
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </refsect1>


409 410 411 412 413 414 415 416 417
 <refsect1>
  <title>Notes</title>

  <para>
   Since <application>pg_dumpall</application> calls
   <application>pg_dump</application> internally, some diagnostic
   messages will refer to <application>pg_dump</application>.
  </para>

418 419 420
  <para>
   Once restored, it is wise to run <command>ANALYZE</> on each
   database so the optimizer has useful statistics. You
421
   can also run <command>vacuumdb -a -z</> to analyze all
422
   databases.
423 424
  </para>

425 426 427 428 429 430 431
  <para>
   <application>pg_dumpall</application> requires all needed
   tablespace directories to exist before the restore or
   database creation will fail for databases in non-default
   locations.
  </para>

432 433 434
 </refsect1>


435 436
 <refsect1 id="app-pg-dumpall-ex">
  <title>Examples</title>
437
  <para>
438 439 440 441 442
   To dump all databases:

<screen>
<prompt>$</prompt> <userinput>pg_dumpall &gt; db.out</userinput>
</screen>
443
  </para>
444

445
  <para>
446 447
   To reload this database use, for example:
<screen>
448
<prompt>$</prompt> <userinput>psql -f db.out postgres</userinput>
449 450 451 452
</screen>
   (It is not important to which database you connect here since the
   script file created by <application>pg_dumpall</application> will
   contain the appropriate commands to create and connect to the saved
453
   databases.)
454 455
  </para>
 </refsect1>
456

457 458
 <refsect1>
  <title>See Also</title>
459

460
  <para>
461
    <xref linkend="app-pgdump">.  Check there for details on possible
462
    error conditions.  Also see supported environment variables
463
    (<xref linkend="libpq-envars">).
464
  </para>
465 466
 </refsect1>   

467
</refentry>