11<!--
2- $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.34 2001/08/12 19:02:39 petere Exp $
2+ $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.35 2001/08/22 20:23:23 petere Exp $
33Postgres documentation
44-->
55
@@ -43,6 +43,7 @@ Postgres documentation
4343 <arg>-t <replaceable>table</replaceable></arg>
4444 <arg>-v</arg>
4545 <arg>-x</arg>
46+ <arg>-X <replaceable>keyword</replaceable></arg>
4647 <arg>-Z <replaceable>0...9</replaceable></arg>
4748 <arg>-h <replaceable>host</replaceable></arg>
4849 <arg>-p <replaceable>port</replaceable></arg>
@@ -59,44 +60,56 @@ Postgres documentation
5960 </title>
6061
6162 <para>
62- <command>pg_dump</command> is a utility for dumping out a
63- <productname>Postgres</productname> database into a script or archive
64- file containing query commands. The script files are in text format
65- and can be used to reconstruct the database, even on other machines
66- and other architectures.
67- The archive files, new with version 7.1, contain enough information for
68- <xref linkend="app-pgrestore"> to rebuild the database, but also
69- allow <command>pg_restore</command> to be selective about what is restored, or even to
70- reorder the items prior to being restored. The archive files are
71- also designed to be portable across architectures.
63+ <command>pg_dump</command> is a utility for saving a
64+ <productname>PostgreSQL</productname> database into a script or an
65+ archive file. The script files are in plain text format and
66+ contain the SQL commands required to reconstruct the database to
67+ the state it was in at the time is was saved. They can be used to
68+ reconstruct the database even on other machines and other
69+ architectures, with some modifications even on other RDBMS
70+ products. The alternative archive file formats are meant to be
71+ used with <xref linkend="app-pgrestore"> to rebuild the database,
72+ and they also allow <command>pg_restore</command> to be selective
73+ about what is restored, or even to reorder the items prior to being
74+ restored. The archive files are also designed to be portable across
75+ architectures.
7276 </para>
7377
7478 <para>
75- <command>pg_dump</command>
76- will produce the queries necessary to re-generate all
77- user-defined types, functions, tables, indexes, aggregates, and
78- operators. In addition, all the data is copied out in text format so
79- that it can be readily copied in again, as well as imported into tools
80- for editing.
79+ <command>pg_dump</command> will save the information necessary to
80+ re-generate all user-defined types, functions, tables, indexes,
81+ aggregates, and operators. In addition, all the data is copied out
82+ in text format so that it can be readily copied in again, as well
83+ as imported into tools for editing.
8184 </para>
8285
8386 <para>
8487 <command>pg_dump</command>
8588 is useful for dumping out the contents of a database to move from one
86- <productname>Postgres</productname> installation to another. After running
87- <command>pg_dump</command>,
88- one should examine the output for any warnings, especially
89- in light of the limitations listed below.
89+ <productname>Postgres</productname> installation to another.
9090 </para>
9191
9292 <para>
93- When used with one of the alternate file formats and combined with
94- <command>pg_restore</command>, it provides a flexible archival
95- and transfer mechanism. <command>pg_dump</command> can be used
96- to backup an entire database, then <command>pg_restore</command>
97- can be used to examine the archive and/or select which parts of the
98- database are to be restored.
99- See the <xref linkend="app-pgrestore"> documentation for details.
93+ When used with one of the archive file formats and combined with
94+ <command>pg_restore</command>, it provides a flexible archival and
95+ transfer mechanism. <command>pg_dump</command> can be used to
96+ backup an entire database, then <command>pg_restore</command> can
97+ be used to examine the archive and/or select which parts of the
98+ database are to be restored. See the <xref
99+ linkend="app-pgrestore"> documentation for details.
100+ </para>
101+
102+ <para>
103+ While running <command>pg_dump</command>, one should examine the
104+ output for any warnings (printed on standard error), especially in
105+ light of the limitations listed below.
106+ </para>
107+
108+ <para>
109+ <command>pg_dump</command> makes consistent backups even if the
110+ database is being used concurrently. <command>pg_dump</command>
111+ does not block other users accessing the database (readers or
112+ writers).
100113 </para>
101114
102115 <refsect2 id="pg-dump-options">
@@ -141,7 +154,7 @@ Postgres documentation
141154 <term>--clean</term>
142155 <listitem>
143156 <para>
144- Dump commands to clean (drop) the schema prior to (the
157+ Output commands to clean (drop) the schema prior to (the
145158 commands for) creating it.
146159 </para>
147160 </listitem>
@@ -162,9 +175,10 @@ Postgres documentation
162175 <term>--inserts</term>
163176 <listitem>
164177 <para>
165- Dump data as proper <command>INSERT</command> commands (not
166- <command>COPY</command>). This will make restoration very
167- slow.
178+ Dump data as proper <command>INSERT</command> commands (rather
179+ than <command>COPY</command>). This will make restoration very
180+ slow, but it makes the archives more portable to other RDBMS
181+ packages.
168182 </para>
169183 </listitem>
170184 </varlistentry>
@@ -189,7 +203,8 @@ Postgres documentation
189203 <term>--file=<replaceable class="parameter">file</replaceable></term>
190204 <listitem>
191205 <para>
192- Send output to the specified file.
206+ Send output to the specified file. If this is omitted, the
207+ standard output is used.
193208 </para>
194209 </listitem>
195210 </varlistentry>
@@ -199,7 +214,8 @@ Postgres documentation
199214 <term>--format=<replaceable class="parameter">format</replaceable></term>
200215 <listitem>
201216 <para>
202- Format can be one of the following:
217+ Selects the format of the output.
218+ <replaceable>format</replaceable> can be one of the following:
203219
204220 <variablelist>
205221 <varlistentry>
@@ -289,7 +305,10 @@ Postgres documentation
289305 <term>--oids</term>
290306 <listitem>
291307 <para>
292- Dump object identifiers (<acronym>OID</acronym>s) for every table.
308+ Dump object identifiers (<acronym>OID</acronym>s) for every
309+ table. Use this option if your application references the oid
310+ columns in some way (e.g., in a foreign key constraint).
311+ Otherwise, this option should not be used.
293312 </para>
294313 </listitem>
295314 </varlistentry>
@@ -299,11 +318,22 @@ Postgres documentation
299318 <term>--no-owner</term>
300319 <listitem>
301320 <para>
302- In plain text output mode, do not set object ownership to
303- match the original database. Typically,
304- <command>pg_dump</command> issues
305- (<command>psql</command>-specific) <command>\connect</command>
306- statements to set ownership of schema elements.
321+ In plain text output mode, do not output commands to set the
322+ object ownership to match the original database. Typically,
323+ <command>pg_dump</command> issues
324+ (<command>psql</command>-specific) <command>\connect</command>
325+ statements to set ownership of schema elements. See also
326+ under <option>-R</option> and <option>-X
327+ use-set-session-authorization</option>. Note that
328+ <option>-O</option> does not prevent all reconnections to the
329+ database, only the ones that are exclusively used for
330+ ownership adjustments.
331+ </para>
332+
333+ <para>
334+ This option is only meaningful for the plain text format. For
335+ the other formats, you need to specify the option when you
336+ call <command>pg_restore</command>.
307337 </para>
308338 </listitem>
309339 </varlistentry>
@@ -313,8 +343,27 @@ Postgres documentation
313343 <term>--no-reconnect</term>
314344 <listitem>
315345 <para>
316- In plain text output mode, prohibit <command>pg_dump</command>
317- from issuing any <command>\connect</command> statements.
346+ In plain text output mode, prohibit <command>pg_dump</command>
347+ from outputting a script that would require reconnections to
348+ the database while being restored. An average restoration
349+ script usually has to reconnect several times as different
350+ users to set the original ownerships of the objects. This
351+ option is a rather blunt instrument because it makes
352+ <command>pg_dump</command> lose this ownership information,
353+ <emphasis>unless</emphasis> you use the <option>-X
354+ use-set-session-authorization</option> option.
355+ </para>
356+
357+ <para>
358+ One possible reason why reconnections during restore might not
359+ be desired is if the access to the database requires manual
360+ interaction (e.g., passwords).
361+ </para>
362+
363+ <para>
364+ This option is only meaningful for the plain text format. For
365+ the other formats, you need to specify the option when you
366+ call <command>pg_restore</command>.
318367 </para>
319368 </listitem>
320369 </varlistentry>
@@ -334,8 +383,10 @@ Postgres documentation
334383 <term>--superuser=<replaceable class="parameter">username</replaceable></term>
335384 <listitem>
336385 <para>
337- Specify the superuser user name to use when disabling triggers and/or
338- setting ownership of schema elements.
386+ The scripts or archives created by <command>pg_dump</command>
387+ need to have superuser access in certain cases, such as when
388+ disabling triggers or setting ownership of schema elements.
389+ This option specifies the user name to use for those cases.
339390 </para>
340391 </listitem>
341392 </varlistentry>
@@ -366,8 +417,42 @@ Postgres documentation
366417 <term>--no-acl</term>
367418 <listitem>
368419 <para>
369- Prevent dumping of access privileges (grant/revoke commands)
370- and table ownership information.
420+ Prevent dumping of access privileges (grant/revoke commands).
421+ </para>
422+ </listitem>
423+ </varlistentry>
424+
425+ <varlistentry>
426+ <term>-X use-set-session-authorization</term>
427+ <term>--use-set-session-authorization</term>
428+ <listitem>
429+ <para>
430+ Normally, if a (plain text mode) script generated by
431+ <command>pg_dump</command> must alter the current database
432+ user (e.g., to set correct object ownerships), it uses the
433+ <xref linkend="app-psql"> <command>\connect</command> command.
434+ This command actually opens a new connection, which might
435+ require manual interaction (e.g., passwords). If you use the
436+ <option>-X use-set-session-authorization</option>, then
437+ <command>pg_dump</command> will instead output <xref
438+ linkend="sql-set-session-authorization"> commands. This has
439+ the same effect, but it requires that the user restoring the
440+ database from the generated script be a database superuser.
441+ This option effectively overrides the <option>-R</option>
442+ option.
443+ </para>
444+
445+ <para>
446+ Since <xref linkend="sql-set-session-authorization"> is a
447+ standard SQL command, whereas <command>\connect</command> only
448+ works in <xref linkend="app-psql">, this option also enhances
449+ the theoretical portability of the output script.
450+ </para>
451+
452+ <para>
453+ This option is only meaningful for the plain text format. For
454+ the other formats, you need to specify the option when you
455+ call <command>pg_restore</command>.
371456 </para>
372457 </listitem>
373458 </varlistentry>
@@ -442,7 +527,6 @@ Postgres documentation
442527
443528 </refsect1>
444529
445-
446530 <refsect1 id="app-pgdump-diagnostics">
447531 <title>Diagnostics</title>
448532
@@ -551,6 +635,17 @@ connectDBStart() -- connect() failed: No such file or directory
551635
552636 </refsect1>
553637
638+ <refsect1>
639+ <title>History</title>
640+
641+ <para>
642+ The <command>pg_dump</command> utility first appeared in
643+ <application>Postgres95 release 0.02</application>. The
644+ non-plain-text output formats were introduced in
645+ <application>PostgreSQL 7.1</application>.
646+ </para>
647+ </refsect1>
648+
554649 <refsect1>
555650 <title>See Also</title>
556651