1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>pg_dumpall</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="app-pgdump.html" title="pg_dump" /><link rel="next" href="app-pg-isready.html" title="pg_isready" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center"><span class="application">pg_dumpall</span></th></tr><tr><td width="10%" align="left"><a accesskey="p" href="app-pgdump.html" title="pg_dump">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="reference-client.html" title="PostgreSQL Client Applications">Up</a></td><th width="60%" align="center">PostgreSQL Client Applications</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="app-pg-isready.html" title="pg_isready">Next</a></td></tr></table><hr /></div><div class="refentry" id="APP-PG-DUMPALL"><div class="titlepage"></div><a id="id-1.9.4.15.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle"><span class="application">pg_dumpall</span></span></h2><p>pg_dumpall — extract a <span class="productname">PostgreSQL</span> database cluster into a script file</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.4.15.4.1"><code class="command">pg_dumpall</code> [<em class="replaceable"><code>connection-option</code></em>...] [<em class="replaceable"><code>option</code></em>...]</p></div></div><div class="refsect1" id="APP-PG-DUMPALL-DESCRIPTION"><h2>Description</h2><p>
3 <span class="application">pg_dumpall</span> is a utility for writing out
4 (<span class="quote">“<span class="quote">dumping</span>”</span>) all <span class="productname">PostgreSQL</span> databases
5 of a cluster into one script file. The script file contains
6 <acronym class="acronym">SQL</acronym> commands that can be used as input to <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a> to restore the databases. It does this by
7 calling <a class="xref" href="app-pgdump.html" title="pg_dump"><span class="refentrytitle"><span class="application">pg_dump</span></span></a> for each database in the cluster.
8 <span class="application">pg_dumpall</span> also dumps global objects
9 that are common to all databases, namely database roles, tablespaces,
10 and privilege grants for configuration parameters.
11 (<span class="application">pg_dump</span> does not save these objects.)
13 Since <span class="application">pg_dumpall</span> reads tables from all
14 databases you will most likely have to connect as a database
15 superuser in order to produce a complete dump. Also you will need
16 superuser privileges to execute the saved script in order to be
17 allowed to add roles and create databases.
19 The SQL script will be written to the standard output. Use the
20 <code class="option">-f</code>/<code class="option">--file</code> option or shell operators to
21 redirect it into a file.
23 <span class="application">pg_dumpall</span> needs to connect several
24 times to the <span class="productname">PostgreSQL</span> server (once per
25 database). If you use password authentication it will ask for
26 a password each time. It is convenient to have a
27 <code class="filename">~/.pgpass</code> file in such cases. See <a class="xref" href="libpq-pgpass.html" title="32.16. The Password File">Section 32.16</a> for more information.
28 </p><div class="warning"><h3 class="title">Warning</h3><p>
29 Restoring a dump causes the destination to execute arbitrary code of the
30 source superusers' choice. Partial dumps and partial restores do not limit
31 that. If the source superusers are not trusted, the dumped SQL statements
32 must be inspected before restoring. Note that the client running the dump
33 and restore need not trust the source or destination superusers.
34 </p></div></div><div class="refsect1" id="id-1.9.4.15.6"><h2>Options</h2><p>
35 The following command-line options control the content and
38 </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-a</code><br /></span><span class="term"><code class="option">--data-only</code></span></dt><dd><p>
39 Dump only the data, not the schema (data definitions) or statistics.
40 </p></dd><dt><span class="term"><code class="option">-c</code><br /></span><span class="term"><code class="option">--clean</code></span></dt><dd><p>
41 Emit SQL commands to <code class="command">DROP</code> all the dumped
42 databases, roles, and tablespaces before recreating them.
43 This option is useful when the restore is to overwrite an existing
44 cluster. If any of the objects do not exist in the destination
45 cluster, ignorable error messages will be reported during
46 restore, unless <code class="option">--if-exists</code> is also specified.
47 </p></dd><dt><span class="term"><code class="option">-E <em class="replaceable"><code>encoding</code></em></code><br /></span><span class="term"><code class="option">--encoding=<em class="replaceable"><code>encoding</code></em></code></span></dt><dd><p>
48 Create the dump in the specified character set encoding. By default,
49 the dump is created in the database encoding. (Another way to get the
50 same result is to set the <code class="envar">PGCLIENTENCODING</code> environment
51 variable to the desired dump encoding.)
52 </p></dd><dt><span class="term"><code class="option">-f <em class="replaceable"><code>filename</code></em></code><br /></span><span class="term"><code class="option">--file=<em class="replaceable"><code>filename</code></em></code></span></dt><dd><p>
53 Send output to the specified file. If this is omitted, the
54 standard output is used.
55 </p></dd><dt><span class="term"><code class="option">-g</code><br /></span><span class="term"><code class="option">--globals-only</code></span></dt><dd><p>
56 Dump only global objects (roles and tablespaces), no databases.
57 </p></dd><dt><span class="term"><code class="option">-O</code><br /></span><span class="term"><code class="option">--no-owner</code></span></dt><dd><p>
58 Do not output commands to set
59 ownership of objects to match the original database.
60 By default, <span class="application">pg_dumpall</span> issues
61 <code class="command">ALTER OWNER</code> or
62 <code class="command">SET SESSION AUTHORIZATION</code>
63 statements to set ownership of created schema elements.
65 will fail when the script is run unless it is started by a superuser
66 (or the same user that owns all of the objects in the script).
67 To make a script that can be restored by any user, but will give
68 that user ownership of all the objects, specify <code class="option">-O</code>.
69 </p></dd><dt><span class="term"><code class="option">-r</code><br /></span><span class="term"><code class="option">--roles-only</code></span></dt><dd><p>
70 Dump only roles, no databases or tablespaces.
71 </p></dd><dt><span class="term"><code class="option">-s</code><br /></span><span class="term"><code class="option">--schema-only</code></span></dt><dd><p>
72 Dump only the object definitions (schema), not data.
73 </p></dd><dt><span class="term"><code class="option">-S <em class="replaceable"><code>username</code></em></code><br /></span><span class="term"><code class="option">--superuser=<em class="replaceable"><code>username</code></em></code></span></dt><dd><p>
74 Specify the superuser user name to use when disabling triggers.
75 This is relevant only if <code class="option">--disable-triggers</code> is used.
76 (Usually, it's better to leave this out, and instead start the
77 resulting script as superuser.)
78 </p></dd><dt><span class="term"><code class="option">-t</code><br /></span><span class="term"><code class="option">--tablespaces-only</code></span></dt><dd><p>
79 Dump only tablespaces, no databases or roles.
80 </p></dd><dt><span class="term"><code class="option">-v</code><br /></span><span class="term"><code class="option">--verbose</code></span></dt><dd><p>
81 Specifies verbose mode. This will cause
82 <span class="application">pg_dumpall</span> to output start/stop
83 times to the dump file, and progress messages to standard error.
84 Repeating the option causes additional debug-level messages
85 to appear on standard error.
86 The option is also passed down to <span class="application">pg_dump</span>.
87 </p></dd><dt><span class="term"><code class="option">-V</code><br /></span><span class="term"><code class="option">--version</code></span></dt><dd><p>
88 Print the <span class="application">pg_dumpall</span> version and exit.
89 </p></dd><dt><span class="term"><code class="option">-x</code><br /></span><span class="term"><code class="option">--no-privileges</code><br /></span><span class="term"><code class="option">--no-acl</code></span></dt><dd><p>
90 Prevent dumping of access privileges (grant/revoke commands).
91 </p></dd><dt><span class="term"><code class="option">--binary-upgrade</code></span></dt><dd><p>
92 This option is for use by in-place upgrade utilities. Its use
93 for other purposes is not recommended or supported. The
94 behavior of the option may change in future releases without
96 </p></dd><dt><span class="term"><code class="option">--column-inserts</code><br /></span><span class="term"><code class="option">--attribute-inserts</code></span></dt><dd><p>
97 Dump data as <code class="command">INSERT</code> commands with explicit
98 column names (<code class="literal">INSERT INTO
99 <em class="replaceable"><code>table</code></em>
100 (<em class="replaceable"><code>column</code></em>, ...) VALUES
101 ...</code>). This will make restoration very slow; it is mainly
102 useful for making dumps that can be loaded into
103 non-<span class="productname">PostgreSQL</span> databases.
104 </p></dd><dt><span class="term"><code class="option">--disable-dollar-quoting</code></span></dt><dd><p>
105 This option disables the use of dollar quoting for function bodies,
106 and forces them to be quoted using SQL standard string syntax.
107 </p></dd><dt><span class="term"><code class="option">--disable-triggers</code></span></dt><dd><p>
108 This option is relevant only when creating a dump with data and without schema.
109 It instructs <span class="application">pg_dumpall</span> to include commands
110 to temporarily disable triggers on the target tables while
111 the data is restored. Use this if you have referential
112 integrity checks or other triggers on the tables that you
113 do not want to invoke during data restore.
115 Presently, the commands emitted for <code class="option">--disable-triggers</code>
116 must be done as superuser. So, you should also specify
117 a superuser name with <code class="option">-S</code>, or preferably be careful to
118 start the resulting script as a superuser.
119 </p></dd><dt><span class="term"><code class="option">--exclude-database=<em class="replaceable"><code>pattern</code></em></code></span></dt><dd><p>
120 Do not dump databases whose name matches
121 <em class="replaceable"><code>pattern</code></em>.
122 Multiple patterns can be excluded by writing multiple
123 <code class="option">--exclude-database</code> switches. The
124 <em class="replaceable"><code>pattern</code></em> parameter is
125 interpreted as a pattern according to the same rules used by
126 <span class="application">psql</span>'s <code class="literal">\d</code>
127 commands (see <a class="xref" href="app-psql.html#APP-PSQL-PATTERNS" title="Patterns">Patterns</a>),
128 so multiple databases can also be excluded by writing wildcard
129 characters in the pattern. When using wildcards, be careful to
130 quote the pattern if needed to prevent shell wildcard expansion.
131 </p></dd><dt><span class="term"><code class="option">--extra-float-digits=<em class="replaceable"><code>ndigits</code></em></code></span></dt><dd><p>
132 Use the specified value of extra_float_digits when dumping
133 floating-point data, instead of the maximum available precision.
134 Routine dumps made for backup purposes should not use this option.
135 </p></dd><dt><span class="term"><code class="option">--filter=<em class="replaceable"><code>filename</code></em></code></span></dt><dd><p>
136 Specify a filename from which to read patterns for databases excluded
137 from the dump. The patterns are interpreted according to the same rules
138 as <code class="option">--exclude-database</code>.
139 To read from <code class="literal">STDIN</code>, use <code class="filename">-</code> as the
140 filename. The <code class="option">--filter</code> option can be specified in
141 conjunction with <code class="option">--exclude-database</code> for excluding
142 databases, and can also be specified more than once for multiple filter
145 The file lists one database pattern per row, with the following format:
146 </p><pre class="synopsis">
147 exclude database <em class="replaceable"><code>PATTERN</code></em>
150 Lines starting with <code class="literal">#</code> are considered comments and
151 ignored. Comments can be placed after an object pattern row as well.
152 Blank lines are also ignored. See <a class="xref" href="app-psql.html#APP-PSQL-PATTERNS" title="Patterns">Patterns</a>
153 for how to perform quoting in patterns.
154 </p></dd><dt><span class="term"><code class="option">--if-exists</code></span></dt><dd><p>
155 Use <code class="literal">DROP ... IF EXISTS</code> commands to drop objects
156 in <code class="option">--clean</code> mode. This suppresses <span class="quote">“<span class="quote">does not
157 exist</span>”</span> errors that might otherwise be reported. This
158 option is not valid unless <code class="option">--clean</code> is also
160 </p></dd><dt><span class="term"><code class="option">--inserts</code></span></dt><dd><p>
161 Dump data as <code class="command">INSERT</code> commands (rather
162 than <code class="command">COPY</code>). This will make restoration very slow;
163 it is mainly useful for making dumps that can be loaded into
164 non-<span class="productname">PostgreSQL</span> databases. Note that
165 the restore might fail altogether if you have rearranged column order.
166 The <code class="option">--column-inserts</code> option is safer, though even
168 </p></dd><dt><span class="term"><code class="option">--load-via-partition-root</code></span></dt><dd><p>
169 When dumping data for a table partition, make
170 the <code class="command">COPY</code> or <code class="command">INSERT</code> statements
171 target the root of the partitioning hierarchy that contains it, rather
172 than the partition itself. This causes the appropriate partition to
173 be re-determined for each row when the data is loaded. This may be
174 useful when restoring data on a server where rows do not always fall
175 into the same partitions as they did on the original server. That
176 could happen, for example, if the partitioning column is of type text
177 and the two systems have different definitions of the collation used
178 to sort the partitioning column.
179 </p></dd><dt><span class="term"><code class="option">--lock-wait-timeout=<em class="replaceable"><code>timeout</code></em></code></span></dt><dd><p>
180 Do not wait forever to acquire shared table locks at the beginning of
181 the dump. Instead, fail if unable to lock a table within the specified
182 <em class="replaceable"><code>timeout</code></em>. The timeout may be
183 specified in any of the formats accepted by <code class="command">SET
184 statement_timeout</code>.
185 </p></dd><dt><span class="term"><code class="option">--no-comments</code></span></dt><dd><p>
186 Do not dump <code class="command">COMMENT</code> commands.
187 </p></dd><dt><span class="term"><code class="option">--no-data</code></span></dt><dd><p>
189 </p></dd><dt><span class="term"><code class="option">--no-policies</code></span></dt><dd><p>
190 Do not dump row security policies.
191 </p></dd><dt><span class="term"><code class="option">--no-publications</code></span></dt><dd><p>
192 Do not dump publications.
193 </p></dd><dt><span class="term"><code class="option">--no-role-passwords</code></span></dt><dd><p>
194 Do not dump passwords for roles. When restored, roles will have a
195 null password, and password authentication will always fail until the
196 password is set. Since password values aren't needed when this option
197 is specified, the role information is read from the catalog
198 view <code class="structname">pg_roles</code> instead
199 of <code class="structname">pg_authid</code>. Therefore, this option also
200 helps if access to <code class="structname">pg_authid</code> is restricted by
201 some security policy.
202 </p></dd><dt><span class="term"><code class="option">--no-schema</code></span></dt><dd><p>
203 Do not dump schema (data definitions).
204 </p></dd><dt><span class="term"><code class="option">--no-security-labels</code></span></dt><dd><p>
205 Do not dump security labels.
206 </p></dd><dt><span class="term"><code class="option">--no-statistics</code></span></dt><dd><p>
207 Do not dump statistics. This is the default.
208 </p></dd><dt><span class="term"><code class="option">--no-subscriptions</code></span></dt><dd><p>
209 Do not dump subscriptions.
210 </p></dd><dt><span class="term"><code class="option">--no-sync</code></span></dt><dd><p>
211 By default, <code class="command">pg_dumpall</code> will wait for all files
212 to be written safely to disk. This option causes
213 <code class="command">pg_dumpall</code> to return without waiting, which is
214 faster, but means that a subsequent operating system crash can leave
215 the dump corrupt. Generally, this option is useful for testing
216 but should not be used when dumping data from production installation.
217 </p></dd><dt><span class="term"><code class="option">--no-table-access-method</code></span></dt><dd><p>
218 Do not output commands to select table access methods.
219 With this option, all objects will be created with whichever
220 table access method is the default during restore.
221 </p></dd><dt><span class="term"><code class="option">--no-tablespaces</code></span></dt><dd><p>
222 Do not output commands to create tablespaces nor select tablespaces
224 With this option, all objects will be created in whichever
225 tablespace is the default during restore.
226 </p></dd><dt><span class="term"><code class="option">--no-toast-compression</code></span></dt><dd><p>
227 Do not output commands to set <acronym class="acronym">TOAST</acronym> compression
229 With this option, all columns will be restored with the default
231 </p></dd><dt><span class="term"><code class="option">--no-unlogged-table-data</code></span></dt><dd><p>
232 Do not dump the contents of unlogged tables. This option has no
233 effect on whether or not the table definitions (schema) are dumped;
234 it only suppresses dumping the table data.
235 </p></dd><dt><span class="term"><code class="option">--on-conflict-do-nothing</code></span></dt><dd><p>
236 Add <code class="literal">ON CONFLICT DO NOTHING</code> to
237 <code class="command">INSERT</code> commands.
238 This option is not valid unless <code class="option">--inserts</code> or
239 <code class="option">--column-inserts</code> is also specified.
240 </p></dd><dt><span class="term"><code class="option">--quote-all-identifiers</code></span></dt><dd><p>
241 Force quoting of all identifiers. This option is recommended when
242 dumping a database from a server whose <span class="productname">PostgreSQL</span>
243 major version is different from <span class="application">pg_dumpall</span>'s, or when
244 the output is intended to be loaded into a server of a different
245 major version. By default, <span class="application">pg_dumpall</span> quotes only
246 identifiers that are reserved words in its own major version.
247 This sometimes results in compatibility issues when dealing with
248 servers of other versions that may have slightly different sets
249 of reserved words. Using <code class="option">--quote-all-identifiers</code> prevents
250 such issues, at the price of a harder-to-read dump script.
251 </p></dd><dt><span class="term"><code class="option">--restrict-key=<em class="replaceable"><code>restrict_key</code></em></code></span></dt><dd><p>
252 Use the provided string as the <span class="application">psql</span>
253 <code class="command">\restrict</code> key in the dump output. If no restrict
254 key is specified, <span class="application">pg_dumpall</span> will generate a
255 random one as needed. Keys may contain only alphanumeric characters.
257 This option is primarily intended for testing purposes and other
258 scenarios that require repeatable output (e.g., comparing dump files).
259 It is not recommended for general use, as a malicious server with
260 advance knowledge of the key may be able to inject arbitrary code that
261 will be executed on the machine that runs
262 <span class="application">psql</span> with the dump output.
263 </p></dd><dt><span class="term"><code class="option">--rows-per-insert=<em class="replaceable"><code>nrows</code></em></code></span></dt><dd><p>
264 Dump data as <code class="command">INSERT</code> commands (rather than
265 <code class="command">COPY</code>). Controls the maximum number of rows per
266 <code class="command">INSERT</code> command. The value specified must be a
267 number greater than zero. Any error during restoring will cause only
268 rows that are part of the problematic <code class="command">INSERT</code> to be
269 lost, rather than the entire table contents.
270 </p></dd><dt><span class="term"><code class="option">--statistics</code></span></dt><dd><p>
272 </p></dd><dt><span class="term"><code class="option">--statistics-only</code></span></dt><dd><p>
273 Dump only the statistics, not the schema (data definitions) or data.
274 Statistics for tables, materialized views, foreign tables,
275 and indexes are dumped.
276 </p></dd><dt><span class="term"><code class="option">--sequence-data</code></span></dt><dd><p>
277 Include sequence data in the dump. This is the default behavior except
278 when <code class="option">--no-data</code>, <code class="option">--schema-only</code>, or
279 <code class="option">--statistics-only</code> is specified.
280 </p></dd><dt><span class="term"><code class="option">--use-set-session-authorization</code></span></dt><dd><p>
281 Output SQL-standard <code class="command">SET SESSION AUTHORIZATION</code> commands
282 instead of <code class="command">ALTER OWNER</code> commands to determine object
283 ownership. This makes the dump more standards compatible, but
284 depending on the history of the objects in the dump, might not restore
286 </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>
287 Show help about <span class="application">pg_dumpall</span> command line
289 </p></dd></dl></div><p>
291 The following command-line options control the database connection parameters.
293 </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-d <em class="replaceable"><code>connstr</code></em></code><br /></span><span class="term"><code class="option">--dbname=<em class="replaceable"><code>connstr</code></em></code></span></dt><dd><p>
294 Specifies parameters used to connect to the server, as a <a class="link" href="libpq-connect.html#LIBPQ-CONNSTRING" title="32.1.1. Connection Strings">connection string</a>; these
295 will override any conflicting command line options.
297 The option is called <code class="literal">--dbname</code> for consistency with other
298 client applications, but because <span class="application">pg_dumpall</span>
299 needs to connect to many databases, the database name in the
300 connection string will be ignored. Use the <code class="literal">-l</code>
301 option to specify the name of the database used for the initial
302 connection, which will dump global objects and discover what other
303 databases should be dumped.
304 </p></dd><dt><span class="term"><code class="option">-h <em class="replaceable"><code>host</code></em></code><br /></span><span class="term"><code class="option">--host=<em class="replaceable"><code>host</code></em></code></span></dt><dd><p>
305 Specifies the host name of the machine on which the database
306 server is running. If the value begins with a slash, it is
307 used as the directory for the Unix domain socket. The default
308 is taken from the <code class="envar">PGHOST</code> environment variable,
309 if set, else a Unix domain socket connection is attempted.
310 </p></dd><dt><span class="term"><code class="option">-l <em class="replaceable"><code>dbname</code></em></code><br /></span><span class="term"><code class="option">--database=<em class="replaceable"><code>dbname</code></em></code></span></dt><dd><p>
311 Specifies the name of the database to connect to for dumping global
312 objects and discovering what other databases should be dumped. If
313 not specified, the <code class="literal">postgres</code> database will be used,
314 and if that does not exist, <code class="literal">template1</code> will be used.
315 </p></dd><dt><span class="term"><code class="option">-p <em class="replaceable"><code>port</code></em></code><br /></span><span class="term"><code class="option">--port=<em class="replaceable"><code>port</code></em></code></span></dt><dd><p>
316 Specifies the TCP port or local Unix domain socket file
317 extension on which the server is listening for connections.
318 Defaults to the <code class="envar">PGPORT</code> environment variable, if
319 set, or a compiled-in default.
320 </p></dd><dt><span class="term"><code class="option">-U <em class="replaceable"><code>username</code></em></code><br /></span><span class="term"><code class="option">--username=<em class="replaceable"><code>username</code></em></code></span></dt><dd><p>
321 User name to connect as.
322 </p></dd><dt><span class="term"><code class="option">-w</code><br /></span><span class="term"><code class="option">--no-password</code></span></dt><dd><p>
323 Never issue a password prompt. If the server requires
324 password authentication and a password is not available by
325 other means such as a <code class="filename">.pgpass</code> file, the
326 connection attempt will fail. This option can be useful in
327 batch jobs and scripts where no user is present to enter a
329 </p></dd><dt><span class="term"><code class="option">-W</code><br /></span><span class="term"><code class="option">--password</code></span></dt><dd><p>
330 Force <span class="application">pg_dumpall</span> to prompt for a
331 password before connecting to a database.
333 This option is never essential, since
334 <span class="application">pg_dumpall</span> will automatically prompt
335 for a password if the server demands password authentication.
336 However, <span class="application">pg_dumpall</span> will waste a
337 connection attempt finding out that the server wants a password.
338 In some cases it is worth typing <code class="option">-W</code> to avoid the extra
341 Note that the password prompt will occur again for each database
342 to be dumped. Usually, it's better to set up a
343 <code class="filename">~/.pgpass</code> file than to rely on manual password entry.
344 </p></dd><dt><span class="term"><code class="option">--role=<em class="replaceable"><code>rolename</code></em></code></span></dt><dd><p>
345 Specifies a role name to be used to create the dump.
346 This option causes <span class="application">pg_dumpall</span> to issue a
347 <code class="command">SET ROLE</code> <em class="replaceable"><code>rolename</code></em>
348 command after connecting to the database. It is useful when the
349 authenticated user (specified by <code class="option">-U</code>) lacks privileges
350 needed by <span class="application">pg_dumpall</span>, but can switch to a role with
351 the required rights. Some installations have a policy against
352 logging in directly as a superuser, and use of this option allows
353 dumps to be made without violating the policy.
354 </p></dd></dl></div><p>
355 </p></div><div class="refsect1" id="id-1.9.4.15.7"><h2>Environment</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="envar">PGHOST</code><br /></span><span class="term"><code class="envar">PGOPTIONS</code><br /></span><span class="term"><code class="envar">PGPORT</code><br /></span><span class="term"><code class="envar">PGUSER</code></span></dt><dd><p>
356 Default connection parameters
357 </p></dd><dt><span class="term"><code class="envar">PG_COLOR</code></span></dt><dd><p>
358 Specifies whether to use color in diagnostic messages. Possible values
359 are <code class="literal">always</code>, <code class="literal">auto</code> and
360 <code class="literal">never</code>.
361 </p></dd></dl></div><p>
362 This utility, like most other <span class="productname">PostgreSQL</span> utilities,
363 also uses the environment variables supported by <span class="application">libpq</span>
364 (see <a class="xref" href="libpq-envars.html" title="32.15. Environment Variables">Section 32.15</a>).
365 </p></div><div class="refsect1" id="id-1.9.4.15.8"><h2>Notes</h2><p>
366 Since <span class="application">pg_dumpall</span> calls
367 <span class="application">pg_dump</span> internally, some diagnostic
368 messages will refer to <span class="application">pg_dump</span>.
370 The <code class="option">--clean</code> option can be useful even when your
371 intention is to restore the dump script into a fresh cluster. Use of
372 <code class="option">--clean</code> authorizes the script to drop and re-create the
373 built-in <code class="literal">postgres</code> and <code class="literal">template1</code>
374 databases, ensuring that those databases will retain the same properties
375 (for instance, locale and encoding) that they had in the source cluster.
376 Without the option, those databases will retain their existing
377 database-level properties, as well as any pre-existing contents.
379 If <code class="option">--statistics</code> is specified,
380 <code class="command">pg_dumpall</code> will include most optimizer statistics in the
381 resulting dump file. However, some statistics may not be included, such as
382 those created explicitly with <a class="xref" href="sql-createstatistics.html" title="CREATE STATISTICS"><span class="refentrytitle">CREATE STATISTICS</span></a> or
383 custom statistics added by an extension. Therefore, it may be useful to
384 run <code class="command">ANALYZE</code> on each database after restoring from a dump
385 file to ensure optimal performance. You can also run <code class="command">vacuumdb -a
386 -z</code> to analyze all databases.
388 The dump script should not be expected to run completely without errors.
389 In particular, because the script will issue <code class="command">CREATE ROLE</code>
390 for every role existing in the source cluster, it is certain to get a
391 <span class="quote">“<span class="quote">role already exists</span>”</span> error for the bootstrap superuser,
392 unless the destination cluster was initialized with a different bootstrap
393 superuser name. This error is harmless and should be ignored. Use of
394 the <code class="option">--clean</code> option is likely to produce additional
395 harmless error messages about non-existent objects, although you can
396 minimize those by adding <code class="option">--if-exists</code>.
398 <span class="application">pg_dumpall</span> requires all needed
399 tablespace directories to exist before the restore; otherwise,
400 database creation will fail for databases in non-default
403 It is generally recommended to use the <code class="option">-X</code>
404 (<code class="option">--no-psqlrc</code>) option when restoring a database from a
405 <span class="application">pg_dumpall</span> script to ensure a clean restore
406 process and prevent potential conflicts with non-default
407 <span class="application">psql</span> configurations. Additionally, because
408 the <span class="application">pg_dumpall</span> script may
409 include <span class="application">psql</span> meta-commands, it may be
410 incompatible with clients other than <span class="application">psql</span>.
411 </p></div><div class="refsect1" id="APP-PG-DUMPALL-EX"><h2>Examples</h2><p>
412 To dump all databases:
414 </p><pre class="screen">
415 <code class="prompt">$</code> <strong class="userinput"><code>pg_dumpall > db.out</code></strong>
418 To restore database(s) from this file, you can use:
419 </p><pre class="screen">
420 <code class="prompt">$</code> <strong class="userinput"><code>psql -X -f db.out -d postgres</code></strong>
422 It is not important which database you connect to here since the
423 script file created by <span class="application">pg_dumpall</span> will
424 contain the appropriate commands to create and connect to the saved
425 databases. An exception is that if you specified <code class="option">--clean</code>,
426 you must connect to the <code class="literal">postgres</code> database initially;
427 the script will attempt to drop other databases immediately, and that
428 will fail for the database you are connected to.
429 </p></div><div class="refsect1" id="id-1.9.4.15.10"><h2>See Also</h2><p>
430 Check <a class="xref" href="app-pgdump.html" title="pg_dump"><span class="refentrytitle"><span class="application">pg_dump</span></span></a> for details on possible
432 </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="app-pgdump.html" title="pg_dump">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference-client.html" title="PostgreSQL Client Applications">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="app-pg-isready.html" title="pg_isready">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="application">pg_dump</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> <span class="application">pg_isready</span></td></tr></table></div></body></html>