1PG_DUMPALL(1)            PostgreSQL 13.3 Documentation           PG_DUMPALL(1)
2
3
4

NAME

6       pg_dumpall - extract a PostgreSQL database cluster into a script file
7

SYNOPSIS

9       pg_dumpall [connection-option...] [option...]
10

DESCRIPTION

12       pg_dumpall is a utility for writing out (“dumping”) all PostgreSQL
13       databases of a cluster into one script file. The script file contains
14       SQL commands that can be used as input to psql(1) to restore the
15       databases. It does this by calling pg_dump(1) for each database in the
16       cluster.  pg_dumpall also dumps global objects that are common to all
17       databases, that is, database roles and tablespaces. (pg_dump does not
18       save these objects.)
19
20       Since pg_dumpall reads tables from all databases you will most likely
21       have to connect as a database superuser in order to produce a complete
22       dump. Also you will need superuser privileges to execute the saved
23       script in order to be allowed to add roles and create databases.
24
25       The SQL script will be written to the standard output. Use the
26       -f/--file option or shell operators to redirect it into a file.
27
28       pg_dumpall needs to connect several times to the PostgreSQL server
29       (once per database). If you use password authentication it will ask for
30       a password each time. It is convenient to have a ~/.pgpass file in such
31       cases. See Section 33.15 for more information.
32

OPTIONS

