]> begriffs open source - ai-pg/blob - full-docs/man1/pg_dumpall.1
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man1 / pg_dumpall.1
1 '\" t
2 .\"     Title: pg_dumpall
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
10 .TH "PG_DUMPALL" "1" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 pg_dumpall \- extract a PostgreSQL database cluster into a script file
32 .SH "SYNOPSIS"
33 .HP \w'\fBpg_dumpall\fR\ 'u
34 \fBpg_dumpall\fR [\fIconnection\-option\fR...] [\fIoption\fR...]
35 .SH "DESCRIPTION"
36 .PP
37 pg_dumpall
38 is a utility for writing out (\(lqdumping\(rq) all
39 PostgreSQL
40 databases of a cluster into one script file\&. The script file contains
41 SQL
42 commands that can be used as input to
43 \fBpsql\fR(1)
44 to restore the databases\&. It does this by calling
45 \fBpg_dump\fR(1)
46 for each database in the cluster\&.
47 pg_dumpall
48 also dumps global objects that are common to all databases, namely database roles, tablespaces, and privilege grants for configuration parameters\&. (pg_dump
49 does not save these objects\&.)
50 .PP
51 Since
52 pg_dumpall
53 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 superuser privileges to execute the saved script in order to be allowed to add roles and create databases\&.
54 .PP
55 The SQL script will be written to the standard output\&. Use the
56 \fB\-f\fR/\fB\-\-file\fR
57 option or shell operators to redirect it into a file\&.
58 .PP
59 pg_dumpall
60 needs to connect several times to the
61 PostgreSQL
62 server (once per database)\&. If you use password authentication it will ask for a password each time\&. It is convenient to have a
63 ~/\&.pgpass
64 file in such cases\&. See
65 Section\ \&32.16
66 for more information\&.
67 .if n \{\
68 .sp
69 .\}
70 .RS 4
71 .it 1 an-trap
72 .nr an-no-space-flag 1
73 .nr an-break-flag 1
74 .br
75 .ps +1
76 \fBWarning\fR
77 .ps -1
78 .br
79 .PP
80 Restoring a dump causes the destination to execute arbitrary code of the source superusers\*(Aq choice\&. Partial dumps and partial restores do not limit that\&. If the source superusers are not trusted, the dumped SQL statements must be inspected before restoring\&. Note that the client running the dump and restore need not trust the source or destination superusers\&.
81 .sp .5v
82 .RE
83 .SH "OPTIONS"
84 .PP
85 The following command\-line options control the content and format of the output\&.
86 .PP
87 \fB\-a\fR
88 .br
89 \fB\-\-data\-only\fR
90 .RS 4
91 Dump only the data, not the schema (data definitions) or statistics\&.
92 .RE
93 .PP
94 \fB\-c\fR
95 .br
96 \fB\-\-clean\fR
97 .RS 4
98 Emit SQL commands to
99 \fBDROP\fR
100 all the dumped databases, roles, and tablespaces before recreating them\&. This option is useful when the restore is to overwrite an existing cluster\&. If any of the objects do not exist in the destination cluster, ignorable error messages will be reported during restore, unless
101 \fB\-\-if\-exists\fR
102 is also specified\&.
103 .RE
104 .PP
105 \fB\-E \fR\fB\fIencoding\fR\fR
106 .br
107 \fB\-\-encoding=\fR\fB\fIencoding\fR\fR
108 .RS 4
109 Create the dump in the specified character set encoding\&. By default, the dump is created in the database encoding\&. (Another way to get the same result is to set the
110 \fBPGCLIENTENCODING\fR
111 environment variable to the desired dump encoding\&.)
112 .RE
113 .PP
114 \fB\-f \fR\fB\fIfilename\fR\fR
115 .br
116 \fB\-\-file=\fR\fB\fIfilename\fR\fR
117 .RS 4
118 Send output to the specified file\&. If this is omitted, the standard output is used\&.
119 .RE
120 .PP
121 \fB\-g\fR
122 .br
123 \fB\-\-globals\-only\fR
124 .RS 4
125 Dump only global objects (roles and tablespaces), no databases\&.
126 .RE
127 .PP
128 \fB\-O\fR
129 .br
130 \fB\-\-no\-owner\fR
131 .RS 4
132 Do not output commands to set ownership of objects to match the original database\&. By default,
133 pg_dumpall
134 issues
135 \fBALTER OWNER\fR
136 or
137 \fBSET SESSION AUTHORIZATION\fR
138 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
139 \fB\-O\fR\&.
140 .RE
141 .PP
142 \fB\-r\fR
143 .br
144 \fB\-\-roles\-only\fR
145 .RS 4
146 Dump only roles, no databases or tablespaces\&.
147 .RE
148 .PP
149 \fB\-s\fR
150 .br
151 \fB\-\-schema\-only\fR
152 .RS 4
153 Dump only the object definitions (schema), not data\&.
154 .RE
155 .PP
156 \fB\-S \fR\fB\fIusername\fR\fR
157 .br
158 \fB\-\-superuser=\fR\fB\fIusername\fR\fR
159 .RS 4
160 Specify the superuser user name to use when disabling triggers\&. This is relevant only if
161 \fB\-\-disable\-triggers\fR
162 is used\&. (Usually, it\*(Aqs better to leave this out, and instead start the resulting script as superuser\&.)
163 .RE
164 .PP
165 \fB\-t\fR
166 .br
167 \fB\-\-tablespaces\-only\fR
168 .RS 4
169 Dump only tablespaces, no databases or roles\&.
170 .RE
171 .PP
172 \fB\-v\fR
173 .br
174 \fB\-\-verbose\fR
175 .RS 4
176 Specifies verbose mode\&. This will cause
177 pg_dumpall
178 to output start/stop times to the dump file, and progress messages to standard error\&. Repeating the option causes additional debug\-level messages to appear on standard error\&. The option is also passed down to
179 pg_dump\&.
180 .RE
181 .PP
182 \fB\-V\fR
183 .br
184 \fB\-\-version\fR
185 .RS 4
186 Print the
187 pg_dumpall
188 version and exit\&.
189 .RE
190 .PP
191 \fB\-x\fR
192 .br
193 \fB\-\-no\-privileges\fR
194 .br
195 \fB\-\-no\-acl\fR
196 .RS 4
197 Prevent dumping of access privileges (grant/revoke commands)\&.
198 .RE
199 .PP
200 \fB\-\-binary\-upgrade\fR
201 .RS 4
202 This option is for use by in\-place upgrade utilities\&. Its use for other purposes is not recommended or supported\&. The behavior of the option may change in future releases without notice\&.
203 .RE
204 .PP
205 \fB\-\-column\-inserts\fR
206 .br
207 \fB\-\-attribute\-inserts\fR
208 .RS 4
209 Dump data as
210 \fBINSERT\fR
211 commands with explicit column names (INSERT INTO \fItable\fR (\fIcolumn\fR, \&.\&.\&.) VALUES \&.\&.\&.)\&. This will make restoration very slow; it is mainly useful for making dumps that can be loaded into non\-PostgreSQL
212 databases\&.
213 .RE
214 .PP
215 \fB\-\-disable\-dollar\-quoting\fR
216 .RS 4
217 This option disables the use of dollar quoting for function bodies, and forces them to be quoted using SQL standard string syntax\&.
218 .RE
219 .PP
220 \fB\-\-disable\-triggers\fR
221 .RS 4
222 This option is relevant only when creating a dump with data and without schema\&. It instructs
223 pg_dumpall
224 to include commands to temporarily disable triggers on the target tables while the data is restored\&. Use this if you have referential integrity checks or other triggers on the tables that you do not want to invoke during data restore\&.
225 .sp
226 Presently, the commands emitted for
227 \fB\-\-disable\-triggers\fR
228 must be done as superuser\&. So, you should also specify a superuser name with
229 \fB\-S\fR, or preferably be careful to start the resulting script as a superuser\&.
230 .RE
231 .PP
232 \fB\-\-exclude\-database=\fR\fB\fIpattern\fR\fR
233 .RS 4
234 Do not dump databases whose name matches
235 \fIpattern\fR\&. Multiple patterns can be excluded by writing multiple
236 \fB\-\-exclude\-database\fR
237 switches\&. The
238 \fIpattern\fR
239 parameter is interpreted as a pattern according to the same rules used by
240 psql\*(Aqs
241 \ed
242 commands (see
243 Patterns), so multiple databases can also be excluded by writing wildcard characters in the pattern\&. When using wildcards, be careful to quote the pattern if needed to prevent shell wildcard expansion\&.
244 .RE
245 .PP
246 \fB\-\-extra\-float\-digits=\fR\fB\fIndigits\fR\fR
247 .RS 4
248 Use the specified value of extra_float_digits when dumping floating\-point data, instead of the maximum available precision\&. Routine dumps made for backup purposes should not use this option\&.
249 .RE
250 .PP
251 \fB\-\-filter=\fR\fB\fIfilename\fR\fR
252 .RS 4
253 Specify a filename from which to read patterns for databases excluded from the dump\&. The patterns are interpreted according to the same rules as
254 \fB\-\-exclude\-database\fR\&. To read from
255 STDIN, use
256 \-
257 as the filename\&. The
258 \fB\-\-filter\fR
259 option can be specified in conjunction with
260 \fB\-\-exclude\-database\fR
261 for excluding databases, and can also be specified more than once for multiple filter files\&.
262 .sp
263 The file lists one database pattern per row, with the following format:
264 .sp
265 .if n \{\
266 .RS 4
267 .\}
268 .nf
269 exclude database \fIPATTERN\fR
270 .fi
271 .if n \{\
272 .RE
273 .\}
274 .sp
275 Lines starting with
276 #
277 are considered comments and ignored\&. Comments can be placed after an object pattern row as well\&. Blank lines are also ignored\&. See
278 Patterns
279 for how to perform quoting in patterns\&.
280 .RE
281 .PP
282 \fB\-\-if\-exists\fR
283 .RS 4
284 Use
285 DROP \&.\&.\&. IF EXISTS
286 commands to drop objects in
287 \fB\-\-clean\fR
288 mode\&. This suppresses
289 \(lqdoes not exist\(rq
290 errors that might otherwise be reported\&. This option is not valid unless
291 \fB\-\-clean\fR
292 is also specified\&.
293 .RE
294 .PP
295 \fB\-\-inserts\fR
296 .RS 4
297 Dump data as
298 \fBINSERT\fR
299 commands (rather than
300 \fBCOPY\fR)\&. This will make restoration very slow; it is mainly useful for making dumps that can be loaded into non\-PostgreSQL
301 databases\&. Note that the restore might fail altogether if you have rearranged column order\&. The
302 \fB\-\-column\-inserts\fR
303 option is safer, though even slower\&.
304 .RE
305 .PP
306 \fB\-\-load\-via\-partition\-root\fR
307 .RS 4
308 When dumping data for a table partition, make the
309 \fBCOPY\fR
310 or
311 \fBINSERT\fR
312 statements target the root of the partitioning hierarchy that contains it, rather than the partition itself\&. This causes the appropriate partition to be re\-determined for each row when the data is loaded\&. This may be useful when restoring data on a server where rows do not always fall into the same partitions as they did on the original server\&. That could happen, for example, if the partitioning column is of type text and the two systems have different definitions of the collation used to sort the partitioning column\&.
313 .RE
314 .PP
315 \fB\-\-lock\-wait\-timeout=\fR\fB\fItimeout\fR\fR
316 .RS 4
317 Do not wait forever to acquire shared table locks at the beginning of the dump\&. Instead, fail if unable to lock a table within the specified
318 \fItimeout\fR\&. The timeout may be specified in any of the formats accepted by
319 \fBSET statement_timeout\fR\&.
320 .RE
321 .PP
322 \fB\-\-no\-comments\fR
323 .RS 4
324 Do not dump
325 \fBCOMMENT\fR
326 commands\&.
327 .RE
328 .PP
329 \fB\-\-no\-data\fR
330 .RS 4
331 Do not dump data\&.
332 .RE
333 .PP
334 \fB\-\-no\-policies\fR
335 .RS 4
336 Do not dump row security policies\&.
337 .RE
338 .PP
339 \fB\-\-no\-publications\fR
340 .RS 4
341 Do not dump publications\&.
342 .RE
343 .PP
344 \fB\-\-no\-role\-passwords\fR
345 .RS 4
346 Do not dump passwords for roles\&. When restored, roles will have a null password, and password authentication will always fail until the password is set\&. Since password values aren\*(Aqt needed when this option is specified, the role information is read from the catalog view
347 pg_roles
348 instead of
349 pg_authid\&. Therefore, this option also helps if access to
350 pg_authid
351 is restricted by some security policy\&.
352 .RE
353 .PP
354 \fB\-\-no\-schema\fR
355 .RS 4
356 Do not dump schema (data definitions)\&.
357 .RE
358 .PP
359 \fB\-\-no\-security\-labels\fR
360 .RS 4
361 Do not dump security labels\&.
362 .RE
363 .PP
364 \fB\-\-no\-statistics\fR
365 .RS 4
366 Do not dump statistics\&. This is the default\&.
367 .RE
368 .PP
369 \fB\-\-no\-subscriptions\fR
370 .RS 4
371 Do not dump subscriptions\&.
372 .RE
373 .PP
374 \fB\-\-no\-sync\fR
375 .RS 4
376 By default,
377 \fBpg_dumpall\fR
378 will wait for all files to be written safely to disk\&. This option causes
379 \fBpg_dumpall\fR
380 to return without waiting, which is faster, but means that a subsequent operating system crash can leave the dump corrupt\&. Generally, this option is useful for testing but should not be used when dumping data from production installation\&.
381 .RE
382 .PP
383 \fB\-\-no\-table\-access\-method\fR
384 .RS 4
385 Do not output commands to select table access methods\&. With this option, all objects will be created with whichever table access method is the default during restore\&.
386 .RE
387 .PP
388 \fB\-\-no\-tablespaces\fR
389 .RS 4
390 Do not output commands to create tablespaces nor select tablespaces for objects\&. With this option, all objects will be created in whichever tablespace is the default during restore\&.
391 .RE
392 .PP
393 \fB\-\-no\-toast\-compression\fR
394 .RS 4
395 Do not output commands to set
396 TOAST
397 compression methods\&. With this option, all columns will be restored with the default compression setting\&.
398 .RE
399 .PP
400 \fB\-\-no\-unlogged\-table\-data\fR
401 .RS 4
402 Do not dump the contents of unlogged tables\&. This option has no effect on whether or not the table definitions (schema) are dumped; it only suppresses dumping the table data\&.
403 .RE
404 .PP
405 \fB\-\-on\-conflict\-do\-nothing\fR
406 .RS 4
407 Add
408 ON CONFLICT DO NOTHING
409 to
410 \fBINSERT\fR
411 commands\&. This option is not valid unless
412 \fB\-\-inserts\fR
413 or
414 \fB\-\-column\-inserts\fR
415 is also specified\&.
416 .RE
417 .PP
418 \fB\-\-quote\-all\-identifiers\fR
419 .RS 4
420 Force quoting of all identifiers\&. This option is recommended when dumping a database from a server whose
421 PostgreSQL
422 major version is different from
423 pg_dumpall\*(Aqs, or when the output is intended to be loaded into a server of a different major version\&. By default,
424 pg_dumpall
425 quotes only identifiers that are reserved words in its own major version\&. This sometimes results in compatibility issues when dealing with servers of other versions that may have slightly different sets of reserved words\&. Using
426 \fB\-\-quote\-all\-identifiers\fR
427 prevents such issues, at the price of a harder\-to\-read dump script\&.
428 .RE
429 .PP
430 \fB\-\-restrict\-key=\fR\fB\fIrestrict_key\fR\fR
431 .RS 4
432 Use the provided string as the
433 psql
434 \fB\erestrict\fR
435 key in the dump output\&. If no restrict key is specified,
436 pg_dumpall
437 will generate a random one as needed\&. Keys may contain only alphanumeric characters\&.
438 .sp
439 This option is primarily intended for testing purposes and other scenarios that require repeatable output (e\&.g\&., comparing dump files)\&. It is not recommended for general use, as a malicious server with advance knowledge of the key may be able to inject arbitrary code that will be executed on the machine that runs
440 psql
441 with the dump output\&.
442 .RE
443 .PP
444 \fB\-\-rows\-per\-insert=\fR\fB\fInrows\fR\fR
445 .RS 4
446 Dump data as
447 \fBINSERT\fR
448 commands (rather than
449 \fBCOPY\fR)\&. Controls the maximum number of rows per
450 \fBINSERT\fR
451 command\&. The value specified must be a number greater than zero\&. Any error during restoring will cause only rows that are part of the problematic
452 \fBINSERT\fR
453 to be lost, rather than the entire table contents\&.
454 .RE
455 .PP
456 \fB\-\-statistics\fR
457 .RS 4
458 Dump statistics\&.
459 .RE
460 .PP
461 \fB\-\-statistics\-only\fR
462 .RS 4
463 Dump only the statistics, not the schema (data definitions) or data\&. Statistics for tables, materialized views, foreign tables, and indexes are dumped\&.
464 .RE
465 .PP
466 \fB\-\-sequence\-data\fR
467 .RS 4
468 Include sequence data in the dump\&. This is the default behavior except when
469 \fB\-\-no\-data\fR,
470 \fB\-\-schema\-only\fR, or
471 \fB\-\-statistics\-only\fR
472 is specified\&.
473 .RE
474 .PP
475 \fB\-\-use\-set\-session\-authorization\fR
476 .RS 4
477 Output SQL\-standard
478 \fBSET SESSION AUTHORIZATION\fR
479 commands instead of
480 \fBALTER OWNER\fR
481 commands to determine object ownership\&. This makes the dump more standards compatible, but depending on the history of the objects in the dump, might not restore properly\&.
482 .RE
483 .PP
484 \fB\-?\fR
485 .br
486 \fB\-\-help\fR
487 .RS 4
488 Show help about
489 pg_dumpall
490 command line arguments, and exit\&.
491 .RE
492 .PP
493 The following command\-line options control the database connection parameters\&.
494 .PP
495 \fB\-d \fR\fB\fIconnstr\fR\fR
496 .br
497 \fB\-\-dbname=\fR\fB\fIconnstr\fR\fR
498 .RS 4
499 Specifies parameters used to connect to the server, as a
500 connection string; these will override any conflicting command line options\&.
501 .sp
502 The option is called
503 \-\-dbname
504 for consistency with other client applications, but because
505 pg_dumpall
506 needs to connect to many databases, the database name in the connection string will be ignored\&. Use the
507 \-l
508 option to specify the name of the database used for the initial connection, which will dump global objects and discover what other databases should be dumped\&.
509 .RE
510 .PP
511 \fB\-h \fR\fB\fIhost\fR\fR
512 .br
513 \fB\-\-host=\fR\fB\fIhost\fR\fR
514 .RS 4
515 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
516 \fBPGHOST\fR
517 environment variable, if set, else a Unix domain socket connection is attempted\&.
518 .RE
519 .PP
520 \fB\-l \fR\fB\fIdbname\fR\fR
521 .br
522 \fB\-\-database=\fR\fB\fIdbname\fR\fR
523 .RS 4
524 Specifies the name of the database to connect to for dumping global objects and discovering what other databases should be dumped\&. If not specified, the
525 postgres
526 database will be used, and if that does not exist,
527 template1
528 will be used\&.
529 .RE
530 .PP
531 \fB\-p \fR\fB\fIport\fR\fR
532 .br
533 \fB\-\-port=\fR\fB\fIport\fR\fR
534 .RS 4
535 Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections\&. Defaults to the
536 \fBPGPORT\fR
537 environment variable, if set, or a compiled\-in default\&.
538 .RE
539 .PP
540 \fB\-U \fR\fB\fIusername\fR\fR
541 .br
542 \fB\-\-username=\fR\fB\fIusername\fR\fR
543 .RS 4
544 User name to connect as\&.
545 .RE
546 .PP
547 \fB\-w\fR
548 .br
549 \fB\-\-no\-password\fR
550 .RS 4
551 Never issue a password prompt\&. If the server requires password authentication and a password is not available by other means such as a
552 \&.pgpass
553 file, the connection attempt will fail\&. This option can be useful in batch jobs and scripts where no user is present to enter a password\&.
554 .RE
555 .PP
556 \fB\-W\fR
557 .br
558 \fB\-\-password\fR
559 .RS 4
560 Force
561 pg_dumpall
562 to prompt for a password before connecting to a database\&.
563 .sp
564 This option is never essential, since
565 pg_dumpall
566 will automatically prompt for a password if the server demands password authentication\&. However,
567 pg_dumpall
568 will waste a connection attempt finding out that the server wants a password\&. In some cases it is worth typing
569 \fB\-W\fR
570 to avoid the extra connection attempt\&.
571 .sp
572 Note that the password prompt will occur again for each database to be dumped\&. Usually, it\*(Aqs better to set up a
573 ~/\&.pgpass
574 file than to rely on manual password entry\&.
575 .RE
576 .PP
577 \fB\-\-role=\fR\fB\fIrolename\fR\fR
578 .RS 4
579 Specifies a role name to be used to create the dump\&. This option causes
580 pg_dumpall
581 to issue a
582 \fBSET ROLE\fR
583 \fIrolename\fR
584 command after connecting to the database\&. It is useful when the authenticated user (specified by
585 \fB\-U\fR) lacks privileges needed by
586 pg_dumpall, but can switch to a role with the required rights\&. Some installations have a policy against logging in directly as a superuser, and use of this option allows dumps to be made without violating the policy\&.
587 .RE
588 .SH "ENVIRONMENT"
589 .PP
590 \fBPGHOST\fR
591 .br
592 \fBPGOPTIONS\fR
593 .br
594 \fBPGPORT\fR
595 .br
596 \fBPGUSER\fR
597 .RS 4
598 Default connection parameters
599 .RE
600 .PP
601 \fBPG_COLOR\fR
602 .RS 4
603 Specifies whether to use color in diagnostic messages\&. Possible values are
604 always,
605 auto
606 and
607 never\&.
608 .RE
609 .PP
610 This utility, like most other
611 PostgreSQL
612 utilities, also uses the environment variables supported by
613 libpq
614 (see
615 Section\ \&32.15)\&.
616 .SH "NOTES"
617 .PP
618 Since
619 pg_dumpall
620 calls
621 pg_dump
622 internally, some diagnostic messages will refer to
623 pg_dump\&.
624 .PP
625 The
626 \fB\-\-clean\fR
627 option can be useful even when your intention is to restore the dump script into a fresh cluster\&. Use of
628 \fB\-\-clean\fR
629 authorizes the script to drop and re\-create the built\-in
630 postgres
631 and
632 template1
633 databases, ensuring that those databases will retain the same properties (for instance, locale and encoding) that they had in the source cluster\&. Without the option, those databases will retain their existing database\-level properties, as well as any pre\-existing contents\&.
634 .PP
635 If
636 \fB\-\-statistics\fR
637 is specified,
638 \fBpg_dumpall\fR
639 will include most optimizer statistics in the resulting dump file\&. However, some statistics may not be included, such as those created explicitly with
640 CREATE STATISTICS (\fBCREATE_STATISTICS\fR(7))
641 or custom statistics added by an extension\&. Therefore, it may be useful to run
642 \fBANALYZE\fR
643 on each database after restoring from a dump file to ensure optimal performance\&. You can also run
644 \fBvacuumdb \-a \-z\fR
645 to analyze all databases\&.
646 .PP
647 The dump script should not be expected to run completely without errors\&. In particular, because the script will issue
648 \fBCREATE ROLE\fR
649 for every role existing in the source cluster, it is certain to get a
650 \(lqrole already exists\(rq
651 error for the bootstrap superuser, unless the destination cluster was initialized with a different bootstrap superuser name\&. This error is harmless and should be ignored\&. Use of the
652 \fB\-\-clean\fR
653 option is likely to produce additional harmless error messages about non\-existent objects, although you can minimize those by adding
654 \fB\-\-if\-exists\fR\&.
655 .PP
656 pg_dumpall
657 requires all needed tablespace directories to exist before the restore; otherwise, database creation will fail for databases in non\-default locations\&.
658 .PP
659 It is generally recommended to use the
660 \fB\-X\fR
661 (\fB\-\-no\-psqlrc\fR) option when restoring a database from a
662 pg_dumpall
663 script to ensure a clean restore process and prevent potential conflicts with non\-default
664 psql
665 configurations\&. Additionally, because the
666 pg_dumpall
667 script may include
668 psql
669 meta\-commands, it may be incompatible with clients other than
670 psql\&.
671 .SH "EXAMPLES"
672 .PP
673 To dump all databases:
674 .sp
675 .if n \{\
676 .RS 4
677 .\}
678 .nf
679 $ \fBpg_dumpall > db\&.out\fR
680 .fi
681 .if n \{\
682 .RE
683 .\}
684 .PP
685 To restore database(s) from this file, you can use:
686 .sp
687 .if n \{\
688 .RS 4
689 .\}
690 .nf
691 $ \fBpsql \-X \-f db\&.out \-d postgres\fR
692 .fi
693 .if n \{\
694 .RE
695 .\}
696 .sp
697 It is not important which database you connect to here since the script file created by
698 pg_dumpall
699 will contain the appropriate commands to create and connect to the saved databases\&. An exception is that if you specified
700 \fB\-\-clean\fR, you must connect to the
701 postgres
702 database initially; the script will attempt to drop other databases immediately, and that will fail for the database you are connected to\&.
703 .SH "SEE ALSO"
704 .PP
705 Check
706 \fBpg_dump\fR(1)
707 for details on possible error conditions\&.