]> begriffs open source - ai-pg/blob - full-docs/man1/pg_restore.1
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man1 / pg_restore.1
1 '\" t
2 .\"     Title: pg_restore
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
10 .TH "PG_RESTORE" "1" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 pg_restore \- restore a PostgreSQL database from an archive file created by pg_dump
32 .SH "SYNOPSIS"
33 .HP \w'\fBpg_restore\fR\ 'u
34 \fBpg_restore\fR [\fIconnection\-option\fR...] [\fIoption\fR...] [\fIfilename\fR]
35 .SH "DESCRIPTION"
36 .PP
37 pg_restore
38 is a utility for restoring a
39 PostgreSQL
40 database from an archive created by
41 \fBpg_dump\fR(1)
42 in one of the non\-plain\-text formats\&. It will issue the commands necessary to reconstruct the database to the state it was in at the time it was saved\&. The archive files also allow
43 pg_restore
44 to be selective about what is restored, or even to reorder the items prior to being restored\&. The archive files are designed to be portable across architectures\&.
45 .PP
46 pg_restore
47 can operate in two modes\&. If a database name is specified,
48 pg_restore
49 connects to that database and restores archive contents directly into the database\&. Otherwise, a script containing the SQL commands necessary to rebuild the database is created and written to a file or standard output\&. This script output is equivalent to the plain text output format of
50 pg_dump\&. Some of the options controlling the output are therefore analogous to
51 pg_dump
52 options\&.
53 .PP
54 Obviously,
55 pg_restore
56 cannot restore information that is not present in the archive file\&. For instance, if the archive was made using the
57 \(lqdump data as \fBINSERT\fR commands\(rq
58 option,
59 pg_restore
60 will not be able to load the data using
61 \fBCOPY\fR
62 statements\&.
63 .if n \{\
64 .sp
65 .\}
66 .RS 4
67 .it 1 an-trap
68 .nr an-no-space-flag 1
69 .nr an-break-flag 1
70 .br
71 .ps +1
72 \fBWarning\fR
73 .ps -1
74 .br
75 .PP
76 Restoring a dump causes the destination to execute arbitrary code of the source superusers\*(Aq choice\&. Partial dumps and partial restores do not limit that\&. If the source superusers are not trusted, the dumped SQL statements must be inspected before restoring\&. Non\-plain\-text dumps can be inspected by using
77 pg_restore\*(Aqs
78 \fB\-\-file\fR
79 option\&. Note that the client running the dump and restore need not trust the source or destination superusers\&.
80 .sp .5v
81 .RE
82 .SH "OPTIONS"
83 .PP
84 pg_restore
85 accepts the following command line arguments\&.
86 .PP
87 \fIfilename\fR
88 .RS 4
89 Specifies the location of the archive file (or directory, for a directory\-format archive) to be restored\&. If not specified, the standard input is used\&.
90 .RE
91 .PP
92 \fB\-a\fR
93 .br
94 \fB\-\-data\-only\fR
95 .RS 4
96 Restore only the data, not the schema (data definitions) or statistics\&. Table data, large objects, and sequence values are restored, if present in the archive\&.
97 .sp
98 This option is similar to, but for historical reasons not identical to, specifying
99 \fB\-\-section=data\fR\&.
100 .RE
101 .PP
102 \fB\-c\fR
103 .br
104 \fB\-\-clean\fR
105 .RS 4
106 Before restoring database objects, issue commands to
107 \fBDROP\fR
108 all the objects that will be restored\&. This option is useful for overwriting an existing database\&. If any of the objects do not exist in the destination database, ignorable error messages will be reported, unless
109 \fB\-\-if\-exists\fR
110 is also specified\&.
111 .RE
112 .PP
113 \fB\-C\fR
114 .br
115 \fB\-\-create\fR
116 .RS 4
117 Create the database before restoring into it\&. If
118 \fB\-\-clean\fR
119 is also specified, drop and recreate the target database before connecting to it\&.
120 .sp
121 With
122 \fB\-\-create\fR,
123 pg_restore
124 also restores the database\*(Aqs comment if any, and any configuration variable settings that are specific to this database, that is, any
125 \fBALTER DATABASE \&.\&.\&. SET \&.\&.\&.\fR
126 and
127 \fBALTER ROLE \&.\&.\&. IN DATABASE \&.\&.\&. SET \&.\&.\&.\fR
128 commands that mention this database\&. Access privileges for the database itself are also restored, unless
129 \fB\-\-no\-acl\fR
130 is specified\&.
131 .sp
132 When this option is used, the database named with
133 \fB\-d\fR
134 is used only to issue the initial
135 \fBDROP DATABASE\fR
136 and
137 \fBCREATE DATABASE\fR
138 commands\&. All data is restored into the database name that appears in the archive\&.
139 .RE
140 .PP
141 \fB\-d \fR\fB\fIdbname\fR\fR
142 .br
143 \fB\-\-dbname=\fR\fB\fIdbname\fR\fR
144 .RS 4
145 Connect to database
146 \fIdbname\fR
147 and restore directly into the database\&. The
148 \fIdbname\fR
149 can be a
150 connection string\&. If so, connection string parameters will override any conflicting command line options\&.
151 .RE
152 .PP
153 \fB\-e\fR
154 .br
155 \fB\-\-exit\-on\-error\fR
156 .RS 4
157 Exit if an error is encountered while sending SQL commands to the database\&. The default is to continue and to display a count of errors at the end of the restoration\&.
158 .RE
159 .PP
160 \fB\-f \fR\fB\fIfilename\fR\fR
161 .br
162 \fB\-\-file=\fR\fB\fIfilename\fR\fR
163 .RS 4
164 Specify output file for generated script, or for the listing when used with
165 \fB\-l\fR\&. Use
166 \-
167 for
168 stdout\&.
169 .RE
170 .PP
171 \fB\-F \fR\fB\fIformat\fR\fR
172 .br
173 \fB\-\-format=\fR\fB\fIformat\fR\fR
174 .RS 4
175 Specify format of the archive\&. It is not necessary to specify the format, since
176 pg_restore
177 will determine the format automatically\&. If specified, it can be one of the following:
178 .PP
179 c
180 .br
181 custom
182 .RS 4
183 The archive is in the custom format of
184 pg_dump\&.
185 .RE
186 .PP
187 d
188 .br
189 directory
190 .RS 4
191 The archive is a directory archive\&.
192 .RE
193 .PP
194 t
195 .br
196 tar
197 .RS 4
198 The archive is a
199 \fBtar\fR
200 archive\&.
201 .RE
202 .RE
203 .PP
204 \fB\-I \fR\fB\fIindex\fR\fR
205 .br
206 \fB\-\-index=\fR\fB\fIindex\fR\fR
207 .RS 4
208 Restore definition of named index only\&. Multiple indexes may be specified with multiple
209 \fB\-I\fR
210 switches\&.
211 .RE
212 .PP
213 \fB\-j \fR\fB\fInumber\-of\-jobs\fR\fR
214 .br
215 \fB\-\-jobs=\fR\fB\fInumber\-of\-jobs\fR\fR
216 .RS 4
217 Run the most time\-consuming steps of
218 pg_restore
219 \(em those that load data, create indexes, or create constraints \(em concurrently, using up to
220 \fInumber\-of\-jobs\fR
221 concurrent sessions\&. This option can dramatically reduce the time to restore a large database to a server running on a multiprocessor machine\&. This option is ignored when emitting a script rather than connecting directly to a database server\&.
222 .sp
223 Each job is one process or one thread, depending on the operating system, and uses a separate connection to the server\&.
224 .sp
225 The optimal value for this option depends on the hardware setup of the server, of the client, and of the network\&. Factors include the number of CPU cores and the disk setup\&. A good place to start is the number of CPU cores on the server, but values larger than that can also lead to faster restore times in many cases\&. Of course, values that are too high will lead to decreased performance because of thrashing\&.
226 .sp
227 Only the custom and directory archive formats are supported with this option\&. The input must be a regular file or directory (not, for example, a pipe or standard input)\&. Also, multiple jobs cannot be used together with the option
228 \fB\-\-single\-transaction\fR\&.
229 .RE
230 .PP
231 \fB\-l\fR
232 .br
233 \fB\-\-list\fR
234 .RS 4
235 List the table of contents of the archive\&. The output of this operation can be used as input to the
236 \fB\-L\fR
237 option\&. Note that if filtering switches such as
238 \fB\-n\fR
239 or
240 \fB\-t\fR
241 are used with
242 \fB\-l\fR, they will restrict the items listed\&.
243 .RE
244 .PP
245 \fB\-L \fR\fB\fIlist\-file\fR\fR
246 .br
247 \fB\-\-use\-list=\fR\fB\fIlist\-file\fR\fR
248 .RS 4
249 Restore only those archive elements that are listed in
250 \fIlist\-file\fR, and restore them in the order they appear in the file\&. Note that if filtering switches such as
251 \fB\-n\fR
252 or
253 \fB\-t\fR
254 are used with
255 \fB\-L\fR, they will further restrict the items restored\&.
256 .sp
257 \fIlist\-file\fR
258 is normally created by editing the output of a previous
259 \fB\-l\fR
260 operation\&. Lines can be moved or removed, and can also be commented out by placing a semicolon (;) at the start of the line\&. See below for examples\&.
261 .RE
262 .PP
263 \fB\-n \fR\fB\fIschema\fR\fR
264 .br
265 \fB\-\-schema=\fR\fB\fIschema\fR\fR
266 .RS 4
267 Restore only objects that are in the named schema\&. Multiple schemas may be specified with multiple
268 \fB\-n\fR
269 switches\&. This can be combined with the
270 \fB\-t\fR
271 option to restore just a specific table\&.
272 .RE
273 .PP
274 \fB\-N \fR\fB\fIschema\fR\fR
275 .br
276 \fB\-\-exclude\-schema=\fR\fB\fIschema\fR\fR
277 .RS 4
278 Do not restore objects that are in the named schema\&. Multiple schemas to be excluded may be specified with multiple
279 \fB\-N\fR
280 switches\&.
281 .sp
282 When both
283 \fB\-n\fR
284 and
285 \fB\-N\fR
286 are given for the same schema name, the
287 \fB\-N\fR
288 switch wins and the schema is excluded\&.
289 .RE
290 .PP
291 \fB\-O\fR
292 .br
293 \fB\-\-no\-owner\fR
294 .RS 4
295 Do not output commands to set ownership of objects to match the original database\&. By default,
296 pg_restore
297 issues
298 \fBALTER OWNER\fR
299 or
300 \fBSET SESSION AUTHORIZATION\fR
301 statements to set ownership of created schema elements\&. These statements will fail unless the initial connection to the database is made by a superuser (or the same user that owns all of the objects in the script)\&. With
302 \fB\-O\fR, any user name can be used for the initial connection, and this user will own all the created objects\&.
303 .RE
304 .PP
305 \fB\-P \fR\fB\fIfunction\-name(argtype [, \&.\&.\&.])\fR\fR
306 .br
307 \fB\-\-function=\fR\fB\fIfunction\-name(argtype [, \&.\&.\&.])\fR\fR
308 .RS 4
309 Restore the named function only\&. Be careful to spell the function name and arguments exactly as they appear in the dump file\*(Aqs table of contents\&. Multiple functions may be specified with multiple
310 \fB\-P\fR
311 switches\&.
312 .RE
313 .PP
314 \fB\-R\fR
315 .br
316 \fB\-\-no\-reconnect\fR
317 .RS 4
318 This option is obsolete but still accepted for backwards compatibility\&.
319 .RE
320 .PP
321 \fB\-s\fR
322 .br
323 \fB\-\-schema\-only\fR
324 .RS 4
325 Restore only the schema (data definitions), not data, to the extent that schema entries are present in the archive\&.
326 .sp
327 This option cannot be used with
328 \fB\-\-data\-only\fR
329 or
330 \fB\-\-statistics\-only\fR\&. It is similar to, but for historical reasons not identical to, specifying
331 \fB\-\-section=pre\-data \-\-section=post\-data \-\-no\-statistics\fR\&.
332 .sp
333 (Do not confuse this with the
334 \fB\-\-schema\fR
335 option, which uses the word
336 \(lqschema\(rq
337 in a different meaning\&.)
338 .RE
339 .PP
340 \fB\-S \fR\fB\fIusername\fR\fR
341 .br
342 \fB\-\-superuser=\fR\fB\fIusername\fR\fR
343 .RS 4
344 Specify the superuser user name to use when disabling triggers\&. This is relevant only if
345 \fB\-\-disable\-triggers\fR
346 is used\&.
347 .RE
348 .PP
349 \fB\-t \fR\fB\fItable\fR\fR
350 .br
351 \fB\-\-table=\fR\fB\fItable\fR\fR
352 .RS 4
353 Restore definition and/or data of only the named table\&. For this purpose,
354 \(lqtable\(rq
355 includes views, materialized views, sequences, and foreign tables\&. Multiple tables can be selected by writing multiple
356 \fB\-t\fR
357 switches\&. This option can be combined with the
358 \fB\-n\fR
359 option to specify table(s) in a particular schema\&.
360 .if n \{\
361 .sp
362 .\}
363 .RS 4
364 .it 1 an-trap
365 .nr an-no-space-flag 1
366 .nr an-break-flag 1
367 .br
368 .ps +1
369 \fBNote\fR
370 .ps -1
371 .br
372 When
373 \fB\-t\fR
374 is specified,
375 pg_restore
376 makes no attempt to restore any other database objects that the selected table(s) might depend upon\&. Therefore, there is no guarantee that a specific\-table restore into a clean database will succeed\&.
377 .sp .5v
378 .RE
379 .if n \{\
380 .sp
381 .\}
382 .RS 4
383 .it 1 an-trap
384 .nr an-no-space-flag 1
385 .nr an-break-flag 1
386 .br
387 .ps +1
388 \fBNote\fR
389 .ps -1
390 .br
391 This flag does not behave identically to the
392 \fB\-t\fR
393 flag of
394 pg_dump\&. There is not currently any provision for wild\-card matching in
395 pg_restore, nor can you include a schema name within its
396 \fB\-t\fR\&. And, while
397 pg_dump\*(Aqs
398 \fB\-t\fR
399 flag will also dump subsidiary objects (such as indexes) of the selected table(s),
400 pg_restore\*(Aqs
401 \fB\-t\fR
402 flag does not include such subsidiary objects\&.
403 .sp .5v
404 .RE
405 .if n \{\
406 .sp
407 .\}
408 .RS 4
409 .it 1 an-trap
410 .nr an-no-space-flag 1
411 .nr an-break-flag 1
412 .br
413 .ps +1
414 \fBNote\fR
415 .ps -1
416 .br
417 In versions prior to
418 PostgreSQL
419 9\&.6, this flag matched only tables, not any other type of relation\&.
420 .sp .5v
421 .RE
422 .RE
423 .PP
424 \fB\-T \fR\fB\fItrigger\fR\fR
425 .br
426 \fB\-\-trigger=\fR\fB\fItrigger\fR\fR
427 .RS 4
428 Restore named trigger only\&. Multiple triggers may be specified with multiple
429 \fB\-T\fR
430 switches\&.
431 .RE
432 .PP
433 \fB\-v\fR
434 .br
435 \fB\-\-verbose\fR
436 .RS 4
437 Specifies verbose mode\&. This will cause
438 pg_restore
439 to output detailed object comments and start/stop times to the output file, and progress messages to standard error\&. Repeating the option causes additional debug\-level messages to appear on standard error\&.
440 .RE
441 .PP
442 \fB\-V\fR
443 .br
444 \fB\-\-version\fR
445 .RS 4
446 Print the
447 pg_restore
448 version and exit\&.
449 .RE
450 .PP
451 \fB\-x\fR
452 .br
453 \fB\-\-no\-privileges\fR
454 .br
455 \fB\-\-no\-acl\fR
456 .RS 4
457 Prevent restoration of access privileges (grant/revoke commands)\&.
458 .RE
459 .PP
460 \fB\-1\fR
461 .br
462 \fB\-\-single\-transaction\fR
463 .RS 4
464 Execute the restore as a single transaction (that is, wrap the emitted commands in
465 \fBBEGIN\fR/\fBCOMMIT\fR)\&. This ensures that either all the commands complete successfully, or no changes are applied\&. This option implies
466 \fB\-\-exit\-on\-error\fR\&.
467 .RE
468 .PP
469 \fB\-\-disable\-triggers\fR
470 .RS 4
471 This option is relevant only when performing a restore without schema\&. It instructs
472 pg_restore
473 to execute commands to temporarily disable triggers on the target tables while the data is restored\&. Use this if you have referential integrity checks or other triggers on the tables that you do not want to invoke during data restore\&.
474 .sp
475 Presently, the commands emitted for
476 \fB\-\-disable\-triggers\fR
477 must be done as superuser\&. So you should also specify a superuser name with
478 \fB\-S\fR
479 or, preferably, run
480 pg_restore
481 as a
482 PostgreSQL
483 superuser\&.
484 .RE
485 .PP
486 \fB\-\-enable\-row\-security\fR
487 .RS 4
488 This option is relevant only when restoring the contents of a table which has row security\&. By default,
489 pg_restore
490 will set
491 row_security
492 to off, to ensure that all data is restored in to the table\&. If the user does not have sufficient privileges to bypass row security, then an error is thrown\&. This parameter instructs
493 pg_restore
494 to set
495 row_security
496 to on instead, allowing the user to attempt to restore the contents of the table with row security enabled\&. This might still fail if the user does not have the right to insert the rows from the dump into the table\&.
497 .sp
498 Note that this option currently also requires the dump be in
499 \fBINSERT\fR
500 format, as
501 \fBCOPY FROM\fR
502 does not support row security\&.
503 .RE
504 .PP
505 \fB\-\-filter=\fR\fB\fIfilename\fR\fR
506 .RS 4
507 Specify a filename from which to read patterns for objects excluded or included from restore\&. The patterns are interpreted according to the same rules as
508 \fB\-n\fR/\fB\-\-schema\fR
509 for including objects in schemas,
510 \fB\-N\fR/\fB\-\-exclude\-schema\fR
511 for excluding objects in schemas,
512 \fB\-P\fR/\fB\-\-function\fR
513 for restoring named functions,
514 \fB\-I\fR/\fB\-\-index\fR
515 for restoring named indexes,
516 \fB\-t\fR/\fB\-\-table\fR
517 for restoring named tables or
518 \fB\-T\fR/\fB\-\-trigger\fR
519 for restoring triggers\&. To read from
520 STDIN, use
521 \-
522 as the filename\&. The
523 \fB\-\-filter\fR
524 option can be specified in conjunction with the above listed options for including or excluding objects, and can also be specified more than once for multiple filter files\&.
525 .sp
526 The file lists one database pattern per row, with the following format:
527 .sp
528 .if n \{\
529 .RS 4
530 .\}
531 .nf
532 { include | exclude } { function | index | schema | table | trigger } \fIPATTERN\fR
533 .fi
534 .if n \{\
535 .RE
536 .\}
537 .sp
538 The first keyword specifies whether the objects matched by the pattern are to be included or excluded\&. The second keyword specifies the type of object to be filtered using the pattern:
539 .sp
540 .RS 4
541 .ie n \{\
542 \h'-04'\(bu\h'+03'\c
543 .\}
544 .el \{\
545 .sp -1
546 .IP \(bu 2.3
547 .\}
548 function: functions, works like the
549 \fB\-P\fR/\fB\-\-function\fR
550 option\&. This keyword can only be used with the
551 include
552 keyword\&.
553 .RE
554 .sp
555 .RS 4
556 .ie n \{\
557 \h'-04'\(bu\h'+03'\c
558 .\}
559 .el \{\
560 .sp -1
561 .IP \(bu 2.3
562 .\}
563 index: indexes, works like the
564 \fB\-I\fR/\fB\-\-indexes\fR
565 option\&. This keyword can only be used with the
566 include
567 keyword\&.
568 .RE
569 .sp
570 .RS 4
571 .ie n \{\
572 \h'-04'\(bu\h'+03'\c
573 .\}
574 .el \{\
575 .sp -1
576 .IP \(bu 2.3
577 .\}
578 schema: schemas, works like the
579 \fB\-n\fR/\fB\-\-schema\fR
580 and
581 \fB\-N\fR/\fB\-\-exclude\-schema\fR
582 options\&.
583 .RE
584 .sp
585 .RS 4
586 .ie n \{\
587 \h'-04'\(bu\h'+03'\c
588 .\}
589 .el \{\
590 .sp -1
591 .IP \(bu 2.3
592 .\}
593 table: tables, works like the
594 \fB\-t\fR/\fB\-\-table\fR
595 option\&. This keyword can only be used with the
596 include
597 keyword\&.
598 .RE
599 .sp
600 .RS 4
601 .ie n \{\
602 \h'-04'\(bu\h'+03'\c
603 .\}
604 .el \{\
605 .sp -1
606 .IP \(bu 2.3
607 .\}
608 trigger: triggers, works like the
609 \fB\-T\fR/\fB\-\-trigger\fR
610 option\&. This keyword can only be used with the
611 include
612 keyword\&.
613 .RE
614 .sp
615 Lines starting with
616 #
617 are considered comments and ignored\&. Comments can be placed after an object pattern row as well\&. Blank lines are also ignored\&. See
618 Patterns
619 for how to perform quoting in patterns\&.
620 .RE
621 .PP
622 \fB\-\-if\-exists\fR
623 .RS 4
624 Use
625 DROP \&.\&.\&. IF EXISTS
626 commands to drop objects in
627 \fB\-\-clean\fR
628 mode\&. This suppresses
629 \(lqdoes not exist\(rq
630 errors that might otherwise be reported\&. This option is not valid unless
631 \fB\-\-clean\fR
632 is also specified\&.
633 .RE
634 .PP
635 \fB\-\-no\-comments\fR
636 .RS 4
637 Do not output commands to restore comments, even if the archive contains them\&.
638 .RE
639 .PP
640 \fB\-\-no\-data\fR
641 .RS 4
642 Do not output commands to restore data, even if the archive contains them\&.
643 .RE
644 .PP
645 \fB\-\-no\-data\-for\-failed\-tables\fR
646 .RS 4
647 By default, table data is restored even if the creation command for the table failed (e\&.g\&., because it already exists)\&. With this option, data for such a table is skipped\&. This behavior is useful if the target database already contains the desired table contents\&. For example, auxiliary tables for
648 PostgreSQL
649 extensions such as
650 PostGIS
651 might already be loaded in the target database; specifying this option prevents duplicate or obsolete data from being loaded into them\&.
652 .sp
653 This option is effective only when restoring directly into a database, not when producing SQL script output\&.
654 .RE
655 .PP
656 \fB\-\-no\-policies\fR
657 .RS 4
658 Do not output commands to restore row security policies, even if the archive contains them\&.
659 .RE
660 .PP
661 \fB\-\-no\-publications\fR
662 .RS 4
663 Do not output commands to restore publications, even if the archive contains them\&.
664 .RE
665 .PP
666 \fB\-\-no\-schema\fR
667 .RS 4
668 Do not output commands to restore schema (data definitions), even if the archive contains them\&.
669 .RE
670 .PP
671 \fB\-\-no\-security\-labels\fR
672 .RS 4
673 Do not output commands to restore security labels, even if the archive contains them\&.
674 .RE
675 .PP
676 \fB\-\-no\-statistics\fR
677 .RS 4
678 Do not output commands to restore statistics, even if the archive contains them\&.
679 .RE
680 .PP
681 \fB\-\-no\-subscriptions\fR
682 .RS 4
683 Do not output commands to restore subscriptions, even if the archive contains them\&.
684 .RE
685 .PP
686 \fB\-\-no\-table\-access\-method\fR
687 .RS 4
688 Do not output commands to select table access methods\&. With this option, all objects will be created with whichever table access method is the default during restore\&.
689 .RE
690 .PP
691 \fB\-\-no\-tablespaces\fR
692 .RS 4
693 Do not output commands to select tablespaces\&. With this option, all objects will be created in whichever tablespace is the default during restore\&.
694 .RE
695 .PP
696 \fB\-\-restrict\-key=\fR\fB\fIrestrict_key\fR\fR
697 .RS 4
698 Use the provided string as the
699 psql
700 \fB\erestrict\fR
701 key in the dump output\&. This can only be specified for SQL script output, i\&.e\&., when the
702 \fB\-\-file\fR
703 option is used\&. If no restrict key is specified,
704 pg_restore
705 will generate a random one as needed\&. Keys may contain only alphanumeric characters\&.
706 .sp
707 This option is primarily intended for testing purposes and other scenarios that require repeatable output (e\&.g\&., comparing dump files)\&. It is not recommended for general use, as a malicious server with advance knowledge of the key may be able to inject arbitrary code that will be executed on the machine that runs
708 psql
709 with the dump output\&.
710 .RE
711 .PP
712 \fB\-\-section=\fR\fB\fIsectionname\fR\fR
713 .RS 4
714 Only restore the named section\&. The section name can be
715 \fBpre\-data\fR,
716 \fBdata\fR, or
717 \fBpost\-data\fR\&. This option can be specified more than once to select multiple sections\&. The default is to restore all sections\&.
718 .sp
719 The data section contains actual table data as well as large\-object definitions\&. Post\-data items consist of definitions of indexes, triggers, rules and constraints other than validated check constraints\&. Pre\-data items consist of all other data definition items\&.
720 .RE
721 .PP
722 \fB\-\-statistics\fR
723 .RS 4
724 Output commands to restore statistics, if the archive contains them\&. This is the default\&.
725 .RE
726 .PP
727 \fB\-\-statistics\-only\fR
728 .RS 4
729 Restore only the statistics, not schema (data definitions) or data\&.
730 .RE
731 .PP
732 \fB\-\-strict\-names\fR
733 .RS 4
734 Require that each schema (\fB\-n\fR/\fB\-\-schema\fR) and table (\fB\-t\fR/\fB\-\-table\fR) qualifier match at least one schema/table in the file to be restored\&.
735 .RE
736 .PP
737 \fB\-\-transaction\-size=\fR\fB\fIN\fR\fR
738 .RS 4
739 Execute the restore as a series of transactions, each processing up to
740 \fIN\fR
741 database objects\&. This option implies
742 \fB\-\-exit\-on\-error\fR\&.
743 .sp
744 \fB\-\-transaction\-size\fR
745 offers an intermediate choice between the default behavior (one transaction per SQL command) and
746 \fB\-1\fR/\fB\-\-single\-transaction\fR
747 (one transaction for all restored objects)\&. While
748 \fB\-\-single\-transaction\fR
749 has the least overhead, it may be impractical for large databases because the transaction will take a lock on each restored object, possibly exhausting the server\*(Aqs lock table space\&. Using
750 \fB\-\-transaction\-size\fR
751 with a size of a few thousand objects offers nearly the same performance benefits while capping the amount of lock table space needed\&.
752 .RE
753 .PP
754 \fB\-\-use\-set\-session\-authorization\fR
755 .RS 4
756 Output SQL\-standard
757 \fBSET SESSION AUTHORIZATION\fR
758 commands instead of
759 \fBALTER OWNER\fR
760 commands to determine object ownership\&. This makes the dump more standards\-compatible, but depending on the history of the objects in the dump, might not restore properly\&.
761 .RE
762 .PP
763 \fB\-?\fR
764 .br
765 \fB\-\-help\fR
766 .RS 4
767 Show help about
768 pg_restore
769 command line arguments, and exit\&.
770 .RE
771 .PP
772 pg_restore
773 also accepts the following command line arguments for connection parameters:
774 .PP
775 \fB\-h \fR\fB\fIhost\fR\fR
776 .br
777 \fB\-\-host=\fR\fB\fIhost\fR\fR
778 .RS 4
779 Specifies the host name of the machine on which the server is running\&. If the value begins with a slash, it is used as the directory for the Unix domain socket\&. The default is taken from the
780 \fBPGHOST\fR
781 environment variable, if set, else a Unix domain socket connection is attempted\&.
782 .RE
783 .PP
784 \fB\-p \fR\fB\fIport\fR\fR
785 .br
786 \fB\-\-port=\fR\fB\fIport\fR\fR
787 .RS 4
788 Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections\&. Defaults to the
789 \fBPGPORT\fR
790 environment variable, if set, or a compiled\-in default\&.
791 .RE
792 .PP
793 \fB\-U \fR\fB\fIusername\fR\fR
794 .br
795 \fB\-\-username=\fR\fB\fIusername\fR\fR
796 .RS 4
797 User name to connect as\&.
798 .RE
799 .PP
800 \fB\-w\fR
801 .br
802 \fB\-\-no\-password\fR
803 .RS 4
804 Never issue a password prompt\&. If the server requires password authentication and a password is not available by other means such as a
805 \&.pgpass
806 file, the connection attempt will fail\&. This option can be useful in batch jobs and scripts where no user is present to enter a password\&.
807 .RE
808 .PP
809 \fB\-W\fR
810 .br
811 \fB\-\-password\fR
812 .RS 4
813 Force
814 pg_restore
815 to prompt for a password before connecting to a database\&.
816 .sp
817 This option is never essential, since
818 pg_restore
819 will automatically prompt for a password if the server demands password authentication\&. However,
820 pg_restore
821 will waste a connection attempt finding out that the server wants a password\&. In some cases it is worth typing
822 \fB\-W\fR
823 to avoid the extra connection attempt\&.
824 .RE
825 .PP
826 \fB\-\-role=\fR\fB\fIrolename\fR\fR
827 .RS 4
828 Specifies a role name to be used to perform the restore\&. This option causes
829 pg_restore
830 to issue a
831 \fBSET ROLE\fR
832 \fIrolename\fR
833 command after connecting to the database\&. It is useful when the authenticated user (specified by
834 \fB\-U\fR) lacks privileges needed by
835 pg_restore, but can switch to a role with the required rights\&. Some installations have a policy against logging in directly as a superuser, and use of this option allows restores to be performed without violating the policy\&.
836 .RE
837 .SH "ENVIRONMENT"
838 .PP
839 \fBPGHOST\fR
840 .br
841 \fBPGOPTIONS\fR
842 .br
843 \fBPGPORT\fR
844 .br
845 \fBPGUSER\fR
846 .RS 4
847 Default connection parameters
848 .RE
849 .PP
850 \fBPG_COLOR\fR
851 .RS 4
852 Specifies whether to use color in diagnostic messages\&. Possible values are
853 always,
854 auto
855 and
856 never\&.
857 .RE
858 .PP
859 This utility, like most other
860 PostgreSQL
861 utilities, also uses the environment variables supported by
862 libpq
863 (see
864 Section\ \&32.15)\&. However, it does not read
865 \fBPGDATABASE\fR
866 when a database name is not supplied\&.
867 .SH "DIAGNOSTICS"
868 .PP
869 When a direct database connection is specified using the
870 \fB\-d\fR
871 option,
872 pg_restore
873 internally executes
874 SQL
875 statements\&. If you have problems running
876 pg_restore, make sure you are able to select information from the database using, for example,
877 \fBpsql\fR(1)\&. Also, any default connection settings and environment variables used by the
878 libpq
879 front\-end library will apply\&.
880 .SH "NOTES"
881 .PP
882 If your installation has any local additions to the
883 template1
884 database, be careful to load the output of
885 pg_restore
886 into a truly empty database; otherwise you are likely to get errors due to duplicate definitions of the added objects\&. To make an empty database without any local additions, copy from
887 template0
888 not
889 template1, for example:
890 .sp
891 .if n \{\
892 .RS 4
893 .\}
894 .nf
895 CREATE DATABASE foo WITH TEMPLATE template0;
896 .fi
897 .if n \{\
898 .RE
899 .\}
900 .PP
901 The limitations of
902 pg_restore
903 are detailed below\&.
904 .sp
905 .RS 4
906 .ie n \{\
907 \h'-04'\(bu\h'+03'\c
908 .\}
909 .el \{\
910 .sp -1
911 .IP \(bu 2.3
912 .\}
913 When restoring data to a pre\-existing table and the option
914 \fB\-\-disable\-triggers\fR
915 is used,
916 pg_restore
917 emits commands to disable triggers on user tables before inserting the data, then emits commands to re\-enable them after the data has been inserted\&. If the restore is stopped in the middle, the system catalogs might be left in the wrong state\&.
918 .RE
919 .sp
920 .RS 4
921 .ie n \{\
922 \h'-04'\(bu\h'+03'\c
923 .\}
924 .el \{\
925 .sp -1
926 .IP \(bu 2.3
927 .\}
928 pg_restore
929 cannot restore large objects selectively; for instance, only those for a specific table\&. If an archive contains large objects, then all large objects will be restored, or none of them if they are excluded via
930 \fB\-L\fR,
931 \fB\-t\fR, or other options\&.
932 .RE
933 .PP
934 See also the
935 \fBpg_dump\fR(1)
936 documentation for details on limitations of
937 pg_dump\&.
938 .PP
939 By default,
940 \fBpg_restore\fR
941 will restore optimizer statistics if included in the dump file\&. If not all statistics were restored, it may be useful to run
942 \fBANALYZE\fR
943 on each restored table so the optimizer has useful statistics; see
944 Section\ \&24.1.3
945 and
946 Section\ \&24.1.6
947 for more information\&.
948 .SH "EXAMPLES"
949 .PP
950 Assume we have dumped a database called
951 mydb
952 into a custom\-format dump file:
953 .sp
954 .if n \{\
955 .RS 4
956 .\}
957 .nf
958 $ \fBpg_dump \-Fc mydb > db\&.dump\fR
959 .fi
960 .if n \{\
961 .RE
962 .\}
963 .PP
964 To drop the database and recreate it from the dump:
965 .sp
966 .if n \{\
967 .RS 4
968 .\}
969 .nf
970 $ \fBdropdb mydb\fR
971 $ \fBpg_restore \-C \-d postgres db\&.dump\fR
972 .fi
973 .if n \{\
974 .RE
975 .\}
976 .sp
977 The database named in the
978 \fB\-d\fR
979 switch can be any database existing in the cluster;
980 pg_restore
981 only uses it to issue the
982 \fBCREATE DATABASE\fR
983 command for
984 mydb\&. With
985 \fB\-C\fR, data is always restored into the database name that appears in the dump file\&.
986 .PP
987 To restore the dump into a new database called
988 newdb:
989 .sp
990 .if n \{\
991 .RS 4
992 .\}
993 .nf
994 $ \fBcreatedb \-T template0 newdb\fR
995 $ \fBpg_restore \-d newdb db\&.dump\fR
996 .fi
997 .if n \{\
998 .RE
999 .\}
1000 .sp
1001 Notice we don\*(Aqt use
1002 \fB\-C\fR, and instead connect directly to the database to be restored into\&. Also note that we clone the new database from
1003 template0
1004 not
1005 template1, to ensure it is initially empty\&.
1006 .PP
1007 To reorder database items, it is first necessary to dump the table of contents of the archive:
1008 .sp
1009 .if n \{\
1010 .RS 4
1011 .\}
1012 .nf
1013 $ \fBpg_restore \-l db\&.dump > db\&.list\fR
1014 .fi
1015 .if n \{\
1016 .RE
1017 .\}
1018 .sp
1019 The listing file consists of a header and one line for each item, e\&.g\&.:
1020 .sp
1021 .if n \{\
1022 .RS 4
1023 .\}
1024 .nf
1025 ;
1026 ; Archive created at Mon Sep 14 13:55:39 2009
1027 ;     dbname: DBDEMOS
1028 ;     TOC Entries: 81
1029 ;     Compression: 9
1030 ;     Dump Version: 1\&.10\-0
1031 ;     Format: CUSTOM
1032 ;     Integer: 4 bytes
1033 ;     Offset: 8 bytes
1034 ;     Dumped from database version: 8\&.3\&.5
1035 ;     Dumped by pg_dump version: 8\&.3\&.8
1036 ;
1037 ;
1038 ; Selected TOC Entries:
1039 ;
1040 3; 2615 2200 SCHEMA \- public pasha
1041 1861; 0 0 COMMENT \- SCHEMA public pasha
1042 1862; 0 0 ACL \- public pasha
1043 317; 1247 17715 TYPE public composite pasha
1044 319; 1247 25899 DOMAIN public domain0 pasha
1045 .fi
1046 .if n \{\
1047 .RE
1048 .\}
1049 .sp
1050 Semicolons start a comment, and the numbers at the start of lines refer to the internal archive ID assigned to each item\&.
1051 .PP
1052 Lines in the file can be commented out, deleted, and reordered\&. For example:
1053 .sp
1054 .if n \{\
1055 .RS 4
1056 .\}
1057 .nf
1058 10; 145433 TABLE map_resolutions postgres
1059 ;2; 145344 TABLE species postgres
1060 ;4; 145359 TABLE nt_header postgres
1061 6; 145402 TABLE species_records postgres
1062 ;8; 145416 TABLE ss_old postgres
1063 .fi
1064 .if n \{\
1065 .RE
1066 .\}
1067 .sp
1068 could be used as input to
1069 pg_restore
1070 and would only restore items 10 and 6, in that order:
1071 .sp
1072 .if n \{\
1073 .RS 4
1074 .\}
1075 .nf
1076 $ \fBpg_restore \-L db\&.list db\&.dump\fR
1077 .fi
1078 .if n \{\
1079 .RE
1080 .\}
1081 .SH "SEE ALSO"
1082 \fBpg_dump\fR(1), \fBpg_dumpall\fR(1), \fBpsql\fR(1)