34       The following command-line options control the content and format of
35       the output.
36
37       -a
38       --data-only
39           Dump only the data, not the schema (data definitions).
40
41       -c
42       --clean
43           Include SQL commands to clean (drop) databases before recreating
44           them.  DROP commands for roles and tablespaces are added as well.
45
46       -E encoding
47       --encoding=encoding
48           Create the dump in the specified character set encoding. By
49           default, the dump is created in the database encoding. (Another way
50           to get the same result is to set the PGCLIENTENCODING environment
51           variable to the desired dump encoding.)
52
53       -f filename
54       --file=filename
55           Send output to the specified file. If this is omitted, the standard
56           output is used.
57
58       -g
59       --globals-only
60           Dump only global objects (roles and tablespaces), no databases.
61
62       -O
63       --no-owner
64           Do not output commands to set ownership of objects to match the
65           original database. By default, pg_dumpall issues ALTER OWNER or SET
66           SESSION AUTHORIZATION statements to set ownership of created schema
67           elements. These statements will fail when the script is run unless
68           it is started by a superuser (or the same user that owns all of the
69           objects in the script). To make a script that can be restored by
70           any user, but will give that user ownership of all the objects,
71           specify -O.
72
73       -r
74       --roles-only
75           Dump only roles, no databases or tablespaces.
76
77       -s
78       --schema-only
79           Dump only the object definitions (schema), not data.
80
81       -S username
82       --superuser=username
83           Specify the superuser user name to use when disabling triggers.
84           This is relevant only if --disable-triggers is used. (Usually, it's
85           better to leave this out, and instead start the resulting script as
86           superuser.)
87
88       -t
89       --tablespaces-only
90           Dump only tablespaces, no databases or roles.
91
92       -v
93       --verbose
94           Specifies verbose mode. This will cause pg_dumpall to output
95           start/stop times to the dump file, and progress messages to
96           standard error. It will also enable verbose output in pg_dump.
97
98       -V
99       --version
100           Print the pg_dumpall version and exit.
101
102       -x
103       --no-privileges
104       --no-acl
105           Prevent dumping of access privileges (grant/revoke commands).
106
107       --binary-upgrade
108           This option is for use by in-place upgrade utilities. Its use for
109           other purposes is not recommended or supported. The behavior of the
110           option may change in future releases without notice.
111
112       --column-inserts
113       --attribute-inserts
114           Dump data as INSERT commands with explicit column names (INSERT
115           INTO table (column, ...) VALUES ...). This will make restoration
116           very slow; it is mainly useful for making dumps that can be loaded
117           into non-PostgreSQL databases.
118
119       --disable-dollar-quoting
120           This option disables the use of dollar quoting for function bodies,
121           and forces them to be quoted using SQL standard string syntax.
122
123       --disable-triggers
124           This option is relevant only when creating a data-only dump. It
125           instructs pg_dumpall to include commands to temporarily disable
126           triggers on the target tables while the data is reloaded. Use this
127           if you have referential integrity checks or other triggers on the
128           tables that you do not want to invoke during data reload.
129
130           Presently, the commands emitted for --disable-triggers must be done
131           as superuser. So, you should also specify a superuser name with -S,
132           or preferably be careful to start the resulting script as a
133           superuser.
134
135       --exclude-database=pattern
136           Do not dump databases whose name matches pattern. Multiple patterns
137           can be excluded by writing multiple --exclude-database switches.
138           The pattern parameter is interpreted as a pattern according to the
139           same rules used by psql's \d commands (see Patterns below), so
140           multiple databases can also be excluded by writing wildcard
141           characters in the pattern. When using wildcards, be careful to
142           quote the pattern if needed to prevent shell wildcard expansion.
143
144       --extra-float-digits=ndigits
145           Use the specified value of extra_float_digits when dumping
146           floating-point data, instead of the maximum available precision.
147           Routine dumps made for backup purposes should not use this option.
148
149       --if-exists
150           Use conditional commands (i.e., add an IF EXISTS clause) to drop
151           databases and other objects. This option is not valid unless
152           --clean is also specified.
153
154       --inserts
155           Dump data as INSERT commands (rather than COPY). This will make
156           restoration very slow; it is mainly useful for making dumps that
157           can be loaded into non-PostgreSQL databases. Note that the restore
158           might fail altogether if you have rearranged column order. The
159           --column-inserts option is safer, though even slower.
160
161       --load-via-partition-root
162           When dumping data for a table partition, make the COPY or INSERT
163           statements target the root of the partitioning hierarchy that
164           contains it, rather than the partition itself. This causes the
165           appropriate partition to be re-determined for each row when the
166           data is loaded. This may be useful when reloading data on a server
167           where rows do not always fall into the same partitions as they did
168           on the original server. That could happen, for example, if the
169           partitioning column is of type text and the two systems have
170           different definitions of the collation used to sort the
171           partitioning column.
172
173       --lock-wait-timeout=timeout
174           Do not wait forever to acquire shared table locks at the beginning
175           of the dump. Instead, fail if unable to lock a table within the
176           specified timeout. The timeout may be specified in any of the
177           formats accepted by SET statement_timeout. Allowed values vary
178           depending on the server version you are dumping from, but an
179           integer number of milliseconds is accepted by all versions since
180           7.3. This option is ignored when dumping from a pre-7.3 server.
181
182       --no-comments
183           Do not dump comments.
184
185       --no-publications
186           Do not dump publications.
187
188       --no-role-passwords
189           Do not dump passwords for roles. When restored, roles will have a
190           null password, and password authentication will always fail until
191           the password is set. Since password values aren't needed when this
192           option is specified, the role information is read from the catalog
193           view pg_roles instead of pg_authid. Therefore, this option also
194           helps if access to pg_authid is restricted by some security policy.
195
196       --no-security-labels
197           Do not dump security labels.
198
199       --no-subscriptions
200           Do not dump subscriptions.
201
202       --no-sync
203           By default, pg_dumpall will wait for all files to be written safely
204           to disk. This option causes pg_dumpall to return without waiting,
205           which is faster, but means that a subsequent operating system crash
206           can leave the dump corrupt. Generally, this option is useful for
207           testing but should not be used when dumping data from production
208           installation.
209
210       --no-tablespaces
211           Do not output commands to create tablespaces nor select tablespaces
212           for objects. With this option, all objects will be created in
213           whichever tablespace is the default during restore.
214
215       --no-unlogged-table-data
216           Do not dump the contents of unlogged tables. This option has no
217           effect on whether or not the table definitions (schema) are dumped;
218           it only suppresses dumping the table data.
219
220       --on-conflict-do-nothing
221           Add ON CONFLICT DO NOTHING to INSERT commands. This option is not
222           valid unless --inserts or --column-inserts is also specified.
223
224       --quote-all-identifiers
225           Force quoting of all identifiers. This option is recommended when
226           dumping a database from a server whose PostgreSQL major version is
227           different from pg_dumpall's, or when the output is intended to be
228           loaded into a server of a different major version. By default,
229           pg_dumpall quotes only identifiers that are reserved words in its
230           own major version. This sometimes results in compatibility issues
231           when dealing with servers of other versions that may have slightly
232           different sets of reserved words. Using --quote-all-identifiers
233           prevents such issues, at the price of a harder-to-read dump script.
234
235       --rows-per-insert=nrows
236           Dump data as INSERT commands (rather than COPY). Controls the
237           maximum number of rows per INSERT command. The value specified must
238           be a number greater than zero. Any error during reloading will
239           cause only rows that are part of the problematic INSERT to be lost,
240           rather than the entire table contents.
241
242       --use-set-session-authorization
243           Output SQL-standard SET SESSION AUTHORIZATION commands instead of
244           ALTER OWNER commands to determine object ownership. This makes the
245           dump more standards compatible, but depending on the history of the
246           objects in the dump, might not restore properly.
247
248       -?
249       --help
250           Show help about pg_dumpall command line arguments, and exit.
251
252       The following command-line options control the database connection
253       parameters.
254
255       -d connstr
256       --dbname=connstr
257           Specifies parameters used to connect to the server, as a connection
258           string; these will override any conflicting command line options.
259
260           The option is called --dbname for consistency with other client
261           applications, but because pg_dumpall needs to connect to many
262           databases, the database name in the connection string will be
263           ignored. Use the -l option to specify the name of the database used
264           for the initial connection, which will dump global objects and
265           discover what other databases should be dumped.
266
267       -h host
268       --host=host
269           Specifies the host name of the machine on which the database server
270           is running. If the value begins with a slash, it is used as the
271           directory for the Unix domain socket. The default is taken from the
272           PGHOST environment variable, if set, else a Unix domain socket
273           connection is attempted.
274
275       -l dbname
276       --database=dbname
277           Specifies the name of the database to connect to for dumping global
278           objects and discovering what other databases should be dumped. If
279           not specified, the postgres database will be used, and if that does
280           not exist, template1 will be used.
281
282       -p port
283       --port=port
284           Specifies the TCP port or local Unix domain socket file extension
285           on which the server is listening for connections. Defaults to the
286           PGPORT environment variable, if set, or a compiled-in default.
287
288       -U username
289       --username=username
290           User name to connect as.
291
292       -w
293       --no-password
294           Never issue a password prompt. If the server requires password
295           authentication and a password is not available by other means such
296           as a .pgpass file, the connection attempt will fail. This option
297           can be useful in batch jobs and scripts where no user is present to
298           enter a password.
299
300       -W
301       --password
302           Force pg_dumpall to prompt for a password before connecting to a
303           database.
304
305           This option is never essential, since pg_dumpall will automatically
306           prompt for a password if the server demands password
307           authentication. However, pg_dumpall will waste a connection attempt
308           finding out that the server wants a password. In some cases it is
309           worth typing -W to avoid the extra connection attempt.
310
311           Note that the password prompt will occur again for each database to
312           be dumped. Usually, it's better to set up a ~/.pgpass file than to
313           rely on manual password entry.
314
315       --role=rolename
316           Specifies a role name to be used to create the dump. This option
317           causes pg_dumpall to issue a SET ROLE rolename command after
318           connecting to the database. It is useful when the authenticated
319           user (specified by -U) lacks privileges needed by pg_dumpall, but
320           can switch to a role with the required rights. Some installations
321           have a policy against logging in directly as a superuser, and use
322           of this option allows dumps to be made without violating the
323           policy.
324

