gooderp18绿色标准版
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

191 line
15KB

  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>18.6. Upgrading a PostgreSQL Cluster</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="server-shutdown.html" title="18.5. Shutting Down the Server" /><link rel="next" href="preventing-server-spoofing.html" title="18.7. Preventing Server Spoofing" /></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">18.6. Upgrading a <span xmlns="http://www.w3.org/1999/xhtml" class="productname">PostgreSQL</span> Cluster</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="server-shutdown.html" title="18.5. Shutting Down the Server">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="runtime.html" title="Chapter 18. Server Setup and Operation">Up</a></td><th width="60%" align="center">Chapter 18. Server Setup and Operation</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="preventing-server-spoofing.html" title="18.7. Preventing Server Spoofing">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="UPGRADING"><div class="titlepage"><div><div><h2 class="title" style="clear: both">18.6. Upgrading a <span class="productname">PostgreSQL</span> Cluster</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="upgrading.html#UPGRADING-VIA-PGDUMPALL">18.6.1. Upgrading Data via <span class="application">pg_dumpall</span></a></span></dt><dt><span class="sect2"><a href="upgrading.html#UPGRADING-VIA-PG-UPGRADE">18.6.2. Upgrading Data via <span class="application">pg_upgrade</span></a></span></dt><dt><span class="sect2"><a href="upgrading.html#UPGRADING-VIA-REPLICATION">18.6.3. Upgrading Data via Replication</a></span></dt></dl></div><a id="id-1.6.5.8.2" class="indexterm"></a><a id="id-1.6.5.8.3" class="indexterm"></a><p>
  3. This section discusses how to upgrade your database data from one
  4. <span class="productname">PostgreSQL</span> release to a newer one.
  5. </p><p>
  6. Current <span class="productname">PostgreSQL</span> version numbers consist of a
  7. major and a minor version number. For example, in the version number 10.1,
  8. the 10 is the major version number and the 1 is the minor version number,
  9. meaning this would be the first minor release of the major release 10. For
  10. releases before <span class="productname">PostgreSQL</span> version 10.0, version
  11. numbers consist of three numbers, for example, 9.5.3. In those cases, the
  12. major version consists of the first two digit groups of the version number,
  13. e.g., 9.5, and the minor version is the third number, e.g., 3, meaning this
  14. would be the third minor release of the major release 9.5.
  15. </p><p>
  16. Minor releases never change the internal storage format and are always
  17. compatible with earlier and later minor releases of the same major version
  18. number. For example, version 10.1 is compatible with version 10.0 and
  19. version 10.6. Similarly, for example, 9.5.3 is compatible with 9.5.0,
  20. 9.5.1, and 9.5.6. To update between compatible versions, you simply
  21. replace the executables while the server is down and restart the server.
  22. The data directory remains unchanged — minor upgrades are that
  23. simple.
  24. </p><p>
  25. For <span class="emphasis"><em>major</em></span> releases of <span class="productname">PostgreSQL</span>, the
  26. internal data storage format is subject to change, thus complicating
  27. upgrades. The traditional method for moving data to a new major version
  28. is to dump and reload the database, though this can be slow. A
  29. faster method is <a class="xref" href="pgupgrade.html" title="pg_upgrade"><span class="refentrytitle"><span class="application">pg_upgrade</span></span></a>. Replication methods are
  30. also available, as discussed below.
  31. </p><p>
  32. New major versions also typically introduce some user-visible
  33. incompatibilities, so application programming changes might be required.
  34. All user-visible changes are listed in the release notes (<a class="xref" href="release.html" title="Appendix E. Release Notes">Appendix E</a>); pay particular attention to the section
  35. labeled "Migration". If you are upgrading across several major
  36. versions, be sure to read the release notes for each intervening
  37. version.
  38. </p><p>
  39. Cautious users will want to test their client applications on the new
  40. version before switching over fully; therefore, it's often a good idea to
  41. set up concurrent installations of old and new versions. When
  42. testing a <span class="productname">PostgreSQL</span> major upgrade, consider the
  43. following categories of possible changes:
  44. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">Administration</span></dt><dd><p>
  45. The capabilities available for administrators to monitor and control
  46. the server often change and improve in each major release.
  47. </p></dd><dt><span class="term">SQL</span></dt><dd><p>
  48. Typically this includes new SQL command capabilities and not changes
  49. in behavior, unless specifically mentioned in the release notes.
  50. </p></dd><dt><span class="term">Library API</span></dt><dd><p>
  51. Typically libraries like <span class="application">libpq</span> only add new
  52. functionality, again unless mentioned in the release notes.
  53. </p></dd><dt><span class="term">System Catalogs</span></dt><dd><p>
  54. System catalog changes usually only affect database management tools.
  55. </p></dd><dt><span class="term">Server C-language API</span></dt><dd><p>
  56. This involves changes in the backend function API, which is written
  57. in the C programming language. Such changes affect code that
  58. references backend functions deep inside the server.
  59. </p></dd></dl></div><div class="sect2" id="UPGRADING-VIA-PGDUMPALL"><div class="titlepage"><div><div><h3 class="title">18.6.1. Upgrading Data via <span class="application">pg_dumpall</span></h3></div></div></div><p>
  60. One upgrade method is to dump data from one major version of
  61. <span class="productname">PostgreSQL</span> and reload it in another — to do
  62. this, you must use a <span class="emphasis"><em>logical</em></span> backup tool like
  63. <span class="application">pg_dumpall</span>; file system
  64. level backup methods will not work. (There are checks in place that prevent
  65. you from using a data directory with an incompatible version of
  66. <span class="productname">PostgreSQL</span>, so no great harm can be done by
  67. trying to start the wrong server version on a data directory.)
  68. </p><p>
  69. It is recommended that you use the <span class="application">pg_dump</span> and
  70. <span class="application">pg_dumpall</span> programs from the <span class="emphasis"><em>newer</em></span>
  71. version of
  72. <span class="productname">PostgreSQL</span>, to take advantage of enhancements
  73. that might have been made in these programs. Current releases of the
  74. dump programs can read data from any server version back to 7.0.
  75. </p><p>
  76. These instructions assume that your existing installation is under the
  77. <code class="filename">/usr/local/pgsql</code> directory, and that the data area is in
  78. <code class="filename">/usr/local/pgsql/data</code>. Substitute your paths
  79. appropriately.
  80. </p><div class="procedure"><ol class="procedure" type="1"><li class="step"><p>
  81. If making a backup, make sure that your database is not being updated.
  82. This does not affect the integrity of the backup, but the changed
  83. data would of course not be included. If necessary, edit the
  84. permissions in the file <code class="filename">/usr/local/pgsql/data/pg_hba.conf</code>
  85. (or equivalent) to disallow access from everyone except you.
  86. See <a class="xref" href="client-authentication.html" title="Chapter 20. Client Authentication">Chapter 20</a> for additional information on
  87. access control.
  88. </p><p>
  89. <a id="id-1.6.5.8.11.5.1.2.1" class="indexterm"></a>
  90. To back up your database installation, type:
  91. </p><pre class="screen">
  92. <strong class="userinput"><code>pg_dumpall &gt; <em class="replaceable"><code>outputfile</code></em></code></strong>
  93. </pre><p>
  94. </p><p>
  95. To make the backup, you can use the <span class="application">pg_dumpall</span>
  96. command from the version you are currently running; see <a class="xref" href="backup-dump.html#BACKUP-DUMP-ALL" title="25.1.2. Using pg_dumpall">Section 25.1.2</a> for more details. For best
  97. results, however, try to use the <span class="application">pg_dumpall</span>
  98. command from <span class="productname">PostgreSQL</span> 12.4,
  99. since this version contains bug fixes and improvements over older
  100. versions. While this advice might seem idiosyncratic since you
  101. haven't installed the new version yet, it is advisable to follow
  102. it if you plan to install the new version in parallel with the
  103. old version. In that case you can complete the installation
  104. normally and transfer the data later. This will also decrease
  105. the downtime.
  106. </p></li><li class="step"><p>
  107. Shut down the old server:
  108. </p><pre class="screen">
  109. <strong class="userinput"><code>pg_ctl stop</code></strong>
  110. </pre><p>
  111. On systems that have <span class="productname">PostgreSQL</span> started at boot time,
  112. there is probably a start-up file that will accomplish the same thing. For
  113. example, on a <span class="systemitem">Red Hat Linux</span> system one
  114. might find that this works:
  115. </p><pre class="screen">
  116. <strong class="userinput"><code>/etc/rc.d/init.d/postgresql stop</code></strong>
  117. </pre><p>
  118. See <a class="xref" href="runtime.html" title="Chapter 18. Server Setup and Operation">Chapter 18</a> for details about starting and
  119. stopping the server.
  120. </p></li><li class="step"><p>
  121. If restoring from backup, rename or delete the old installation
  122. directory if it is not version-specific. It is a good idea to
  123. rename the directory, rather than
  124. delete it, in case you have trouble and need to revert to it. Keep
  125. in mind the directory might consume significant disk space. To rename
  126. the directory, use a command like this:
  127. </p><pre class="screen">
  128. <strong class="userinput"><code>mv /usr/local/pgsql /usr/local/pgsql.old</code></strong>
  129. </pre><p>
  130. (Be sure to move the directory as a single unit so relative paths
  131. remain unchanged.)
  132. </p></li><li class="step"><p>
  133. Install the new version of <span class="productname">PostgreSQL</span> as
  134. outlined in <a class="xref" href="install-procedure.html" title="16.4. Installation Procedure">Section 16.4</a>.
  135. </p></li><li class="step"><p>
  136. Create a new database cluster if needed. Remember that you must
  137. execute these commands while logged in to the special database user
  138. account (which you already have if you are upgrading).
  139. </p><pre class="programlisting">
  140. <strong class="userinput"><code>/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data</code></strong>
  141. </pre><p>
  142. </p></li><li class="step"><p>
  143. Restore your previous <code class="filename">pg_hba.conf</code> and any
  144. <code class="filename">postgresql.conf</code> modifications.
  145. </p></li><li class="step"><p>
  146. Start the database server, again using the special database user
  147. account:
  148. </p><pre class="programlisting">
  149. <strong class="userinput"><code>/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data</code></strong>
  150. </pre><p>
  151. </p></li><li class="step"><p>
  152. Finally, restore your data from backup with:
  153. </p><pre class="screen">
  154. <strong class="userinput"><code>/usr/local/pgsql/bin/psql -d postgres -f <em class="replaceable"><code>outputfile</code></em></code></strong>
  155. </pre><p>
  156. using the <span class="emphasis"><em>new</em></span> <span class="application">psql</span>.
  157. </p></li></ol></div><p>
  158. The least downtime can be achieved by installing the new server in
  159. a different directory and running both the old and the new servers
  160. in parallel, on different ports. Then you can use something like:
  161. </p><pre class="programlisting">
  162. pg_dumpall -p 5432 | psql -d postgres -p 5433
  163. </pre><p>
  164. to transfer your data.
  165. </p></div><div class="sect2" id="UPGRADING-VIA-PG-UPGRADE"><div class="titlepage"><div><div><h3 class="title">18.6.2. Upgrading Data via <span class="application">pg_upgrade</span></h3></div></div></div><p>
  166. The <a class="xref" href="pgupgrade.html" title="pg_upgrade"><span class="refentrytitle"><span class="application">pg_upgrade</span></span></a> module allows an installation to
  167. be migrated in-place from one major <span class="productname">PostgreSQL</span>
  168. version to another. Upgrades can be performed in minutes,
  169. particularly with <code class="option">--link</code> mode. It requires steps similar to
  170. <span class="application">pg_dumpall</span> above, e.g. starting/stopping the server,
  171. running <span class="application">initdb</span>. The <span class="application">pg_upgrade</span> <a class="link" href="pgupgrade.html" title="pg_upgrade">documentation</a> outlines the necessary steps.
  172. </p></div><div class="sect2" id="UPGRADING-VIA-REPLICATION"><div class="titlepage"><div><div><h3 class="title">18.6.3. Upgrading Data via Replication</h3></div></div></div><p>
  173. It is also possible to use logical replication methods to create a standby
  174. server with the updated version of <span class="productname">PostgreSQL</span>.
  175. This is possible because logical replication supports
  176. replication between different major versions of
  177. <span class="productname">PostgreSQL</span>. The standby can be on the same computer or
  178. a different computer. Once it has synced up with the master server
  179. (running the older version of <span class="productname">PostgreSQL</span>), you can
  180. switch masters and make the standby the master and shut down the older
  181. database instance. Such a switch-over results in only several seconds
  182. of downtime for an upgrade.
  183. </p><p>
  184. This method of upgrading can be performed using the built-in logical
  185. replication facilities as well as using external logical replication
  186. systems such as <span class="productname">pglogical</span>,
  187. <span class="productname">Slony</span>, <span class="productname">Londiste</span>, and
  188. <span class="productname">Bucardo</span>.
  189. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="server-shutdown.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="runtime.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="preventing-server-spoofing.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">18.5. Shutting Down the Server </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 18.7. Preventing Server Spoofing</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1