1PG_DUMPALL(1)            PostgreSQL 14.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 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 reloaded. 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 reload.
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 reloading 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-tablespaces
210           Do not output commands to create tablespaces nor select tablespaces
211           for objects. With this option, all objects will be created in
212           whichever tablespace is the default during restore.
213
214       --no-toast-compression
215           Do not output commands to set TOAST compression methods. With this
216           option, all columns will be restored with the default compression
217           setting.
218
219       --no-unlogged-table-data
220           Do not dump the contents of unlogged tables. This option has no
221           effect on whether or not the table definitions (schema) are dumped;
222           it only suppresses dumping the table data.
223
224       --on-conflict-do-nothing
225           Add ON CONFLICT DO NOTHING to INSERT commands. This option is not
226           valid unless --inserts or --column-inserts is also specified.
227
228       --quote-all-identifiers
229           Force quoting of all identifiers. This option is recommended when
230           dumping a database from a server whose PostgreSQL major version is
231           different from pg_dumpall's, or when the output is intended to be
232           loaded into a server of a different major version. By default,
233           pg_dumpall quotes only identifiers that are reserved words in its
234           own major version. This sometimes results in compatibility issues
235           when dealing with servers of other versions that may have slightly
236           different sets of reserved words. Using --quote-all-identifiers
237           prevents such issues, at the price of a harder-to-read dump script.
238
239       --rows-per-insert=nrows
240           Dump data as INSERT commands (rather than COPY). Controls the
241           maximum number of rows per INSERT command. The value specified must
242           be a number greater than zero. Any error during reloading will
243           cause only rows that are part of the problematic INSERT to be lost,
244           rather than the entire table contents.
245
246       --use-set-session-authorization
247           Output SQL-standard SET SESSION AUTHORIZATION commands instead of
248           ALTER OWNER commands to determine object ownership. This makes the
249           dump more standards compatible, but depending on the history of the
250           objects in the dump, might not restore properly.
251
252       -?
253       --help
254           Show help about pg_dumpall command line arguments, and exit.
255
256       The following command-line options control the database connection
257       parameters.
258
259       -d connstr
260       --dbname=connstr
261           Specifies parameters used to connect to the server, as a connection
262           string; these will override any conflicting command line options.
263
264           The option is called --dbname for consistency with other client
265           applications, but because pg_dumpall needs to connect to many
266           databases, the database name in the connection string will be
267           ignored. Use the -l option to specify the name of the database used
268           for the initial connection, which will dump global objects and
269           discover what other databases should be dumped.
270
271       -h host
272       --host=host
273           Specifies the host name of the machine on which the database server
274           is running. If the value begins with a slash, it is used as the
275           directory for the Unix domain socket. The default is taken from the
276           PGHOST environment variable, if set, else a Unix domain socket
277           connection is attempted.
278
279       -l dbname
280       --database=dbname
281           Specifies the name of the database to connect to for dumping global
282           objects and discovering what other databases should be dumped. If
283           not specified, the postgres database will be used, and if that does
284           not exist, template1 will be used.
285
286       -p port
287       --port=port
288           Specifies the TCP port or local Unix domain socket file extension
289           on which the server is listening for connections. Defaults to the
290           PGPORT environment variable, if set, or a compiled-in default.
291
292       -U username
293       --username=username
294           User name to connect as.
295
296       -w
297       --no-password
298           Never issue a password prompt. If the server requires password
299           authentication and a password is not available by other means such
300           as a .pgpass file, the connection attempt will fail. This option
301           can be useful in batch jobs and scripts where no user is present to
302           enter a password.
303
304       -W
305       --password
306           Force pg_dumpall to prompt for a password before connecting to a
307           database.
308
309           This option is never essential, since pg_dumpall will automatically
310           prompt for a password if the server demands password
311           authentication. However, pg_dumpall will waste a connection attempt
312           finding out that the server wants a password. In some cases it is
313           worth typing -W to avoid the extra connection attempt.
314
315           Note that the password prompt will occur again for each database to
316           be dumped. Usually, it's better to set up a ~/.pgpass file than to
317           rely on manual password entry.
318
319       --role=rolename
320           Specifies a role name to be used to create the dump. This option
321           causes pg_dumpall to issue a SET ROLE rolename command after
322           connecting to the database. It is useful when the authenticated
323           user (specified by -U) lacks privileges needed by pg_dumpall, but
324           can switch to a role with the required rights. Some installations
325           have a policy against logging in directly as a superuser, and use
326           of this option allows dumps to be made without violating the
327           policy.
328

ENVIRONMENT

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

NOTES

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

EXAMPLES

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

SEE ALSO

391       Check pg_dump(1) for details on possible error conditions.
392
393
394
395PostgreSQL 14.3                      2022                        PG_DUMPALL(1)
Impressum