1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
8
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
10
HREF="mailto:pgsql-docs@postgresql.org"><LINK
12
TITLE="PostgreSQL 9.1beta1 Documentation"
13
HREF="index.html"><LINK
15
TITLE="PostgreSQL Client Applications"
16
HREF="reference-client.html"><LINK
19
HREF="app-pg-dumpall.html"><LINK
22
HREF="app-psql.html"><LINK
25
HREF="stylesheet.css"><META
26
HTTP-EQUIV="Content-Type"
27
CONTENT="text/html; charset=ISO-8859-1"><META
29
CONTENT="2011-04-27T21:20:33"></HEAD
35
SUMMARY="Header navigation table"
47
>PostgreSQL 9.1beta1 Documentation</A
57
HREF="app-pg-dumpall.html"
67
HREF="app-pg-dumpall.html"
111
>pg_restore -- restore a <SPAN
115
archive file created by <SPAN
121
CLASS="REFSYNOPSISDIV"
134
>connection-option</I
151
NAME="APP-PGRESTORE-DESCRIPTION"
159
> is a utility for restoring a
163
> database from an archive
165
HREF="app-pgdump.html"
167
> in one of the non-plain-text
168
formats. It will issue the commands necessary to reconstruct the
169
database to the state it was in at the time it was saved. The
170
archive files also allow <SPAN
174
be selective about what is restored, or even to reorder the items
175
prior to being restored. The archive files are designed to be
176
portable across architectures.
182
> can operate in two modes.
183
If a database name is specified, <SPAN
187
connects to that database and restores archive contents directly into
188
the database. Otherwise, a script containing the SQL
189
commands necessary to rebuild the database is created and written
190
to a file or standard output. This script output is equivalent to
191
the plain text output format of <SPAN
195
Some of the options controlling the output are therefore analogous to
205
> cannot restore information
206
that is not present in the archive file. For instance, if the
207
archive was made using the <SPAN
218
> will not be able to load the data
228
NAME="APP-PGRESTORE-OPTIONS"
236
> accepts the following command
253
> Specifies the location of the archive file (or directory, for a
254
directory-format archive) to be restored.
255
If not specified, the standard input is used.
268
> Restore only the data, not the schema (data definitions).
281
> Clean (drop) database objects before recreating them.
294
> Create the database before restoring into it. (When this
295
option is used, the database named with <TT
299
used only to issue the initial <TT
303
command. All data is restored into the database name that
304
appears in the archive.)
327
> Connect to database <TT
332
> and restore directly
346
> Exit if an error is encountered while sending SQL commands to
347
the database. The default is to continue and to display a count of
348
errors at the end of the restoration.
371
> Specify output file for generated script, or for the listing
375
>. Default is the standard
399
> Specify format of the archive. It is not necessary to specify
400
the format, since <SPAN
404
determine the format automatically. If specified, it can be
405
one of the following:
422
> The archive is a <TT
438
> The archive is a <TT
454
> The archive is in the custom format of
472
>--ignore-version</TT
476
> A deprecated option that is now ignored.
499
> Restore definition of named index only.
522
> Run the most time-consuming parts
526
> — those which load data,
527
create indexes, or create constraints — using multiple
528
concurrent jobs. This option can dramatically reduce the time
529
to restore a large database to a server running on a
530
multiprocessor machine.
533
> Each job is one process or one thread, depending on the
534
operating system, and uses a separate connection to the
538
> The optimal value for this option depends on the hardware
539
setup of the server, of the client, and of the network.
540
Factors include the number of CPU cores and the disk setup. A
541
good place to start is the number of CPU cores on the server,
542
but values larger than that can also lead to faster restore
543
times in many cases. Of course, values that are too high will
544
lead to decreased performance because of thrashing.
547
> Only the custom archive format is supported with this option.
548
The input file must be a regular file (not, for example, a
549
pipe). This option is ignored when emitting a script rather
550
than connecting directly to a database server. Also, multiple
551
jobs cannot be used together with the
554
>--single-transaction</TT
568
> List the contents of the archive. The output of this operation
569
can be used as input to the <TT
573
if filtering switches such as <TT
583
>, they will restrict the items listed.
606
> Restore only those archive elements that are listed in <TT
611
>, and restore them in the
612
order they appear in the file. Note that
613
if filtering switches such as <TT
623
>, they will further restrict the items restored.
631
> is normally created by
632
editing the output of a previous <TT
636
Lines can be moved or removed, and can also
637
be commented out by placing a semicolon (<TT
641
start of the line. See below for examples.
664
> Restore only objects that are in the named schema. This can be
665
combined with the <TT
668
> option to restore just a
682
> Do not output commands to set
683
ownership of objects to match the original database.
694
>SET SESSION AUTHORIZATION</TT
696
statements to set ownership of created schema elements.
697
These statements will fail unless the initial connection to the
698
database is made by a superuser
699
(or the same user that owns all of the objects in the script).
703
>, any user name can be used for the
704
initial connection, and this user will own all the created objects.
710
>--no-tablespaces</TT
714
> Do not output commands to select tablespaces.
715
With this option, all objects will be created in whichever
716
tablespace is the default during restore.
722
>--no-security-label</TT
726
> Do not output commands to restore security labels,
727
even if the archive contains them.
736
>function-name(argtype [, ...])</I
744
>function-name(argtype [, ...])</I
750
> Restore the named function only. Be careful to spell the function
751
name and arguments exactly as they appear in the dump file's table
765
> This option is obsolete but still accepted for backwards
779
> Restore only the schema (data definitions), not the data (table
780
contents). Current sequence values will not be restored, either.
781
(Do not confuse this with the <TT
788
> in a different meaning.)
811
> Specify the superuser user name to use when disabling triggers.
812
This is only relevant if <TT
814
>--disable-triggers</TT
838
> Restore definition and/or data of named table only. This can be
839
combined with the <TT
842
> option to specify a schema.
865
> Restore named trigger only.
878
> Specifies verbose mode.
910
> Prevent restoration of access privileges (grant/revoke commands).
916
>--disable-triggers</TT
920
> This option is only relevant when performing a data-only restore.
924
> to execute commands
925
to temporarily disable triggers on the target tables while
926
the data is reloaded. Use this if you have referential
927
integrity checks or other triggers on the tables that you
928
do not want to invoke during data reload.
931
> Presently, the commands emitted for
934
>--disable-triggers</TT
935
> must be done as superuser. So, you
936
should also specify a superuser name with <TT
953
>--use-set-session-authorization</TT
957
> Output SQL-standard <TT
959
>SET SESSION AUTHORIZATION</TT
964
> commands to determine object
965
ownership. This makes the dump more standards-compatible, but
966
depending on the history of the objects in the dump, might not restore
973
>--no-data-for-failed-tables</TT
977
> By default, table data is restored even if the creation command
978
for the table failed (e.g., because it already exists).
979
With this option, data for such a table is skipped.
980
This behavior is useful if the target database already
981
contains the desired table contents. For example,
982
auxiliary tables for <SPAN
989
> might already be loaded in
990
the target database; specifying this option prevents duplicate
991
or obsolete data from being loaded into them.
994
> This option is effective only when restoring directly into a
995
database, not when producing SQL script output.
1004
>--single-transaction</TT
1008
> Execute the restore as a single transaction (that is, wrap the
1009
emitted commands in <TT
1016
ensures that either all the commands complete successfully, or no
1017
changes are applied. This option implies
1020
>--exit-on-error</TT
1034
> Show help about <SPAN
1038
arguments, and exit.
1050
the following command line arguments for connection parameters:
1055
CLASS="VARIABLELIST"
1077
> Specifies the host name of the machine on which the server is
1078
running. If the value begins with a slash, it is used as the
1079
directory for the Unix domain socket. The default is taken
1083
> environment variable, if set,
1084
else a Unix domain socket connection is attempted.
1107
> Specifies the TCP port or local Unix domain socket file
1108
extension on which the server is listening for connections.
1112
> environment variable, if
1113
set, or a compiled-in default.
1136
> User name to connect as.
1149
> Never issue a password prompt. If the server requires
1150
password authentication and a password is not available by
1151
other means such as a <TT
1155
connection attempt will fail. This option can be useful in
1156
batch jobs and scripts where no user is present to enter a
1174
password before connecting to a database.
1177
> This option is never essential, since
1181
> will automatically prompt
1182
for a password if the server demands password authentication.
1187
connection attempt finding out that the server wants a password.
1188
In some cases it is worth typing <TT
1191
> to avoid the extra
1207
> Specifies a role name to be used to perform the restore.
1208
This option causes <SPAN
1221
command after connecting to the database. It is useful when the
1222
authenticated user (specified by <TT
1229
>, but can switch to a role with
1230
the required rights. Some installations have a policy against
1231
logging in directly as a superuser, and use of this option allows
1232
restores to be performed without violating the policy.
1250
CLASS="VARIABLELIST"
1268
> Default connection parameters
1274
> This utility, like most other <SPAN
1278
also uses the environment variables supported by <SPAN
1283
HREF="libpq-envars.html"
1291
NAME="APP-PGRESTORE-DIAGNOSTICS"
1296
> When a direct database connection is specified using the
1304
internally executes <ACRONYM
1307
> statements. If you have
1308
problems running <SPAN
1312
you are able to select information from the database using, for
1314
HREF="app-psql.html"
1319
>. Also, any default connection
1320
settings and environment variables used by the
1324
> front-end library will apply.
1330
NAME="APP-PGRESTORE-NOTES"
1335
> If your installation has any local additions to the
1339
> database, be careful to load the output of
1343
> into a truly empty database;
1344
otherwise you are likely to get errors due to duplicate definitions
1345
of the added objects. To make an empty database without any local
1346
additions, copy from <TT
1354
CLASS="PROGRAMLISTING"
1355
>CREATE DATABASE foo WITH TEMPLATE template0;</PRE
1359
> The limitations of <SPAN
1362
> are detailed below.
1369
> When restoring data to a pre-existing table and the option
1372
>--disable-triggers</TT
1378
to disable triggers on user tables before inserting the data, then emits commands to
1379
re-enable them after the data has been inserted. If the restore is stopped in the
1380
middle, the system catalogs might be left in the wrong state.
1388
> cannot restore large objects
1389
selectively; for instance, only those for a specific table. If
1390
an archive contains large objects, then all large objects will be
1391
restored, or none of them if they are excluded via <TT
1398
>, or other options.
1406
HREF="app-pgdump.html"
1408
> documentation for details on
1409
limitations of <SPAN
1415
> Once restored, it is wise to run <TT
1419
restored table so the optimizer has useful statistics; see
1421
HREF="routine-vacuuming.html#VACUUM-FOR-STATISTICS"
1425
HREF="routine-vacuuming.html#AUTOVACUUM"
1427
> for more information.
1433
NAME="APP-PGRESTORE-EXAMPLES"
1438
> Assume we have dumped a database called <TT
1442
custom-format dump file:
1451
>pg_dump -Fc mydb > db.dump</KBD
1456
> To drop the database and recreate it from the dump:
1472
>pg_restore -C -d postgres db.dump</KBD
1476
The database named in the <TT
1479
> switch can be any database existing
1480
in the cluster; <SPAN
1483
> only uses it to issue the
1486
>CREATE DATABASE</TT
1494
>, data is always restored into the database name that appears
1498
> To reload the dump into a new database called <TT
1510
>createdb -T template0 newdb</KBD
1517
>pg_restore -d newdb db.dump</KBD
1521
Notice we don't use <TT
1524
>, and instead connect directly to the
1525
database to be restored into. Also note that we clone the new database
1536
> To reorder database items, it is first necessary to dump the table of
1537
contents of the archive:
1545
>pg_restore -l db.dump > db.list</KBD
1548
The listing file consists of a header and one line for each item, e.g.:
1550
CLASS="PROGRAMLISTING"
1552
; Archive created at Mon Sep 14 13:55:39 2009
1556
; Dump Version: 1.10-0
1560
; Dumped from database version: 8.3.5
1561
; Dumped by pg_dump version: 8.3.8
1564
; Selected TOC Entries:
1566
3; 2615 2200 SCHEMA - public pasha
1567
1861; 0 0 COMMENT - SCHEMA public pasha
1568
1862; 0 0 ACL - public pasha
1569
317; 1247 17715 TYPE public composite pasha
1570
319; 1247 25899 DOMAIN public domain0 pasha</PRE
1572
Semicolons start a comment, and the numbers at the start of lines refer to the
1573
internal archive ID assigned to each item.
1576
> Lines in the file can be commented out, deleted, and reordered. For example:
1578
CLASS="PROGRAMLISTING"
1579
>10; 145433 TABLE map_resolutions postgres
1580
;2; 145344 TABLE species postgres
1581
;4; 145359 TABLE nt_header postgres
1582
6; 145402 TABLE species_records postgres
1583
;8; 145416 TABLE ss_old postgres</PRE
1585
could be used as input to <SPAN
1588
> and would only restore
1589
items 10 and 6, in that order:
1597
>pg_restore -L db.list db.dump</KBD
1610
HREF="app-pgdump.html"
1613
HREF="app-pg-dumpall.html"
1619
HREF="app-psql.html"
1630
SUMMARY="Footer navigation table"
1641
HREF="app-pg-dumpall.html"
1659
HREF="app-psql.html"
1678
HREF="reference-client.html"
b'\\ No newline at end of file'