1PG_UPGRADE(1)           PostgreSQL 9.2.24 Documentation          PG_UPGRADE(1)
2
3
4

NAME

6       pg_upgrade - upgrade a PostgreSQL server instance
7

SYNOPSIS

9       pg_upgrade -b oldbindir -B newbindir -d olddatadir -D newdatadir
10                  [option...]
11

DESCRIPTION

13       pg_upgrade (formerly called pg_migrator) allows data stored in
14       PostgreSQL data files to be upgraded to a later PostgreSQL major
15       version without the data dump/reload typically required for major
16       version upgrades, e.g. from 8.4.7 to the current major release of
17       PostgreSQL. It is not required for minor version upgrades, e.g. from
18       9.0.1 to 9.0.4.
19
20       Major PostgreSQL releases regularly add new features that often change
21       the layout of the system tables, but the internal data storage format
22       rarely changes.  pg_upgrade uses this fact to perform rapid upgrades by
23       creating new system tables and simply reusing the old user data files.
24       If a future major release ever changes the data storage format in a way
25       that makes the old data format unreadable, pg_upgrade will not be
26       usable for such upgrades. (The community will attempt to avoid such
27       situations.)
28
29       pg_upgrade does its best to make sure the old and new clusters are
30       binary-compatible, e.g. by checking for compatible compile-time
31       settings, including 32/64-bit binaries. It is important that any
32       external modules are also binary compatible, though this cannot be
33       checked by pg_upgrade.
34
35       pg_upgrade supports upgrades from 8.3.X and later to the current major
36       release of PostgreSQL, including snapshot and alpha releases.
37

OPTIONS

39       pg_upgrade accepts the following command-line arguments:
40
41       -b old_bindir, --old-bindir=old_bindir
42           the old cluster executable directory; environment variable PGBINOLD
43
44       -B new_bindir, --new-bindir=new_bindir
45           the new cluster executable directory; environment variable PGBINNEW
46
47       -c, --check
48           check clusters only, don't change any data
49
50       -d old_datadir, --old-datadir=old_datadir
51           the old cluster data directory; environment variable PGDATAOLD
52
53       -D new_datadir, --new-datadir=new_datadir
54           the new cluster data directory; environment variable PGDATANEW
55
56       -k, --link
57           use hard links instead of copying files to the new cluster
58
59       -o options, --old-options options
60           options to be passed directly to the old postgres command
61
62       -O options, --new-options options
63           options to be passed directly to the new postgres command
64
65       -p old_port_number, --old-port=old_portnum
66           the old cluster port number; environment variable PGPORTOLD
67
68       -P new_port_number, --new-port=new_portnum
69           the new cluster port number; environment variable PGPORTNEW
70
71       -r, --retain
72           retain SQL and log files even after successful completion
73
74       -u user_name, --user=user_name
75           cluster's super user name; environment variable PGUSER
76
77       -v, --verbose
78           enable verbose internal logging
79
80       -V, --version
81           display version information, then exit
82
83       -?, -h, --help
84           show help, then exit
85

USAGE

