PG_DUMPALL(1)
pg_dumpall ๐ (that's the PostgreSQL 18.6 Documentation manual, bestie)
โจ NAME โจ
pg_dumpall โ grab a whole PostgreSQL database cluster and yeet it into a script file ๐ซถ
๐ธ SYNOPSIS ๐ธ
pg_dumpall [connection-option...] [option...]
๐ฆ DESCRIPTION ๐ฆ
okay so picture this: pg_dumpall is the utility that writes out (aka "dumps", we love a verb) all the PostgreSQL databases of a cluster into one single script file. iconic behavior honestly. That script file is full of SQL commands, and you can feed it straight into psql(1) to restore the databases back. The way it pulls this off? It literally calls pg_dump(1) for every single database in the cluster. no cap.
But wait, there's more ๐
โ pg_dumpall also dumps the global objects that are shared across all databases, which are:
- database roles
- tablespaces
- privilege grants for configuration parameters
(and yeah, pg_dump does not save these objects. so this is the moment where pg_dumpall is the main character.)
Because pg_dumpall reads tables from every database, you will most likely have to connect as a database superuser to get a complete dump. Also โ and this part matters โ you need superuser privileges to execute the saved script, because that's what lets it add roles and create databases. ๐
The SQL script goes to standard output. If you want it in a file, use the -f/--file option or just use shell operators to redirect it. easy.
pg_dumpall needs to connect to the PostgreSQL server several times โ once per database, bestie, it's a lot. So if you're using password authentication, it will ask for a password each and every time. ๐ญ In those cases it's super convenient to have a ~/.pgpass file. See Section 32.16 for more info.
โ ๏ธ Warning โ ๏ธ Restoring a dump causes the destination to execute arbitrary code of the source superusers' choice. Partial dumps and partial restores do not limit that. So 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.
๐ OPTIONS ๐
The following command-line options control the content and format of the output. let's get into it ๐
-a,--data-onlyโ Dump only the data, no schema (data definitions) and no statistics. just the vibes, none of the structure.-c,--cleanโ Emit SQL commands toDROPall the dumped databases, roles, and tablespaces before recreating them. obsessed with a fresh start. This is useful when the restore is meant to overwrite an existing cluster. Heads up tho: if any of those objects don't exist in the destination cluster, you'll get ignorable error messages during restore โ unless--if-existsis also specified. ๐-Eencoding,--encoding=encoding โ 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: set thePGCLIENTENCODINGenvironment variable to the dump encoding you want. two paths, same slay.) โจ-ffilename,--file=filename โ Send output to the specified file. If you omit this, standard output is used.-g,--globals-onlyโ Dump only global objects (roles and tablespaces), no databases. globals only, no crumbs.-O,--no-ownerโ Do not output commands to set ownership of objects to match the original database. By default,pg_dumpallissuesALTER OWNERorSET SESSION AUTHORIZATIONstatements to set ownership of created schema elements. Those statements will fail when the script is run unless it's started by a superuser (or the same user that owns all the objects in the script). So if you want a script that any user can restore โ but which gives that user ownership of all the objects โ specify-O.-r,--roles-onlyโ Dump only roles, no databases or tablespaces. roles only, periodt.-s,--schema-onlyโ Dump only the object definitions (schema), not data.-Susername,--superuser=username โ Specify the superuser user name to use when disabling triggers. This only matters if--disable-triggersis used. (Usually it's better to leave this out and instead start the resulting script as superuser. fr fr.)-t,--tablespaces-onlyโ Dump only tablespaces, no databases or roles.-v,--verboseโ Specifies verbose mode. This makespg_dumpalloutput start/stop times to the dump file, and progress messages to standard error. Repeat the option and you get additional debug-level messages on standard error too. This option is also passed down topg_dump. ๐ฃ๏ธ-V,--versionโ Print thepg_dumpallversion and exit. short and sweet.-x,--no-privileges,--no-aclโ Prevent dumping of access privileges (grant/revoke commands).--binary-upgradeโ This option is for use by in-place upgrade utilities. Its use for other purposes is not recommended or supported. The behavior of this option may change in future releases without notice. โ ๏ธ (so like, don't just casually use it, bestie)--column-inserts,--attribute-insertsโ Dump data asINSERTcommands with explicit column names (INSERT INTO table (column, ...) VALUES ...). This will make restoration very slow; it's mainly useful for making dumps that can be loaded into non-PostgreSQL databases.--disable-dollar-quotingโ This disables the use of dollar quoting for function bodies, and forces them to be quoted using SQL standard string syntax.--disable-triggersโ This one is only relevant when you're creating a dump with data and without schema. It tellspg_dumpallto include commands that 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. ๐ซ
Presently, the commands emitted for --disable-triggers must be done as superuser. So you should also specify a superuser name with -S, or โ preferably โ be careful to start the resulting script as a superuser.
--exclude-database=pattern โ Do not dump databases whose name matches pattern. You can exclude multiple patterns by writing multiple--exclude-databaseswitches. The pattern parameter is interpreted as a pattern according to the same rules used by psql's\dcommands (see Patterns), so you can also exclude multiple databases by writing wildcard characters in the pattern. When using wildcards, be careful to quote the pattern if needed, so the shell doesn't do wildcard expansion on you. ๐--extra-float-digits=ndigits โ Use the specified value ofextra_float_digitswhen dumping floating-point data, instead of the maximum available precision. Routine dumps made for backup purposes should not use this option.--filter=filename โ Specify a filename from which to read patterns for databases excluded from the dump. The patterns are interpreted according to the same rules as--exclude-database. To read from STDIN, use-as the filename. The--filteroption can be specified in conjunction with--exclude-databasefor excluding databases, and it can also be specified more than once for multiple filter files. ๐
The file lists one database pattern per row, with the following format:
exclude database PATTERN
Lines starting with # are considered comments and ignored. Comments can be placed after an object pattern row as well. Blank lines are also ignored. See Patterns for how to perform quoting in patterns.
--if-existsโ UseDROP ... IF EXISTScommands to drop objects in--cleanmode. This suppresses the "does not exist" errors that might otherwise be reported. This option is not valid unless--cleanis also specified.--insertsโ Dump data asINSERTcommands (rather thanCOPY). This will make restoration very slow; it's mainly useful for making dumps that can be loaded into non-PostgreSQL databases. Note that the restore might fail altogether if you have rearranged column order. The--column-insertsoption is safer, though even slower. ๐--load-via-partition-rootโ When dumping data for a table partition, make theCOPYorINSERTstatements 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 don't always fall into the same partitions as they did on the original server. That could happen, for example, if the partitioning column is of typetextand the two systems have different definitions of the collation used to sort the partitioning column. ๐ฆ--lock-wait-timeout=timeout โ 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 timeout. The timeout may be specified in any of the formats accepted bySET statement_timeout.--no-commentsโ Do not dumpCOMMENTcommands.--no-dataโ Do not dump data.--no-policiesโ Do not dump row security policies.--no-publicationsโ Do not dump publications.--no-role-passwordsโ 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't needed when this option is specified, the role information is read from the catalog viewpg_rolesinstead ofpg_authid. Therefore, this option also helps if access topg_authidis restricted by some security policy. ๐--no-schemaโ Do not dump schema (data definitions).--no-security-labelsโ Do not dump security labels.--no-statisticsโ Do not dump statistics. This is the default.--no-subscriptionsโ Do not dump subscriptions.--no-syncโ By default,pg_dumpallwill wait for all files to be written safely to disk. This option causespg_dumpallto return without waiting, which is faster โ but it means that a subsequent operating system crash can leave the dump corrupt. Generally this option is useful for testing, but it should not be used when dumping data from a production installation. โ ๏ธ--no-table-access-methodโ 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.--no-tablespacesโ 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.--no-toast-compressionโ Do not output commands to set TOAST compression methods. With this option, all columns will be restored with the default compression setting.
more coming, bestie โ don't go anywhere ๐
--no-unlogged-table-dataโ bestie, this one says: do NOT dump the contents of unlogged tables. Quick clarification tho, because people get confused โ it does not touch whether the table definitions (aka the schema) get dumped. Schema stays. Only the actual table data gets suppressed. ๐ซถ--on-conflict-do-nothingโ slapsON CONFLICT DO NOTHINGontoINSERTcommands. โ ๏ธ But heads up: this option is not valid unless you also specify--insertsor--column-inserts. It needs a buddy. No buddy, no deal.--quote-all-identifiersโ forces quoting of all identifiers. Highly recommended when you're dumping from a server whose PostgreSQL major version is different frompg_dumpall's, or when the output is meant to be loaded into a server of a different major version. By default,pg_dumpallonly quotes identifiers that are reserved words in its own major version, and that lowkey causes compatibility drama with other-version servers that have slightly different reserved-word lists. So this option prevents those issues โ the tradeoff being a dump script that's harder to read. Worth it tho. ๐--restrict-key=restrict_keyโ uses the string you provide as thepsql\restrictkey in the dump output. If you don't specify a restrict key,pg_dumpallwill generate a random one as needed. Keys may contain only alphanumeric characters.
This option is primarily intended for testing purposes and other scenarios that need repeatable output (like comparing dump files). It is not recommended for general use โ because a malicious server that knows the key ahead of time may be able to inject arbitrary code that will be executed on the machine running psql with the dump output. ๐ญ So like. Know what you're doing.
--rows-per-insert=nrowsโ dumps data asINSERTcommands (instead ofCOPY) and controls the maximum number of rows perINSERTcommand. The value must be a number greater than zero. The cute part: any error during restore only loses the rows that are part of the problematicINSERT, rather than the entire table's contents. Damage control, but make it fashion. โจ--statisticsโ dumps optimizer statistics.--statistics-onlyโ dumps only the statistics, not the schema (data definitions) and not the data. Optimizer statistics for tables, materialized views, foreign tables, and indexes are what gets dumped.--sequence-dataโ includes sequence data in the dump. This is the default behavior except when--no-data,--schema-only, or--statistics-onlyis specified.--use-set-session-authorizationโ outputs SQL-standardSET SESSION AUTHORIZATIONcommands instead ofALTER OWNERcommands to determine object ownership. This makes the dump more standards compatible, but depending on the history of the objects in the dump, it might not restore properly. ๐-?,--helpโ shows help aboutpg_dumpallcommand line arguments, and exits. The classic "what do I even type" button.
Okay so the next lil squad of command-line options controls the database connection parameters. Group chat, assemble: ๐ฆ
-d connstr,--dbname=connstrโ specifies the parameters used to connect to the server, as a connection string; these will override any conflicting command line options.
The option is called --dbname for consistency with other client applications, but because pg_dumpall needs to connect to many databases, the database name in the connection string will be ignored. Use the -l option to specify the name of the database used for the initial connection โ that one dumps global objects and discovers what other databases should be dumped. ๐ง
-h host,--host=hostโ specifies the host name of the machine on which the database server is running. If the value begins with a slash, it's used as the directory for the Unix domain socket. The default comes from thePGHOSTenvironment variable if it's set, else a Unix domain socket connection is attempted.-l dbname,--database=dbnameโ specifies the name of the database to connect to for dumping global objects and discovering what other databases should be dumped. If you don't specify it, thepostgresdatabase will be used, and if that one doesn't exist,template1will be used. Backup plan built in. ๐-p port,--port=portโ specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to thePGPORTenvironment variable if set, or a compiled-in default.-U username,--username=usernameโ user name to connect as.-w,--no-passwordโ never issue a password prompt. If the server requires password authentication and a password isn't available by other means such as a.pgpassfile, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password. Set it and forget it, respectfully. ๐-W,--passwordโ forcespg_dumpallto prompt for a password before connecting to a database.
This option is never essential, since pg_dumpall will automatically prompt for a password if the server demands password authentication. However, pg_dumpall will waste a connection attempt finding out that the server wants a password. In some cases it's worth typing -W to avoid that extra connection attempt.
Note that the password prompt will occur again for each database to be dumped. Usually, it's better to set up a ~/.pgpass file than to rely on manual password entry. fr fr, save yourself. ๐ญ
--role=rolenameโ specifies a role name to be used to create the dump. This option causespg_dumpallto issue aSET ROLE rolenamecommand after connecting to the database. It's useful when the authenticated user (specified by-U) lacks privileges needed bypg_dumpall, but can switch to a role with the required rights. Some installations have a policy against logging in directly as a superuser, and using this option lets dumps be made without violating that policy. Iconic workaround behavior. ๐
โจ ENVIRONMENT โจ
PGHOSTPGOPTIONSPGPORTPGUSER
โ these are the default connection parameters. ๐ซถ
PG_COLORโ specifies whether to use color in diagnostic messages. Possible values arealways,autoandnever.
This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 32.15).
๐ NOTES ๐
Since pg_dumpall calls pg_dump internally, some diagnostic messages will refer to pg_dump. Not a bug, just the vibes. ๐ธ
The --clean option can be useful even when your intention is to restore the dump script into a fresh cluster. Use of --clean authorizes the script to drop and re-create the built-in postgres and template1 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.
When --statistics is specified, pg_dumpall will include most optimizer statistics in the resulting dump file. This does not include all statistics โ such as those created explicitly with CREATE STATISTICS (CREATE_STATISTICS(7)), custom statistics added by an extension, or statistics collected by the cumulative statistics system. Therefore, it may still be useful to run ANALYZE on each database after restoring from a dump file to ensure optimal performance. You can also run vacuumdb -a -z to analyze all databases. ๐ง
The dump script should not be expected to run completely without errors. In particular, because the script will issueCREATE ROLEfor every role existing in the source cluster, it is certain to get a "role already exists" 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--cleanoption is likely to produce additional harmless error messages about non-existent objects, although you can minimize those by adding--if-exists.
pg_dumpall requires all needed tablespace directories to exist before the restore; otherwise, database creation will fail for databases in non-default locations. ๐ญ
It is generally recommended to use the -X (--no-psqlrc) option when restoring a database from a pg_dumpall script to ensure a clean restore process and prevent potential conflicts with non-default psql configurations. Additionally, because the pg_dumpall script may include psql meta-commands, it may be incompatible with clients other than psql. ๐
๐ EXAMPLES ๐
To dump all databases:
$ pg_dumpall > db.out
To restore database(s) from this file, you can use:
$ psql -X -f db.out -d postgres
It's not important which database you connect to here, since the script file created by pg_dumpall will contain the appropriate commands to create and connect to the saved databases. Exception tho: if you specified --clean, you must connect to the postgres database initially; the script will attempt to drop other databases immediately, and that will fail for the database you're connected to. ๐ซ
๐ SEE ALSO ๐
Check pg_dump(1) for details on possible error conditions.
That's the whole page, bestie โ every flag, every env var, every warning, all of it. This was PostgreSQL 18.6, dated 2026, and the page is PG_DUMPALL(1). Go dump responsibly and hydrate. ๐โจ
๐ฆ where this page comes from
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- opensuse-leap 16.0: postgresql18 18.6-160000.1.1 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms