gooderp18绿色标准版
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

786 lignes
60KB

  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_dump</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-pgconfig.html" title="pg_config" /><link rel="next" href="app-pg-dumpall.html" title="pg_dumpall" /></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_dump</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="app-pgconfig.html" title="pg_config">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-pg-dumpall.html" title="pg_dumpall">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="APP-PGDUMP"><div class="titlepage"></div><a id="id-1.9.4.12.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">pg_dump</span></h2><p>pg_dump —
  3. extract a <span class="productname">PostgreSQL</span> database into a script file or other archive file
  4. </p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.4.12.4.1"><code class="command">pg_dump</code> [<em class="replaceable"><code>connection-option</code></em>...] [<em class="replaceable"><code>option</code></em>...] [<em class="replaceable"><code>dbname</code></em>]</p></div></div><div class="refsect1" id="PG-DUMP-DESCRIPTION"><h2>
  5. Description
  6. </h2><p>
  7. <span class="application">pg_dump</span> is a utility for backing up a
  8. <span class="productname">PostgreSQL</span> database. It makes consistent
  9. backups even if the database is being used concurrently.
  10. <span class="application">pg_dump</span> does not block other users
  11. accessing the database (readers or writers).
  12. </p><p>
  13. <span class="application">pg_dump</span> only dumps a single database.
  14. To back up an entire cluster, or to back up global objects that are
  15. common to all databases in a cluster (such as roles and tablespaces),
  16. use <a class="xref" href="app-pg-dumpall.html" title="pg_dumpall"><span class="refentrytitle"><span class="application">pg_dumpall</span></span></a>.
  17. </p><p>
  18. Dumps can be output in script or archive file formats. Script
  19. dumps are plain-text files containing the SQL commands required
  20. to reconstruct the database to the state it was in at the time it was
  21. saved. To restore from such a script, feed it to <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a>. Script files
  22. can be used to reconstruct the database even on other machines and
  23. other architectures; with some modifications, even on other SQL
  24. database products.
  25. </p><p>
  26. The alternative archive file formats must be used with
  27. <a class="xref" href="app-pgrestore.html" title="pg_restore"><span class="refentrytitle">pg_restore</span></a> to rebuild the database. They
  28. allow <span class="application">pg_restore</span> to be selective about
  29. what is restored, or even to reorder the items prior to being
  30. restored.
  31. The archive file formats are designed to be portable across
  32. architectures.
  33. </p><p>
  34. When used with one of the archive file formats and combined with
  35. <span class="application">pg_restore</span>,
  36. <span class="application">pg_dump</span> provides a flexible archival and
  37. transfer mechanism. <span class="application">pg_dump</span> can be used to
  38. backup an entire database, then <span class="application">pg_restore</span>
  39. can be used to examine the archive and/or select which parts of the
  40. database are to be restored. The most flexible output file formats are
  41. the <span class="quote">“<span class="quote">custom</span>”</span> format (<code class="option">-Fc</code>) and the
  42. <span class="quote">“<span class="quote">directory</span>”</span> format (<code class="option">-Fd</code>). They allow
  43. for selection and reordering of all archived items, support parallel
  44. restoration, and are compressed by default. The <span class="quote">“<span class="quote">directory</span>”</span>
  45. format is the only format that supports parallel dumps.
  46. </p><p>
  47. While running <span class="application">pg_dump</span>, one should examine the
  48. output for any warnings (printed on standard error), especially in
  49. light of the limitations listed below.
  50. </p></div><div class="refsect1" id="PG-DUMP-OPTIONS"><h2>Options</h2><p>
  51. The following command-line options control the content and
  52. format of the output.
  53. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>dbname</code></em></span></dt><dd><p>
  54. Specifies the name of the database to be dumped. If this is
  55. not specified, the environment variable
  56. <code class="envar">PGDATABASE</code> is used. If that is not set, the
  57. user name specified for the connection is used.
  58. </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>
  59. Dump only the data, not the schema (data definitions).
  60. Table data, large objects, and sequence values are dumped.
  61. </p><p>
  62. This option is similar to, but for historical reasons not identical
  63. to, specifying <code class="option">--section=data</code>.
  64. </p></dd><dt><span class="term"><code class="option">-b</code><br /></span><span class="term"><code class="option">--blobs</code></span></dt><dd><p>
  65. Include large objects in the dump. This is the default behavior
  66. except when <code class="option">--schema</code>, <code class="option">--table</code>, or
  67. <code class="option">--schema-only</code> is specified. The <code class="option">-b</code>
  68. switch is therefore only useful to add large objects to dumps
  69. where a specific schema or table has been requested. Note that
  70. blobs are considered data and therefore will be included when
  71. <code class="option">--data-only</code> is used, but not
  72. when <code class="option">--schema-only</code> is.
  73. </p></dd><dt><span class="term"><code class="option">-B</code><br /></span><span class="term"><code class="option">--no-blobs</code></span></dt><dd><p>
  74. Exclude large objects in the dump.
  75. </p><p>
  76. When both <code class="option">-b</code> and <code class="option">-B</code> are given, the behavior
  77. is to output large objects, when data is being dumped, see the
  78. <code class="option">-b</code> documentation.
  79. </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>
  80. Output commands to clean (drop)
  81. database objects prior to outputting the commands for creating them.
  82. (Unless <code class="option">--if-exists</code> is also specified,
  83. restore might generate some harmless error messages, if any objects
  84. were not present in the destination database.)
  85. </p><p>
  86. This option is only meaningful for the plain-text format. For
  87. the archive formats, you can specify the option when you
  88. call <code class="command">pg_restore</code>.
  89. </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>
  90. Begin the output with a command to create the
  91. database itself and reconnect to the created database. (With a
  92. script of this form, it doesn't matter which database in the
  93. destination installation you connect to before running the script.)
  94. If <code class="option">--clean</code> is also specified, the script drops and
  95. recreates the target database before reconnecting to it.
  96. </p><p>
  97. With <code class="option">--create</code>, the output also includes the
  98. database's comment if any, and any configuration variable settings
  99. that are specific to this database, that is,
  100. any <code class="command">ALTER DATABASE ... SET ...</code>
  101. and <code class="command">ALTER ROLE ... IN DATABASE ... SET ...</code>
  102. commands that mention this database.
  103. Access privileges for the database itself are also dumped,
  104. unless <code class="option">--no-acl</code> is specified.
  105. </p><p>
  106. This option is only meaningful for the plain-text format. For
  107. the archive formats, you can specify the option when you
  108. call <code class="command">pg_restore</code>.
  109. </p></dd><dt><span class="term"><code class="option">-E <em class="replaceable"><code>encoding</code></em></code><br /></span><span class="term"><code class="option">--encoding=<em class="replaceable"><code>encoding</code></em></code></span></dt><dd><p>
  110. Create the dump in the specified character set encoding. By default,
  111. the dump is created in the database encoding. (Another way to get the
  112. same result is to set the <code class="envar">PGCLIENTENCODING</code> environment
  113. variable to the desired dump encoding.)
  114. </p></dd><dt><span class="term"><code class="option">-f <em class="replaceable"><code>file</code></em></code><br /></span><span class="term"><code class="option">--file=<em class="replaceable"><code>file</code></em></code></span></dt><dd><p>
  115. Send output to the specified file. This parameter can be omitted for
  116. file based output formats, in which case the standard output is used.
  117. It must be given for the directory output format however, where it
  118. specifies the target directory instead of a file. In this case the
  119. directory is created by <code class="command">pg_dump</code> and must not exist
  120. before.
  121. </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>
  122. Selects the format of the output.
  123. <em class="replaceable"><code>format</code></em> can be one of the following:
  124. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="literal">p</code><br /></span><span class="term"><code class="literal">plain</code></span></dt><dd><p>
  125. Output a plain-text <acronym class="acronym">SQL</acronym> script file (the default).
  126. </p></dd><dt><span class="term"><code class="literal">c</code><br /></span><span class="term"><code class="literal">custom</code></span></dt><dd><p>
  127. Output a custom-format archive suitable for input into
  128. <span class="application">pg_restore</span>.
  129. Together with the directory output format, this is the most flexible
  130. output format in that it allows manual selection and reordering of
  131. archived items during restore. This format is also compressed by
  132. default.
  133. </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>
  134. Output a directory-format archive suitable for input into
  135. <span class="application">pg_restore</span>. This will create a directory
  136. with one file for each table and blob being dumped, plus a
  137. so-called Table of Contents file describing the dumped objects in a
  138. machine-readable format that <span class="application">pg_restore</span>
  139. can read. A directory format archive can be manipulated with
  140. standard Unix tools; for example, files in an uncompressed archive
  141. can be compressed with the <span class="application">gzip</span> tool.
  142. This format is compressed by default and also supports parallel
  143. dumps.
  144. </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>
  145. Output a <code class="command">tar</code>-format archive suitable for input
  146. into <span class="application">pg_restore</span>. The tar format is
  147. compatible with the directory format: extracting a tar-format
  148. archive produces a valid directory-format archive.
  149. However, the tar format does not support compression. Also, when
  150. using tar format the relative order of table data items cannot be
  151. changed during restore.
  152. </p></dd></dl></div></dd><dt><span class="term"><code class="option">-j <em class="replaceable"><code>njobs</code></em></code><br /></span><span class="term"><code class="option">--jobs=<em class="replaceable"><code>njobs</code></em></code></span></dt><dd><p>
  153. Run the dump in parallel by dumping <em class="replaceable"><code>njobs</code></em>
  154. tables simultaneously. This option reduces the time of the dump but it also
  155. increases the load on the database server. You can only use this option with the
  156. directory output format because this is the only output format where multiple processes
  157. can write their data at the same time.
  158. </p><p><span class="application">pg_dump</span> will open <em class="replaceable"><code>njobs</code></em>
  159. + 1 connections to the database, so make sure your <a class="xref" href="runtime-config-connection.html#GUC-MAX-CONNECTIONS">max_connections</a>
  160. setting is high enough to accommodate all connections.
  161. </p><p>
  162. Requesting exclusive locks on database objects while running a parallel dump could
  163. cause the dump to fail. The reason is that the <span class="application">pg_dump</span> master process
  164. requests shared locks on the objects that the worker processes are going to dump later
  165. in order to
  166. make sure that nobody deletes them and makes them go away while the dump is running.
  167. If another client then requests an exclusive lock on a table, that lock will not be
  168. granted but will be queued waiting for the shared lock of the master process to be
  169. released. Consequently any other access to the table will not be granted either and
  170. will queue after the exclusive lock request. This includes the worker process trying
  171. to dump the table. Without any precautions this would be a classic deadlock situation.
  172. To detect this conflict, the <span class="application">pg_dump</span> worker process requests another
  173. shared lock using the <code class="literal">NOWAIT</code> option. If the worker process is not granted
  174. this shared lock, somebody else must have requested an exclusive lock in the meantime
  175. and there is no way to continue with the dump, so <span class="application">pg_dump</span> has no choice
  176. but to abort the dump.
  177. </p><p>
  178. For a consistent backup, the database server needs to support
  179. synchronized snapshots, a feature that was introduced in
  180. <span class="productname">PostgreSQL</span> 9.2 for primary servers and 10
  181. for standbys. With this feature, database clients can ensure they see
  182. the same data set even though they use different connections.
  183. <code class="command">pg_dump -j</code> uses multiple database connections; it
  184. connects to the database once with the master process and once again
  185. for each worker job. Without the synchronized snapshot feature, the
  186. different worker jobs wouldn't be guaranteed to see the same data in
  187. each connection, which could lead to an inconsistent backup.
  188. </p><p>
  189. If you want to run a parallel dump of a pre-9.2 server, you need to make sure that the
  190. database content doesn't change from between the time the master connects to the
  191. database until the last worker job has connected to the database. The easiest way to
  192. do this is to halt any data modifying processes (DDL and DML) accessing the database
  193. before starting the backup. You also need to specify the
  194. <code class="option">--no-synchronized-snapshots</code> parameter when running
  195. <code class="command">pg_dump -j</code> against a pre-9.2 <span class="productname">PostgreSQL</span>
  196. server.
  197. </p></dd><dt><span class="term"><code class="option">-n <em class="replaceable"><code>pattern</code></em></code><br /></span><span class="term"><code class="option">--schema=<em class="replaceable"><code>pattern</code></em></code></span></dt><dd><p>
  198. Dump only schemas matching <em class="replaceable"><code>pattern</code></em>; this selects both the
  199. schema itself, and all its contained objects. When this option is
  200. not specified, all non-system schemas in the target database will be
  201. dumped. Multiple schemas can be
  202. selected by writing multiple <code class="option">-n</code> switches. The
  203. <em class="replaceable"><code>pattern</code></em> parameter is
  204. interpreted as a pattern according to the same rules used by
  205. <span class="application">psql</span>'s <code class="literal">\d</code> commands (see <a class="xref" href="app-psql.html#APP-PSQL-PATTERNS" title="Patterns">Patterns</a>),
  206. so multiple schemas can also be selected by writing wildcard characters
  207. in the pattern. When using wildcards, be careful to quote the pattern
  208. if needed to prevent the shell from expanding the wildcards; see
  209. <a class="xref" href="app-pgdump.html#PG-DUMP-EXAMPLES" title="Examples">Examples</a>.
  210. </p><div class="note"><h3 class="title">Note</h3><p>
  211. When <code class="option">-n</code> is specified, <span class="application">pg_dump</span>
  212. makes no attempt to dump any other database objects that the selected
  213. schema(s) might depend upon. Therefore, there is no guarantee
  214. that the results of a specific-schema dump can be successfully
  215. restored by themselves into a clean database.
  216. </p></div><div class="note"><h3 class="title">Note</h3><p>
  217. Non-schema objects such as blobs are not dumped when <code class="option">-n</code> is
  218. specified. You can add blobs back to the dump with the
  219. <code class="option">--blobs</code> switch.
  220. </p></div></dd><dt><span class="term"><code class="option">-N <em class="replaceable"><code>pattern</code></em></code><br /></span><span class="term"><code class="option">--exclude-schema=<em class="replaceable"><code>pattern</code></em></code></span></dt><dd><p>
  221. Do not dump any schemas matching <em class="replaceable"><code>pattern</code></em>. The pattern is
  222. interpreted according to the same rules as for <code class="option">-n</code>.
  223. <code class="option">-N</code> can be given more than once to exclude schemas
  224. matching any of several patterns.
  225. </p><p>
  226. When both <code class="option">-n</code> and <code class="option">-N</code> are given, the behavior
  227. is to dump just the schemas that match at least one <code class="option">-n</code>
  228. switch but no <code class="option">-N</code> switches. If <code class="option">-N</code> appears
  229. without <code class="option">-n</code>, then schemas matching <code class="option">-N</code> are
  230. excluded from what is otherwise a normal dump.
  231. </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>
  232. Do not output commands to set
  233. ownership of objects to match the original database.
  234. By default, <span class="application">pg_dump</span> issues
  235. <code class="command">ALTER OWNER</code> or
  236. <code class="command">SET SESSION AUTHORIZATION</code>
  237. statements to set ownership of created database objects.
  238. These statements
  239. will fail when the script is run unless it is started by a superuser
  240. (or the same user that owns all of the objects in the script).
  241. To make a script that can be restored by any user, but will give
  242. that user ownership of all the objects, specify <code class="option">-O</code>.
  243. </p><p>
  244. This option is only meaningful for the plain-text format. For
  245. the archive formats, you can specify the option when you
  246. call <code class="command">pg_restore</code>.
  247. </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>
  248. This option is obsolete but still accepted for backwards
  249. compatibility.
  250. </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>
  251. Dump only the object definitions (schema), not data.
  252. </p><p>
  253. This option is the inverse of <code class="option">--data-only</code>.
  254. It is similar to, but for historical reasons not identical to,
  255. specifying
  256. <code class="option">--section=pre-data --section=post-data</code>.
  257. </p><p>
  258. (Do not confuse this with the <code class="option">--schema</code> option, which
  259. uses the word <span class="quote">“<span class="quote">schema</span>”</span> in a different meaning.)
  260. </p><p>
  261. To exclude table data for only a subset of tables in the database,
  262. see <code class="option">--exclude-table-data</code>.
  263. </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>
  264. Specify the superuser user name to use when disabling triggers.
  265. This is relevant only if <code class="option">--disable-triggers</code> is used.
  266. (Usually, it's better to leave this out, and instead start the
  267. resulting script as superuser.)
  268. </p></dd><dt><span class="term"><code class="option">-t <em class="replaceable"><code>pattern</code></em></code><br /></span><span class="term"><code class="option">--table=<em class="replaceable"><code>pattern</code></em></code></span></dt><dd><p>
  269. Dump only tables with names matching
  270. <em class="replaceable"><code>pattern</code></em>.
  271. For this purpose, <span class="quote">“<span class="quote">table</span>”</span> includes views, materialized views,
  272. sequences, and foreign tables. Multiple tables
  273. can be selected by writing multiple <code class="option">-t</code> switches. The
  274. <em class="replaceable"><code>pattern</code></em> parameter is
  275. interpreted as a pattern according to the same rules used by
  276. <span class="application">psql</span>'s <code class="literal">\d</code> commands (see <a class="xref" href="app-psql.html#APP-PSQL-PATTERNS" title="Patterns">Patterns</a>),
  277. so multiple tables can also be selected by writing wildcard characters
  278. in the pattern. When using wildcards, be careful to quote the pattern
  279. if needed to prevent the shell from expanding the wildcards; see
  280. <a class="xref" href="app-pgdump.html#PG-DUMP-EXAMPLES" title="Examples">Examples</a>.
  281. </p><p>
  282. The <code class="option">-n</code> and <code class="option">-N</code> switches have no effect when
  283. <code class="option">-t</code> is used, because tables selected by <code class="option">-t</code> will
  284. be dumped regardless of those switches, and non-table objects will not
  285. be dumped.
  286. </p><div class="note"><h3 class="title">Note</h3><p>
  287. When <code class="option">-t</code> is specified, <span class="application">pg_dump</span>
  288. makes no attempt to dump any other database objects that the selected
  289. table(s) might depend upon. Therefore, there is no guarantee
  290. that the results of a specific-table dump can be successfully
  291. restored by themselves into a clean database.
  292. </p></div><div class="note"><h3 class="title">Note</h3><p>
  293. The behavior of the <code class="option">-t</code> switch is not entirely upward
  294. compatible with pre-8.2 <span class="productname">PostgreSQL</span>
  295. versions. Formerly, writing <code class="literal">-t tab</code> would dump all
  296. tables named <code class="literal">tab</code>, but now it just dumps whichever one
  297. is visible in your default search path. To get the old behavior
  298. you can write <code class="literal">-t '*.tab'</code>. Also, you must write something
  299. like <code class="literal">-t sch.tab</code> to select a table in a particular schema,
  300. rather than the old locution of <code class="literal">-n sch -t tab</code>.
  301. </p></div></dd><dt><span class="term"><code class="option">-T <em class="replaceable"><code>pattern</code></em></code><br /></span><span class="term"><code class="option">--exclude-table=<em class="replaceable"><code>pattern</code></em></code></span></dt><dd><p>
  302. Do not dump any tables matching <em class="replaceable"><code>pattern</code></em>. The pattern is
  303. interpreted according to the same rules as for <code class="option">-t</code>.
  304. <code class="option">-T</code> can be given more than once to exclude tables
  305. matching any of several patterns.
  306. </p><p>
  307. When both <code class="option">-t</code> and <code class="option">-T</code> are given, the behavior
  308. is to dump just the tables that match at least one <code class="option">-t</code>
  309. switch but no <code class="option">-T</code> switches. If <code class="option">-T</code> appears
  310. without <code class="option">-t</code>, then tables matching <code class="option">-T</code> are
  311. excluded from what is otherwise a normal dump.
  312. </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>
  313. Specifies verbose mode. This will cause
  314. <span class="application">pg_dump</span> to output detailed object
  315. comments and start/stop times to the dump file, and progress
  316. messages to standard error.
  317. </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>
  318. Print the <span class="application">pg_dump</span> version and exit.
  319. </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>
  320. Prevent dumping of access privileges (grant/revoke commands).
  321. </p></dd><dt><span class="term"><code class="option">-Z <em class="replaceable"><code>0..9</code></em></code><br /></span><span class="term"><code class="option">--compress=<em class="replaceable"><code>0..9</code></em></code></span></dt><dd><p>
  322. Specify the compression level to use. Zero means no compression.
  323. For the custom archive format, this specifies compression of
  324. individual table-data segments, and the default is to compress
  325. at a moderate level.
  326. For plain text output, setting a nonzero compression level causes
  327. the entire output file to be compressed, as though it had been
  328. fed through <span class="application">gzip</span>; but the default is not to compress.
  329. The tar archive format currently does not support compression at all.
  330. </p></dd><dt><span class="term"><code class="option">--binary-upgrade</code></span></dt><dd><p>
  331. This option is for use by in-place upgrade utilities. Its use
  332. for other purposes is not recommended or supported. The
  333. behavior of the option may change in future releases without
  334. notice.
  335. </p></dd><dt><span class="term"><code class="option">--column-inserts</code><br /></span><span class="term"><code class="option">--attribute-inserts</code></span></dt><dd><p>
  336. Dump data as <code class="command">INSERT</code> commands with explicit
  337. column names (<code class="literal">INSERT INTO
  338. <em class="replaceable"><code>table</code></em>
  339. (<em class="replaceable"><code>column</code></em>, ...) VALUES
  340. ...</code>). This will make restoration very slow; it is mainly
  341. useful for making dumps that can be loaded into
  342. non-<span class="productname">PostgreSQL</span> databases.
  343. Any error during reloading will cause only rows that are part of the
  344. problematic <code class="command">INSERT</code> to be lost, rather than the
  345. entire table contents.
  346. </p></dd><dt><span class="term"><code class="option">--disable-dollar-quoting</code></span></dt><dd><p>
  347. This option disables the use of dollar quoting for function bodies,
  348. and forces them to be quoted using SQL standard string syntax.
  349. </p></dd><dt><span class="term"><code class="option">--disable-triggers</code></span></dt><dd><p>
  350. This option is relevant only when creating a data-only dump.
  351. It instructs <span class="application">pg_dump</span> to include commands
  352. to temporarily disable triggers on the target tables while
  353. the data is reloaded. Use this if you have referential
  354. integrity checks or other triggers on the tables that you
  355. do not want to invoke during data reload.
  356. </p><p>
  357. Presently, the commands emitted for <code class="option">--disable-triggers</code>
  358. must be done as superuser. So, you should also specify
  359. a superuser name with <code class="option">-S</code>, or preferably be careful to
  360. start the resulting script as a superuser.
  361. </p><p>
  362. This option is only meaningful for the plain-text format. For
  363. the archive formats, you can specify the option when you
  364. call <code class="command">pg_restore</code>.
  365. </p></dd><dt><span class="term"><code class="option">--enable-row-security</code></span></dt><dd><p>
  366. This option is relevant only when dumping the contents of a table
  367. which has row security. By default, <span class="application">pg_dump</span> will set
  368. <a class="xref" href="runtime-config-client.html#GUC-ROW-SECURITY">row_security</a> to off, to ensure
  369. that all data is dumped from the table. If the user does not have
  370. sufficient privileges to bypass row security, then an error is thrown.
  371. This parameter instructs <span class="application">pg_dump</span> to set
  372. <a class="xref" href="runtime-config-client.html#GUC-ROW-SECURITY">row_security</a> to on instead, allowing the user
  373. to dump the parts of the contents of the table that they have access to.
  374. </p><p>
  375. Note that if you use this option currently, you probably also want
  376. the dump be in <code class="command">INSERT</code> format, as the
  377. <code class="command">COPY FROM</code> during restore does not support row security.
  378. </p></dd><dt><span class="term"><code class="option">--exclude-table-data=<em class="replaceable"><code>pattern</code></em></code></span></dt><dd><p>
  379. Do not dump data for any tables matching <em class="replaceable"><code>pattern</code></em>. The pattern is
  380. interpreted according to the same rules as for <code class="option">-t</code>.
  381. <code class="option">--exclude-table-data</code> can be given more than once to
  382. exclude tables matching any of several patterns. This option is
  383. useful when you need the definition of a particular table even
  384. though you do not need the data in it.
  385. </p><p>
  386. To exclude data for all tables in the database, see <code class="option">--schema-only</code>.
  387. </p></dd><dt><span class="term"><code class="option">--extra-float-digits=<em class="replaceable"><code>ndigits</code></em></code></span></dt><dd><p>
  388. Use the specified value of <code class="option">extra_float_digits</code> when dumping
  389. floating-point data, instead of the maximum available precision.
  390. Routine dumps made for backup purposes should not use this option.
  391. </p></dd><dt><span class="term"><code class="option">--if-exists</code></span></dt><dd><p>
  392. Use conditional commands (i.e. add an <code class="literal">IF EXISTS</code>
  393. clause) when cleaning database objects. This option is not valid
  394. unless <code class="option">--clean</code> is also specified.
  395. </p></dd><dt><span class="term"><code class="option">--inserts</code></span></dt><dd><p>
  396. Dump data as <code class="command">INSERT</code> commands (rather
  397. than <code class="command">COPY</code>). This will make restoration very slow;
  398. it is mainly useful for making dumps that can be loaded into
  399. non-<span class="productname">PostgreSQL</span> databases.
  400. Any error during reloading will cause only rows that are part of the
  401. problematic <code class="command">INSERT</code> to be lost, rather than the
  402. entire table contents. Note that the restore might fail altogether if
  403. you have rearranged column order. The
  404. <code class="option">--column-inserts</code> option is safe against column order
  405. changes, though even slower.
  406. </p></dd><dt><span class="term"><code class="option">--load-via-partition-root</code></span></dt><dd><p>
  407. When dumping data for a table partition, make
  408. the <code class="command">COPY</code> or <code class="command">INSERT</code> statements
  409. target the root of the partitioning hierarchy that contains it, rather
  410. than the partition itself. This causes the appropriate partition to
  411. be re-determined for each row when the data is loaded. This may be
  412. useful when reloading data on a server where rows do not always fall
  413. into the same partitions as they did on the original server. That
  414. could happen, for example, if the partitioning column is of type text
  415. and the two systems have different definitions of the collation used
  416. to sort the partitioning column.
  417. </p><p>
  418. It is best not to use parallelism when restoring from an archive made
  419. with this option, because <span class="application">pg_restore</span> will
  420. not know exactly which partition(s) a given archive data item will
  421. load data into. This could result in inefficiency due to lock
  422. conflicts between parallel jobs, or perhaps even reload failures due
  423. to foreign key constraints being set up before all the relevant data
  424. is loaded.
  425. </p></dd><dt><span class="term"><code class="option">--lock-wait-timeout=<em class="replaceable"><code>timeout</code></em></code></span></dt><dd><p>
  426. Do not wait forever to acquire shared table locks at the beginning of
  427. the dump. Instead fail if unable to lock a table within the specified
  428. <em class="replaceable"><code>timeout</code></em>. The timeout may be
  429. specified in any of the formats accepted by <code class="command">SET
  430. statement_timeout</code>. (Allowed formats vary depending on the server
  431. version you are dumping from, but an integer number of milliseconds
  432. is accepted by all versions.)
  433. </p></dd><dt><span class="term"><code class="option">--no-comments</code></span></dt><dd><p>
  434. Do not dump comments.
  435. </p></dd><dt><span class="term"><code class="option">--no-publications</code></span></dt><dd><p>
  436. Do not dump publications.
  437. </p></dd><dt><span class="term"><code class="option">--no-security-labels</code></span></dt><dd><p>
  438. Do not dump security labels.
  439. </p></dd><dt><span class="term"><code class="option">--no-subscriptions</code></span></dt><dd><p>
  440. Do not dump subscriptions.
  441. </p></dd><dt><span class="term"><code class="option">--no-sync</code></span></dt><dd><p>
  442. By default, <code class="command">pg_dump</code> will wait for all files
  443. to be written safely to disk. This option causes
  444. <code class="command">pg_dump</code> to return without waiting, which is
  445. faster, but means that a subsequent operating system crash can leave
  446. the dump corrupt. Generally, this option is useful for testing
  447. but should not be used when dumping data from production installation.
  448. </p></dd><dt><span class="term"><code class="option">--no-synchronized-snapshots</code></span></dt><dd><p>
  449. This option allows running <code class="command">pg_dump -j</code> against a pre-9.2
  450. server, see the documentation of the <code class="option">-j</code> parameter
  451. for more details.
  452. </p></dd><dt><span class="term"><code class="option">--no-tablespaces</code></span></dt><dd><p>
  453. Do not output commands to select tablespaces.
  454. With this option, all objects will be created in whichever
  455. tablespace is the default during restore.
  456. </p><p>
  457. This option is only meaningful for the plain-text format. For
  458. the archive formats, you can specify the option when you
  459. call <code class="command">pg_restore</code>.
  460. </p></dd><dt><span class="term"><code class="option">--no-unlogged-table-data</code></span></dt><dd><p>
  461. Do not dump the contents of unlogged tables. This option has no
  462. effect on whether or not the table definitions (schema) are dumped;
  463. it only suppresses dumping the table data. Data in unlogged tables
  464. is always excluded when dumping from a standby server.
  465. </p></dd><dt><span class="term"><code class="option">--on-conflict-do-nothing</code></span></dt><dd><p>
  466. Add <code class="literal">ON CONFLICT DO NOTHING</code> to
  467. <code class="command">INSERT</code> commands.
  468. This option is not valid unless <code class="option">--inserts</code>,
  469. <code class="option">--column-inserts</code> or
  470. <code class="option">--rows-per-insert</code> is also specified.
  471. </p></dd><dt><span class="term"><code class="option">--quote-all-identifiers</code></span></dt><dd><p>
  472. Force quoting of all identifiers. This option is recommended when
  473. dumping a database from a server whose <span class="productname">PostgreSQL</span>
  474. major version is different from <span class="application">pg_dump</span>'s, or when
  475. the output is intended to be loaded into a server of a different
  476. major version. By default, <span class="application">pg_dump</span> quotes only
  477. identifiers that are reserved words in its own major version.
  478. This sometimes results in compatibility issues when dealing with
  479. servers of other versions that may have slightly different sets
  480. of reserved words. Using <code class="option">--quote-all-identifiers</code> prevents
  481. such issues, at the price of a harder-to-read dump script.
  482. </p></dd><dt><span class="term"><code class="option">--rows-per-insert=<em class="replaceable"><code>nrows</code></em></code></span></dt><dd><p>
  483. Dump data as <code class="command">INSERT</code> commands (rather than
  484. <code class="command">COPY</code>). Controls the maximum number of rows per
  485. <code class="command">INSERT</code> command. The value specified must be a
  486. number greater than zero. Any error during reloading will cause only
  487. rows that are part of the problematic <code class="command">INSERT</code> to be
  488. lost, rather than the entire table contents.
  489. </p></dd><dt><span class="term"><code class="option">--section=<em class="replaceable"><code>sectionname</code></em></code></span></dt><dd><p>
  490. Only dump the named section. The section name can be
  491. <code class="option">pre-data</code>, <code class="option">data</code>, or <code class="option">post-data</code>.
  492. This option can be specified more than once to select multiple
  493. sections. The default is to dump all sections.
  494. </p><p>
  495. The data section contains actual table data, large-object
  496. contents, and sequence values.
  497. Post-data items include definitions of indexes, triggers, rules,
  498. and constraints other than validated check constraints.
  499. Pre-data items include all other data definition items.
  500. </p></dd><dt><span class="term"><code class="option">--serializable-deferrable</code></span></dt><dd><p>
  501. Use a <code class="literal">serializable</code> transaction for the dump, to
  502. ensure that the snapshot used is consistent with later database
  503. states; but do this by waiting for a point in the transaction stream
  504. at which no anomalies can be present, so that there isn't a risk of
  505. the dump failing or causing other transactions to roll back with a
  506. <code class="literal">serialization_failure</code>. See <a class="xref" href="mvcc.html" title="Chapter 13. Concurrency Control">Chapter 13</a>
  507. for more information about transaction isolation and concurrency
  508. control.
  509. </p><p>
  510. This option is not beneficial for a dump which is intended only for
  511. disaster recovery. It could be useful for a dump used to load a
  512. copy of the database for reporting or other read-only load sharing
  513. while the original database continues to be updated. Without it the
  514. dump may reflect a state which is not consistent with any serial
  515. execution of the transactions eventually committed. For example, if
  516. batch processing techniques are used, a batch may show as closed in
  517. the dump without all of the items which are in the batch appearing.
  518. </p><p>
  519. This option will make no difference if there are no read-write
  520. transactions active when pg_dump is started. If read-write
  521. transactions are active, the start of the dump may be delayed for an
  522. indeterminate length of time. Once running, performance with or
  523. without the switch is the same.
  524. </p></dd><dt><span class="term"><code class="option">--snapshot=<em class="replaceable"><code>snapshotname</code></em></code></span></dt><dd><p>
  525. Use the specified synchronized snapshot when making a dump of the
  526. database (see
  527. <a class="xref" href="functions-admin.html#FUNCTIONS-SNAPSHOT-SYNCHRONIZATION-TABLE" title="Table 9.87. Snapshot Synchronization Functions">Table 9.87</a> for more
  528. details).
  529. </p><p>
  530. This option is useful when needing to synchronize the dump with
  531. a logical replication slot (see <a class="xref" href="logicaldecoding.html" title="Chapter 48. Logical Decoding">Chapter 48</a>)
  532. or with a concurrent session.
  533. </p><p>
  534. In the case of a parallel dump, the snapshot name defined by this
  535. option is used rather than taking a new snapshot.
  536. </p></dd><dt><span class="term"><code class="option">--strict-names</code></span></dt><dd><p>
  537. Require that each schema
  538. (<code class="option">-n</code>/<code class="option">--schema</code>) and table
  539. (<code class="option">-t</code>/<code class="option">--table</code>) qualifier match at
  540. least one schema/table in the database to be dumped. Note that if
  541. none of the schema/table qualifiers find
  542. matches, <span class="application">pg_dump</span> will generate an error
  543. even without <code class="option">--strict-names</code>.
  544. </p><p>
  545. This option has no effect
  546. on <code class="option">-N</code>/<code class="option">--exclude-schema</code>,
  547. <code class="option">-T</code>/<code class="option">--exclude-table</code>,
  548. or <code class="option">--exclude-table-data</code>. An exclude pattern failing
  549. to match any objects is not considered an error.
  550. </p></dd><dt><span class="term"><code class="option">--use-set-session-authorization</code></span></dt><dd><p>
  551. Output SQL-standard <code class="command">SET SESSION AUTHORIZATION</code> commands
  552. instead of <code class="command">ALTER OWNER</code> commands to determine object
  553. ownership. This makes the dump more standards-compatible, but
  554. depending on the history of the objects in the dump, might not restore
  555. properly. Also, a dump using <code class="command">SET SESSION AUTHORIZATION</code>
  556. will certainly require superuser privileges to restore correctly,
  557. whereas <code class="command">ALTER OWNER</code> requires lesser privileges.
  558. </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>
  559. Show help about <span class="application">pg_dump</span> command line
  560. arguments, and exit.
  561. </p></dd></dl></div><p>
  562. </p><p>
  563. The following command-line options control the database connection parameters.
  564. </p><div class="variablelist"><dl class="variablelist"><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>
  565. Specifies the name of the database to connect to. This is
  566. equivalent to specifying <em class="replaceable"><code>dbname</code></em> as the first non-option
  567. argument on the command line.
  568. </p><p>
  569. If this parameter contains an <code class="symbol">=</code> sign or starts
  570. with a valid <acronym class="acronym">URI</acronym> prefix
  571. (<code class="literal">postgresql://</code>
  572. or <code class="literal">postgres://</code>), it is treated as a
  573. <em class="parameter"><code>conninfo</code></em> string. See <a class="xref" href="libpq-connect.html" title="33.1. Database Connection Control Functions">Section 33.1</a> for more information.
  574. </p></dd><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>
  575. Specifies the host name of the machine on which the server is
  576. running. If the value begins with a slash, it is used as the
  577. directory for the Unix domain socket. The default is taken
  578. from the <code class="envar">PGHOST</code> environment variable, if set,
  579. else a Unix domain socket connection is attempted.
  580. </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>
  581. Specifies the TCP port or local Unix domain socket file
  582. extension on which the server is listening for connections.
  583. Defaults to the <code class="envar">PGPORT</code> environment variable, if
  584. set, or a compiled-in default.
  585. </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>
  586. User name to connect as.
  587. </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>
  588. Never issue a password prompt. If the server requires
  589. password authentication and a password is not available by
  590. other means such as a <code class="filename">.pgpass</code> file, the
  591. connection attempt will fail. This option can be useful in
  592. batch jobs and scripts where no user is present to enter a
  593. password.
  594. </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>
  595. Force <span class="application">pg_dump</span> to prompt for a
  596. password before connecting to a database.
  597. </p><p>
  598. This option is never essential, since
  599. <span class="application">pg_dump</span> will automatically prompt
  600. for a password if the server demands password authentication.
  601. However, <span class="application">pg_dump</span> will waste a
  602. connection attempt finding out that the server wants a password.
  603. In some cases it is worth typing <code class="option">-W</code> to avoid the extra
  604. connection attempt.
  605. </p></dd><dt><span class="term"><code class="option">--role=<em class="replaceable"><code>rolename</code></em></code></span></dt><dd><p>
  606. Specifies a role name to be used to create the dump.
  607. This option causes <span class="application">pg_dump</span> to issue a
  608. <code class="command">SET ROLE</code> <em class="replaceable"><code>rolename</code></em>
  609. command after connecting to the database. It is useful when the
  610. authenticated user (specified by <code class="option">-U</code>) lacks privileges
  611. needed by <span class="application">pg_dump</span>, but can switch to a role with
  612. the required rights. Some installations have a policy against
  613. logging in directly as a superuser, and use of this option allows
  614. dumps to be made without violating the policy.
  615. </p></dd></dl></div><p>
  616. </p></div><div class="refsect1" id="id-1.9.4.12.7"><h2>Environment</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="envar">PGDATABASE</code><br /></span><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>
  617. Default connection parameters.
  618. </p></dd><dt><span class="term"><code class="envar">PG_COLOR</code></span></dt><dd><p>
  619. Specifies whether to use color in diagnostic messages. Possible values
  620. are <code class="literal">always</code>, <code class="literal">auto</code> and
  621. <code class="literal">never</code>.
  622. </p></dd></dl></div><p>
  623. This utility, like most other <span class="productname">PostgreSQL</span> utilities,
  624. also uses the environment variables supported by <span class="application">libpq</span>
  625. (see <a class="xref" href="libpq-envars.html" title="33.14. Environment Variables">Section 33.14</a>).
  626. </p></div><div class="refsect1" id="APP-PGDUMP-DIAGNOSTICS"><h2>Diagnostics</h2><p>
  627. <span class="application">pg_dump</span> internally executes
  628. <code class="command">SELECT</code> statements. If you have problems running
  629. <span class="application">pg_dump</span>, make sure you are able to
  630. select information from the database using, for example, <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a>. Also, any default connection settings and environment
  631. variables used by the <span class="application">libpq</span> front-end
  632. library will apply.
  633. </p><p>
  634. The database activity of <span class="application">pg_dump</span> is
  635. normally collected by the statistics collector. If this is
  636. undesirable, you can set parameter <code class="varname">track_counts</code>
  637. to false via <code class="envar">PGOPTIONS</code> or the <code class="literal">ALTER
  638. USER</code> command.
  639. </p></div><div class="refsect1" id="PG-DUMP-NOTES"><h2>Notes</h2><p>
  640. If your database cluster has any local additions to the <code class="literal">template1</code> database,
  641. be careful to restore the output of <span class="application">pg_dump</span> into a
  642. truly empty database; otherwise you are likely to get errors due to
  643. duplicate definitions of the added objects. To make an empty database
  644. without any local additions, copy from <code class="literal">template0</code> not <code class="literal">template1</code>,
  645. for example:
  646. </p><pre class="programlisting">
  647. CREATE DATABASE foo WITH TEMPLATE template0;
  648. </pre><p>
  649. </p><p>
  650. When a data-only dump is chosen and the option <code class="option">--disable-triggers</code>
  651. is used, <span class="application">pg_dump</span> emits commands
  652. to disable triggers on user tables before inserting the data,
  653. and then commands to re-enable them after the data has been
  654. inserted. If the restore is stopped in the middle, the system
  655. catalogs might be left in the wrong state.
  656. </p><p>
  657. The dump file produced by <span class="application">pg_dump</span>
  658. does not contain the statistics used by the optimizer to make
  659. query planning decisions. Therefore, it is wise to run
  660. <code class="command">ANALYZE</code> after restoring from a dump file
  661. to ensure optimal performance; see <a class="xref" href="routine-vacuuming.html#VACUUM-FOR-STATISTICS" title="24.1.3. Updating Planner Statistics">Section 24.1.3</a>
  662. and <a class="xref" href="routine-vacuuming.html#AUTOVACUUM" title="24.1.6. The Autovacuum Daemon">Section 24.1.6</a> for more information.
  663. </p><p>
  664. Because <span class="application">pg_dump</span> is used to transfer data
  665. to newer versions of <span class="productname">PostgreSQL</span>, the output of
  666. <span class="application">pg_dump</span> can be expected to load into
  667. <span class="productname">PostgreSQL</span> server versions newer than
  668. <span class="application">pg_dump</span>'s version. <span class="application">pg_dump</span> can also
  669. dump from <span class="productname">PostgreSQL</span> servers older than its own version.
  670. (Currently, servers back to version 8.0 are supported.)
  671. However, <span class="application">pg_dump</span> cannot dump from
  672. <span class="productname">PostgreSQL</span> servers newer than its own major version;
  673. it will refuse to even try, rather than risk making an invalid dump.
  674. Also, it is not guaranteed that <span class="application">pg_dump</span>'s output can
  675. be loaded into a server of an older major version — not even if the
  676. dump was taken from a server of that version. Loading a dump file
  677. into an older server may require manual editing of the dump file
  678. to remove syntax not understood by the older server.
  679. Use of the <code class="option">--quote-all-identifiers</code> option is recommended
  680. in cross-version cases, as it can prevent problems arising from varying
  681. reserved-word lists in different <span class="productname">PostgreSQL</span> versions.
  682. </p><p>
  683. When dumping logical replication subscriptions,
  684. <span class="application">pg_dump</span> will generate <code class="command">CREATE
  685. SUBSCRIPTION</code> commands that use the <code class="literal">connect = false</code>
  686. option, so that restoring the subscription does not make remote connections
  687. for creating a replication slot or for initial table copy. That way, the
  688. dump can be restored without requiring network access to the remote
  689. servers. It is then up to the user to reactivate the subscriptions in a
  690. suitable way. If the involved hosts have changed, the connection
  691. information might have to be changed. It might also be appropriate to
  692. truncate the target tables before initiating a new full table copy.
  693. </p></div><div class="refsect1" id="PG-DUMP-EXAMPLES"><h2>Examples</h2><p>
  694. To dump a database called <code class="literal">mydb</code> into a SQL-script file:
  695. </p><pre class="screen">
  696. <code class="prompt">$</code> <strong class="userinput"><code>pg_dump mydb &gt; db.sql</code></strong>
  697. </pre><p>
  698. </p><p>
  699. To reload such a script into a (freshly created) database named
  700. <code class="literal">newdb</code>:
  701. </p><pre class="screen">
  702. <code class="prompt">$</code> <strong class="userinput"><code>psql -d newdb -f db.sql</code></strong>
  703. </pre><p>
  704. </p><p>
  705. To dump a database into a custom-format archive file:
  706. </p><pre class="screen">
  707. <code class="prompt">$</code> <strong class="userinput"><code>pg_dump -Fc mydb &gt; db.dump</code></strong>
  708. </pre><p>
  709. </p><p>
  710. To dump a database into a directory-format archive:
  711. </p><pre class="screen">
  712. <code class="prompt">$</code> <strong class="userinput"><code>pg_dump -Fd mydb -f dumpdir</code></strong>
  713. </pre><p>
  714. </p><p>
  715. To dump a database into a directory-format archive in parallel with
  716. 5 worker jobs:
  717. </p><pre class="screen">
  718. <code class="prompt">$</code> <strong class="userinput"><code>pg_dump -Fd mydb -j 5 -f dumpdir</code></strong>
  719. </pre><p>
  720. </p><p>
  721. To reload an archive file into a (freshly created) database named
  722. <code class="literal">newdb</code>:
  723. </p><pre class="screen">
  724. <code class="prompt">$</code> <strong class="userinput"><code>pg_restore -d newdb db.dump</code></strong>
  725. </pre><p>
  726. </p><p>
  727. To reload an archive file into the same database it was dumped from,
  728. discarding the current contents of that database:
  729. </p><pre class="screen">
  730. <code class="prompt">$</code> <strong class="userinput"><code>pg_restore -d postgres --clean --create db.dump</code></strong>
  731. </pre><p>
  732. </p><p>
  733. To dump a single table named <code class="literal">mytab</code>:
  734. </p><pre class="screen">
  735. <code class="prompt">$</code> <strong class="userinput"><code>pg_dump -t mytab mydb &gt; db.sql</code></strong>
  736. </pre><p>
  737. </p><p>
  738. To dump all tables whose names start with <code class="literal">emp</code> in the
  739. <code class="literal">detroit</code> schema, except for the table named
  740. <code class="literal">employee_log</code>:
  741. </p><pre class="screen">
  742. <code class="prompt">$</code> <strong class="userinput"><code>pg_dump -t 'detroit.emp*' -T detroit.employee_log mydb &gt; db.sql</code></strong>
  743. </pre><p>
  744. </p><p>
  745. To dump all schemas whose names start with <code class="literal">east</code> or
  746. <code class="literal">west</code> and end in <code class="literal">gsm</code>, excluding any schemas whose
  747. names contain the word <code class="literal">test</code>:
  748. </p><pre class="screen">
  749. <code class="prompt">$</code> <strong class="userinput"><code>pg_dump -n 'east*gsm' -n 'west*gsm' -N '*test*' mydb &gt; db.sql</code></strong>
  750. </pre><p>
  751. </p><p>
  752. The same, using regular expression notation to consolidate the switches:
  753. </p><pre class="screen">
  754. <code class="prompt">$</code> <strong class="userinput"><code>pg_dump -n '(east|west)*gsm' -N '*test*' mydb &gt; db.sql</code></strong>
  755. </pre><p>
  756. </p><p>
  757. To dump all database objects except for tables whose names begin with
  758. <code class="literal">ts_</code>:
  759. </p><pre class="screen">
  760. <code class="prompt">$</code> <strong class="userinput"><code>pg_dump -T 'ts_*' mydb &gt; db.sql</code></strong>
  761. </pre><p>
  762. </p><p>
  763. To specify an upper-case or mixed-case name in <code class="option">-t</code> and related
  764. switches, you need to double-quote the name; else it will be folded to
  765. lower case (see <a class="xref" href="app-psql.html#APP-PSQL-PATTERNS" title="Patterns">Patterns</a>). But
  766. double quotes are special to the shell, so in turn they must be quoted.
  767. Thus, to dump a single table with a mixed-case name, you need something
  768. like
  769. </p><pre class="screen">
  770. <code class="prompt">$</code> <strong class="userinput"><code>pg_dump -t "\"MixedCaseName\"" mydb &gt; mytab.sql</code></strong>
  771. </pre></div><div class="refsect1" id="id-1.9.4.12.11"><h2>See Also</h2><span class="simplelist"><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-pgrestore.html" title="pg_restore"><span class="refentrytitle">pg_restore</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-pgconfig.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-pg-dumpall.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">pg_config </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">pg_dumpall</span></td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1