87       These are the steps to perform an upgrade with pg_upgrade:
88
89        1. Optionally move the old cluster: If you are using a
90           version-specific installation directory, e.g.  /opt/PostgreSQL/9.1,
91           you do not need to move the old cluster. The graphical installers
92           all use version-specific installation directories.
93
94           If your installation directory is not version-specific, e.g.
95           /usr/local/pgsql, it is necessary to move the current PostgreSQL
96           install directory so it does not interfere with the new PostgreSQL
97           installation. Once the current PostgreSQL server is shut down, it
98           is safe to rename the PostgreSQL installation directory; assuming
99           the old directory is /usr/local/pgsql, you can do:
100
101               mv /usr/local/pgsql /usr/local/pgsql.old
102
103           to rename the directory.
104
105        2. For source installs, build the new version: Build the new
106           PostgreSQL source with configure flags that are compatible with the
107           old cluster.  pg_upgrade will check pg_controldata to make sure all
108           settings are compatible before starting the upgrade.
109
110        3. Install the new PostgreSQL binaries: Install the new server's
111           binaries and support files.
112
113           For source installs, if you wish to install the new server in a
114           custom location, use the prefix variable:
115
116               gmake prefix=/usr/local/pgsql.new install
117
118        4. Install pg_upgrade and pg_upgrade_support: Install the pg_upgrade
119           binary and pg_upgrade_support library in the new PostgreSQL
120           cluster.
121
122        5. Initialize the new PostgreSQL cluster: Initialize the new cluster
123           using initdb. Again, use compatible initdb flags that match the old
124           cluster. Many prebuilt installers do this step automatically. There
125           is no need to start the new cluster.
126
127        6. Install custom shared object files: Install any custom shared
128           object files (or DLLs) used by the old cluster into the new
129           cluster, e.g.  pgcrypto.so, whether they are from contrib or some
130           other source. Do not install the schema definitions, e.g.
131           pgcrypto.sql, because these will be upgraded from the old cluster.
132
133        7. Adjust authentication: pg_upgrade will connect to the old and new
134           servers several times, so you might want to set authentication to
135           peer in pg_hba.conf or use a ~/.pgpass file (see Section 31.15,
136           “The Password File”, in the documentation).
137
138        8. Stop both servers: Make sure both database servers are stopped
139           using, on Unix, e.g.:
140
141               pg_ctl -D /opt/PostgreSQL/8.4 stop
142               pg_ctl -D /opt/PostgreSQL/9.0 stop
143
144           or on Windows, using the proper service names:
145
146               NET STOP postgresql-8.4
147               NET STOP postgresql-9.0
148
149           or
150
151               NET STOP pgsql-8.3  (PostgreSQL 8.3 and older used a different service name)
152
153        9. Run pg_upgrade: Always run the pg_upgrade binary of the new server,
154           not the old one.  pg_upgrade requires the specification of the old
155           and new cluster's data and executable (bin) directories. You can
156           also specify user and port values, and whether you want the data
157           linked instead of copied (the default).
158
159           If you use link mode, the upgrade will be much faster (no file
160           copying), but you will not be able to access your old cluster once
161           you start the new cluster after the upgrade. Link mode also
162           requires that the old and new cluster data directories be in the
163           same file system. See pg_upgrade --help for a full list of options.
164
165           For Windows users, you must be logged into an administrative
166           account, and then start a shell as the postgres user and set the
167           proper path:
168
169               RUNAS /USER:postgres "CMD.EXE"
170               SET PATH=%PATH%;C:\Program Files\PostgreSQL\9.0\bin;
171
172           and then run pg_upgrade with quoted directories, e.g.:
173
174               pg_upgrade.exe
175                       --old-datadir "C:/Program Files/PostgreSQL/8.4/data"
176                       --new-datadir "C:/Program Files/PostgreSQL/9.0/data"
177                       --old-bindir "C:/Program Files/PostgreSQL/8.4/bin"
178                       --new-bindir "C:/Program Files/PostgreSQL/9.0/bin"
179
180           Once started, pg_upgrade will verify the two clusters are
181           compatible and then do the upgrade. You can use pg_upgrade --check
182           to perform only the checks, even if the old server is still
183           running.  pg_upgrade --check will also outline any manual
184           adjustments you will need to make after the upgrade. If you are
185           going to be using link mode, you should use the --link option with
186           --check to enable link-mode-specific checks.  pg_upgrade requires
187           write permission in the current directory.
188
189           Obviously, no one should be accessing the clusters during the
190           upgrade.  pg_upgrade defaults to running servers on port 50432 to
191           avoid unintended client connections. You can use the same port
192           number for both clusters when doing an upgrade because the old and
193           new clusters will not be running at the same time. However, when
194           checking an old running server, the old and new port numbers must
195           be different.
196
197           If an error occurs while restoring the database schema, pg_upgrade
198           will exit and you will have to revert to the old cluster as
199           outlined in Step 14 below. To try pg_upgrade again, you will need
200           to modify the old cluster so the pg_upgrade schema restore
201           succeeds. If the problem is a contrib module, you might need to
202           uninstall the contrib module from the old cluster and install it in
203           the new cluster after the upgrade, assuming the module is not being
204           used to store user data.
205
206        10. Restore pg_hba.conf: If you modified pg_hba.conf, restore its
207           original settings. It might also be necessary to adjust other
208           configuration files in the new cluster to match the old cluster,
209           e.g.  postgresql.conf.
210
211        11. Post-Upgrade processing: If any post-upgrade processing is
212           required, pg_upgrade will issue warnings as it completes. It will
213           also generate script files that must be run by the administrator.
214           The script files will connect to each database that needs
215           post-upgrade processing. Each script should be run using:
216
217               psql --username postgres --file script.sql postgres
218
219           The scripts can be run in any order and can be deleted once they
220           have been run.
221
222               Caution
223               In general it is unsafe to access tables referenced in rebuild
224               scripts until the rebuild scripts have run to completion; doing
225               so could yield incorrect results or poor performance. Tables
226               not referenced in rebuild scripts can be accessed immediately.
227
228        12. Statistics: Because optimizer statistics are not transferred by
229           pg_upgrade, you will be instructed to run a command to regenerate
230           that information at the end of the upgrade.
231
232        13. Delete old cluster: Once you are satisfied with the upgrade, you
233           can delete the old cluster's data directories by running the script
234           mentioned when pg_upgrade completes. You can also delete the old
235           installation directories (e.g.  bin, share).
236
237        14. Reverting to old cluster: If, after running pg_upgrade, you wish
238           to revert to the old cluster, there are several options:
239
240           ·   If you ran pg_upgrade with --check, no modifications were made
241               to the old cluster and you can re-use it anytime.
242
243           ·   If you ran pg_upgrade with --link, the data files are shared
244               between the old and new cluster. If you started the new
245               cluster, the new server has written to those shared files and
246               it is unsafe to use the old cluster.
247
248           ·   If you ran pg_upgradewithout--link or did not start the new
249               server, the old cluster was not modified except that, if
250               linking started, a .old suffix was appended to
251               $PGDATA/global/pg_control. To reuse the old cluster, possibly
252               remove the .old suffix from $PGDATA/global/pg_control; you can
253               then restart the old cluster.
254
255

