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

ENVIRONMENT

335       PGHOST
336       PGOPTIONS
337       PGPORT
338       PGUSER
339           Default connection parameters
340
341       PG_COLOR
342           Specifies whether to use color in diagnostic messages. Possible
343           values are always, auto and never.
344
345       This utility, like most other PostgreSQL utilities, also uses the
346       environment variables supported by libpq (see Section 34.15).
347

NOTES

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

EXAMPLES

380       To dump all databases:
381
382           $ pg_dumpall > db.out
383
384       To restore database(s) from this file, you can use:
385
386           $ psql -f db.out postgres
387
388       It is not important to which database you connect here since the script
389       file created by pg_dumpall will contain the appropriate commands to
390       create and connect to the saved databases. An exception is that if you
391       specified --clean, you must connect to the postgres database initially;
392       the script will attempt to drop other databases immediately, and that
393       will fail for the database you are connected to.
394

SEE ALSO

396       Check pg_dump(1) for details on possible error conditions.
397
398
399
400PostgreSQL 15.4                      2023                        PG_DUMPALL(1)
Impressum