Linux "pg_dumpall" Command Line Options and Examples
extract a PostgreSQL database cluster into a script file

pg_dumpall is a utility for writing out (“dumping”) all PostgreSQL databases of a cluster into one script file. The script file contains SQL commands that can be used as input to psql(1) to restore the databases. It does this by calling pg_dump(1) for each database in a cluster.


Usage:

pg_dumpall [connection-option...] [option...]




Command Line Options:

--data-only
Dump only the data, not the schema (data definitions).
pg_dumpall --data-only ...
--clean
Include SQL commands to clean (drop) databases before recreating them. DROP commands for roles andtablespaces are added as well.
pg_dumpall --clean ...
--file
Send output to the specified file. If this is omitted, the standard output is used.
pg_dumpall --file ...
--globals-only
Dump only global objects (roles and tablespaces), no databases.
pg_dumpall --globals-only ...
--oids
Dump object identifiers (OIDs) as part of the data for every table. Use this option if your applicationreferences the OID columns in some way (e.g., in a foreign key constraint). Otherwise, this option shouldnot be used.
pg_dumpall --oids ...
--no-owner
Do not output commands to set ownership of objects to match the original database. By default, pg_dumpallissues ALTER OWNER or SET SESSION AUTHORIZATION 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 userthat owns all of the objects in the script). To make a script that can be restored by any user, but willgive that user ownership of all the objects, specify -O.
pg_dumpall --no-owner ...
--roles-only
Dump only roles, no databases or tablespaces.
pg_dumpall --roles-only ...
--schema-only
Dump only the object definitions (schema), not data.
pg_dumpall --schema-only ...
--superuser
Specify the superuser user name to use when disabling triggers. This is relevant only if
pg_dumpall --superuser ...
--tablespaces-only
Dump only tablespaces, no databases or roles.
pg_dumpall --tablespaces-only ...
--verbose
Specifies verbose mode. This will cause pg_dumpall to output start/stop times to the dump file, andprogress messages to standard error. It will also enable verbose output in pg_dump.
pg_dumpall --verbose ...
--version
Print the pg_dumpall version and exit.
pg_dumpall --version ...
--no-acl
Prevent dumping of access privileges (grant/revoke commands).
pg_dumpall --no-acl ...
--binary-upgrade
This option is for use by in-place upgrade utilities. Its use for other purposes is not recommended orsupported. The behavior of the option may change in future releases without notice.
pg_dumpall --binary-upgrade ...
--attribute-inserts
Dump data as INSERT commands with explicit column names (INSERT INTO table (column, ...) VALUES ...). Thiswill make restoration very slow; it is mainly useful for making dumps that can be loaded intonon-PostgreSQL databases.
pg_dumpall --attribute-inserts ...
--disable-dollar-quoting
This option disables the use of dollar quoting for function bodies, and forces them to be quoted using SQLstandard string syntax.
pg_dumpall --disable-dollar-quoting ...
--disable-triggers
This option is relevant only when creating a data-only dump. It instructs pg_dumpall to include commandsto temporarily disable triggers on the target tables while the data is reloaded. Use this if you havereferential integrity checks or other triggers on the tables that you do not want to invoke during datareload.Presently, the commands emitted for --disable-triggers must be done as superuser. So, you should alsospecify a superuser name with -S, or preferably be careful to start the resulting script as a superuser.
pg_dumpall --disable-triggers ...
--if-exists
Use conditional commands (i.e. add an IF EXISTS clause) to clean databases and other objects. This optionis not valid unless --clean is also specified.
pg_dumpall --if-exists ...
--inserts
Dump data as INSERT commands (rather than COPY). This will make restoration very slow; it is mainly usefulfor making dumps that can be loaded into non-PostgreSQL databases. Note that the restore might failaltogether if you have rearranged column order. The --column-inserts option is safer, though even slower.
pg_dumpall --inserts ...
--lock-wait-timeout
Do not wait forever to acquire shared table locks at the beginning of the dump. Instead, fail if unable tolock a table within the specified timeout. The timeout may be specified in any of the formats accepted bySET statement_timeout. Allowed values vary depending on the server version you are dumping from, but aninteger number of milliseconds is accepted by all versions since 7.3. This option is ignored when dumpingfrom a pre-7.3 server.
pg_dumpall --lock-wait-timeout ...
--no-publications
Do not dump publications.
pg_dumpall --no-publications ...
--no-role-passwords
Do not dump passwords for roles. When restored, roles will have a null password, and passwordauthentication will always fail until the password is set. Since password values aren't needed when thisoption is specified, the role information is read from the catalog view pg_roles instead of pg_authid.Therefore, this option also helps if access to pg_authid is restricted by some security policy.
pg_dumpall --no-role-passwords ...
--no-security-labels
Do not dump security labels.
pg_dumpall --no-security-labels ...
--no-subscriptions
Do not dump subscriptions.
pg_dumpall --no-subscriptions ...
--no-sync
By default, pg_dumpall will wait for all files to be written safely to disk. This option causes pg_dumpallto return without waiting, which is faster, but means that a subsequent operating system crash can leavethe dump corrupt. Generally, this option is useful for testing but should not be used when dumping datafrom production installation.
pg_dumpall --no-sync ...
--no-tablespaces
Do not output commands to create tablespaces nor select tablespaces for objects. With this option, allobjects will be created in whichever tablespace is the default during restore.
pg_dumpall --no-tablespaces ...
--no-unlogged-table-data
Do not dump the contents of unlogged tables. This option has no effect on whether or not the tabledefinitions (schema) are dumped; it only suppresses dumping the table data.
pg_dumpall --no-unlogged-table-data ...
--quote-all-identifiers
Force quoting of all identifiers. This option is recommended when dumping a database from a server whosePostgreSQL major version is different from pg_dumpall's, or when the output is intended to be loaded intoa server of a different major version. By default, pg_dumpall quotes only identifiers that are reservedwords in its own major version. This sometimes results in compatibility issues when dealing with serversof other versions that may have slightly different sets of reserved words. Using --quote-all-identifiersprevents such issues, at the price of a harder-to-read dump script.
pg_dumpall --quote-all-identifiers ...
--use-set-session-authorization
Output SQL-standard SET SESSION AUTHORIZATION commands instead of ALTER OWNER commands to determine objectownership. This makes the dump more standards compatible, but depending on the history of the objects inthe dump, might not restore properly.
pg_dumpall --use-set-session-authorization ...
--help
Show help about pg_dumpall command line arguments, and exit.The following command-line options control the database connection parameters.
pg_dumpall --help ...
--dbname
Specifies parameters used to connect to the server, as a connection string. See Section 33.1.1 for moreinformation.The option is called --dbname for consistency with other client applications, but because pg_dumpall needsto connect to many databases, database name in the connection string will be ignored. Use -l option tospecify the name of the database used to dump global objects and to discover what other databases shouldbe dumped.
pg_dumpall --dbname ...
--host
Specifies the host name of the machine on which the database server is running. If the value begins with aslash, it is used as the directory for the Unix domain socket. The default is taken from the PGHOSTenvironment variable, if set, else a Unix domain socket connection is attempted.
pg_dumpall --host ...
--database
Specifies the name of the database to connect to for dumping global objects and discovering what otherdatabases should be dumped. If not specified, the postgres database will be used, and if that does notexist, template1 will be used.
pg_dumpall --database ...
--port
Specifies the TCP port or local Unix domain socket file extension on which the server is listening forconnections. Defaults to the PGPORT environment variable, if set, or a compiled-in default.
pg_dumpall --port ...
--username
User name to connect as.
pg_dumpall --username ...
--no-password
Never issue a password prompt. If the server requires password authentication and a password is notavailable by other means such as a .pgpass file, the connection attempt will fail. This option can beuseful in batch jobs and scripts where no user is present to enter a password.
pg_dumpall --no-password ...
--password
Force pg_dumpall to 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 serverdemands password authentication. However, pg_dumpall will waste a connection attempt finding out that theserver wants a password. In some cases it is worth typing -W to avoid the extra connection attempt.Note that the password prompt will occur again for each database to be dumped. Usually, it's better to setup a ~/.pgpass file than to rely on manual password entry.
pg_dumpall --password ...
--role
Specifies a role name to be used to create the dump. This option causes pg_dumpall to issue a SET ROLErolename command after connecting to the database. It is useful when the authenticated user (specified by
pg_dumpall --role ...
-U)
installations have a policy against logging in directly as a superuser, and use of this option allowsdumps to be made without violating the policy.ENVIRONMENTPGHOSTPGOPTIONSPGPORTPGUSERDefault connection parametersThis utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq(see Section 33.14).NOTESSince pg_dumpall calls pg_dump internally, some diagnostic messages will refer to pg_dump.Once restored, it is wise to run ANALYZE on each database so the optimizer has useful statistics. You can alsorun vacuumdb -a -z to analyze all databases.pg_dumpall requires all needed tablespace directories to exist before the restore; otherwise, databasecreation will fail for databases in non-default locations.EXAMPLESTo dump all databases:$ pg_dumpall > db.outTo reload database(s) from this file, you can use:$ psql -f db.out postgres(It is not important to which database you connect here since the script file created by pg_dumpall willcontain the appropriate commands to create and connect to the saved databases.)
pg_dumpall -U) ...