-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpgupgrade.sgml
572 lines (474 loc) · 18.9 KB
/
pgupgrade.sgml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
<!-- doc/src/sgml/pgupgrade.sgml -->
<sect1 id="pgupgrade" xreflabel="pg_upgrade">
<title>pg_upgrade</title>
<indexterm zone="pgupgrade">
<primary>pg_upgrade</primary>
</indexterm>
<para>
<application>pg_upgrade</> (formerly called <application>pg_migrator</>) allows data
stored in <productname>PostgreSQL</> data files to be upgraded to a later <productname>PostgreSQL</>
major version without the data dump/reload typically required for
major version upgrades, e.g. from 8.4.7 to the current major release
of <productname>PostgreSQL</>. It is not required for minor version upgrades, e.g. from
9.0.1 to 9.0.4.
</para>
<para>
Major PostgreSQL releases regularly add new features that often
change the layout of the system tables, but the internal data storage
format rarely changes. <application>pg_upgrade</> uses this fact
to perform rapid upgrades by creating new system tables and simply
reusing the old user data files. If a future major release ever
changes the data storage format in a way that makes the old data
format unreadable, <application>pg_upgrade</> will not be usable
for such upgrades. (The community will attempt to avoid such
situations.)
</para>
<para>
<application>pg_upgrade</> does its best to
make sure the old and new clusters are binary-compatible, e.g. by
checking for compatible compile-time settings, including 32/64-bit
binaries. It is important that
any external modules are also binary compatible, though this cannot
be checked by <application>pg_upgrade</>.
</para>
<sect2>
<title>Supported Versions</title>
<para>
pg_upgrade supports upgrades from 8.3.X and later to the current
major release of <productname>PostgreSQL</>, including snapshot and alpha releases.
</para>
</sect2>
<sect2>
<title><application>pg_upgrade</> Options</title>
<para>
<application>pg_upgrade</application> accepts the following command-line arguments:
<variablelist>
<varlistentry>
<term><option>-b</option> <replaceable>old_bindir</></term>
<term><option>--old-bindir=</option><replaceable>old_bindir</></term>
<listitem><para>the old cluster executable directory;
environment variable <envar>OLDBINDIR</></para></listitem>
</varlistentry>
<varlistentry>
<term><option>-B</option> <replaceable>new_bindir</></term>
<term><option>--new-bindir=</option><replaceable>new_bindir</></term>
<listitem><para>the new cluster executable directory;
environment variable <envar>NEWBINDIR</></para></listitem>
</varlistentry>
<varlistentry>
<term><option>-c</option></term>
<term><option>--check</option></term>
<listitem><para>check clusters only, don't change any data</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-d</option> <replaceable>old_datadir</></term>
<term><option>--old-datadir=</option><replaceable>old_datadir</></term>
<listitem><para>the old cluster data directory; environment
variable <envar>OLDDATADIR</></para></listitem>
</varlistentry>
<varlistentry>
<term><option>-D</option> <replaceable>new_datadir</></term>
<term><option>--new-datadir=</option><replaceable>new_datadir</></term>
<listitem><para>the new cluster data directory; environment
variable <envar>NEWDATADIR</></para></listitem>
</varlistentry>
<varlistentry>
<term><option>-g</option></term>
<term><option>--debug</option></term>
<listitem><para>enable debugging</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-G</option> <replaceable>debug_filename</></term>
<term><option>--debugfile=</option><replaceable>debug_filename</></term>
<listitem><para>output debugging activity to file</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-k</option></term>
<term><option>--link</option></term>
<listitem><para>use hard links instead of copying files to the new cluster</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-l</option> <replaceable>log_filename</></term>
<term><option>--logfile=</option><replaceable>log_filename</></term>
<listitem><para>log session activity to file</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-p</option> <replaceable>old_port_number</></term>
<term><option>--old-port=</option><replaceable>old_portnum</></term>
<listitem><para>the old cluster port number; environment
variable <envar>PGPORT</></para></listitem>
</varlistentry>
<varlistentry>
<term><option>-P</option> <replaceable>new_port_number</></term>
<term><option>--new-port=</option><replaceable>new_portnum</></term>
<listitem><para>the new cluster port number; environment
variable <envar>PGPORT</></para></listitem>
</varlistentry>
<varlistentry>
<term><option>-u</option> <replaceable>user_name</></term>
<term><option>--user=</option><replaceable>user_name</></term>
<listitem><para>cluster's super user name; environment
variable <envar>PGUSER</></para></listitem>
</varlistentry>
<varlistentry>
<term><option>-v</option></term>
<term><option>--verbose</option></term>
<listitem><para>enable verbose output</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-V</option></term>
<term><option>--version</option></term>
<listitem><para>display version information, then exit</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-?</option></term>
<term><option>-h</option></term>
<term><option>--help</option></term>
<listitem><para>show help, then exit</para></listitem>
</varlistentry>
</variablelist>
</para>
</sect2>
<sect2>
<title>Upgrade Steps</title>
<procedure>
<step performance="optional">
<title>Optionally move the old cluster</title>
<para>
If you are using a version-specific installation directory, e.g.
<filename>/opt/PostgreSQL/8.4</>, you do not need to move the old cluster. The
one-click installers all use version-specific installation directories.
</para>
<para>
If your installation directory is not version-specific, e.g.
<filename>/usr/local/pgsql</>, it is necessary to move the current PostgreSQL install
directory so it does not interfere with the new <productname>PostgreSQL</> installation.
Once the current <productname>PostgreSQL</> server is shut down, it is safe to rename the
PostgreSQL installation directory; assuming the old directory is
<filename>/usr/local/pgsql</>, you can do:
<programlisting>
mv /usr/local/pgsql /usr/local/pgsql.old
</programlisting>
to rename the directory.
</para>
</step>
<step>
<title>For source installs, build the new version</title>
<para>
Build the new PostgreSQL source with <command>configure</> flags that are compatible
with the old cluster. <application>pg_upgrade</> will check <command>pg_controldata</> to make
sure all settings are compatible before starting the upgrade.
</para>
</step>
<step>
<title>Install the new PostgreSQL binaries</title>
<para>
Install the new server's binaries and support files. You can use the
same port numbers for both clusters, typically 5432, because the old and
new clusters will not be running at the same time.
</para>
<para>
For source installs, if you wish to install the new server in a custom
location, use the <literal>prefix</literal> variable:
<programlisting>
gmake prefix=/usr/local/pgsql.new install
</programlisting>
</para>
</step>
<step>
<title>Install pg_upgrade and pg_upgrade_support</title>
<para>
Install the <application>pg_upgrade</> binary and
<application>pg_upgrade_support</> library in the new PostgreSQL cluster.
</para>
</step>
<step>
<title>Initialize the new PostgreSQL cluster</title>
<para>
Initialize the new cluster using <command>initdb</command>.
Again, use compatible <command>initdb</command>
flags that match the old cluster. Many
prebuilt installers do this step automatically. There is no need to
start the new cluster.
</para>
</step>
<step>
<title>Install custom shared object files</title>
<para>
Install any custom shared object files (or DLLs) used by the old cluster
into the new cluster, e.g. <filename>pgcrypto.so</filename>, whether they are from <filename>contrib</filename>
or some other source. Do not install the schema definitions, e.g.
<filename>pgcrypto.sql</>, because these will be upgraded from the old cluster.
</para>
</step>
<step>
<title>Adjust authentication</title>
<para>
<command>pg_upgrade</> will connect to the old and new servers several times,
so you might want to set authentication to <literal>trust</> in
<filename>pg_hba.conf</>, or if using <literal>md5</> authentication,
use a <filename>~/.pgpass</> file (see <xref linkend="libpq-pgpass">)
to avoid being prompted repeatedly for a password.
</para>
</step>
<step>
<title>Stop both servers</title>
<para>
Make sure both database servers are stopped using, on Unix, e.g.:
<programlisting>
pg_ctl -D /opt/PostgreSQL/8.4 stop
pg_ctl -D /opt/PostgreSQL/9.0 stop
</programlisting>
or on Windows, using the proper service names:
<programlisting>
NET STOP postgresql-8.4
NET STOP postgresql-9.0
</programlisting>
or
<programlisting>
NET STOP pgsql-8.3 (<productname>PostgreSQL</> 8.3 and older used a different service name)
</programlisting>
</para>
</step>
<step>
<title>Run <application>pg_upgrade</></title>
<para>
Always run the <application>pg_upgrade</> binary of the new server, not the old one.
<application>pg_upgrade</> requires the specification of the old and new cluster's
data and executable (<filename>bin</>) directories. You can also specify
user and port values, and whether you want the data linked instead of
copied (the default).
</para>
<para>
If you use link mode, the upgrade will be much faster (no file
copying), but you will not be able to access your old cluster
once you start the new cluster after the upgrade. Link mode also
requires that the old and new cluster data directories be in the
same file system. See <literal>pg_upgrade --help</> for a full
list of options.
</para>
<para>
For Windows users, you must be logged into an administrative account, and
then start a shell as the <literal>postgres</> user and set the proper path:
<programlisting>
RUNAS /USER:postgres "CMD.EXE"
SET PATH=%PATH%;C:\Program Files\PostgreSQL\9.0\bin;
</programlisting>
and then run <application>pg_upgrade</> with quoted directories, e.g.:
<programlisting>
pg_upgrade.exe
--old-datadir "C:/Program Files/PostgreSQL/8.4/data"
--new-datadir "C:/Program Files/PostgreSQL/9.0/data"
--old-bindir "C:/Program Files/PostgreSQL/8.4/bin"
--new-bindir "C:/Program Files/PostgreSQL/9.0/bin"
</programlisting>
Once started, <command>pg_upgrade</> will verify the two clusters are compatible
and then do the upgrade. You can use <command>pg_upgrade --check</>
to perform only the checks, even if the old server is still
running. <command>pg_upgrade --check</> will also outline any
manual adjustments you will need to make after the upgrade.
<command>pg_upgrade</> requires write permission in the current directory.
</para>
<para>
Obviously, no one should be accessing the clusters during the upgrade.
Consider using a non-default port number, e.g. 50432, for old
and new clusters to avoid unintended client connections during
the upgrade.
</para>
<para>
If an error occurs while restoring the database schema, <command>pg_upgrade</> will
exit and you will have to revert to the old cluster as outlined in <xref linkend="pgupgrade-step-revert">
below. To try <command>pg_upgrade</command> again, you will need to modify the old
cluster so the pg_upgrade schema restore succeeds. If the problem is a
contrib module, you might need to uninstall the contrib module from
the old cluster and install it in the new cluster after the upgrade,
assuming the module is not being used to store user data.
</para>
</step>
<step>
<title>Restore <filename>pg_hba.conf</></title>
<para>
If you modified <filename>pg_hba.conf</> to use <literal>trust</>,
restore its original authentication settings.
</para>
</step>
<step>
<title>Post-Upgrade processing</title>
<para>
If any post-upgrade processing is required, pg_upgrade will issue
warnings as it completes. It will also generate script files that must
be run by the administrator. The script files will connect to each
database that needs post-upgrade processing. Each script should be
run using:
<programlisting>
psql --username postgres --file script.sql postgres
</programlisting>
The scripts can be run in any order and can be deleted once they have
been run.
</para>
<caution>
<para>
In general it is unsafe to access tables referenced in rebuild scripts
until the rebuild scripts have run to completion; doing so could yield
incorrect results or poor performance. Tables not referenced in rebuild
scripts can be accessed immediately.
</para>
</caution>
</step>
<step>
<title>Statistics</title>
<para>
Because optimizer statistics are not transferred by <command>pg_upgrade</>, you will
be instructed to run a command to regenerate that information at the end
of the upgrade.
</para>
</step>
<step>
<title>Delete old cluster</title>
<para>
Once you are satisfied with the upgrade, you can delete the old
cluster's data directories by running the script mentioned when
<command>pg_upgrade</command> completes. You can also delete the
old installation directories
(e.g. <filename>bin</>, <filename>share</>).
</para>
</step>
<step id="pgupgrade-step-revert" performance="optional">
<title>Reverting to old cluster</title>
<para>
If, after running <command>pg_upgrade</command>, you wish to revert to the old cluster,
there are several options:
<itemizedlist>
<listitem>
<para>
If you ran <command>pg_upgrade</command>
with <option>--check</>, no modifications were made to the old
cluster and you can re-use it anytime.
</para>
</listitem>
<listitem>
<para>
If you ran <command>pg_upgrade</command>
with <option>--link</>, the data files are shared between the
old and new cluster. If you started the new cluster, the new
server has written to those shared files and it is unsafe to
use the old cluster.
</para>
</listitem>
<listitem>
<para>
If you
ran <command>pg_upgrade</command> <emphasis>without</> <option>--link</>
or did not start the new server, the old cluster was not
modified except that an <literal>.old</> suffix was appended
to <filename>$PGDATA/global/pg_control</> and perhaps
tablespace directories. To reuse the old cluster, remove
the <filename>.old</> suffix
from <filename>$PGDATA/global/pg_control</>. and, if upgrading
to 8.4 or earlier, remove the tablespace directories created
by the upgrade and remove the <filename>.old</> suffix from
the tablespace directory names; then you can restart the old
cluster.
</para>
</listitem>
</itemizedlist>
</para>
</step>
</procedure>
</sect2>
<sect2>
<title>Limitations in Upgrading <emphasis>from</> PostgreSQL 8.3</title>
<para>
Upgrading from PostgreSQL 8.3 has additional restrictions not present
when upgrading from later PostgreSQL releases. For example,
pg_upgrade will not work for upgrading from 8.3 if a user column
is defined as:
<itemizedlist>
<listitem>
<para>
a <type>tsquery</> data type
</para>
</listitem>
<listitem>
<para>
data type <type>name</> and is not the first column
</para>
</listitem>
</itemizedlist>
</para>
<para>
You must drop any such columns and upgrade them manually.
</para>
<para>
pg_upgrade will not work if the <filename>ltree</>
contrib module is installed in a database.
</para>
<para>
pg_upgrade will require a table rebuild if:
<itemizedlist>
<listitem>
<para>
a user column is of data type <type>tsvector</type>
</para>
</listitem>
</itemizedlist>
</para>
<para>
pg_upgrade will require a reindex if:
<itemizedlist>
<listitem>
<para>
an index is of type hash or GIN
</para>
</listitem>
<listitem>
<para>
an index uses <function>bpchar_pattern_ops</>
</para>
</listitem>
</itemizedlist>
</para>
<para>
Also, the default datetime storage format changed to integer after
<productname>PostgreSQL</> 8.3. pg_upgrade will check that the datetime storage format
used by the old and new clusters match. Make sure your new cluster is
built with the configure flag <option>--disable-integer-datetimes</>.
</para>
<para>
For Windows users, note that due to different integer datetimes settings
used by the one-click installer and the MSI installer, it is only
possible to upgrade from version 8.3 of the one-click distribution to
version 8.4 or later of the one-click distribution. It is not
possible to upgrade from the MSI installer to the one-click installer.
</para>
</sect2>
<sect2>
<title>Notes</title>
<para>
<application>pg_upgrade</> does not support upgrading of databases
containing these <type>reg*</> OID-referencing system data types:
<type>regproc</>, <type>regprocedure</>, <type>regoper</>,
<type>regoperator</>, <type>regclass</>, <type>regconfig</>, and
<type>regdictionary</>. (<type>regtype</> can be upgraded.)
</para>
<para>
All failure, rebuild, and reindex cases will be reported by
<application>pg_upgrade</> if they affect your installation;
post-upgrade scripts to rebuild tables and indexes will be
generated automatically.
</para>
<para>
For deployment testing, create a schema-only copy of the old cluster,
insert dummy data, and upgrade that.
</para>
<para>
If you want to use link mode and you don't want your old cluster
to be modified when the new cluster is started, make a copy of the
old cluster and upgrade that with link mode. To make a valid copy
of the old cluster, use <command>rsync</> to create a dirty
copy of the old cluster while the server is running, then shut down
the old server and run <command>rsync</> again to update the copy with any
changes to make it consistent.
</para>
</sect2>
</sect1>