- database are to be restored. See the
- linkend="app-pgrestore"> documentation for details.
+ database are to be restored.
+ The most flexible output file format is the custom
+ format (). It allows for selection and
+ reordering of all archived items, and is compressed by default. The
+ tar format () is not
+ compressed and it is not possible to reorder data when loading, but
+ it is otherwise quite flexible; moreover, it can be manipulated with
+ other tools such as tar.
dbname
- Specifies the name of the database to be extracted.
+ Specifies the name of the database to be dumped.
Dump only the data, not the schema (data definitions).
+
+ This option is only meaningful for the plain text format. For
+ the other formats, you may specify the option when you
+ call pg_restore.
+
--clean
- Output commands to clean (drop) the schema prior to (the
- commands for) creating it.
+ Output commands to clean (drop)
+ database objects prior to (the commands for) creating them.
+
+
+ This option is only meaningful for the plain text format. For
+ the other formats, you may specify the option when you
+ call pg_restore.
--create
- For plain text (script) output, include commands to create the database itself.
+ Begin the output with a command to create the
+ database itself and reconnect to the created database. (With a
+ script of this form, it doesn't matter which database you connect
+ to before running the script.)
+
+
+ This option is only meaningful for the plain text format. For
+ the other formats, you may specify the option when you
+ call pg_restore.
--inserts
- Dump data as proper INSERT commands (rather
+ Dump data as INSERT commands (rather
than COPY). This will make restoration very
slow, but it makes the archives more portable to other RDBMS
packages.
column names (INSERT INTO
table
(column, ...) VALUES
- ...). This will make restoration very slow.
+ ...). This will make restoration very slow,
+ but it is necessary if you desire to rearrange column ordering.
Dump object identifiers (
OIDs) for every
- table. Use this option if your application references the oid
+ table. Use this option if your application references the OID
columns in some way (e.g., in a foreign key constraint).
Otherwise, this option should not be used.
--no-owner
- In plain text output mode, do not output commands to set the
+ Do not output commands to set the
object ownership to match the original database. Typically,
pg_dump issues
(psql-specific) \connect
This option is only meaningful for the plain text format. For
- the other formats, you need to specify the option when you
+ the other formats, you may specify the option when you
call pg_restore.
--no-reconnect
- In plain text output mode, prohibit pg_dump
+ Prohibit pg_dump
from outputting a script that would require reconnections to
the database while being restored. An average restoration
script usually has to reconnect several times as different
This option is only meaningful for the plain text format. For
- the other formats, you need to specify the option when you
+ the other formats, you may specify the option when you
call pg_restore.
This option is only meaningful for the plain text format. For
- the other formats, you need to specify the option when you
+ the other formats, you may specify the option when you
call pg_restore.
-
+
pg_restore is a utility for restoring a
Postgres database from an archive
created by in one of the non-plain-text
- formats.
+ formats. It
+ will issue the commands necessary to re-generate all user-defined
+ types, functions, tables, indexes, aggregates, and operators, as
+ well as the data in the tables.
pg_restore to rebuild the database, but also
allow pg_restore 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. It
- will issue the commands necessary to re-generate all user-defined
- types, functions, tables, indexes, aggregates, and operators, as
- well as the data in the tables.
+ archive files are designed to be portable across architectures.
or standard output), similar to the ones created by the
pg_dump plain text format. Some of the options
controlling the script output are therefore analogous to
- pg_dump.
+ pg_dump options.
using COPY statements.
- The most flexible output file format is the custom
- format (). It allows for selection and
- reordering of all archived items, and is compressed by default. The
- tar format () is not
- compressed and it is not possible to reorder data when loading, but
- it is otherwise quite flexible.
-
-
- To reorder the items, it is first necessary to dump the table of
- contents of the archive:
-
-
$ pg_restore archive.file -l > archive.list
-
- This file consists of a header and one line for each item, e.g.,
-;
-; Archive created at Fri Jul 28 22:28:36 2000
-; dbname: birds
-; TOC Entries: 74
-; Compression: 0
-; Dump Version: 1.4-0
-; Format: CUSTOM
-;
-;
-; Selected TOC Entries:
-;
-2; 145344 TABLE species postgres
-3; 145344 ACL species
-4; 145359 TABLE nt_header postgres
-5; 145359 ACL nt_header
-6; 145402 TABLE species_records postgres
-7; 145402 ACL species_records
-8; 145416 TABLE ss_old postgres
-9; 145416 ACL ss_old
-10; 145433 TABLE map_resolutions postgres
-11; 145433 ACL map_resolutions
-12; 145443 TABLE hs_old postgres
-13; 145443 ACL hs_old
-
- Semi-colons are comment delimiters, and the numbers at the start of lines refer to the
- internal archive ID assigned to each item.
-
-
- Lines in the file can be commented out, deleted, and reordered. For example,
-10; 145433 TABLE map_resolutions postgres
-;2; 145344 TABLE species postgres
-;4; 145359 TABLE nt_header postgres
-6; 145402 TABLE species_records postgres
-;8; 145416 TABLE ss_old postgres
-
- could be used as input to pg_restore and would only restore
- items 10 and 6, in that order.
-
-
$ pg_restore archive.file -L archive.list
-
-
-
Options
--clean
- Clean (drop) schema prior to create.
+ Clean (drop) database objects before recreating them.
--create
- Include SQL to create the schema.
+ Create the database before restoring into it.
+ (When this switch appears, the database named with
+ is used only
+ to issue the initial CREATE DATABASE command. All data is restored
+ into the database name that appears in the archive.)
--file=filename
- Specify output file for generated script. (Use with the
- option.) Default is the standard output.
+ Specify output file for generated script, or for the listing
+ when used with . Default is the standard output.
While restoring an archive, pg_restore
typically has to reconnect to the database several times with
different user names to set the correct ownership of the
- created objects. If this is undesriable (e.g., because manual
+ created objects. If this is undesirable (e.g., because manual
interaction (passwords) would be necessary for each
reconnection), this option prevents
pg_restore from issuing any reconnection
Normally, if restoring an archive requires altering the
current database user (e.g., to set correct object
- ownerships), a new connection to the database must be openend,
+ ownerships), a new connection to the database must be opened,
which might require manual interaction (e.g., passwords). If
you use the ,
then
pg_restore will instead use the
$ pg_restore -d newdb db.tar
+
+
+
+ To reorder database items, it is first necessary to dump the table of
+ contents of the archive:
+
+
$ pg_restore archive.file -l > archive.list
+
+ The listing file consists of a header and one line for each item, e.g.,
+;
+; Archive created at Fri Jul 28 22:28:36 2000
+; dbname: birds
+; TOC Entries: 74
+; Compression: 0
+; Dump Version: 1.4-0
+; Format: CUSTOM
+;
+;
+; Selected TOC Entries:
+;
+2; 145344 TABLE species postgres
+3; 145344 ACL species
+4; 145359 TABLE nt_header postgres
+5; 145359 ACL nt_header
+6; 145402 TABLE species_records postgres
+7; 145402 ACL species_records
+8; 145416 TABLE ss_old postgres
+9; 145416 ACL ss_old
+10; 145433 TABLE map_resolutions postgres
+11; 145433 ACL map_resolutions
+12; 145443 TABLE hs_old postgres
+13; 145443 ACL hs_old
+
+ Semi-colons are comment delimiters, and the numbers at the start of lines refer to the
+ internal archive ID assigned to each item.
+
+
+ Lines in the file can be commented out, deleted, and reordered. For example,
+10; 145433 TABLE map_resolutions postgres
+;2; 145344 TABLE species postgres
+;4; 145359 TABLE nt_header postgres
+6; 145402 TABLE species_records postgres
+;8; 145416 TABLE ss_old postgres
+
+ could be used as input to pg_restore and would only restore
+ items 10 and 6, in that order.
+
+
$ pg_restore archive.file -L archive.list