pg_restore - restore a PostgreSQL database from backup files created by pg_dump in.

SYNOPSIS

pg_restore [ option...] [ filename]

DESCRIPTION Description

pg_restore is a process for the recovery of pg_dump apply any non-plain-text format (1) created in the PostgreSQL database. It will issue the commands necessary to reconstruct the database in order to preserve the way it is time to put it back into. Archiving (backup) files also allow pg_restore to selectively recover even to reorder the items prior to being restored. Archived files are designed to be portable across different hardware architectures.

pg_restore can operate in two modes: If a database name is specified, the archive is restored directly into the database. Large objects can only be restored with a direct database connection. Otherwise, the script must rebuild the database SQL commands to create a contained (and written to a file or standard output), similar to the kind of script created pg_dump plain text format when. Therefore, some control script output option is to mimic the operation of pg_dump.

Obviously, pg_restore can not restore information that is not present in the archive; for example, if the filing is made with the "dump data as INSERT commands" option, then pg_restore will not be able to load the data using COPY statements.

OPTIONS Options

pg_restore accepts the following command-line parameters.

filename

Location of backup files to be restored statement. If not specified, the standard input.
-a
--data-only

Recovery data only, without recovery mode table (data definitions).
-c
--clean

Before creating database objects to clean (delete) them.
-C
--create

Before restoring the database to create it. (If this option appears, and -d database name is used only to issue the initial CREATE DATABASE command. All data is restored to the name appears in the archive database.)
-d dbname
--dbname= dbname

And to database dbname and restore directly into the database.
-f filename
--file= filename

The output file generated script, or appear -l file for a list of the option, the default is the standard output.
-F format
--format = formats

Format of the archive. Since pg_restore will determine the format automatically, so if declared, it can be one of the following:
t

Backup is a tar archive. Using this format allows reordering at the time of recovery of the database and / or the schema elements excluded. It also may limit data loaded at the time of recovery.
c

Backup format is in the custom format of pg_dump. This is the most flexible format because it allows re-sort the data, but also allows you to override the table schema elements. The default format is compressed.

 

-i
--ignore-version

Ignore database version checks.
-I index
--index= index

Only restore the named index.
-l
--list

List the contents of the backup. The output of this operation may project -L option to restrict and reorder the recovered used.
-L list-file
--use-list= list-file

In the list-file restore only elements inside, in the order they appear in the file. Note manner; you can move the respective line and may also be put through the start of the line. (See below for examples.)
-N
--orig-order

To dump the order originally generated in pg_dump in restoration projects. This option is no practical use, since pg_dump generates the items in their own convenient order, this order can not be restored order in which these data are secure. (This order is not the order of the last item listed in the archive of the contents of the list.) See also -r.
-O
--oid-order

OID order to restore the project. This option is of little use, because only an approximate indication of the OID order was originally created. If you have declared -N, then this option also cover it. See also -r.
-O
--no-owner

Do not set the output object permissions to match the original database commands. By default, pg_restore emits SET SESSION AUTHORIZATION owner permissions statement setting out to create a schema elements. If the initial database connection is not the super-user (or have all created out of objects of the same user) initiated, then the statement will fail. Use -O, any user can be used for the initial connection, and the user will have all created out of objects.
-P function-name(argtype [, ...])
--function= function-name(argtype [, ...])

Restore only specific named function. Please pay careful attention to the spelling of the function name and its parameters, and dump the contents of the list should be the same.
-r
--rearrange

Rearrangement type of the object item (this occurs after sorting to -N or -o). Rearrangement to give the best possible performance.

If you do not -N , -o , and -r , then pg_restore to the order of items in the archive of the contents of the list appear to recover them or restore them according to their order in the list-file inside - if given -L words. a combination of -o and -r copy the sort carried out pg_dump before creating an archive of the contents of the list, therefore, this option is usually not necessary declarations.

-R
--no-reconnect

This option is obsolete but still accepted for backward compatibility.
-s
--schema-only

Only to restore the schema (data definitions). Data is not restored, the sequence values ​​are reset.
-S username
--superuser= username

Specify the superuser user's username when disabling triggers. Only set --disable-triggers when useful.
-t table
--table = table

Only restore the table specified table definition and / or data.
-T trigger
--trigger= trigger

Restore only the specified trigger.
-v
--verbose

Declared redundant mode.
-x
--no-privileges
--no-acl

Avoid ACL recovery (grant / revoke commands).
-X use-set-session-authorization
--use-set-session-authorization

This option is obsolete, but for backward compatibility, still acceptable. pg_restore now always behave like before this option is selected the same.
-X disable-triggers
--disable-triggers

This is only relevant when performing a restore only the data. It pg_restore to execute commands to temporarily disable triggers on the target table when loading data. If you have integrity checks or other triggers on the table, and you do not want to activate them, you can use this option when loading data.


At present, for the --disable-triggers command is issued must be given by a super user. Therefore, you should also specify a superuser name with -S, or preferably set --use-set-session-authorization and to PostgreSQL superuser run pg_restore.

 

pg_restore also accepts the following command line arguments for connection parameters:

-h host
--host= host

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 PGHOST environment variable (if set), otherwise it will attempt to Unix domain socket.
-p port
--port = Port

The server is listening TCP port or local Unix domain socket file extension. The default value is PGPORT environment variable (if set of words), otherwise the default compiler said.
-U username

To give the identity of the user connection.
-W

Force a password prompt. If the server requires password authentication, then this should happen automatically.

 

ENVIRONMENT Environment

PGHOST
PGPORT
PGUSER

The default connection parameters.

DIAGNOSTICS diagnosis


When using the -d option declares a direct database connection, pg_restore internally executes SQL statements inside. If you run pg_restore goes wrong, make sure you are able psql (1) such a thing to select information from the database.

NOTES Note


If you install adds any database to template1 your own thing, be careful to restore the output of pg_dump into a truly empty database; otherwise you may receive an error message because duplicate definitions of the added objects caused. To create a database without any local additions, you can copy from template0 instead of template1, for example:

 

CREATE DATABASE foo WITH TEMPLATE template0;

pg_restore limitations listed below.

*

When restoring data to an existing table, and also use the --disable-triggers option, pg_restore release some queries to disable triggers on user tables, open them after the data is inserted before the completion of re-inserting data. If the recovery midway stop, the system catalogs may be in an error state.
*
pg_restore will not restore large objects into a single table. If an archive contains large objects, then all large objects will be restored.

 


See also refer to pg_dump (1) documents to obtain details on limitations of pg_dump.


Once the recovery is complete, it is best to run on each object to restore the ANALYZE , so useful statistics to the optimizer.

EXAMPLES Examples


To dump a database called mydb that contains large objects to a tar file:

 

$ pg_dump -Ft -b mydb > db.tar


To restore the database to an existing database called newdb (along with BLOB):

 

$ pg_restore -d newdb db.tar


To reorder items, you must first dump archive directory:

 

$ pg_restore -l archive.file > archive.list


This file consists of one head and one item per line composition, for example.

 

;
; 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


Here is a comment delimiters semicolon, and the line number represents the beginning of the internal archive ID assigned to each item.


You can comment out the line in the file, delete, and / or rearranged. such as,

 

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


Pg_restore can be used as input and will only restore items 10 and 6, (in this order):

 

$ pg_restore -L archive.list archive.file

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11097507.html