📄 pg_restore.1
字号:
.\\" auto-generated by docbook2man-spec $Revision: 1.1.1.1 $.TH "PG_RESTORE" "1" "2008-01-03" "Application" "PostgreSQL Client Applications".SH NAMEpg_restore \- restore a PostgreSQL database from an archive file created by pg_dump.SH SYNOPSIS.sp\fBpg_restore\fR [ \fB\fIoption\fB\fR\fI...\fR ] [ \fB\fIfilename\fB\fR ] .SH "DESCRIPTION".PP\fBpg_restore\fR is a utility for restoring aPostgreSQL database from an archivecreated by \fBpg_dump\fR(1) in one of the non-plain-textformats. It will issue the commands necessary to reconstruct thedatabase to the state it was in at the time it was saved. Thearchive files also allow \fBpg_restore\fR tobe selective about what is restored, or even to reorder the itemsprior to being restored. The archive files are designed to beportable across architectures..PP\fBpg_restore\fR can operate in two modes.If a database name is specified, the archive is restored directly intothe database. Otherwise, a script containing the SQLcommands necessary to rebuild the database is created and writtento a file or standard output. The script output is equivalent tothe plain text output format of \fBpg_dump\fR.Some of the options controlling the output are therefore analogous to\fBpg_dump\fR options..PPObviously, \fBpg_restore\fR cannot restore informationthat is not present in the archive file. For instance, if thearchive was made using the ``dump data as\fBINSERT\fR commands'' option,\fBpg_restore\fR will not be able to load the datausing \fBCOPY\fR statements..SH "OPTIONS".PP\fBpg_restore\fR accepts the following commandline arguments..TP\fB\fIfilename\fB\fRSpecifies the location of the archive file to be restored.If not specified, the standard input is used..TP\fB-a\fR.TP\fB--data-only\fRRestore only the data, not the schema (data definitions)..TP\fB-c\fR.TP\fB--clean\fRClean (drop) database objects before recreating them..TP\fB-C\fR.TP\fB--create\fRCreate the database before restoring into it. (When thisoption is used, the database named with \fB-d\fR isused only to issue the initial \fBCREATE DATABASE\fRcommand. All data is restored into the database name thatappears in the archive.).TP\fB-d \fIdbname\fB\fR.TP\fB--dbname=\fIdbname\fB\fRConnect to database \fIdbname\fR and restore directlyinto the database..TP\fB-e\fR.TP\fB--exit-on-error\fRExit if an error is encountered while sending SQL commands tothe database. The default is to continue and to display a count of errors at the end of the restoration..TP\fB-f \fIfilename\fB\fR.TP\fB--file=\fIfilename\fB\fRSpecify output file for generated script, or for the listingwhen used with \fB-l\fR. Default is the standardoutput..TP\fB-F \fIformat\fB\fR.TP\fB--format=\fIformat\fB\fRSpecify format of the archive. It is not necessary to specifythe format, since \fBpg_restore\fR willdetermine the format automatically. If specified, it can beone of the following:.RS.TP\fBt\fR.TP\fBtar\fRThe archive is a \fBtar\fR archive. Using thisarchive format allows reordering and/or exclusion of schemaelements at the time the database is restored. It is alsopossible to limit which data is reloaded at restore time..TP\fBc\fR.TP\fBcustom\fRThe archive is in the custom format of\fBpg_dump\fR. This is the mostflexible format in that it allows reordering of data loadas well as schema elements. This format is also compressedby default..RE.PP.TP\fB-i\fR.TP\fB--ignore-version\fRIgnore database version checks..TP\fB-I \fIindex\fB\fR.TP\fB--index=\fIindex\fB\fRRestore definition of named index only..TP\fB-l\fR.TP\fB--list\fRList the contents of the archive. The output of this operationcan be used with the \fB-L\fR option to restrictand reorder the items that are restored..TP\fB-L \fIlist-file\fB\fR.TP\fB--use-list=\fIlist-file\fB\fRRestore elements in \fI list-file\fR only, and in theorder they appear in the file. Lines can be moved and may alsobe commented out by placing a ; at thestart of the line. (See below for examples.).TP\fB-n \fInamespace\fB\fR.TP\fB--schema=\fIschema\fB\fRRestore only objects that are in the named schema. This can becombined with the \fB-t\fR option to restore just aspecific table..TP\fB-O\fR.TP\fB--no-owner\fRDo not output commands to setownership of objects to match the original database.By default, \fBpg_restore\fR issues\fBALTER OWNER\fR or \fBSET SESSION AUTHORIZATION\fRstatements to set ownership of created schema elements.These statements will fail unless the initial connection to thedatabase is made by a superuser(or the same user that owns all of the objects in the script).With \fB-O\fR, any user name can be used for theinitial connection, and this user will own all the created objects..TP\fB-P \fIfunction-name(argtype [, ...])\fB\fR.TP\fB--function=\fIfunction-name(argtype [, ...])\fB\fRRestore the named function only. Be careful to spell the functionname and arguments exactly as they appear in the dump file's tableof contents..TP\fB-R\fR.TP\fB--no-reconnect\fRThis option is obsolete but still accepted for backwardscompatibility..TP\fB-s\fR.TP\fB--schema-only\fRRestore only the schema (data definitions), not the data (tablecontents). Sequence current values will not be restored, either.(Do not confuse this with the \fB--schema\fR option, whichuses the word ``schema'' in a different meaning.).TP\fB-S \fIusername\fB\fR.TP\fB--superuser=\fIusername\fB\fRSpecify the superuser user name to use when disabling triggers.This is only relevant if \fB--disable-triggers\fR is used..TP\fB-t \fItable\fB\fR.TP\fB--table=\fItable\fB\fRRestore definition and/or data of named table only..TP\fB-T \fItrigger\fB\fR.TP\fB--trigger=\fItrigger\fB\fRRestore named trigger only..TP\fB-v\fR.TP\fB--verbose\fRSpecifies verbose mode..TP\fB-x\fR.TP\fB--no-privileges\fR.TP\fB--no-acl\fRPrevent restoration of access privileges (grant/revoke commands)..TP\fB--disable-triggers\fRThis option is only relevant when performing a data-only restore.It instructs \fBpg_restore\fR to execute commandsto temporarily disable triggers on the target tables whilethe data is reloaded. Use this if you have referentialintegrity checks or other triggers on the tables that youdo not want to invoke during data reload.Presently, the commands emitted for\fB--disable-triggers\fR must be done as superuser. So, youshould also specify a superuser name with \fB-S\fR, orpreferably run \fBpg_restore\fR as aPostgreSQL superuser..TP\fB--use-set-session-authorization\fROutput SQL-standard \fBSET SESSION AUTHORIZATION\fR commandsinstead of \fBALTER OWNER\fR commands to determine objectownership. This makes the dump more standards compatible, butdepending on the history of the objects in the dump, may not restoreproperly..TP\fB--no-data-for-failed-tables\fRBy default, table data is restored even if the creation commandfor the table failed (e.g., because it already exists).With this option, data for such a table is skipped.This behavior is useful when the target database may alreadycontain the desired table contents. For example,auxiliary tables for PostgreSQL extensionssuch as PostGIS may already be loaded inthe target database; specifying this option prevents duplicateor obsolete data from being loaded into them.This option is effective only when restoring directly into adatabase, not when producing SQL script output..PP.PP\fBpg_restore\fR also acceptsthe following command line arguments for connection parameters:.TP\fB-h \fIhost\fB\fR.TP\fB--host=\fIhost\fB\fRSpecifies the host name of the machine on which the server isrunning. If the value begins with a slash, it is used as thedirectory for the Unix domain socket. The default is takenfrom the \fBPGHOST\fR environment variable, if set,else a Unix domain socket connection is attempted..TP\fB-p \fIport\fB\fR.TP\fB--port=\fIport\fB\fRSpecifies the TCP port or local Unix domain socket fileextension on which the server is listening for connections.Defaults to the \fBPGPORT\fR environment variable, ifset, or a compiled-in default..TP\fB-U \fIusername\fB\fRConnect as the given user.TP\fB-W\fRForce a password prompt. This should happen automatically ifthe server requires password authentication..TP\fB-1\fR.TP\fB--single-transaction\fRExecute the restore as a single transaction (that is, wrap theemitted commands in \fBBEGIN\fR/\fBCOMMIT\fR). Thisensures that either all the commands complete successfully, or nochanges are applied. This option implies\fB--exit-on-error\fR..PP.SH "ENVIRONMENT".TP\fBPGHOST\fR.TP\fBPGPORT\fR.TP\fBPGUSER\fRDefault connection parameters.PPThis utility, like most other PostgreSQL utilities,also uses the environment variables supported by \fBlibpq\fR(see in the documentation)..PP.SH "DIAGNOSTICS".PPWhen a direct database connection is specified using the\fB-d\fR option, \fBpg_restore\fRinternally executes SQL statements. If you haveproblems running \fBpg_restore\fR, make sureyou are able to select information from the database using, forexample, \fBpsql\fR(1). Also, any default connectionsettings and environment variables used by the\fBlibpq\fR front-end library will apply..SH "NOTES".PPIf your installation has any local additions to thetemplate1 database, be careful to load the output of\fBpg_restore\fR into a truly empty database;otherwise you are likely to get errors due to duplicate definitionsof the added objects. To make an empty database without any localadditions, copy from template0 not template1, for example:.sp.nfCREATE DATABASE foo WITH TEMPLATE template0;.sp.fi.PPThe limitations of \fBpg_restore\fR are detailed below..TP 0.2i\(buWhen restoring data to a pre-existing table and the option\fB--disable-triggers\fR is used,\fBpg_restore\fR emits commandsto disable triggers on user tables before inserting the data then emits commands tore-enable them after the data has been inserted. If the restore is stopped in themiddle, the system catalogs may be left in the wrong state..TP 0.2i\(bu\fBpg_restore\fR will not restore large objects for a single table. Ifan archive contains large objects, then all large objects will be restored..PP.PPSee also the \fBpg_dump\fR(1) documentation for details onlimitations of \fBpg_dump\fR..PPOnce restored, it is wise to run \fBANALYZE\fR on eachrestored table so the optimizer has useful statistics..SH "EXAMPLES".PPAssume we have dumped a database called mydb into acustom-format dump file:.sp.nf$ \fBpg_dump -Fc mydb > db.dump\fR.sp.fi.PPTo drop the database and recreate it from the dump:.sp.nf$ \fBdropdb mydb\fR$ \fBpg_restore -C -d postgres db.dump\fR.sp.fiThe database named in the \fB-d\fR switch can be any database existingin the cluster; \fBpg_restore\fR only uses it to issue the\fBCREATE DATABASE\fR command for mydb. With\fB-C\fR, data is always restored into the database name that appearsin the dump file..PPTo reload the dump into a new database called newdb:.sp.nf$ \fBcreatedb -T template0 newdb\fR$ \fBpg_restore -d newdb db.dump\fR.sp.fiNotice we don't use \fB-C\fR, and instead connect directly to thedatabase to be restored into. Also note that we clone the new databasefrom template0 not template1, to ensure it isinitially empty..PPTo reorder database items, it is first necessary to dump the table ofcontents of the archive:.sp.nf$ \fBpg_restore -l db.dump > db.list\fR.sp.fiThe listing file consists of a header and one line for each item, e.g.,.sp.nf;; Archive created at Fri Jul 28 22:28:36 2000; dbname: mydb; TOC Entries: 74; Compression: 0; Dump Version: 1.4-0; Format: CUSTOM;;; Selected TOC Entries:;2; 145344 TABLE species postgres3; 145344 ACL species4; 145359 TABLE nt_header postgres5; 145359 ACL nt_header6; 145402 TABLE species_records postgres7; 145402 ACL species_records8; 145416 TABLE ss_old postgres9; 145416 ACL ss_old10; 145433 TABLE map_resolutions postgres11; 145433 ACL map_resolutions12; 145443 TABLE hs_old postgres13; 145443 ACL hs_old.sp.fiSemicolons start a comment, and the numbers at the start of lines refer to theinternal archive ID assigned to each item..PPLines in the file can be commented out, deleted, and reordered. For example,.sp.nf10; 145433 TABLE map_resolutions postgres;2; 145344 TABLE species postgres;4; 145359 TABLE nt_header postgres6; 145402 TABLE species_records postgres;8; 145416 TABLE ss_old postgres.sp.ficould be used as input to \fBpg_restore\fR and would only restoreitems 10 and 6, in that order:.sp.nf$ \fBpg_restore -L db.list db.dump\fR.sp.fi.SH "HISTORY".PPThe \fBpg_restore\fR utility first appeared inPostgreSQL 7.1..SH "SEE ALSO"\fBpg_dump\fR(1), \fBpg_dumpall\fR(1), \fBpsql\fR(1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -