codekingpro/portable-devtools
115k
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 Vsnapshot" /><link rel="prev" href="pgtesttiming.html" title="pg_test_timing" /><link rel="next" href="pgwaldump.html" title="pg_waldump" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center"><span 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 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="pgwaldump.html" title="pg_waldump">Next</a></td></tr></table><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 data4 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/restore typically required for6 major version upgrades, e.g., from 12.14 to 13.10 or from 14.9 to 15.5.7 It is not required for minor version upgrades, e.g., from 12.7 to 12.88 or from 14.1 to 14.5.9 </p><p>10 Major PostgreSQL releases regularly add new features that often11 change the layout of the system tables, but the internal data storage12 format rarely changes. <span class="application">pg_upgrade</span> uses this fact13 to perform rapid upgrades by creating new system tables and simply14 reusing the old user data files. If a future major release ever15 changes the data storage format in a way that makes the old data16 format unreadable, <span class="application">pg_upgrade</span> will not be usable17 for such upgrades. (The community will attempt to avoid such18 situations.)19 </p><p>20 <span class="application">pg_upgrade</span> does its best to21 make sure the old and new clusters are binary-compatible, e.g., by22 checking for compatible compile-time settings, including 32/64-bit23 binaries. It is important that24 any external modules are also binary compatible, though this cannot25 be checked by <span class="application">pg_upgrade</span>.26 </p><p>27 pg_upgrade supports upgrades from 9.2.X and later to the current28 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 32 </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;33 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;34 default is the directory where <span class="application">pg_upgrade</span> resides;35 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; environment36 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; environment37 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 use38 </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 new39 cluster</p></dd><dt><span class="term"><code class="option">-N</code><br /></span><span class="term"><code class="option">--no-sync</code></span></dt><dd><p>40 By default, <code class="command">pg_upgrade</code> will wait for all files41 of the upgraded cluster to be written safely to disk. This option42 causes <code class="command">pg_upgrade</code> to return without waiting, which43 is faster, but means that a subsequent operating system crash can leave44 the data directory corrupt. Generally, this option is45 useful for testing but should not be used on a production46 installation.47 </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 the48 old <code class="command">postgres</code> command; multiple49 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 the50 new <code class="command">postgres</code> command; multiple51 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; environment52 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; environment53 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 completion54 </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;55 default is current working directory; environment56 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; environment57 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>58 Use efficient file cloning (also known as <span class="quote">“<span class="quote">reflinks</span>”</span> on59 some systems) instead of copying files to the new cluster. This can60 result in near-instantaneous copying of the data files, giving the61 speed advantages of <code class="option">-k</code>/<code class="option">--link</code> while62 leaving the old cluster untouched.63 </p><p>64 File cloning is only supported on some operating systems and file65 systems. If it is selected but not supported, the66 <span class="application">pg_upgrade</span> run will error. At present, it67 is supported on Linux (kernel 4.5 or later) with Btrfs and XFS (on68 file systems created with reflink support), and on macOS with APFS.69 </p></dd><dt><span class="term"><code class="option">--copy</code></span></dt><dd><p>70 Copy files to the new cluster. This is the default. (See also71 <code class="option">--link</code> and <code class="option">--clone</code>.)72 </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>73 </p></div><div class="refsect1" id="id-1.9.5.12.7"><h2>Usage</h2><p>74 These are the steps to perform an upgrade75 with <span class="application">pg_upgrade</span>:76 </p><div class="procedure"><ol class="procedure" type="1"><li class="step"><p class="title"><strong>Optionally move the old cluster</strong></p><p>77 If you are using a version-specific installation directory, e.g.,78 <code class="filename">/opt/PostgreSQL/16</code>, you do not need to move the old cluster. The79 graphical installers all use version-specific installation directories.80 </p><p>81 If your installation directory is not version-specific, e.g.,82 <code class="filename">/usr/local/pgsql</code>, it is necessary to move the current PostgreSQL install83 directory so it does not interfere with the new <span class="productname">PostgreSQL</span> installation.84 Once the current <span class="productname">PostgreSQL</span> server is shut down, it is safe to rename the85 PostgreSQL installation directory; assuming the old directory is86 <code class="filename">/usr/local/pgsql</code>, you can do:87 88</p><pre class="programlisting">89mv /usr/local/pgsql /usr/local/pgsql.old90</pre><p>91 to rename the directory.92 </p></li><li class="step"><p class="title"><strong>For source installs, build the new version</strong></p><p>93 Build the new PostgreSQL source with <code class="command">configure</code> flags that are compatible94 with the old cluster. <span class="application">pg_upgrade</span> will check <code class="command">pg_controldata</code> to make95 sure all settings are compatible before starting the upgrade.96 </p></li><li class="step"><p class="title"><strong>Install the new PostgreSQL binaries</strong></p><p>97 Install the new server's binaries and support98 files. <span class="application">pg_upgrade</span> is included in a default installation.99 </p><p>100 For source installs, if you wish to install the new server in a custom101 location, use the <code class="literal">prefix</code> variable:102 103</p><pre class="programlisting">104make prefix=/usr/local/pgsql.new install105</pre></li><li class="step"><p class="title"><strong>Initialize the new PostgreSQL cluster</strong></p><p>106 Initialize the new cluster using <code class="command">initdb</code>.107 Again, use compatible <code class="command">initdb</code>108 flags that match the old cluster. Many109 prebuilt installers do this step automatically. There is no need to110 start the new cluster.111 </p></li><li class="step"><p class="title"><strong>Install extension shared object files</strong></p><p>112 Many extensions and custom modules, whether from113 <code class="filename">contrib</code> or another source, use shared object114 files (or DLLs), e.g., <code class="filename">pgcrypto.so</code>. If the old115 cluster used these, shared object files matching the new server binary116 must be installed in the new cluster, usually via operating system117 commands. Do not load the schema definitions, e.g., <code class="command">CREATE118 EXTENSION pgcrypto</code>, because these will be duplicated from119 the old cluster. If extension updates are available,120 <span class="application">pg_upgrade</span> will report this and create121 a script that can be run later to update them.122 </p></li><li class="step"><p class="title"><strong>Copy custom full-text search files</strong></p><p>123 Copy any custom full text search files (dictionary, synonym,124 thesaurus, stop words) from the old to the new cluster.125 </p></li><li class="step"><p class="title"><strong>Adjust authentication</strong></p><p>126 <code class="command">pg_upgrade</code> will connect to the old and new servers several127 times, so you might want to set authentication to <code class="literal">peer</code>128 in <code class="filename">pg_hba.conf</code> or use a <code class="filename">~/.pgpass</code> file129 (see <a class="xref" href="libpq-pgpass.html" title="34.16. The Password File">Section 34.16</a>).130 </p></li><li class="step"><p class="title"><strong>Stop both servers</strong></p><p>131 Make sure both database servers are stopped using, on Unix, e.g.:132 133</p><pre class="programlisting">134pg_ctl -D /opt/PostgreSQL/12 stop135pg_ctl -D /opt/PostgreSQL/16 stop136</pre><p>137 138 or on Windows, using the proper service names:139 140</p><pre class="programlisting">141NET STOP postgresql-12142NET STOP postgresql-16143</pre><p>144 </p><p>145 Streaming replication and log-shipping standby servers must be146 running during this shutdown so they receive all changes.147 </p></li><li class="step"><p class="title"><strong>Prepare for standby server upgrades</strong></p><p>148 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 11</a>, verify that the old standby149 servers are caught up by running <span class="application">pg_controldata</span>150 against the old primary and standby clusters. Verify that the151 <span class="quote">“<span class="quote">Latest checkpoint location</span>”</span> values match in all clusters.152 Also, make sure <code class="varname">wal_level</code> is not set to153 <code class="literal">minimal</code> in the <code class="filename">postgresql.conf</code> file on the154 new primary cluster.155 </p></li><li class="step"><p class="title"><strong>Run <span class="application">pg_upgrade</span></strong></p><p>156 Always run the <span class="application">pg_upgrade</span> binary of the new server, not the old one.157 <span class="application">pg_upgrade</span> requires the specification of the old and new cluster's158 data and executable (<code class="filename">bin</code>) directories. You can also specify159 user and port values, and whether you want the data files linked or cloned160 instead of the default copy behavior.161 </p><p>162 If you use link mode, the upgrade will be much faster (no file163 copying) and use less disk space, but you will not be able to access164 your old cluster165 once you start the new cluster after the upgrade. Link mode also166 requires that the old and new cluster data directories be in the167 same file system. (Tablespaces and <code class="filename">pg_wal</code> can be on168 different file systems.)169 Clone mode provides the same speed and disk space advantages but170 does not cause the old cluster to be unusable once the new cluster171 is started. Clone mode also requires that the old and new data172 directories be in the same file system. This mode is only available173 on certain operating systems and file systems.174 </p><p>175 The <code class="option">--jobs</code> option allows multiple CPU cores to be used176 for copying/linking of files and to dump and restore database schemas177 in parallel; a good place to start is the maximum of the number of178 CPU cores and tablespaces. This option can dramatically reduce the179 time to upgrade a multi-database server running on a multiprocessor180 machine.181 </p><p>182 For Windows users, you must be logged into an administrative account, and183 then start a shell as the <code class="literal">postgres</code> user and set the proper path:184 185</p><pre class="programlisting">186RUNAS /USER:postgres "CMD.EXE"187SET PATH=%PATH%;C:\Program Files\PostgreSQL\16\bin;188</pre><p>189 190 and then run <span class="application">pg_upgrade</span> with quoted directories, e.g.:191 192</p><pre class="programlisting">193pg_upgrade.exe194 --old-datadir "C:/Program Files/PostgreSQL/12/data"195 --new-datadir "C:/Program Files/PostgreSQL/16/data"196 --old-bindir "C:/Program Files/PostgreSQL/12/bin"197 --new-bindir "C:/Program Files/PostgreSQL/16/bin"198</pre><p>199 200 Once started, <code class="command">pg_upgrade</code> will verify the two clusters are compatible201 and then do the upgrade. You can use <code class="command">pg_upgrade --check</code>202 to perform only the checks, even if the old server is still203 running. <code class="command">pg_upgrade --check</code> will also outline any204 manual adjustments you will need to make after the upgrade. If you205 are going to be using link or clone mode, you should use the option206 <code class="option">--link</code> or <code class="option">--clone</code> with207 <code class="option">--check</code> to enable mode-specific checks.208 <code class="command">pg_upgrade</code> requires write permission in the current directory.209 </p><p>210 Obviously, no one should be accessing the clusters during the211 upgrade. <span class="application">pg_upgrade</span> defaults to running servers212 on port 50432 to avoid unintended client connections.213 You can use the same port number for both clusters when doing an214 upgrade because the old and new clusters will not be running at the215 same time. However, when checking an old running server, the old216 and new port numbers must be different.217 </p><p>218 If an error occurs while restoring the database schema, <code class="command">pg_upgrade</code> will219 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 17</a>220 below. To try <code class="command">pg_upgrade</code> again, you will need to modify the old221 cluster so the pg_upgrade schema restore succeeds. If the problem is a222 <code class="filename">contrib</code> module, you might need to uninstall the <code class="filename">contrib</code> module from223 the old cluster and install it in the new cluster after the upgrade,224 assuming the module is not being used to store user data.225 </p></li><li class="step" id="PGUPGRADE-STEP-REPLICAS"><p class="title"><strong>Upgrade streaming replication and log-shipping standby servers</strong></p><p>226 If you used link mode and have Streaming Replication (see <a class="xref" href="warm-standby.html#STREAMING-REPLICATION" title="27.2.5. Streaming Replication">Section 27.2.5</a>) or Log-Shipping (see <a class="xref" href="warm-standby.html" title="27.2. Log-Shipping Standby Servers">Section 27.2</a>) standby servers, you can follow these steps to227 quickly upgrade them. You will not be running <span class="application">pg_upgrade</span> on228 the standby servers, but rather <span class="application">rsync</span> on the primary.229 Do not start any servers yet.230 </p><p>231 If you did <span class="emphasis"><em>not</em></span> use link mode, do not have or do not232 want to use <span class="application">rsync</span>, or want an easier solution, skip233 the instructions in this section and simply recreate the standby234 servers once <span class="application">pg_upgrade</span> completes and the new primary235 is running.236 </p><div class="procedure"><ol class="procedure" type="1"><li class="step"><p class="title"><strong>Install the new PostgreSQL binaries on standby servers</strong></p><p>237 Make sure the new binaries and support files are installed on all238 standby servers.239 </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>240 Make sure the new standby data directories do <span class="emphasis"><em>not</em></span>241 exist or are empty. If <span class="application">initdb</span> was run, delete242 the standby servers' new data directories.243 </p></li><li class="step"><p class="title"><strong>Install extension shared object files</strong></p><p>244 Install the same extension shared object files on the new standbys245 that you installed in the new primary cluster.246 </p></li><li class="step"><p class="title"><strong>Stop standby servers</strong></p><p>247 If the standby servers are still running, stop them now using the248 above instructions.249 </p></li><li class="step"><p class="title"><strong>Save configuration files</strong></p><p>250 Save any configuration files from the old standbys' configuration251 directories you need to keep, e.g., <code class="filename">postgresql.conf</code>252 (and any files included by it), <code class="filename">postgresql.auto.conf</code>,253 <code class="literal">pg_hba.conf</code>, because these will be overwritten254 or removed in the next step.255 </p></li><li class="step"><p class="title"><strong>Run <span class="application">rsync</span></strong></p><p>256 When using link mode, standby servers can be quickly upgraded using257 <span class="application">rsync</span>. To accomplish this, from a directory on258 the primary server that is above the old and new database cluster259 directories, run this on the <span class="emphasis"><em>primary</em></span> for each standby260 server:261 262</p><pre class="programlisting">263rsync --archive --delete --hard-links --size-only --no-inc-recursive old_cluster new_cluster remote_dir264</pre><p>265 266 where <code class="option">old_cluster</code> and <code class="option">new_cluster</code> are relative267 to the current directory on the primary, and <code class="option">remote_dir</code>268 is <span class="emphasis"><em>above</em></span> the old and new cluster directories269 on the standby. The directory structure under the specified270 directories on the primary and standbys must match. Consult the271 <span class="application">rsync</span> manual page for details on specifying the272 remote directory, e.g.,273 274</p><pre class="programlisting">275rsync --archive --delete --hard-links --size-only --no-inc-recursive /opt/PostgreSQL/12 \276 /opt/PostgreSQL/16 standby.example.com:/opt/PostgreSQL277</pre><p>278 279 You can verify what the command will do using280 <span class="application">rsync</span>'s <code class="option">--dry-run</code> option. While281 <span class="application">rsync</span> must be run on the primary for at least one282 standby, it is possible to run <span class="application">rsync</span> on an upgraded283 standby to upgrade other standbys, as long as the upgraded standby284 has not been started.285 </p><p>286 What this does is to record the links created by287 <span class="application">pg_upgrade</span>'s link mode that connect files in the288 old and new clusters on the primary server. It then finds matching289 files in the standby's old cluster and creates links for them in the290 standby's new cluster. Files that were not linked on the primary291 are copied from the primary to the standby. (They are usually292 small.) This provides rapid standby upgrades. Unfortunately,293 <span class="application">rsync</span> needlessly copies files associated with294 temporary and unlogged tables because these files don't normally295 exist on standby servers.296 </p><p>297 If you have tablespaces, you will need to run a similar298 <span class="application">rsync</span> command for each tablespace directory, e.g.:299 300</p><pre class="programlisting">301rsync --archive --delete --hard-links --size-only --no-inc-recursive /vol1/pg_tblsp/PG_12_201909212 \302 /vol1/pg_tblsp/PG_16_202307071 standby.example.com:/vol1/pg_tblsp303</pre><p>304 305 If you have relocated <code class="filename">pg_wal</code> outside the data306 directories, <span class="application">rsync</span> must be run on those directories307 too.308 </p></li><li class="step"><p class="title"><strong>Configure streaming replication and log-shipping standby servers</strong></p><p>309 Configure the servers for log shipping. (You do not need to run310 <code class="function">pg_backup_start()</code> and <code class="function">pg_backup_stop()</code>311 or take a file system backup as the standbys are still synchronized312 with the primary.) Replication slots are not copied and must313 be recreated.314 </p></li></ol></div></li><li class="step"><p class="title"><strong>Restore <code class="filename">pg_hba.conf</code></strong></p><p>315 If you modified <code class="filename">pg_hba.conf</code>, restore its original settings.316 It might also be necessary to adjust other configuration files in the new317 cluster to match the old cluster, e.g., <code class="filename">postgresql.conf</code>318 (and any files included by it), <code class="filename">postgresql.auto.conf</code>.319 </p></li><li class="step"><p class="title"><strong>Start the new server</strong></p><p>320 The new server can now be safely started, and then any321 <span class="application">rsync</span>'ed standby servers.322 </p></li><li class="step"><p class="title"><strong>Post-upgrade processing</strong></p><p>323 If any post-upgrade processing is required, pg_upgrade will issue324 warnings as it completes. It will also generate script files that must325 be run by the administrator. The script files will connect to each326 database that needs post-upgrade processing. Each script should be327 run using:328 329</p><pre class="programlisting">330psql --username=postgres --file=script.sql postgres331</pre><p>332 333 The scripts can be run in any order and can be deleted once they have334 been run.335 </p><div class="caution"><h3 class="title">Caution</h3><p>336 In general it is unsafe to access tables referenced in rebuild scripts337 until the rebuild scripts have run to completion; doing so could yield338 incorrect results or poor performance. Tables not referenced in rebuild339 scripts can be accessed immediately.340 </p></div></li><li class="step"><p class="title"><strong>Statistics</strong></p><p>341 Because optimizer statistics are not transferred by <code class="command">pg_upgrade</code>, you will342 be instructed to run a command to regenerate that information at the end343 of the upgrade. You might need to set connection parameters to344 match your new cluster.345 </p></li><li class="step"><p class="title"><strong>Delete old cluster</strong></p><p>346 Once you are satisfied with the upgrade, you can delete the old347 cluster's data directories by running the script mentioned when348 <code class="command">pg_upgrade</code> completes. (Automatic deletion is not349 possible if you have user-defined tablespaces inside the old data350 directory.) You can also delete the old installation directories351 (e.g., <code class="filename">bin</code>, <code class="filename">share</code>).352 </p></li><li class="step" id="PGUPGRADE-STEP-REVERT"><p class="title"><strong>Reverting to old cluster</strong></p><p>353 If, after running <code class="command">pg_upgrade</code>, you wish to revert to the old cluster,354 there are several options:355 356 </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>357 If the <code class="option">--check</code> option was used, the old cluster358 was unmodified; it can be restarted.359 </p></li><li class="listitem"><p>360 If the <code class="option">--link</code> option was <span class="emphasis"><em>not</em></span>361 used, the old cluster was unmodified; it can be restarted.362 </p></li><li class="listitem"><p>363 If the <code class="option">--link</code> option was used, the data364 files might be shared between the old and new cluster:365 366 </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>367 If <code class="command">pg_upgrade</code> aborted before linking started,368 the old cluster was unmodified; it can be restarted.369 </p></li><li class="listitem"><p>370 If you did <span class="emphasis"><em>not</em></span> start the new cluster, the old371 cluster was unmodified except that, when linking started, a372 <code class="literal">.old</code> suffix was appended to373 <code class="filename">$PGDATA/global/pg_control</code>. To reuse the old374 cluster, remove the <code class="filename">.old</code> suffix from375 <code class="filename">$PGDATA/global/pg_control</code>; you can then restart376 the old cluster.377 </p></li><li class="listitem"><p>378 If you did start the new cluster, it has written to shared files379 and it is unsafe to use the old cluster. The old cluster will380 need to be restored from backup in this case.381 </p></li></ul></div></li></ul></div></li></ol></div></div><div class="refsect1" id="id-1.9.5.12.8"><h2>Notes</h2><p>382 <span class="application">pg_upgrade</span> creates various working files, such383 as schema dumps, stored within <code class="filename">pg_upgrade_output.d</code> in384 the directory of the new cluster. Each run creates a new subdirectory named385 with a timestamp formatted as per ISO 8601386 (<code class="literal">%Y%m%dT%H%M%S</code>), where all its generated files are387 stored.388 <code class="filename">pg_upgrade_output.d</code> and its contained files will be389 removed automatically if <span class="application">pg_upgrade</span> completes390 successfully; but in the event of trouble, the files there may provide391 useful debugging information.392 </p><p>393 <span class="application">pg_upgrade</span> launches short-lived postmasters in394 the old and new data directories. Temporary Unix socket files for395 communication with these postmasters are, by default, made in the current396 working directory. In some situations the path name for the current397 directory might be too long to be a valid socket name. In that case you398 can use the <code class="option">-s</code> option to put the socket files in some399 directory with a shorter path name. For security, be sure that that400 directory is not readable or writable by any other users.401 (This is not supported on Windows.)402 </p><p>403 All failure, rebuild, and reindex cases will be reported by404 <span class="application">pg_upgrade</span> if they affect your installation;405 post-upgrade scripts to rebuild tables and indexes will be406 generated automatically. If you are trying to automate the upgrade407 of many clusters, you should find that clusters with identical database408 schemas require the same post-upgrade steps for all cluster upgrades;409 this is because the post-upgrade steps are based on the database410 schemas, and not user data.411 </p><p>412 For deployment testing, create a schema-only copy of the old cluster,413 insert dummy data, and upgrade that.414 </p><p>415 <span class="application">pg_upgrade</span> does not support upgrading of databases416 containing table columns using these <code class="type">reg*</code> OID-referencing system data types:417 </p><table border="0" summary="Simple list" class="simplelist"><tr><td><code class="type">regcollation</code></td></tr><tr><td><code class="type">regconfig</code></td></tr><tr><td><code class="type">regdictionary</code></td></tr><tr><td><code class="type">regnamespace</code></td></tr><tr><td><code class="type">regoper</code></td></tr><tr><td><code class="type">regoperator</code></td></tr><tr><td><code class="type">regproc</code></td></tr><tr><td><code class="type">regprocedure</code></td></tr></table><p>418 (<code class="type">regclass</code>, <code class="type">regrole</code>, and <code class="type">regtype</code> can be upgraded.)419 </p><p>420 If you want to use link mode and you do not want your old cluster421 to be modified when the new cluster is started, consider using the clone mode.422 If that is not available, make a copy of the423 old cluster and upgrade that in link mode. To make a valid copy424 of the old cluster, use <code class="command">rsync</code> to create a dirty425 copy of the old cluster while the server is running, then shut down426 the old server and run <code class="command">rsync --checksum</code> again to update the427 copy with any changes to make it consistent. (<code class="option">--checksum</code>428 is necessary because <code class="command">rsync</code> only has file modification-time429 granularity of one second.) You might want to exclude some430 files, e.g., <code class="filename">postmaster.pid</code>, as documented in <a class="xref" href="continuous-archiving.html#BACKUP-LOWLEVEL-BASE-BACKUP" title="26.3.3. Making a Base Backup Using the Low Level API">Section 26.3.3</a>. If your file system supports431 file system snapshots or copy-on-write file copies, you can use that432 to make a backup of the old cluster and tablespaces, though the snapshot433 and copies must be created simultaneously or while the database server434 is down.435 </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"><span class="application">initdb</span></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"><span class="application">pg_dump</span></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" title="pg_test_timing">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference-server.html" title="PostgreSQL Server Applications">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="pgwaldump.html" title="pg_waldump">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" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> <span class="application">pg_waldump</span></td></tr></table></div></body></html>