3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
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 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 pg_dumpall \- extract a PostgreSQL database cluster into a script file
33 .HP \w'\fBpg_dumpall\fR\ 'u
34 \fBpg_dumpall\fR [\fIconnection\-option\fR...] [\fIoption\fR...]
38 is a utility for writing out (\(lqdumping\(rq) all
40 databases of a cluster into one script file\&. The script file contains
42 commands that can be used as input to
44 to restore the databases\&. It does this by calling
46 for each database in the cluster\&.
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\&.)
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\&.
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\&.
60 needs to connect several times to the
62 server (once per database)\&. If you use password authentication it will ask for a password each time\&. It is convenient to have a
64 file in such cases\&. See
66 for more information\&.
72 .nr an-no-space-flag 1
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\&.
85 The following command\-line options control the content and format of the output\&.
91 Dump only the data, not the schema (data definitions) or statistics\&.
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
105 \fB\-E \fR\fB\fIencoding\fR\fR
107 \fB\-\-encoding=\fR\fB\fIencoding\fR\fR
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\&.)
114 \fB\-f \fR\fB\fIfilename\fR\fR
116 \fB\-\-file=\fR\fB\fIfilename\fR\fR
118 Send output to the specified file\&. If this is omitted, the standard output is used\&.
123 \fB\-\-globals\-only\fR
125 Dump only global objects (roles and tablespaces), no databases\&.
132 Do not output commands to set ownership of objects to match the original database\&. By default,
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
144 \fB\-\-roles\-only\fR
146 Dump only roles, no databases or tablespaces\&.
151 \fB\-\-schema\-only\fR
153 Dump only the object definitions (schema), not data\&.
156 \fB\-S \fR\fB\fIusername\fR\fR
158 \fB\-\-superuser=\fR\fB\fIusername\fR\fR
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\&.)
167 \fB\-\-tablespaces\-only\fR
169 Dump only tablespaces, no databases or roles\&.
176 Specifies verbose mode\&. This will cause
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
193 \fB\-\-no\-privileges\fR
197 Prevent dumping of access privileges (grant/revoke commands)\&.
200 \fB\-\-binary\-upgrade\fR
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\&.
205 \fB\-\-column\-inserts\fR
207 \fB\-\-attribute\-inserts\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
215 \fB\-\-disable\-dollar\-quoting\fR
217 This option disables the use of dollar quoting for function bodies, and forces them to be quoted using SQL standard string syntax\&.
220 \fB\-\-disable\-triggers\fR
222 This option is relevant only when creating a dump with data and without schema\&. It instructs
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\&.
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\&.
232 \fB\-\-exclude\-database=\fR\fB\fIpattern\fR\fR
234 Do not dump databases whose name matches
235 \fIpattern\fR\&. Multiple patterns can be excluded by writing multiple
236 \fB\-\-exclude\-database\fR
239 parameter is interpreted as a pattern according to the same rules used by
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\&.
246 \fB\-\-extra\-float\-digits=\fR\fB\fIndigits\fR\fR
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\&.
251 \fB\-\-filter=\fR\fB\fIfilename\fR\fR
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
257 as the filename\&. The
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\&.
263 The file lists one database pattern per row, with the following format:
269 exclude database \fIPATTERN\fR
277 are considered comments and ignored\&. Comments can be placed after an object pattern row as well\&. Blank lines are also ignored\&. See
279 for how to perform quoting in patterns\&.
285 DROP \&.\&.\&. IF EXISTS
286 commands to drop objects in
288 mode\&. This suppresses
289 \(lqdoes not exist\(rq
290 errors that might otherwise be reported\&. This option is not valid unless
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\&.
306 \fB\-\-load\-via\-partition\-root\fR
308 When dumping data for a table partition, make the
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\&.
315 \fB\-\-lock\-wait\-timeout=\fR\fB\fItimeout\fR\fR
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\&.
322 \fB\-\-no\-comments\fR
334 \fB\-\-no\-policies\fR
336 Do not dump row security policies\&.
339 \fB\-\-no\-publications\fR
341 Do not dump publications\&.
344 \fB\-\-no\-role\-passwords\fR
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
349 pg_authid\&. Therefore, this option also helps if access to
351 is restricted by some security policy\&.
356 Do not dump schema (data definitions)\&.
359 \fB\-\-no\-security\-labels\fR
361 Do not dump security labels\&.
364 \fB\-\-no\-statistics\fR
366 Do not dump statistics\&. This is the default\&.
369 \fB\-\-no\-subscriptions\fR
371 Do not dump subscriptions\&.
378 will wait for all files to be written safely to disk\&. This option causes
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\&.
383 \fB\-\-no\-table\-access\-method\fR
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\&.
388 \fB\-\-no\-tablespaces\fR
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\&.
393 \fB\-\-no\-toast\-compression\fR
395 Do not output commands to set
397 compression methods\&. With this option, all columns will be restored with the default compression setting\&.
400 \fB\-\-no\-unlogged\-table\-data\fR
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\&.
405 \fB\-\-on\-conflict\-do\-nothing\fR
408 ON CONFLICT DO NOTHING
411 commands\&. This option is not valid unless
414 \fB\-\-column\-inserts\fR
418 \fB\-\-quote\-all\-identifiers\fR
420 Force quoting of all identifiers\&. This option is recommended when dumping a database from a server whose
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,
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\&.
430 \fB\-\-restrict\-key=\fR\fB\fIrestrict_key\fR\fR
432 Use the provided string as the
435 key in the dump output\&. If no restrict key is specified,
437 will generate a random one as needed\&. Keys may contain only alphanumeric characters\&.
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
441 with the dump output\&.
444 \fB\-\-rows\-per\-insert=\fR\fB\fInrows\fR\fR
448 commands (rather than
449 \fBCOPY\fR)\&. Controls the maximum number of rows per
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
453 to be lost, rather than the entire table contents\&.
461 \fB\-\-statistics\-only\fR
463 Dump only the statistics, not the schema (data definitions) or data\&. Statistics for tables, materialized views, foreign tables, and indexes are dumped\&.
466 \fB\-\-sequence\-data\fR
468 Include sequence data in the dump\&. This is the default behavior except when
470 \fB\-\-schema\-only\fR, or
471 \fB\-\-statistics\-only\fR
475 \fB\-\-use\-set\-session\-authorization\fR
478 \fBSET SESSION AUTHORIZATION\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\&.
490 command line arguments, and exit\&.
493 The following command\-line options control the database connection parameters\&.
495 \fB\-d \fR\fB\fIconnstr\fR\fR
497 \fB\-\-dbname=\fR\fB\fIconnstr\fR\fR
499 Specifies parameters used to connect to the server, as a
500 connection string; these will override any conflicting command line options\&.
504 for consistency with other client applications, but because
506 needs to connect to many databases, the database name in the connection string will be ignored\&. Use the
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\&.
511 \fB\-h \fR\fB\fIhost\fR\fR
513 \fB\-\-host=\fR\fB\fIhost\fR\fR
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
517 environment variable, if set, else a Unix domain socket connection is attempted\&.
520 \fB\-l \fR\fB\fIdbname\fR\fR
522 \fB\-\-database=\fR\fB\fIdbname\fR\fR
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
526 database will be used, and if that does not exist,
531 \fB\-p \fR\fB\fIport\fR\fR
533 \fB\-\-port=\fR\fB\fIport\fR\fR
535 Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections\&. Defaults to the
537 environment variable, if set, or a compiled\-in default\&.
540 \fB\-U \fR\fB\fIusername\fR\fR
542 \fB\-\-username=\fR\fB\fIusername\fR\fR
544 User name to connect as\&.
549 \fB\-\-no\-password\fR
551 Never issue a password prompt\&. If the server requires password authentication and a password is not available by other means such as a
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\&.
562 to prompt for a password before connecting to a database\&.
564 This option is never essential, since
566 will automatically prompt for a password if the server demands password authentication\&. However,
568 will waste a connection attempt finding out that the server wants a password\&. In some cases it is worth typing
570 to avoid the extra connection attempt\&.
572 Note that the password prompt will occur again for each database to be dumped\&. Usually, it\*(Aqs better to set up a
574 file than to rely on manual password entry\&.
577 \fB\-\-role=\fR\fB\fIrolename\fR\fR
579 Specifies a role name to be used to create the dump\&. This option causes
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\&.
598 Default connection parameters
603 Specifies whether to use color in diagnostic messages\&. Possible values are
610 This utility, like most other
612 utilities, also uses the environment variables supported by
622 internally, some diagnostic messages will refer to
627 option can be useful even when your intention is to restore the dump script into a fresh cluster\&. Use of
629 authorizes the script to drop and re\-create the built\-in
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\&.
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
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\&.
647 The dump script should not be expected to run completely without errors\&. In particular, because the script will issue
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
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\&.
657 requires all needed tablespace directories to exist before the restore; otherwise, database creation will fail for databases in non\-default locations\&.
659 It is generally recommended to use the
661 (\fB\-\-no\-psqlrc\fR) option when restoring a database from a
663 script to ensure a clean restore process and prevent potential conflicts with non\-default
665 configurations\&. Additionally, because the
669 meta\-commands, it may be incompatible with clients other than
673 To dump all databases:
679 $ \fBpg_dumpall > db\&.out\fR
685 To restore database(s) from this file, you can use:
691 $ \fBpsql \-X \-f db\&.out \-d postgres\fR
697 It is not important which database you connect to here since the script file created by
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
702 database initially; the script will attempt to drop other databases immediately, and that will fail for the database you are connected to\&.
707 for details on possible error conditions\&.