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.

424 line
35KB

  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_upgrade</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="pgtesttiming.html" title="pg_test_timing" /><link rel="next" href="pgwaldump.html" title="pg_waldump" /></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"><span xmlns="http://www.w3.org/1999/xhtml" class="application">pg_upgrade</span></th></tr><tr><td width="10%" align="left"><a accesskey="p" href="pgtesttiming.html" title="pg_test_timing">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="reference-server.html" title="PostgreSQL Server Applications">Up</a></td><th width="60%" align="center">PostgreSQL Server 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="pgwaldump.html" title="pg_waldump">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="PGUPGRADE"><div class="titlepage"></div><a id="id-1.9.5.12.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle"><span class="application">pg_upgrade</span></span></h2><p>pg_upgrade — upgrade a <span class="productname">PostgreSQL</span> server instance</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.5.12.4.1"><code class="command">pg_upgrade</code> <code class="option">-b</code> <em class="replaceable"><code>oldbindir</code></em> <code class="option">-B</code> <em class="replaceable"><code>newbindir</code></em> <code class="option">-d</code> <em class="replaceable"><code>oldconfigdir</code></em> <code class="option">-D</code> <em class="replaceable"><code>newconfigdir</code></em> [<em class="replaceable"><code>option</code></em>...]</p></div></div><div class="refsect1" id="id-1.9.5.12.5"><h2>Description</h2><p>
  3. <span class="application">pg_upgrade</span> (formerly called <span class="application">pg_migrator</span>) allows data
  4. stored in <span class="productname">PostgreSQL</span> data files to be upgraded to a later <span class="productname">PostgreSQL</span>
  5. major version without the data dump/reload typically required for
  6. major version upgrades, e.g. from 9.5.8 to 9.6.4 or from 10.7 to 11.2.
  7. It is not required for minor version upgrades, e.g. from 9.6.2 to 9.6.3
  8. or from 10.1 to 10.2.
  9. </p><p>
  10. Major PostgreSQL releases regularly add new features that often
  11. change the layout of the system tables, but the internal data storage
  12. format rarely changes. <span class="application">pg_upgrade</span> uses this fact
  13. to perform rapid upgrades by creating new system tables and simply
  14. reusing the old user data files. If a future major release ever
  15. changes the data storage format in a way that makes the old data
  16. format unreadable, <span class="application">pg_upgrade</span> will not be usable
  17. for such upgrades. (The community will attempt to avoid such
  18. situations.)
  19. </p><p>
  20. <span class="application">pg_upgrade</span> does its best to
  21. make sure the old and new clusters are binary-compatible, e.g. by
  22. checking for compatible compile-time settings, including 32/64-bit
  23. binaries. It is important that
  24. any external modules are also binary compatible, though this cannot
  25. be checked by <span class="application">pg_upgrade</span>.
  26. </p><p>
  27. pg_upgrade supports upgrades from 8.4.X and later to the current
  28. major release of <span class="productname">PostgreSQL</span>, including snapshot and beta releases.
  29. </p></div><div class="refsect1" id="id-1.9.5.12.6"><h2>Options</h2><p>
  30. <span class="application">pg_upgrade</span> accepts the following command-line arguments:
  31. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-b</code> <em class="replaceable"><code>bindir</code></em><br /></span><span class="term"><code class="option">--old-bindir=</code><em class="replaceable"><code>bindir</code></em></span></dt><dd><p>the old PostgreSQL executable directory;
  32. environment variable <code class="envar">PGBINOLD</code></p></dd><dt><span class="term"><code class="option">-B</code> <em class="replaceable"><code>bindir</code></em><br /></span><span class="term"><code class="option">--new-bindir=</code><em class="replaceable"><code>bindir</code></em></span></dt><dd><p>the new PostgreSQL executable directory;
  33. environment variable <code class="envar">PGBINNEW</code></p></dd><dt><span class="term"><code class="option">-c</code><br /></span><span class="term"><code class="option">--check</code></span></dt><dd><p>check clusters only, don't change any data</p></dd><dt><span class="term"><code class="option">-d</code> <em class="replaceable"><code>configdir</code></em><br /></span><span class="term"><code class="option">--old-datadir=</code><em class="replaceable"><code>configdir</code></em></span></dt><dd><p>the old database cluster configuration directory; environment
  34. variable <code class="envar">PGDATAOLD</code></p></dd><dt><span class="term"><code class="option">-D</code> <em class="replaceable"><code>configdir</code></em><br /></span><span class="term"><code class="option">--new-datadir=</code><em class="replaceable"><code>configdir</code></em></span></dt><dd><p>the new database cluster configuration directory; environment
  35. variable <code class="envar">PGDATANEW</code></p></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>number of simultaneous processes or threads to use
  36. </p></dd><dt><span class="term"><code class="option">-k</code><br /></span><span class="term"><code class="option">--link</code></span></dt><dd><p>use hard links instead of copying files to the new
  37. cluster</p></dd><dt><span class="term"><code class="option">-o</code> <em class="replaceable"><code>options</code></em><br /></span><span class="term"><code class="option">--old-options</code> <em class="replaceable"><code>options</code></em></span></dt><dd><p>options to be passed directly to the
  38. old <code class="command">postgres</code> command; multiple
  39. option invocations are appended</p></dd><dt><span class="term"><code class="option">-O</code> <em class="replaceable"><code>options</code></em><br /></span><span class="term"><code class="option">--new-options</code> <em class="replaceable"><code>options</code></em></span></dt><dd><p>options to be passed directly to the
  40. new <code class="command">postgres</code> command; multiple
  41. option invocations are appended</p></dd><dt><span class="term"><code class="option">-p</code> <em class="replaceable"><code>port</code></em><br /></span><span class="term"><code class="option">--old-port=</code><em class="replaceable"><code>port</code></em></span></dt><dd><p>the old cluster port number; environment
  42. variable <code class="envar">PGPORTOLD</code></p></dd><dt><span class="term"><code class="option">-P</code> <em class="replaceable"><code>port</code></em><br /></span><span class="term"><code class="option">--new-port=</code><em class="replaceable"><code>port</code></em></span></dt><dd><p>the new cluster port number; environment
  43. variable <code class="envar">PGPORTNEW</code></p></dd><dt><span class="term"><code class="option">-r</code><br /></span><span class="term"><code class="option">--retain</code></span></dt><dd><p>retain SQL and log files even after successful completion
  44. </p></dd><dt><span class="term"><code class="option">-s</code> <em class="replaceable"><code>dir</code></em><br /></span><span class="term"><code class="option">--socketdir=</code><em class="replaceable"><code>dir</code></em></span></dt><dd><p>directory to use for postmaster sockets during upgrade;
  45. default is current working directory; environment
  46. variable <code class="envar">PGSOCKETDIR</code></p></dd><dt><span class="term"><code class="option">-U</code> <em class="replaceable"><code>username</code></em><br /></span><span class="term"><code class="option">--username=</code><em class="replaceable"><code>username</code></em></span></dt><dd><p>cluster's install user name; environment
  47. variable <code class="envar">PGUSER</code></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>enable verbose internal logging</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>display version information, then exit</p></dd><dt><span class="term"><code class="option">--clone</code></span></dt><dd><p>
  48. Use efficient file cloning (also known as <span class="quote">“<span class="quote">reflinks</span>”</span> on
  49. some systems) instead of copying files to the new cluster. This can
  50. result in near-instantaneous copying of the data files, giving the
  51. speed advantages of <code class="option">-k</code>/<code class="option">--link</code> while
  52. leaving the old cluster untouched.
  53. </p><p>
  54. File cloning is only supported on some operating systems and file
  55. systems. If it is selected but not supported, the
  56. <span class="application">pg_upgrade</span> run will error. At present, it
  57. is supported on Linux (kernel 4.5 or later) with Btrfs and XFS (on
  58. file systems created with reflink support), and on macOS with APFS.
  59. </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>show help, then exit</p></dd></dl></div><p>
  60. </p></div><div class="refsect1" id="id-1.9.5.12.7"><h2>Usage</h2><p>
  61. These are the steps to perform an upgrade
  62. with <span class="application">pg_upgrade</span>:
  63. </p><div class="procedure"><ol class="procedure" type="1"><li class="step"><p class="title"><strong>Optionally move the old cluster</strong></p><p>
  64. If you are using a version-specific installation directory, e.g.
  65. <code class="filename">/opt/PostgreSQL/12</code>, you do not need to move the old cluster. The
  66. graphical installers all use version-specific installation directories.
  67. </p><p>
  68. If your installation directory is not version-specific, e.g.
  69. <code class="filename">/usr/local/pgsql</code>, it is necessary to move the current PostgreSQL install
  70. directory so it does not interfere with the new <span class="productname">PostgreSQL</span> installation.
  71. Once the current <span class="productname">PostgreSQL</span> server is shut down, it is safe to rename the
  72. PostgreSQL installation directory; assuming the old directory is
  73. <code class="filename">/usr/local/pgsql</code>, you can do:
  74. </p><pre class="programlisting">
  75. mv /usr/local/pgsql /usr/local/pgsql.old
  76. </pre><p>
  77. to rename the directory.
  78. </p></li><li class="step"><p class="title"><strong>For source installs, build the new version</strong></p><p>
  79. Build the new PostgreSQL source with <code class="command">configure</code> flags that are compatible
  80. with the old cluster. <span class="application">pg_upgrade</span> will check <code class="command">pg_controldata</code> to make
  81. sure all settings are compatible before starting the upgrade.
  82. </p></li><li class="step"><p class="title"><strong>Install the new PostgreSQL binaries</strong></p><p>
  83. Install the new server's binaries and support
  84. files. <span class="application">pg_upgrade</span> is included in a default installation.
  85. </p><p>
  86. For source installs, if you wish to install the new server in a custom
  87. location, use the <code class="literal">prefix</code> variable:
  88. </p><pre class="programlisting">
  89. make prefix=/usr/local/pgsql.new install
  90. </pre></li><li class="step"><p class="title"><strong>Initialize the new PostgreSQL cluster</strong></p><p>
  91. Initialize the new cluster using <code class="command">initdb</code>.
  92. Again, use compatible <code class="command">initdb</code>
  93. flags that match the old cluster. Many
  94. prebuilt installers do this step automatically. There is no need to
  95. start the new cluster.
  96. </p></li><li class="step"><p class="title"><strong>Install custom shared object files</strong></p><p>
  97. Install any custom shared object files (or DLLs) used by the old cluster
  98. into the new cluster, e.g. <code class="filename">pgcrypto.so</code>,
  99. whether they are from <code class="filename">contrib</code>
  100. or some other source. Do not install the schema definitions, e.g.
  101. <code class="command">CREATE EXTENSION pgcrypto</code>, because these will be upgraded
  102. from the old cluster.
  103. Also, any custom full text search files (dictionary, synonym,
  104. thesaurus, stop words) must also be copied to the new cluster.
  105. </p></li><li class="step"><p class="title"><strong>Adjust authentication</strong></p><p>
  106. <code class="command">pg_upgrade</code> will connect to the old and new servers several
  107. times, so you might want to set authentication to <code class="literal">peer</code>
  108. in <code class="filename">pg_hba.conf</code> or use a <code class="filename">~/.pgpass</code> file
  109. (see <a class="xref" href="libpq-pgpass.html" title="33.15. The Password File">Section 33.15</a>).
  110. </p></li><li class="step"><p class="title"><strong>Stop both servers</strong></p><p>
  111. Make sure both database servers are stopped using, on Unix, e.g.:
  112. </p><pre class="programlisting">
  113. pg_ctl -D /opt/PostgreSQL/9.6 stop
  114. pg_ctl -D /opt/PostgreSQL/12 stop
  115. </pre><p>
  116. or on Windows, using the proper service names:
  117. </p><pre class="programlisting">
  118. NET STOP postgresql-9.6
  119. NET STOP postgresql-12
  120. </pre><p>
  121. </p><p>
  122. Streaming replication and log-shipping standby servers can
  123. remain running until a later step.
  124. </p></li><li class="step"><p class="title"><strong>Prepare for standby server upgrades</strong></p><p>
  125. If you are upgrading standby servers using methods outlined in section <a class="xref" href="pgupgrade.html#PGUPGRADE-STEP-REPLICAS" title="Upgrade streaming replication and log-shipping standby servers">Step 10</a>, verify that the old standby
  126. servers are caught up by running <span class="application">pg_controldata</span>
  127. against the old primary and standby clusters. Verify that the
  128. <span class="quote">“<span class="quote">Latest checkpoint location</span>”</span> values match in all clusters.
  129. (There will be a mismatch if old standby servers were shut down
  130. before the old primary or if the old standby servers are still running.)
  131. Also, make sure <code class="varname">wal_level</code> is not set to
  132. <code class="literal">minimal</code> in the <code class="filename">postgresql.conf</code> file on the
  133. new primary cluster.
  134. </p></li><li class="step"><p class="title"><strong>Run <span class="application">pg_upgrade</span></strong></p><p>
  135. Always run the <span class="application">pg_upgrade</span> binary of the new server, not the old one.
  136. <span class="application">pg_upgrade</span> requires the specification of the old and new cluster's
  137. data and executable (<code class="filename">bin</code>) directories. You can also specify
  138. user and port values, and whether you want the data files linked or cloned
  139. instead of the default copy behavior.
  140. </p><p>
  141. If you use link mode, the upgrade will be much faster (no file
  142. copying) and use less disk space, but you will not be able to access
  143. your old cluster
  144. once you start the new cluster after the upgrade. Link mode also
  145. requires that the old and new cluster data directories be in the
  146. same file system. (Tablespaces and <code class="filename">pg_wal</code> can be on
  147. different file systems.)
  148. Clone mode provides the same speed and disk space advantages but
  149. does not cause the old cluster to be unusable once the new cluster
  150. is started. Clone mode also requires that the old and new data
  151. directories be in the same file system. This mode is only available
  152. on certain operating systems and file systems.
  153. </p><p>
  154. The <code class="option">--jobs</code> option allows multiple CPU cores to be used
  155. for copying/linking of files and to dump and reload database schemas
  156. in parallel; a good place to start is the maximum of the number of
  157. CPU cores and tablespaces. This option can dramatically reduce the
  158. time to upgrade a multi-database server running on a multiprocessor
  159. machine.
  160. </p><p>
  161. For Windows users, you must be logged into an administrative account, and
  162. then start a shell as the <code class="literal">postgres</code> user and set the proper path:
  163. </p><pre class="programlisting">
  164. RUNAS /USER:postgres "CMD.EXE"
  165. SET PATH=%PATH%;C:\Program Files\PostgreSQL\12\bin;
  166. </pre><p>
  167. and then run <span class="application">pg_upgrade</span> with quoted directories, e.g.:
  168. </p><pre class="programlisting">
  169. pg_upgrade.exe
  170. --old-datadir "C:/Program Files/PostgreSQL/9.6/data"
  171. --new-datadir "C:/Program Files/PostgreSQL/12/data"
  172. --old-bindir "C:/Program Files/PostgreSQL/9.6/bin"
  173. --new-bindir "C:/Program Files/PostgreSQL/12/bin"
  174. </pre><p>
  175. Once started, <code class="command">pg_upgrade</code> will verify the two clusters are compatible
  176. and then do the upgrade. You can use <code class="command">pg_upgrade --check</code>
  177. to perform only the checks, even if the old server is still
  178. running. <code class="command">pg_upgrade --check</code> will also outline any
  179. manual adjustments you will need to make after the upgrade. If you
  180. are going to be using link or clone mode, you should use the option
  181. <code class="option">--link</code> or <code class="option">--clone</code> with
  182. <code class="option">--check</code> to enable mode-specific checks.
  183. <code class="command">pg_upgrade</code> requires write permission in the current directory.
  184. </p><p>
  185. Obviously, no one should be accessing the clusters during the
  186. upgrade. <span class="application">pg_upgrade</span> defaults to running servers
  187. on port 50432 to avoid unintended client connections.
  188. You can use the same port number for both clusters when doing an
  189. upgrade because the old and new clusters will not be running at the
  190. same time. However, when checking an old running server, the old
  191. and new port numbers must be different.
  192. </p><p>
  193. If an error occurs while restoring the database schema, <code class="command">pg_upgrade</code> will
  194. exit and you will have to revert to the old cluster as outlined in <a class="xref" href="pgupgrade.html#PGUPGRADE-STEP-REVERT" title="Reverting to old cluster">Step 16</a>
  195. below. To try <code class="command">pg_upgrade</code> again, you will need to modify the old
  196. cluster so the pg_upgrade schema restore succeeds. If the problem is a
  197. <code class="filename">contrib</code> module, you might need to uninstall the <code class="filename">contrib</code> module from
  198. the old cluster and install it in the new cluster after the upgrade,
  199. assuming the module is not being used to store user data.
  200. </p></li><li class="step" id="PGUPGRADE-STEP-REPLICAS"><p class="title"><strong>Upgrade streaming replication and log-shipping standby servers</strong></p><p>
  201. If you used link mode and have Streaming Replication (see <a class="xref" href="warm-standby.html#STREAMING-REPLICATION" title="26.2.5. Streaming Replication">Section 26.2.5</a>) or Log-Shipping (see <a class="xref" href="warm-standby.html" title="26.2. Log-Shipping Standby Servers">Section 26.2</a>) standby servers, you can follow these steps to
  202. quickly upgrade them. You will not be running <span class="application">pg_upgrade</span> on
  203. the standby servers, but rather <span class="application">rsync</span> on the primary.
  204. Do not start any servers yet.
  205. </p><p>
  206. If you did <span class="emphasis"><em>not</em></span> use link mode, do not have or do not
  207. want to use <span class="application">rsync</span>, or want an easier solution, skip
  208. the instructions in this section and simply recreate the standby
  209. servers once <span class="application">pg_upgrade</span> completes and the new primary
  210. is running.
  211. </p><ol type="a" class="substeps"><li class="step"><p class="title"><strong>Install the new PostgreSQL binaries on standby servers</strong></p><p>
  212. Make sure the new binaries and support files are installed on all
  213. standby servers.
  214. </p></li><li class="step"><p class="title"><strong>Make sure the new standby data directories do <span class="emphasis"><em>not</em></span> exist</strong></p><p>
  215. Make sure the new standby data directories do <span class="emphasis"><em>not</em></span>
  216. exist or are empty. If <span class="application">initdb</span> was run, delete
  217. the standby servers' new data directories.
  218. </p></li><li class="step"><p class="title"><strong>Install custom shared object files</strong></p><p>
  219. Install the same custom shared object files on the new standbys
  220. that you installed in the new primary cluster.
  221. </p></li><li class="step"><p class="title"><strong>Stop standby servers</strong></p><p>
  222. If the standby servers are still running, stop them now using the
  223. above instructions.
  224. </p></li><li class="step"><p class="title"><strong>Save configuration files</strong></p><p>
  225. Save any configuration files from the old standbys' configuration
  226. directories you need to keep, e.g. <code class="filename">postgresql.conf</code>,
  227. <code class="literal">pg_hba.conf</code>, because these will be overwritten or
  228. removed in the next step.
  229. </p></li><li class="step"><p class="title"><strong>Run <span class="application">rsync</span></strong></p><p>
  230. When using link mode, standby servers can be quickly upgraded using
  231. <span class="application">rsync</span>. To accomplish this, from a directory on
  232. the primary server that is above the old and new database cluster
  233. directories, run this on the <span class="emphasis"><em>primary</em></span> for each standby
  234. server:
  235. </p><pre class="programlisting">
  236. rsync --archive --delete --hard-links --size-only --no-inc-recursive old_cluster new_cluster remote_dir
  237. </pre><p>
  238. where <code class="option">old_cluster</code> and <code class="option">new_cluster</code> are relative
  239. to the current directory on the primary, and <code class="option">remote_dir</code>
  240. is <span class="emphasis"><em>above</em></span> the old and new cluster directories
  241. on the standby. The directory structure under the specified
  242. directories on the primary and standbys must match. Consult the
  243. <span class="application">rsync</span> manual page for details on specifying the
  244. remote directory, e.g.
  245. </p><pre class="programlisting">
  246. rsync --archive --delete --hard-links --size-only --no-inc-recursive /opt/PostgreSQL/9.5 \
  247. /opt/PostgreSQL/9.6 standby.example.com:/opt/PostgreSQL
  248. </pre><p>
  249. You can verify what the command will do using
  250. <span class="application">rsync</span>'s <code class="option">--dry-run</code> option. While
  251. <span class="application">rsync</span> must be run on the primary for at least one
  252. standby, it is possible to run <span class="application">rsync</span> on an upgraded
  253. standby to upgrade other standbys, as long as the upgraded standby
  254. has not been started.
  255. </p><p>
  256. What this does is to record the links created by
  257. <span class="application">pg_upgrade</span>'s link mode that connect files in the
  258. old and new clusters on the primary server. It then finds matching
  259. files in the standby's old cluster and creates links for them in the
  260. standby's new cluster. Files that were not linked on the primary
  261. are copied from the primary to the standby. (They are usually
  262. small.) This provides rapid standby upgrades. Unfortunately,
  263. <span class="application">rsync</span> needlessly copies files associated with
  264. temporary and unlogged tables because these files don't normally
  265. exist on standby servers.
  266. </p><p>
  267. If you have tablespaces, you will need to run a similar
  268. <span class="application">rsync</span> command for each tablespace directory, e.g.:
  269. </p><pre class="programlisting">
  270. rsync --archive --delete --hard-links --size-only --no-inc-recursive /vol1/pg_tblsp/PG_9.5_201510051 \
  271. /vol1/pg_tblsp/PG_9.6_201608131 standby.example.com:/vol1/pg_tblsp
  272. </pre><p>
  273. If you have relocated <code class="filename">pg_wal</code> outside the data
  274. directories, <span class="application">rsync</span> must be run on those directories
  275. too.
  276. </p></li><li class="step"><p class="title"><strong>Configure streaming replication and log-shipping standby servers</strong></p><p>
  277. Configure the servers for log shipping. (You do not need to run
  278. <code class="function">pg_start_backup()</code> and <code class="function">pg_stop_backup()</code>
  279. or take a file system backup as the standbys are still synchronized
  280. with the primary.)
  281. </p></li></ol></li><li class="step"><p class="title"><strong>Restore <code class="filename">pg_hba.conf</code></strong></p><p>
  282. If you modified <code class="filename">pg_hba.conf</code>, restore its original settings.
  283. It might also be necessary to adjust other configuration files in the new
  284. cluster to match the old cluster, e.g. <code class="filename">postgresql.conf</code>.
  285. </p></li><li class="step"><p class="title"><strong>Start the new server</strong></p><p>
  286. The new server can now be safely started, and then any
  287. <span class="application">rsync</span>'ed standby servers.
  288. </p></li><li class="step"><p class="title"><strong>Post-upgrade processing</strong></p><p>
  289. If any post-upgrade processing is required, pg_upgrade will issue
  290. warnings as it completes. It will also generate script files that must
  291. be run by the administrator. The script files will connect to each
  292. database that needs post-upgrade processing. Each script should be
  293. run using:
  294. </p><pre class="programlisting">
  295. psql --username=postgres --file=script.sql postgres
  296. </pre><p>
  297. The scripts can be run in any order and can be deleted once they have
  298. been run.
  299. </p><div class="caution"><h3 class="title">Caution</h3><p>
  300. In general it is unsafe to access tables referenced in rebuild scripts
  301. until the rebuild scripts have run to completion; doing so could yield
  302. incorrect results or poor performance. Tables not referenced in rebuild
  303. scripts can be accessed immediately.
  304. </p></div></li><li class="step"><p class="title"><strong>Statistics</strong></p><p>
  305. Because optimizer statistics are not transferred by <code class="command">pg_upgrade</code>, you will
  306. be instructed to run a command to regenerate that information at the end
  307. of the upgrade. You might need to set connection parameters to
  308. match your new cluster.
  309. </p></li><li class="step"><p class="title"><strong>Delete old cluster</strong></p><p>
  310. Once you are satisfied with the upgrade, you can delete the old
  311. cluster's data directories by running the script mentioned when
  312. <code class="command">pg_upgrade</code> completes. (Automatic deletion is not
  313. possible if you have user-defined tablespaces inside the old data
  314. directory.) You can also delete the old installation directories
  315. (e.g. <code class="filename">bin</code>, <code class="filename">share</code>).
  316. </p></li><li class="step" id="PGUPGRADE-STEP-REVERT"><p class="title"><strong>Reverting to old cluster</strong></p><p>
  317. If, after running <code class="command">pg_upgrade</code>, you wish to revert to the old cluster,
  318. there are several options:
  319. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
  320. If the <code class="option">--check</code> option was used, the old cluster
  321. was unmodified; it can be restarted.
  322. </p></li><li class="listitem"><p>
  323. If the <code class="option">--link</code> option was <span class="emphasis"><em>not</em></span>
  324. used, the old cluster was unmodified; it can be restarted.
  325. </p></li><li class="listitem"><p>
  326. If the <code class="option">--link</code> option was used, the data
  327. files might be shared between the old and new cluster:
  328. </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
  329. If <code class="command">pg_upgrade</code> aborted before linking started,
  330. the old cluster was unmodified; it can be restarted.
  331. </p></li><li class="listitem"><p>
  332. If you did <span class="emphasis"><em>not</em></span> start the new cluster, the old
  333. cluster was unmodified except that, when linking started, a
  334. <code class="literal">.old</code> suffix was appended to
  335. <code class="filename">$PGDATA/global/pg_control</code>. To reuse the old
  336. cluster, remove the <code class="filename">.old</code> suffix from
  337. <code class="filename">$PGDATA/global/pg_control</code>; you can then restart
  338. the old cluster.
  339. </p></li><li class="listitem"><p>
  340. If you did start the new cluster, it has written to shared files
  341. and it is unsafe to use the old cluster. The old cluster will
  342. need to be restored from backup in this case.
  343. </p></li></ul></div><p>
  344. </p></li></ul></div><p>
  345. </p></li></ol></div></div><div class="refsect1" id="id-1.9.5.12.8"><h2>Notes</h2><p>
  346. <span class="application">pg_upgrade</span> creates various working files, such
  347. as schema dumps, in the current working directory. For security, be sure
  348. that that directory is not readable or writable by any other users.
  349. </p><p>
  350. <span class="application">pg_upgrade</span> launches short-lived postmasters in
  351. the old and new data directories. Temporary Unix socket files for
  352. communication with these postmasters are, by default, made in the current
  353. working directory. In some situations the path name for the current
  354. directory might be too long to be a valid socket name. In that case you
  355. can use the <code class="option">-s</code> option to put the socket files in some
  356. directory with a shorter path name. For security, be sure that that
  357. directory is not readable or writable by any other users.
  358. (This is not relevant on Windows.)
  359. </p><p>
  360. All failure, rebuild, and reindex cases will be reported by
  361. <span class="application">pg_upgrade</span> if they affect your installation;
  362. post-upgrade scripts to rebuild tables and indexes will be
  363. generated automatically. If you are trying to automate the upgrade
  364. of many clusters, you should find that clusters with identical database
  365. schemas require the same post-upgrade steps for all cluster upgrades;
  366. this is because the post-upgrade steps are based on the database
  367. schemas, and not user data.
  368. </p><p>
  369. For deployment testing, create a schema-only copy of the old cluster,
  370. insert dummy data, and upgrade that.
  371. </p><p>
  372. <span class="application">pg_upgrade</span> does not support upgrading of databases
  373. containing table columns using these <code class="type">reg*</code> OID-referencing system data types:
  374. <code class="type">regproc</code>, <code class="type">regprocedure</code>, <code class="type">regoper</code>,
  375. <code class="type">regoperator</code>, <code class="type">regconfig</code>, and
  376. <code class="type">regdictionary</code>. (<code class="type">regtype</code> can be upgraded.)
  377. </p><p>
  378. If you are upgrading a pre-<span class="productname">PostgreSQL</span> 9.2 cluster
  379. that uses a configuration-file-only directory, you must pass the
  380. real data directory location to <span class="application">pg_upgrade</span>, and
  381. pass the configuration directory location to the server, e.g.
  382. <code class="literal">-d /real-data-directory -o '-D /configuration-directory'</code>.
  383. </p><p>
  384. If using a pre-9.1 old server that is using a non-default Unix-domain
  385. socket directory or a default that differs from the default of the
  386. new cluster, set <code class="envar">PGHOST</code> to point to the old server's socket
  387. location. (This is not relevant on Windows.)
  388. </p><p>
  389. If you want to use link mode and you do not want your old cluster
  390. to be modified when the new cluster is started, consider using the clone mode.
  391. If that is not available, make a copy of the
  392. old cluster and upgrade that in link mode. To make a valid copy
  393. of the old cluster, use <code class="command">rsync</code> to create a dirty
  394. copy of the old cluster while the server is running, then shut down
  395. the old server and run <code class="command">rsync --checksum</code> again to update the
  396. copy with any changes to make it consistent. (<code class="option">--checksum</code>
  397. is necessary because <code class="command">rsync</code> only has file modification-time
  398. granularity of one second.) You might want to exclude some
  399. files, e.g. <code class="filename">postmaster.pid</code>, as documented in <a class="xref" href="continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP" title="25.3.3. Making a Base Backup Using the Low Level API">Section 25.3.3</a>. If your file system supports
  400. file system snapshots or copy-on-write file copies, you can use that
  401. to make a backup of the old cluster and tablespaces, though the snapshot
  402. and copies must be created simultaneously or while the database server
  403. is down.
  404. </p></div><div class="refsect1" id="id-1.9.5.12.9"><h2>See Also</h2><span class="simplelist"><a class="xref" href="app-initdb.html" title="initdb"><span class="refentrytitle">initdb</span></a>, <a class="xref" href="app-pg-ctl.html" title="pg_ctl"><span class="refentrytitle"><span class="application">pg_ctl</span></span></a>, <a class="xref" href="app-pgdump.html" title="pg_dump"><span class="refentrytitle">pg_dump</span></a>, <a class="xref" href="app-postgres.html" title="postgres"><span class="refentrytitle"><span class="application">postgres</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="pgtesttiming.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference-server.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="pgwaldump.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="application">pg_test_timing</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">pg_waldump</span></td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1