1PG_DUMPALL(1) PostgreSQL 9.2.24 Documentation PG_DUMPALL(1)
2
3
4
6 pg_dumpall - extract a PostgreSQL database cluster into a script file
7
9 pg_dumpall [connection-option...] [option...]
10
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 a
16 cluster. pg_dumpall also dumps global objects that are common to all
17 databases. (pg_dump does not save these objects.) This currently
18 includes information about database users and groups, tablespaces, and
19 properties such as access permissions that apply to databases as a
20 whole.
21
22 Since pg_dumpall reads tables from all databases you will most likely
23 have to connect as a database superuser in order to produce a complete
24 dump. Also you will need superuser privileges to execute the saved
25 script in order to be allowed to add users and groups, and to create
26 databases.
27
28 The SQL script will be written to the standard output. Use the
29 [-f|file] option or shell operators to redirect it into a file.
30
31 pg_dumpall needs to connect several times to the PostgreSQL server
32 (once per database). If you use password authentication it will ask for
33 a password each time. It is convenient to have a ~/.pgpass file in such
34 cases. See Section 31.15, “The Password File”, in the documentation for
35 more information.
36
38 The following command-line options control the content and format of
39 the output.
40
41 -a, --data-only
42 Dump only the data, not the schema (data definitions).
43
44 -c, --clean
45 Include SQL commands to clean (drop) databases before recreating
46 them. DROP commands for roles and tablespaces are added as well.
47
48 -f filename, --file=filename
49 Send output to the specified file. If this is omitted, the standard
50 output is used.
51
52 -g, --globals-only
53 Dump only global objects (roles and tablespaces), no databases.
54
55 -i, --ignore-version
56 A deprecated option that is now ignored.
57
58 -o, --oids
59 Dump object identifiers (OIDs) as part of the data for every table.
60 Use this option if your application references the OID columns in
61 some way (e.g., in a foreign key constraint). Otherwise, this
62 option should not be used.
63
64 -O, --no-owner
65 Do not output commands to set ownership of objects to match the
66 original database. By default, pg_dumpall issues ALTER OWNER or SET
67 SESSION AUTHORIZATION statements to set ownership of created schema
68 elements. These statements will fail when the script is run unless
69 it is started by a superuser (or the same user that owns all of the
70 objects in the script). To make a script that can be restored by
71 any user, but will give that user ownership of all the objects,
72 specify -O.
73
74 -r, --roles-only
75 Dump only roles, no databases or tablespaces.
76
77 -s, --schema-only
78 Dump only the object definitions (schema), not data.
79
80 -S username, --superuser=username
81 Specify the superuser user name to use when disabling triggers.
82 This is only relevant if --disable-triggers is used. (Usually, it's
83 better to leave this out, and instead start the resulting script as
84 superuser.)
85
86 -t, --tablespaces-only
87 Dump only tablespaces, no databases or roles.
88
89 -v, --verbose
90 Specifies verbose mode. This will cause pg_dumpall to output
91 start/stop times to the dump file, and progress messages to
92 standard error. It will also enable verbose output in pg_dump.
93
94 -V, --version
95 Print the pg_dumpall version and exit.
96
97 -x, --no-privileges, --no-acl
98 Prevent dumping of access privileges (grant/revoke commands).
99
100 --binary-upgrade
101 This option is for use by in-place upgrade utilities. Its use for
102 other purposes is not recommended or supported. The behavior of the
103 option may change in future releases without notice.
104
105 --column-inserts, --attribute-inserts
106 Dump data as INSERT commands with explicit column names (INSERT
107 INTO table (column, ...) VALUES ...). This will make restoration
108 very slow; it is mainly useful for making dumps that can be loaded
109 into non-PostgreSQL databases.
110
111 --disable-dollar-quoting
112 This option disables the use of dollar quoting for function bodies,
113 and forces them to be quoted using SQL standard string syntax.
114
115 --disable-triggers
116 This option is only relevant when creating a data-only dump. It
117 instructs pg_dumpall to include commands to temporarily disable
118 triggers on the target tables while the data is reloaded. Use this
119 if you have referential integrity checks or other triggers on the
120 tables that you do not want to invoke during data reload.
121
122 Presently, the commands emitted for --disable-triggers must be done
123 as superuser. So, you should also specify a superuser name with -S,
124 or preferably be careful to start the resulting script as a
125 superuser.
126
127 --inserts
128 Dump data as INSERT commands (rather than COPY). This will make
129 restoration very slow; it is mainly useful for making dumps that
130 can be loaded into non-PostgreSQL databases. Note that the restore
131 might fail altogether if you have rearranged column order. The
132 --column-inserts option is safer, though even slower.
133
134 --lock-wait-timeout=timeout
135 Do not wait forever to acquire shared table locks at the beginning
136 of the dump. Instead, fail if unable to lock a table within the
137 specified timeout. The timeout may be specified in any of the
138 formats accepted by SET statement_timeout. Allowed values vary
139 depending on the server version you are dumping from, but an
140 integer number of milliseconds is accepted by all versions since
141 7.3. This option is ignored when dumping from a pre-7.3 server.
142
143 --no-security-labels
144 Do not dump security labels.
145
146 --no-tablespaces
147 Do not output commands to create tablespaces nor select tablespaces
148 for objects. With this option, all objects will be created in
149 whichever tablespace is the default during restore.
150
151 --no-unlogged-table-data
152 Do not dump the contents of unlogged tables. This option has no
153 effect on whether or not the table definitions (schema) are dumped;
154 it only suppresses dumping the table data.
155
156 --quote-all-identifiers
157 Force quoting of all identifiers. This option is recommended when
158 dumping a database from a server whose PostgreSQL major version is
159 different from pg_dumpall's, or when the output is intended to be
160 loaded into a server of a different major version. By default,
161 pg_dumpall quotes only identifiers that are reserved words in its
162 own major version. This sometimes results in compatibility issues
163 when dealing with servers of other versions that may have slightly
164 different sets of reserved words. Using --quote-all-identifiers
165 prevents such issues, at the price of a harder-to-read dump script.
166
167 --use-set-session-authorization
168 Output SQL-standard SET SESSION AUTHORIZATION commands instead of
169 ALTER OWNER commands to determine object ownership. This makes the
170 dump more standards compatible, but depending on the history of the
171 objects in the dump, might not restore properly.
172
173 -?, --help
174 Show help about pg_dumpall command line arguments, and exit.
175
176 The following command-line options control the database connection
177 parameters.
178
179 -h host, --host=host
180 Specifies the host name of the machine on which the database server
181 is running. If the value begins with a slash, it is used as the
182 directory for the Unix domain socket. The default is taken from the
183 PGHOST environment variable, if set, else a Unix domain socket
184 connection is attempted.
185
186 -l dbname, --database=dbname
187 Specifies the name of the database to connect to to dump global
188 objects and discover what other databases should be dumped. If not
189 specified, the postgres database will be used, and if that does not
190 exist, template1 will be used.
191
192 -p port, --port=port
193 Specifies the TCP port or local Unix domain socket file extension
194 on which the server is listening for connections. Defaults to the
195 PGPORT environment variable, if set, or a compiled-in default.
196
197 -U username, --username=username
198 User name to connect as.
199
200 -w, --no-password
201 Never issue a password prompt. If the server requires password
202 authentication and a password is not available by other means such
203 as a .pgpass file, the connection attempt will fail. This option
204 can be useful in batch jobs and scripts where no user is present to
205 enter a password.
206
207 -W, --password
208 Force pg_dumpall to prompt for a password before connecting to a
209 database.
210
211 This option is never essential, since pg_dumpall will automatically
212 prompt for a password if the server demands password
213 authentication. However, pg_dumpall will waste a connection attempt
214 finding out that the server wants a password. In some cases it is
215 worth typing -W to avoid the extra connection attempt.
216
217 Note that the password prompt will occur again for each database to
218 be dumped. Usually, it's better to set up a ~/.pgpass file than to
219 rely on manual password entry.
220
221 --role=rolename
222 Specifies a role name to be used to create the dump. This option
223 causes pg_dumpall to issue a SET ROLErolename command after
224 connecting to the database. It is useful when the authenticated
225 user (specified by -U) lacks privileges needed by pg_dumpall, but
226 can switch to a role with the required rights. Some installations
227 have a policy against logging in directly as a superuser, and use
228 of this option allows dumps to be made without violating the
229 policy.
230
232 PGHOST, PGOPTIONS, PGPORT, PGUSER
233 Default connection parameters
234
235 This utility, like most other PostgreSQL utilities, also uses the
236 environment variables supported by libpq (see Section 31.14,
237 “Environment Variables”, in the documentation).
238
240 Since pg_dumpall calls pg_dump internally, some diagnostic messages
241 will refer to pg_dump.
242
243 Once restored, it is wise to run ANALYZE on each database so the
244 optimizer has useful statistics. You can also run vacuumdb -a -z to
245 analyze all databases.
246
247 pg_dumpall requires all needed tablespace directories to exist before
248 the restore; otherwise, database creation will fail for databases in
249 non-default locations.
250
252 To dump all databases:
253
254 $ pg_dumpall > db.out
255
256 To reload database(s) from this file, you can use:
257
258 $ psql -f db.out postgres
259
260 (It is not important to which database you connect here since the
261 script file created by pg_dumpall will contain the appropriate commands
262 to create and connect to the saved databases.)
263
265 Check pg_dump(1) for details on possible error conditions.
266
267
268
269PostgreSQL 9.2.24 2017-11-06 PG_DUMPALL(1)