NOTES

257       pg_upgrade does not support upgrading of databases containing these
258       reg* OID-referencing system data types: regproc, regprocedure, regoper,
259       regoperator, regconfig, and regdictionary. (regtype can be upgraded.)
260
261       All failure, rebuild, and reindex cases will be reported by pg_upgrade
262       if they affect your installation; post-upgrade scripts to rebuild
263       tables and indexes will be generated automatically.
264
265       For deployment testing, create a schema-only copy of the old cluster,
266       insert dummy data, and upgrade that.
267
268       If you are upgrading a pre-PostgreSQL 9.2 cluster that uses a
269       configuration-file-only directory, you must pass the real data
270       directory location to pg_upgrade, and pass the configuration directory
271       location to the server, e.g.  -d /real-data-directory -o '-D
272       /configuration-directory'.
273
274       If using a pre-9.1 old server that is using a non-default Unix-domain
275       socket directory or a default that differs from the default of the new
276       cluster, set PGHOST to point to the old server's socket location. (This
277       is not relevant on Windows.)
278
279       A Log-Shipping Standby Server (Section 25.2, “Log-Shipping Standby
280       Servers”, in the documentation) cannot be upgraded because the server
281       must allow writes. The simplest way is to upgrade the primary and use
282       rsync to rebuild the standbys. You can run rsync while the primary is
283       down, or as part of a base backup (Section 24.3.2, “Making a Base
284       Backup”, in the documentation) which overwrites the old standby
285       cluster.
286
287       If you want to use link mode and you do not want your old cluster to be
288       modified when the new cluster is started, make a copy of the old
289       cluster and upgrade that in link mode. To make a valid copy of the old
290       cluster, use rsync to create a dirty copy of the old cluster while the
291       server is running, then shut down the old server and run rsync again to
292       update the copy with any changes to make it consistent. You might want
293       to exclude some files, e.g.  postmaster.pid, as documented in Section
294       24.3.3, “Making a Base Backup Using the Low Level API”, in the
295       documentation.
296
297   Limitations in Upgrading from PostgreSQL 8.3
298       Upgrading from PostgreSQL 8.3 has additional restrictions not present
299       when upgrading from later PostgreSQL releases. For example, pg_upgrade
300       will not work for upgrading from 8.3 if a user column is defined as:
301
302       ·   a tsquery data type
303
304       ·   data type name and is not the first column
305
306       You must drop any such columns and upgrade them manually.
307
308       pg_upgrade will not work if the ltree contrib module is installed in a
309       database.
310
311       pg_upgrade will require a table rebuild if:
312
313       ·   a user column is of data type tsvector
314
315       pg_upgrade will require a reindex if:
316
317       ·   an index is of type hash or GIN
318
319       ·   an index uses bpchar_pattern_ops
320
321       Also, the default datetime storage format changed to integer after
322       PostgreSQL 8.3. pg_upgrade will check that the datetime storage format
323       used by the old and new clusters match. Make sure your new cluster is
324       built with the configure flag --disable-integer-datetimes.
325
326       For Windows users, note that due to different integer datetimes
327       settings used by the graphical installer and the MSI installer, it is
328       only possible to upgrade from version 8.3 of the installer distribution
329       to version 8.4 or later of the installer distribution. It is not
330       possible to upgrade from the MSI installer to the new graphical
331       installer.
332

SEE ALSO

334       initdb(1), pg_ctl(1), pg_dump(1), postgres(1)
335
336
337
338PostgreSQL 9.2.24                 2017-11-06                     PG_UPGRADE(1)
Impressum