gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

488 line
38KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>pg_restore</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="app-pgrecvlogical.html" title="pg_recvlogical" /><link rel="next" href="app-psql.html" title="psql" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">pg_restore</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="app-pgrecvlogical.html" title="pg_recvlogical">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="reference-client.html" title="PostgreSQL Client Applications">Up</a></td><th width="60%" align="center">PostgreSQL Client Applications</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="app-psql.html" title="psql">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="APP-PGRESTORE"><div class="titlepage"></div><a id="id-1.9.4.17.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">pg_restore</span></h2><p>pg_restore —
  3. restore a <span class="productname">PostgreSQL</span> database from an
  4. archive file created by <span class="application">pg_dump</span>
  5. </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.4.17.4.1"><code class="command">pg_restore</code> [<em class="replaceable"><code>connection-option</code></em>...] [<em class="replaceable"><code>option</code></em>...] [<em class="replaceable"><code>filename</code></em>]</p></div></div><div class="refsect1" id="APP-PGRESTORE-DESCRIPTION"><h2>Description</h2><p>
  6. <span class="application">pg_restore</span> is a utility for restoring a
  7. <span class="productname">PostgreSQL</span> database from an archive
  8. created by <a class="xref" href="app-pgdump.html" title="pg_dump"><span class="refentrytitle">pg_dump</span></a> in one of the non-plain-text
  9. formats. It will issue the commands necessary to reconstruct the
  10. database to the state it was in at the time it was saved. The
  11. archive files also allow <span class="application">pg_restore</span> to
  12. be selective about what is restored, or even to reorder the items
  13. prior to being restored. The archive files are designed to be
  14. portable across architectures.
  15. </p><p>
  16. <span class="application">pg_restore</span> can operate in two modes.
  17. If a database name is specified, <span class="application">pg_restore</span>
  18. connects to that database and restores archive contents directly into
  19. the database. Otherwise, a script containing the SQL
  20. commands necessary to rebuild the database is created and written
  21. to a file or standard output. This script output is equivalent to
  22. the plain text output format of <span class="application">pg_dump</span>.
  23. Some of the options controlling the output are therefore analogous to
  24. <span class="application">pg_dump</span> options.
  25. </p><p>
  26. Obviously, <span class="application">pg_restore</span> cannot restore information
  27. that is not present in the archive file. For instance, if the
  28. archive was made using the <span class="quote">“<span class="quote">dump data as
  29. <code class="command">INSERT</code> commands</span>”</span> option,
  30. <span class="application">pg_restore</span> will not be able to load the data
  31. using <code class="command">COPY</code> statements.
  32. </p></div><div class="refsect1" id="APP-PGRESTORE-OPTIONS"><h2>Options</h2><p>
  33. <span class="application">pg_restore</span> accepts the following command
  34. line arguments.
  35. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>filename</code></em></span></dt><dd><p>
  36. Specifies the location of the archive file (or directory, for a
  37. directory-format archive) to be restored.
  38. If not specified, the standard input is used.
  39. </p></dd><dt><span class="term"><code class="option">-a</code><br /></span><span class="term"><code class="option">--data-only</code></span></dt><dd><p>
  40. Restore only the data, not the schema (data definitions).
  41. Table data, large objects, and sequence values are restored,
  42. if present in the archive.
  43. </p><p>
  44. This option is similar to, but for historical reasons not identical
  45. to, specifying <code class="option">--section=data</code>.
  46. </p></dd><dt><span class="term"><code class="option">-c</code><br /></span><span class="term"><code class="option">--clean</code></span></dt><dd><p>
  47. Clean (drop) database objects before recreating them.
  48. (Unless <code class="option">--if-exists</code> is used,
  49. this might generate some harmless error messages, if any objects
  50. were not present in the destination database.)
  51. </p></dd><dt><span class="term"><code class="option">-C</code><br /></span><span class="term"><code class="option">--create</code></span></dt><dd><p>
  52. Create the database before restoring into it.
  53. If <code class="option">--clean</code> is also specified, drop and
  54. recreate the target database before connecting to it.
  55. </p><p>
  56. With <code class="option">--create</code>, <span class="application">pg_restore</span>
  57. also restores the database's comment if any, and any configuration
  58. variable settings that are specific to this database, that is,
  59. any <code class="command">ALTER DATABASE ... SET ...</code>
  60. and <code class="command">ALTER ROLE ... IN DATABASE ... SET ...</code>
  61. commands that mention this database.
  62. Access privileges for the database itself are also restored,
  63. unless <code class="option">--no-acl</code> is specified.
  64. </p><p>
  65. When this option is used, the database named with <code class="option">-d</code>
  66. is used only to issue the initial <code class="command">DROP DATABASE</code> and
  67. <code class="command">CREATE DATABASE</code> commands. All data is restored into the
  68. database name that appears in the archive.
  69. </p></dd><dt><span class="term"><code class="option">-d <em class="replaceable"><code>dbname</code></em></code><br /></span><span class="term"><code class="option">--dbname=<em class="replaceable"><code>dbname</code></em></code></span></dt><dd><p>
  70. Connect to database <em class="replaceable"><code>dbname</code></em> and restore directly
  71. into the database.
  72. </p></dd><dt><span class="term"><code class="option">-e</code><br /></span><span class="term"><code class="option">--exit-on-error</code></span></dt><dd><p>
  73. Exit if an error is encountered while sending SQL commands to
  74. the database. The default is to continue and to display a count of
  75. errors at the end of the restoration.
  76. </p></dd><dt><span class="term"><code class="option">-f <em class="replaceable"><code>filename</code></em></code><br /></span><span class="term"><code class="option">--file=<em class="replaceable"><code>filename</code></em></code></span></dt><dd><p>
  77. Specify output file for generated script, or for the listing
  78. when used with <code class="option">-l</code>. Use <code class="literal">-</code>
  79. for <span class="systemitem">stdout</span>.
  80. </p></dd><dt><span class="term"><code class="option">-F <em class="replaceable"><code>format</code></em></code><br /></span><span class="term"><code class="option">--format=<em class="replaceable"><code>format</code></em></code></span></dt><dd><p>
  81. Specify format of the archive. It is not necessary to specify
  82. the format, since <span class="application">pg_restore</span> will
  83. determine the format automatically. If specified, it can be
  84. one of the following:
  85. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">c</code><br /></span><span class="term"><code class="literal">custom</code></span></dt><dd><p>
  86. The archive is in the custom format of
  87. <span class="application">pg_dump</span>.
  88. </p></dd><dt><span class="term"><code class="literal">d</code><br /></span><span class="term"><code class="literal">directory</code></span></dt><dd><p>
  89. The archive is a directory archive.
  90. </p></dd><dt><span class="term"><code class="literal">t</code><br /></span><span class="term"><code class="literal">tar</code></span></dt><dd><p>
  91. The archive is a <code class="command">tar</code> archive.
  92. </p></dd></dl></div></dd><dt><span class="term"><code class="option">-I <em class="replaceable"><code>index</code></em></code><br /></span><span class="term"><code class="option">--index=<em class="replaceable"><code>index</code></em></code></span></dt><dd><p>
  93. Restore definition of named index only. Multiple indexes
  94. may be specified with multiple <code class="option">-I</code> switches.
  95. </p></dd><dt><span class="term"><code class="option">-j <em class="replaceable"><code>number-of-jobs</code></em></code><br /></span><span class="term"><code class="option">--jobs=<em class="replaceable"><code>number-of-jobs</code></em></code></span></dt><dd><p>
  96. Run the most time-consuming steps
  97. of <span class="application">pg_restore</span> — those that load data,
  98. create indexes, or create constraints — concurrently, using up
  99. to <em class="replaceable"><code>number-of-jobs</code></em>
  100. concurrent sessions. This option can dramatically reduce the time
  101. to restore a large database to a server running on a
  102. multiprocessor machine. This option is ignored when emitting a script
  103. rather than connecting directly to a database server.
  104. </p><p>
  105. Each job is one process or one thread, depending on the
  106. operating system, and uses a separate connection to the
  107. server.
  108. </p><p>
  109. The optimal value for this option depends on the hardware
  110. setup of the server, of the client, and of the network.
  111. Factors include the number of CPU cores and the disk setup. A
  112. good place to start is the number of CPU cores on the server,
  113. but values larger than that can also lead to faster restore
  114. times in many cases. Of course, values that are too high will
  115. lead to decreased performance because of thrashing.
  116. </p><p>
  117. Only the custom and directory archive formats are supported
  118. with this option.
  119. The input must be a regular file or directory (not, for example, a
  120. pipe or standard input). Also, multiple
  121. jobs cannot be used together with the
  122. option <code class="option">--single-transaction</code>.
  123. </p></dd><dt><span class="term"><code class="option">-l</code><br /></span><span class="term"><code class="option">--list</code></span></dt><dd><p>
  124. List the table of contents of the archive. The output of this operation
  125. can be used as input to the <code class="option">-L</code> option. Note that
  126. if filtering switches such as <code class="option">-n</code> or <code class="option">-t</code> are
  127. used with <code class="option">-l</code>, they will restrict the items listed.
  128. </p></dd><dt><span class="term"><code class="option">-L <em class="replaceable"><code>list-file</code></em></code><br /></span><span class="term"><code class="option">--use-list=<em class="replaceable"><code>list-file</code></em></code></span></dt><dd><p>
  129. Restore only those archive elements that are listed in <em class="replaceable"><code>list-file</code></em>, and restore them in the
  130. order they appear in the file. Note that
  131. if filtering switches such as <code class="option">-n</code> or <code class="option">-t</code> are
  132. used with <code class="option">-L</code>, they will further restrict the items restored.
  133. </p><p><em class="replaceable"><code>list-file</code></em> is normally created by
  134. editing the output of a previous <code class="option">-l</code> operation.
  135. Lines can be moved or removed, and can also
  136. be commented out by placing a semicolon (<code class="literal">;</code>) at the
  137. start of the line. See below for examples.
  138. </p></dd><dt><span class="term"><code class="option">-n <em class="replaceable"><code>schema</code></em></code><br /></span><span class="term"><code class="option">--schema=<em class="replaceable"><code>schema</code></em></code></span></dt><dd><p>
  139. Restore only objects that are in the named schema. Multiple schemas
  140. may be specified with multiple <code class="option">-n</code> switches. This can be
  141. combined with the <code class="option">-t</code> option to restore just a
  142. specific table.
  143. </p></dd><dt><span class="term"><code class="option">-N <em class="replaceable"><code>schema</code></em></code><br /></span><span class="term"><code class="option">--exclude-schema=<em class="replaceable"><code>schema</code></em></code></span></dt><dd><p>
  144. Do not restore objects that are in the named schema. Multiple schemas
  145. to be excluded may be specified with multiple <code class="option">-N</code> switches.
  146. </p><p>
  147. When both <code class="option">-n</code> and <code class="option">-N</code> are given for the same
  148. schema name, the <code class="option">-N</code> switch wins and the schema is excluded.
  149. </p></dd><dt><span class="term"><code class="option">-O</code><br /></span><span class="term"><code class="option">--no-owner</code></span></dt><dd><p>
  150. Do not output commands to set
  151. ownership of objects to match the original database.
  152. By default, <span class="application">pg_restore</span> issues
  153. <code class="command">ALTER OWNER</code> or
  154. <code class="command">SET SESSION AUTHORIZATION</code>
  155. statements to set ownership of created schema elements.
  156. These statements will fail unless the initial connection to the
  157. database is made by a superuser
  158. (or the same user that owns all of the objects in the script).
  159. With <code class="option">-O</code>, any user name can be used for the
  160. initial connection, and this user will own all the created objects.
  161. </p></dd><dt><span class="term"><code class="option">-P <em class="replaceable"><code>function-name(argtype [, ...])</code></em></code><br /></span><span class="term"><code class="option">--function=<em class="replaceable"><code>function-name(argtype [, ...])</code></em></code></span></dt><dd><p>
  162. Restore the named function only. Be careful to spell the function
  163. name and arguments exactly as they appear in the dump file's table
  164. of contents. Multiple functions may be specified with multiple
  165. <code class="option">-P</code> switches.
  166. </p></dd><dt><span class="term"><code class="option">-R</code><br /></span><span class="term"><code class="option">--no-reconnect</code></span></dt><dd><p>
  167. This option is obsolete but still accepted for backwards
  168. compatibility.
  169. </p></dd><dt><span class="term"><code class="option">-s</code><br /></span><span class="term"><code class="option">--schema-only</code></span></dt><dd><p>
  170. Restore only the schema (data definitions), not data,
  171. to the extent that schema entries are present in the archive.
  172. </p><p>
  173. This option is the inverse of <code class="option">--data-only</code>.
  174. It is similar to, but for historical reasons not identical to,
  175. specifying
  176. <code class="option">--section=pre-data --section=post-data</code>.
  177. </p><p>
  178. (Do not confuse this with the <code class="option">--schema</code> option, which
  179. uses the word <span class="quote">“<span class="quote">schema</span>”</span> in a different meaning.)
  180. </p></dd><dt><span class="term"><code class="option">-S <em class="replaceable"><code>username</code></em></code><br /></span><span class="term"><code class="option">--superuser=<em class="replaceable"><code>username</code></em></code></span></dt><dd><p>
  181. Specify the superuser user name to use when disabling triggers.
  182. This is relevant only if <code class="option">--disable-triggers</code> is used.
  183. </p></dd><dt><span class="term"><code class="option">-t <em class="replaceable"><code>table</code></em></code><br /></span><span class="term"><code class="option">--table=<em class="replaceable"><code>table</code></em></code></span></dt><dd><p>
  184. Restore definition and/or data of only the named table.
  185. For this purpose, <span class="quote">“<span class="quote">table</span>”</span> includes views, materialized views,
  186. sequences, and foreign tables. Multiple tables
  187. can be selected by writing multiple <code class="option">-t</code> switches.
  188. This option can be combined with the <code class="option">-n</code> option to
  189. specify table(s) in a particular schema.
  190. </p><div class="note"><h3 class="title">Note</h3><p>
  191. When <code class="option">-t</code> is specified, <span class="application">pg_restore</span>
  192. makes no attempt to restore any other database objects that the
  193. selected table(s) might depend upon. Therefore, there is no
  194. guarantee that a specific-table restore into a clean database will
  195. succeed.
  196. </p></div><div class="note"><h3 class="title">Note</h3><p>
  197. This flag does not behave identically to the <code class="option">-t</code>
  198. flag of <span class="application">pg_dump</span>. There is not currently
  199. any provision for wild-card matching in <span class="application">pg_restore</span>,
  200. nor can you include a schema name within its <code class="option">-t</code>.
  201. And, while <span class="application">pg_dump</span>'s <code class="option">-t</code>
  202. flag will also dump subsidiary objects (such as indexes) of the
  203. selected table(s),
  204. <span class="application">pg_restore</span>'s <code class="option">-t</code>
  205. flag does not include such subsidiary objects.
  206. </p></div><div class="note"><h3 class="title">Note</h3><p>
  207. In versions prior to <span class="productname">PostgreSQL</span> 9.6, this flag
  208. matched only tables, not any other type of relation.
  209. </p></div></dd><dt><span class="term"><code class="option">-T <em class="replaceable"><code>trigger</code></em></code><br /></span><span class="term"><code class="option">--trigger=<em class="replaceable"><code>trigger</code></em></code></span></dt><dd><p>
  210. Restore named trigger only. Multiple triggers may be specified with
  211. multiple <code class="option">-T</code> switches.
  212. </p></dd><dt><span class="term"><code class="option">-v</code><br /></span><span class="term"><code class="option">--verbose</code></span></dt><dd><p>
  213. Specifies verbose mode.
  214. </p></dd><dt><span class="term"><code class="option">-V</code><br /></span><span class="term"><code class="option">--version</code></span></dt><dd><p>
  215. Print the <span class="application">pg_restore</span> version and exit.
  216. </p></dd><dt><span class="term"><code class="option">-x</code><br /></span><span class="term"><code class="option">--no-privileges</code><br /></span><span class="term"><code class="option">--no-acl</code></span></dt><dd><p>
  217. Prevent restoration of access privileges (grant/revoke commands).
  218. </p></dd><dt><span class="term"><code class="option">-1</code><br /></span><span class="term"><code class="option">--single-transaction</code></span></dt><dd><p>
  219. Execute the restore as a single transaction (that is, wrap the
  220. emitted commands in <code class="command">BEGIN</code>/<code class="command">COMMIT</code>). This
  221. ensures that either all the commands complete successfully, or no
  222. changes are applied. This option implies
  223. <code class="option">--exit-on-error</code>.
  224. </p></dd><dt><span class="term"><code class="option">--disable-triggers</code></span></dt><dd><p>
  225. This option is relevant only when performing a data-only restore.
  226. It instructs <span class="application">pg_restore</span> to execute commands
  227. to temporarily disable triggers on the target tables while
  228. the data is reloaded. Use this if you have referential
  229. integrity checks or other triggers on the tables that you
  230. do not want to invoke during data reload.
  231. </p><p>
  232. Presently, the commands emitted for
  233. <code class="option">--disable-triggers</code> must be done as superuser. So you
  234. should also specify a superuser name with <code class="option">-S</code> or,
  235. preferably, run <span class="application">pg_restore</span> as a
  236. <span class="productname">PostgreSQL</span> superuser.
  237. </p></dd><dt><span class="term"><code class="option">--enable-row-security</code></span></dt><dd><p>
  238. This option is relevant only when restoring the contents of a table
  239. which has row security. By default, <span class="application">pg_restore</span> will set
  240. <a class="xref" href="runtime-config-client.html#GUC-ROW-SECURITY">row_security</a> to off, to ensure
  241. that all data is restored in to the table. If the user does not have
  242. sufficient privileges to bypass row security, then an error is thrown.
  243. This parameter instructs <span class="application">pg_restore</span> to set
  244. <a class="xref" href="runtime-config-client.html#GUC-ROW-SECURITY">row_security</a> to on instead, allowing the user to attempt to restore
  245. the contents of the table with row security enabled. This might still
  246. fail if the user does not have the right to insert the rows from the
  247. dump into the table.
  248. </p><p>
  249. Note that this option currently also requires the dump be in <code class="command">INSERT</code>
  250. format, as <code class="command">COPY FROM</code> does not support row security.
  251. </p></dd><dt><span class="term"><code class="option">--if-exists</code></span></dt><dd><p>
  252. Use conditional commands (i.e. add an <code class="literal">IF EXISTS</code>
  253. clause) to drop database objects. This option is not valid
  254. unless <code class="option">--clean</code> is also specified.
  255. </p></dd><dt><span class="term"><code class="option">--no-comments</code></span></dt><dd><p>
  256. Do not output commands to restore comments, even if the archive
  257. contains them.
  258. </p></dd><dt><span class="term"><code class="option">--no-data-for-failed-tables</code></span></dt><dd><p>
  259. By default, table data is restored even if the creation command
  260. for the table failed (e.g., because it already exists).
  261. With this option, data for such a table is skipped.
  262. This behavior is useful if the target database already
  263. contains the desired table contents. For example,
  264. auxiliary tables for <span class="productname">PostgreSQL</span> extensions
  265. such as <span class="productname">PostGIS</span> might already be loaded in
  266. the target database; specifying this option prevents duplicate
  267. or obsolete data from being loaded into them.
  268. </p><p>
  269. This option is effective only when restoring directly into a
  270. database, not when producing SQL script output.
  271. </p></dd><dt><span class="term"><code class="option">--no-publications</code></span></dt><dd><p>
  272. Do not output commands to restore publications, even if the archive
  273. contains them.
  274. </p></dd><dt><span class="term"><code class="option">--no-security-labels</code></span></dt><dd><p>
  275. Do not output commands to restore security labels,
  276. even if the archive contains them.
  277. </p></dd><dt><span class="term"><code class="option">--no-subscriptions</code></span></dt><dd><p>
  278. Do not output commands to restore subscriptions, even if the archive
  279. contains them.
  280. </p></dd><dt><span class="term"><code class="option">--no-tablespaces</code></span></dt><dd><p>
  281. Do not output commands to select tablespaces.
  282. With this option, all objects will be created in whichever
  283. tablespace is the default during restore.
  284. </p></dd><dt><span class="term"><code class="option">--section=<em class="replaceable"><code>sectionname</code></em></code></span></dt><dd><p>
  285. Only restore the named section. The section name can be
  286. <code class="option">pre-data</code>, <code class="option">data</code>, or <code class="option">post-data</code>.
  287. This option can be specified more than once to select multiple
  288. sections. The default is to restore all sections.
  289. </p><p>
  290. The data section contains actual table data as well as large-object
  291. definitions.
  292. Post-data items consist of definitions of indexes, triggers, rules
  293. and constraints other than validated check constraints.
  294. Pre-data items consist of all other data definition items.
  295. </p></dd><dt><span class="term"><code class="option">--strict-names</code></span></dt><dd><p>
  296. Require that each schema
  297. (<code class="option">-n</code>/<code class="option">--schema</code>) and table
  298. (<code class="option">-t</code>/<code class="option">--table</code>) qualifier match at
  299. least one schema/table in the backup file.
  300. </p></dd><dt><span class="term"><code class="option">--use-set-session-authorization</code></span></dt><dd><p>
  301. Output SQL-standard <code class="command">SET SESSION AUTHORIZATION</code> commands
  302. instead of <code class="command">ALTER OWNER</code> commands to determine object
  303. ownership. This makes the dump more standards-compatible, but
  304. depending on the history of the objects in the dump, might not restore
  305. properly.
  306. </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>
  307. Show help about <span class="application">pg_restore</span> command line
  308. arguments, and exit.
  309. </p></dd></dl></div><p>
  310. </p><p>
  311. <span class="application">pg_restore</span> also accepts
  312. the following command line arguments for connection parameters:
  313. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-h <em class="replaceable"><code>host</code></em></code><br /></span><span class="term"><code class="option">--host=<em class="replaceable"><code>host</code></em></code></span></dt><dd><p>
  314. Specifies the host name of the machine on which the server is
  315. running. If the value begins with a slash, it is used as the
  316. directory for the Unix domain socket. The default is taken
  317. from the <code class="envar">PGHOST</code> environment variable, if set,
  318. else a Unix domain socket connection is attempted.
  319. </p></dd><dt><span class="term"><code class="option">-p <em class="replaceable"><code>port</code></em></code><br /></span><span class="term"><code class="option">--port=<em class="replaceable"><code>port</code></em></code></span></dt><dd><p>
  320. Specifies the TCP port or local Unix domain socket file
  321. extension on which the server is listening for connections.
  322. Defaults to the <code class="envar">PGPORT</code> environment variable, if
  323. set, or a compiled-in default.
  324. </p></dd><dt><span class="term"><code class="option">-U <em class="replaceable"><code>username</code></em></code><br /></span><span class="term"><code class="option">--username=<em class="replaceable"><code>username</code></em></code></span></dt><dd><p>
  325. User name to connect as.
  326. </p></dd><dt><span class="term"><code class="option">-w</code><br /></span><span class="term"><code class="option">--no-password</code></span></dt><dd><p>
  327. Never issue a password prompt. If the server requires
  328. password authentication and a password is not available by
  329. other means such as a <code class="filename">.pgpass</code> file, the
  330. connection attempt will fail. This option can be useful in
  331. batch jobs and scripts where no user is present to enter a
  332. password.
  333. </p></dd><dt><span class="term"><code class="option">-W</code><br /></span><span class="term"><code class="option">--password</code></span></dt><dd><p>
  334. Force <span class="application">pg_restore</span> to prompt for a
  335. password before connecting to a database.
  336. </p><p>
  337. This option is never essential, since
  338. <span class="application">pg_restore</span> will automatically prompt
  339. for a password if the server demands password authentication.
  340. However, <span class="application">pg_restore</span> will waste a
  341. connection attempt finding out that the server wants a password.
  342. In some cases it is worth typing <code class="option">-W</code> to avoid the extra
  343. connection attempt.
  344. </p></dd><dt><span class="term"><code class="option">--role=<em class="replaceable"><code>rolename</code></em></code></span></dt><dd><p>
  345. Specifies a role name to be used to perform the restore.
  346. This option causes <span class="application">pg_restore</span> to issue a
  347. <code class="command">SET ROLE</code> <em class="replaceable"><code>rolename</code></em>
  348. command after connecting to the database. It is useful when the
  349. authenticated user (specified by <code class="option">-U</code>) lacks privileges
  350. needed by <span class="application">pg_restore</span>, but can switch to a role with
  351. the required rights. Some installations have a policy against
  352. logging in directly as a superuser, and use of this option allows
  353. restores to be performed without violating the policy.
  354. </p></dd></dl></div><p>
  355. </p></div><div class="refsect1" id="id-1.9.4.17.7"><h2>Environment</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="envar">PGHOST</code><br /></span><span class="term"><code class="envar">PGOPTIONS</code><br /></span><span class="term"><code class="envar">PGPORT</code><br /></span><span class="term"><code class="envar">PGUSER</code></span></dt><dd><p>
  356. Default connection parameters
  357. </p></dd><dt><span class="term"><code class="envar">PG_COLOR</code></span></dt><dd><p>
  358. Specifies whether to use color in diagnostic messages. Possible values
  359. are <code class="literal">always</code>, <code class="literal">auto</code> and
  360. <code class="literal">never</code>.
  361. </p></dd></dl></div><p>
  362. This utility, like most other <span class="productname">PostgreSQL</span> utilities,
  363. also uses the environment variables supported by <span class="application">libpq</span>
  364. (see <a class="xref" href="libpq-envars.html" title="33.14. Environment Variables">Section 33.14</a>). However, it does not read
  365. <code class="envar">PGDATABASE</code> when a database name is not supplied.
  366. </p></div><div class="refsect1" id="APP-PGRESTORE-DIAGNOSTICS"><h2>Diagnostics</h2><p>
  367. When a direct database connection is specified using the
  368. <code class="option">-d</code> option, <span class="application">pg_restore</span>
  369. internally executes <acronym class="acronym">SQL</acronym> statements. If you have
  370. problems running <span class="application">pg_restore</span>, make sure
  371. you are able to select information from the database using, for
  372. example, <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a>. Also, any default connection
  373. settings and environment variables used by the
  374. <span class="application">libpq</span> front-end library will apply.
  375. </p></div><div class="refsect1" id="APP-PGRESTORE-NOTES"><h2>Notes</h2><p>
  376. If your installation has any local additions to the
  377. <code class="literal">template1</code> database, be careful to load the output of
  378. <span class="application">pg_restore</span> into a truly empty database;
  379. otherwise you are likely to get errors due to duplicate definitions
  380. of the added objects. To make an empty database without any local
  381. additions, copy from <code class="literal">template0</code> not <code class="literal">template1</code>, for example:
  382. </p><pre class="programlisting">
  383. CREATE DATABASE foo WITH TEMPLATE template0;
  384. </pre><p>
  385. </p><p>
  386. The limitations of <span class="application">pg_restore</span> are detailed below.
  387. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  388. When restoring data to a pre-existing table and the option
  389. <code class="option">--disable-triggers</code> is used,
  390. <span class="application">pg_restore</span> emits commands
  391. to disable triggers on user tables before inserting the data, then emits commands to
  392. re-enable them after the data has been inserted. If the restore is stopped in the
  393. middle, the system catalogs might be left in the wrong state.
  394. </p></li><li class="listitem"><p><span class="application">pg_restore</span> cannot restore large objects
  395. selectively; for instance, only those for a specific table. If
  396. an archive contains large objects, then all large objects will be
  397. restored, or none of them if they are excluded via <code class="option">-L</code>,
  398. <code class="option">-t</code>, or other options.
  399. </p></li></ul></div><p>
  400. </p><p>
  401. See also the <a class="xref" href="app-pgdump.html" title="pg_dump"><span class="refentrytitle">pg_dump</span></a> documentation for details on
  402. limitations of <span class="application">pg_dump</span>.
  403. </p><p>
  404. Once restored, it is wise to run <code class="command">ANALYZE</code> on each
  405. restored table so the optimizer has useful statistics; see
  406. <a class="xref" href="routine-vacuuming.html#VACUUM-FOR-STATISTICS" title="24.1.3. Updating Planner Statistics">Section 24.1.3</a> and
  407. <a class="xref" href="routine-vacuuming.html#AUTOVACUUM" title="24.1.6. The Autovacuum Daemon">Section 24.1.6</a> for more information.
  408. </p></div><div class="refsect1" id="APP-PGRESTORE-EXAMPLES"><h2>Examples</h2><p>
  409. Assume we have dumped a database called <code class="literal">mydb</code> into a
  410. custom-format dump file:
  411. </p><pre class="screen">
  412. <code class="prompt">$</code> <strong class="userinput"><code>pg_dump -Fc mydb &gt; db.dump</code></strong>
  413. </pre><p>
  414. </p><p>
  415. To drop the database and recreate it from the dump:
  416. </p><pre class="screen">
  417. <code class="prompt">$</code> <strong class="userinput"><code>dropdb mydb</code></strong>
  418. <code class="prompt">$</code> <strong class="userinput"><code>pg_restore -C -d postgres db.dump</code></strong>
  419. </pre><p>
  420. The database named in the <code class="option">-d</code> switch can be any database existing
  421. in the cluster; <span class="application">pg_restore</span> only uses it to issue the
  422. <code class="command">CREATE DATABASE</code> command for <code class="literal">mydb</code>. With
  423. <code class="option">-C</code>, data is always restored into the database name that appears
  424. in the dump file.
  425. </p><p>
  426. To reload the dump into a new database called <code class="literal">newdb</code>:
  427. </p><pre class="screen">
  428. <code class="prompt">$</code> <strong class="userinput"><code>createdb -T template0 newdb</code></strong>
  429. <code class="prompt">$</code> <strong class="userinput"><code>pg_restore -d newdb db.dump</code></strong>
  430. </pre><p>
  431. Notice we don't use <code class="option">-C</code>, and instead connect directly to the
  432. database to be restored into. Also note that we clone the new database
  433. from <code class="literal">template0</code> not <code class="literal">template1</code>, to ensure it is
  434. initially empty.
  435. </p><p>
  436. To reorder database items, it is first necessary to dump the table of
  437. contents of the archive:
  438. </p><pre class="screen">
  439. <code class="prompt">$</code> <strong class="userinput"><code>pg_restore -l db.dump &gt; db.list</code></strong>
  440. </pre><p>
  441. The listing file consists of a header and one line for each item, e.g.:
  442. </p><pre class="programlisting">
  443. ;
  444. ; Archive created at Mon Sep 14 13:55:39 2009
  445. ; dbname: DBDEMOS
  446. ; TOC Entries: 81
  447. ; Compression: 9
  448. ; Dump Version: 1.10-0
  449. ; Format: CUSTOM
  450. ; Integer: 4 bytes
  451. ; Offset: 8 bytes
  452. ; Dumped from database version: 8.3.5
  453. ; Dumped by pg_dump version: 8.3.8
  454. ;
  455. ;
  456. ; Selected TOC Entries:
  457. ;
  458. 3; 2615 2200 SCHEMA - public pasha
  459. 1861; 0 0 COMMENT - SCHEMA public pasha
  460. 1862; 0 0 ACL - public pasha
  461. 317; 1247 17715 TYPE public composite pasha
  462. 319; 1247 25899 DOMAIN public domain0 pasha
  463. </pre><p>
  464. Semicolons start a comment, and the numbers at the start of lines refer to the
  465. internal archive ID assigned to each item.
  466. </p><p>
  467. Lines in the file can be commented out, deleted, and reordered. For example:
  468. </p><pre class="programlisting">
  469. 10; 145433 TABLE map_resolutions postgres
  470. ;2; 145344 TABLE species postgres
  471. ;4; 145359 TABLE nt_header postgres
  472. 6; 145402 TABLE species_records postgres
  473. ;8; 145416 TABLE ss_old postgres
  474. </pre><p>
  475. could be used as input to <span class="application">pg_restore</span> and would only restore
  476. items 10 and 6, in that order:
  477. </p><pre class="screen">
  478. <code class="prompt">$</code> <strong class="userinput"><code>pg_restore -L db.list db.dump</code></strong>
  479. </pre></div><div class="refsect1" id="id-1.9.4.17.11"><h2>See Also</h2><span class="simplelist"><a class="xref" href="app-pgdump.html" title="pg_dump"><span class="refentrytitle">pg_dump</span></a>, <a class="xref" href="app-pg-dumpall.html" title="pg_dumpall"><span class="refentrytitle"><span class="application">pg_dumpall</span></span></a>, <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="app-pgrecvlogical.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference-client.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="app-psql.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="application">pg_recvlogical</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> <span class="application">psql</span></td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1