ENVIRONMENT

326       PGHOST
327       PGOPTIONS
328       PGPORT
329       PGUSER
330           Default connection parameters
331
332       PG_COLOR
333           Specifies whether to use color in diagnostic messages. Possible
334           values are always, auto and never.
335
336       This utility, like most other PostgreSQL utilities, also uses the
337       environment variables supported by libpq (see Section 33.14).
338

NOTES

340       Since pg_dumpall calls pg_dump internally, some diagnostic messages
341       will refer to pg_dump.
342
343       The --clean option can be useful even when your intention is to restore
344       the dump script into a fresh cluster. Use of --clean authorizes the
345       script to drop and re-create the built-in postgres and template1
346       databases, ensuring that those databases will retain the same
347       properties (for instance, locale and encoding) that they had in the
348       source cluster. Without the option, those databases will retain their
349       existing database-level properties, as well as any pre-existing
350       contents.
351
352       Once restored, it is wise to run ANALYZE on each database so the
353       optimizer has useful statistics. You can also run vacuumdb -a -z to
354       analyze all databases.
355
356       The dump script should not be expected to run completely without
357       errors. In particular, because the script will issue CREATE ROLE for
358       every role existing in the source cluster, it is certain to get a “role
359       already exists” error for the bootstrap superuser, unless the
360       destination cluster was initialized with a different bootstrap
361       superuser name. This error is harmless and should be ignored. Use of
362       the --clean option is likely to produce additional harmless error
363       messages about non-existent objects, although you can minimize those by
364       adding --if-exists.
365
366       pg_dumpall requires all needed tablespace directories to exist before
367       the restore; otherwise, database creation will fail for databases in
368       non-default locations.
369

EXAMPLES

371       To dump all databases:
372
373           $ pg_dumpall > db.out
374
375       To reload database(s) from this file, you can use:
376
377           $ psql -f db.out postgres
378
379       It is not important to which database you connect here since the script
380       file created by pg_dumpall will contain the appropriate commands to
381       create and connect to the saved databases. An exception is that if you
382       specified --clean, you must connect to the postgres database initially;
383       the script will attempt to drop other databases immediately, and that
384       will fail for the database you are connected to.
385

SEE ALSO

387       Check pg_dump(1) for details on possible error conditions.
388
389
390
391PostgreSQL 13.3                      2021                        PG_DUMPALL(1)
Impressum