]> begriffs open source - ai-pg/blob - full-docs/src/sgml/man1/pg_upgrade.1
WIP: toc builder
[ai-pg] / full-docs / src / sgml / man1 / pg_upgrade.1
1 '\" t
2 .\"     Title: pg_upgrade
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
10 .TH "PG_UPGRADE" "1" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 pg_upgrade \- upgrade a PostgreSQL server instance
32 .SH "SYNOPSIS"
33 .HP \w'\fBpg_upgrade\fR\ 'u
34 \fBpg_upgrade\fR \fB\-b\fR \fIoldbindir\fR [\fB\-B\fR\ \fInewbindir\fR] \fB\-d\fR \fIoldconfigdir\fR \fB\-D\fR \fInewconfigdir\fR [\fIoption\fR...]
35 .SH "DESCRIPTION"
36 .PP
37 pg_upgrade
38 (formerly called
39 pg_migrator) allows data stored in
40 PostgreSQL
41 data files to be upgraded to a later
42 PostgreSQL
43 major version without the data dump/restore typically required for major version upgrades, e\&.g\&., from 12\&.14 to 13\&.10 or from 14\&.9 to 15\&.5\&. It is not required for minor version upgrades, e\&.g\&., from 12\&.7 to 12\&.8 or from 14\&.1 to 14\&.5\&.
44 .PP
45 Major PostgreSQL releases regularly add new features that often change the layout of the system tables, but the internal data storage format rarely changes\&.
46 pg_upgrade
47 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,
48 pg_upgrade
49 will not be usable for such upgrades\&. (The community will attempt to avoid such situations\&.)
50 .PP
51 pg_upgrade
52 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
53 pg_upgrade\&.
54 .PP
55 pg_upgrade
56 supports upgrades from 9\&.2\&.X and later to the current major release of
57 PostgreSQL, including snapshot and beta releases\&.
58 .if n \{\
59 .sp
60 .\}
61 .RS 4
62 .it 1 an-trap
63 .nr an-no-space-flag 1
64 .nr an-break-flag 1
65 .br
66 .ps +1
67 \fBWarning\fR
68 .ps -1
69 .br
70 .PP
71 Upgrading a cluster causes the destination to execute arbitrary code of the source superusers\*(Aq choice\&. Ensure that the source superusers are trusted before upgrading\&.
72 .sp .5v
73 .RE
74 .SH "OPTIONS"
75 .PP
76 pg_upgrade
77 accepts the following command\-line arguments:
78 .PP
79 \fB\-b\fR \fIbindir\fR
80 .br
81 \fB\-\-old\-bindir=\fR\fIbindir\fR
82 .RS 4
83 the old PostgreSQL executable directory; environment variable
84 \fBPGBINOLD\fR
85 .RE
86 .PP
87 \fB\-B\fR \fIbindir\fR
88 .br
89 \fB\-\-new\-bindir=\fR\fIbindir\fR
90 .RS 4
91 the new PostgreSQL executable directory; default is the directory where
92 pg_upgrade
93 resides; environment variable
94 \fBPGBINNEW\fR
95 .RE
96 .PP
97 \fB\-c\fR
98 .br
99 \fB\-\-check\fR
100 .RS 4
101 check clusters only, don\*(Aqt change any data
102 .RE
103 .PP
104 \fB\-d\fR \fIconfigdir\fR
105 .br
106 \fB\-\-old\-datadir=\fR\fIconfigdir\fR
107 .RS 4
108 the old database cluster configuration directory; environment variable
109 \fBPGDATAOLD\fR
110 .RE
111 .PP
112 \fB\-D\fR \fIconfigdir\fR
113 .br
114 \fB\-\-new\-datadir=\fR\fIconfigdir\fR
115 .RS 4
116 the new database cluster configuration directory; environment variable
117 \fBPGDATANEW\fR
118 .RE
119 .PP
120 \fB\-j \fR\fB\fInjobs\fR\fR
121 .br
122 \fB\-\-jobs=\fR\fB\fInjobs\fR\fR
123 .RS 4
124 number of simultaneous connections and processes/threads to use
125 .RE
126 .PP
127 \fB\-k\fR
128 .br
129 \fB\-\-link\fR
130 .RS 4
131 use hard links instead of copying files to the new cluster
132 .RE
133 .PP
134 \fB\-N\fR
135 .br
136 \fB\-\-no\-sync\fR
137 .RS 4
138 By default,
139 \fBpg_upgrade\fR
140 will wait for all files of the upgraded cluster to be written safely to disk\&. This option causes
141 \fBpg_upgrade\fR
142 to return without waiting, which is faster, but means that a subsequent operating system crash can leave the data directory corrupt\&. Generally, this option is useful for testing but should not be used on a production installation\&.
143 .RE
144 .PP
145 \fB\-o\fR \fIoptions\fR
146 .br
147 \fB\-\-old\-options\fR \fIoptions\fR
148 .RS 4
149 options to be passed directly to the old
150 \fBpostgres\fR
151 command; multiple option invocations are appended
152 .RE
153 .PP
154 \fB\-O\fR \fIoptions\fR
155 .br
156 \fB\-\-new\-options\fR \fIoptions\fR
157 .RS 4
158 options to be passed directly to the new
159 \fBpostgres\fR
160 command; multiple option invocations are appended
161 .RE
162 .PP
163 \fB\-p\fR \fIport\fR
164 .br
165 \fB\-\-old\-port=\fR\fIport\fR
166 .RS 4
167 the old cluster port number; environment variable
168 \fBPGPORTOLD\fR
169 .RE
170 .PP
171 \fB\-P\fR \fIport\fR
172 .br
173 \fB\-\-new\-port=\fR\fIport\fR
174 .RS 4
175 the new cluster port number; environment variable
176 \fBPGPORTNEW\fR
177 .RE
178 .PP
179 \fB\-r\fR
180 .br
181 \fB\-\-retain\fR
182 .RS 4
183 retain SQL and log files even after successful completion
184 .RE
185 .PP
186 \fB\-s\fR \fIdir\fR
187 .br
188 \fB\-\-socketdir=\fR\fIdir\fR
189 .RS 4
190 directory to use for postmaster sockets during upgrade; default is current working directory; environment variable
191 \fBPGSOCKETDIR\fR
192 .RE
193 .PP
194 \fB\-U\fR \fIusername\fR
195 .br
196 \fB\-\-username=\fR\fIusername\fR
197 .RS 4
198 cluster\*(Aqs install user name; environment variable
199 \fBPGUSER\fR
200 .RE
201 .PP
202 \fB\-v\fR
203 .br
204 \fB\-\-verbose\fR
205 .RS 4
206 enable verbose internal logging
207 .RE
208 .PP
209 \fB\-V\fR
210 .br
211 \fB\-\-version\fR
212 .RS 4
213 display version information, then exit
214 .RE
215 .PP
216 \fB\-\-clone\fR
217 .RS 4
218 Use efficient file cloning (also known as
219 \(lqreflinks\(rq
220 on some systems) instead of copying files to the new cluster\&. This can result in near\-instantaneous copying of the data files, giving the speed advantages of
221 \fB\-k\fR/\fB\-\-link\fR
222 while leaving the old cluster untouched\&.
223 .sp
224 File cloning is only supported on some operating systems and file systems\&. If it is selected but not supported, the
225 pg_upgrade
226 run will error\&. At present, it is supported on Linux (kernel 4\&.5 or later) with Btrfs and XFS (on file systems created with reflink support), and on macOS with APFS\&.
227 .RE
228 .PP
229 \fB\-\-copy\fR
230 .RS 4
231 Copy files to the new cluster\&. This is the default\&. (See also
232 \fB\-\-link\fR,
233 \fB\-\-clone\fR,
234 \fB\-\-copy\-file\-range\fR, and
235 \fB\-\-swap\fR\&.)
236 .RE
237 .PP
238 \fB\-\-copy\-file\-range\fR
239 .RS 4
240 Use the
241 \fBcopy_file_range\fR
242 system call for efficient copying\&. On some file systems this gives results similar to
243 \fB\-\-clone\fR, sharing physical disk blocks, while on others it may still copy blocks, but do so via an optimized path\&. At present, it is supported on Linux and FreeBSD\&.
244 .RE
245 .PP
246 \fB\-\-no\-statistics\fR
247 .RS 4
248 Do not restore statistics from the old cluster into the new cluster\&.
249 .RE
250 .PP
251 \fB\-\-set\-char\-signedness=\fR\fIoption\fR
252 .RS 4
253 Manually set the default char signedness of new clusters\&. Possible values are
254 signed
255 and
256 unsigned\&.
257 .sp
258 In the C language, the default signedness of the
259 char
260 type (when not explicitly specified) varies across platforms\&. For example,
261 char
262 defaults to
263 signed char
264 on x86 CPUs but to
265 unsigned char
266 on ARM CPUs\&.
267 .sp
268 Starting from
269 PostgreSQL
270 18, database clusters maintain their own default char signedness setting, which can be used to ensure consistent behavior across platforms with different default char signedness\&. By default,
271 pg_upgrade
272 preserves the char signedness setting when upgrading from an existing cluster\&. However, when upgrading from
273 PostgreSQL
274 17 or earlier,
275 pg_upgrade
276 adopts the char signedness of the platform on which it was built\&.
277 .sp
278 This option allows you to explicitly set the default char signedness for the new cluster, overriding any inherited values\&. There are two specific scenarios where this option is relevant:
279 .sp
280 .RS 4
281 .ie n \{\
282 \h'-04'\(bu\h'+03'\c
283 .\}
284 .el \{\
285 .sp -1
286 .IP \(bu 2.3
287 .\}
288 If you are planning to migrate to a different platform after the upgrade, you should not use this option\&. The default behavior is right in this case\&. Instead, perform the upgrade on the original platform without this flag, and then migrate the cluster afterward\&. This is the recommended and safest approach\&.
289 .RE
290 .sp
291 .RS 4
292 .ie n \{\
293 \h'-04'\(bu\h'+03'\c
294 .\}
295 .el \{\
296 .sp -1
297 .IP \(bu 2.3
298 .\}
299 If you have already migrated the cluster to a platform with different char signedness (for example, from an x86\-based system to an ARM\-based system), you should use this option to specify the signedness matching the original platform\*(Aqs default char signedness\&. Additionally, it\*(Aqs essential not to modify any data files between migrating data files and running
300 \fBpg_upgrade\fR\&.
301 \fBpg_upgrade\fR
302 should be the first operation that starts the cluster on the new platform\&.
303 .RE
304 .sp
305 .RE
306 .PP
307 \fB\-\-swap\fR
308 .RS 4
309 Move the data directories from the old cluster to the new cluster\&. Then, replace the catalog files with those generated for the new cluster\&. This mode can outperform
310 \fB\-\-link\fR,
311 \fB\-\-clone\fR,
312 \fB\-\-copy\fR, and
313 \fB\-\-copy\-file\-range\fR, especially on clusters with many relations\&.
314 .sp
315 However, this mode creates many garbage files in the old cluster, which can prolong the file synchronization step if
316 \fB\-\-sync\-method=syncfs\fR
317 is used\&. Therefore, it is recommended to use
318 \fB\-\-sync\-method=fsync\fR
319 with
320 \fB\-\-swap\fR\&.
321 .sp
322 Additionally, once the file transfer step begins, the old cluster will be destructively modified and therefore will no longer be safe to start\&. See
323 Step 17
324 for details\&.
325 .RE
326 .PP
327 \fB\-\-sync\-method=\fR\fImethod\fR
328 .RS 4
329 When set to
330 fsync, which is the default,
331 \fBpg_upgrade\fR
332 will recursively open and synchronize all files in the upgraded cluster\*(Aqs data directory\&. The search for files will follow symbolic links for the WAL directory and each configured tablespace\&.
333 .sp
334 On Linux,
335 syncfs
336 may be used instead to ask the operating system to synchronize the whole file systems that contain the upgraded cluster\*(Aqs data directory, its WAL files, and each tablespace\&. See
337 recovery_init_sync_method
338 for information about the caveats to be aware of when using
339 syncfs\&.
340 .sp
341 This option has no effect when
342 \fB\-\-no\-sync\fR
343 is used\&.
344 .RE
345 .PP
346 \fB\-?\fR
347 .br
348 \fB\-\-help\fR
349 .RS 4
350 show help, then exit
351 .RE
352 .SH "USAGE"
353 .PP
354 These are the steps to perform an upgrade with
355 pg_upgrade:
356 .if n \{\
357 .sp
358 .\}
359 .RS 4
360 .it 1 an-trap
361 .nr an-no-space-flag 1
362 .nr an-break-flag 1
363 .br
364 .ps +1
365 \fBNote\fR
366 .ps -1
367 .br
368 .PP
369 The steps to upgrade
370 logical replication clusters
371 are not covered here; refer to
372 Section\ \&29.13
373 for details\&.
374 .sp .5v
375 .RE
376 .sp
377 .RS 4
378 .ie n \{\
379 \h'-04' 1.\h'+01'\c
380 .\}
381 .el \{\
382 .sp -1
383 .IP "  1." 4.2
384 .\}
385 Optionally move the old cluster: If you are using a version\-specific installation directory, e\&.g\&.,
386 /opt/PostgreSQL/18, you do not need to move the old cluster\&. The graphical installers all use version\-specific installation directories\&.
387 .sp
388 If your installation directory is not version\-specific, e\&.g\&.,
389 /usr/local/pgsql, it is necessary to move the current PostgreSQL install directory so it does not interfere with the new
390 PostgreSQL
391 installation\&. Once the current
392 PostgreSQL
393 server is shut down, it is safe to rename the PostgreSQL installation directory; assuming the old directory is
394 /usr/local/pgsql, you can do:
395 .sp
396 .if n \{\
397 .RS 4
398 .\}
399 .nf
400 mv /usr/local/pgsql /usr/local/pgsql\&.old
401 .fi
402 .if n \{\
403 .RE
404 .\}
405 .sp
406 to rename the directory\&.
407 .RE
408 .sp
409 .RS 4
410 .ie n \{\
411 \h'-04' 2.\h'+01'\c
412 .\}
413 .el \{\
414 .sp -1
415 .IP "  2." 4.2
416 .\}
417 For source installs, build the new version: Build the new PostgreSQL source with
418 \fBconfigure\fR
419 flags that are compatible with the old cluster\&.
420 pg_upgrade
421 will check
422 \fBpg_controldata\fR
423 to make sure all settings are compatible before starting the upgrade\&.
424 .RE
425 .sp
426 .RS 4
427 .ie n \{\
428 \h'-04' 3.\h'+01'\c
429 .\}
430 .el \{\
431 .sp -1
432 .IP "  3." 4.2
433 .\}
434 Install the new PostgreSQL binaries: Install the new server\*(Aqs binaries and support files\&.
435 pg_upgrade
436 is included in a default installation\&.
437 .sp
438 For source installs, if you wish to install the new server in a custom location, use the
439 prefix
440 variable:
441 .sp
442 .if n \{\
443 .RS 4
444 .\}
445 .nf
446 make prefix=/usr/local/pgsql\&.new install
447 .fi
448 .if n \{\
449 .RE
450 .\}
451 .RE
452 .sp
453 .RS 4
454 .ie n \{\
455 \h'-04' 4.\h'+01'\c
456 .\}
457 .el \{\
458 .sp -1
459 .IP "  4." 4.2
460 .\}
461 Initialize the new PostgreSQL cluster: Initialize the new cluster using
462 \fBinitdb\fR\&. Again, use compatible
463 \fBinitdb\fR
464 flags that match the old cluster\&. Many prebuilt installers do this step automatically\&. There is no need to start the new cluster\&.
465 .RE
466 .sp
467 .RS 4
468 .ie n \{\
469 \h'-04' 5.\h'+01'\c
470 .\}
471 .el \{\
472 .sp -1
473 .IP "  5." 4.2
474 .\}
475 Install extension shared object files: Many extensions and custom modules, whether from
476 contrib
477 or another source, use shared object files (or DLLs), e\&.g\&.,
478 pgcrypto\&.so\&. If the old cluster used these, shared object files matching the new server binary must be installed in the new cluster, usually via operating system commands\&. Do not load the schema definitions, e\&.g\&.,
479 \fBCREATE EXTENSION pgcrypto\fR, because these will be duplicated from the old cluster\&. If extension updates are available,
480 pg_upgrade
481 will report this and create a script that can be run later to update them\&.
482 .RE
483 .sp
484 .RS 4
485 .ie n \{\
486 \h'-04' 6.\h'+01'\c
487 .\}
488 .el \{\
489 .sp -1
490 .IP "  6." 4.2
491 .\}
492 Copy custom full\-text search files: Copy any custom full text search files (dictionary, synonym, thesaurus, stop words) from the old to the new cluster\&.
493 .RE
494 .sp
495 .RS 4
496 .ie n \{\
497 \h'-04' 7.\h'+01'\c
498 .\}
499 .el \{\
500 .sp -1
501 .IP "  7." 4.2
502 .\}
503 Adjust authentication: \fBpg_upgrade\fR
504 will connect to the old and new servers several times, so you might want to set authentication to
505 peer
506 in
507 pg_hba\&.conf
508 or use a
509 ~/\&.pgpass
510 file (see
511 Section\ \&32.16)\&.
512 .RE
513 .sp
514 .RS 4
515 .ie n \{\
516 \h'-04' 8.\h'+01'\c
517 .\}
518 .el \{\
519 .sp -1
520 .IP "  8." 4.2
521 .\}
522 Stop both servers: Make sure both database servers are stopped using, on Unix, e\&.g\&.:
523 .sp
524 .if n \{\
525 .RS 4
526 .\}
527 .nf
528 pg_ctl \-D /opt/PostgreSQL/12 stop
529 pg_ctl \-D /opt/PostgreSQL/18 stop
530 .fi
531 .if n \{\
532 .RE
533 .\}
534 .sp
535 or on Windows, using the proper service names:
536 .sp
537 .if n \{\
538 .RS 4
539 .\}
540 .nf
541 NET STOP postgresql\-12
542 NET STOP postgresql\-18
543 .fi
544 .if n \{\
545 .RE
546 .\}
547 .sp
548 Streaming replication and log\-shipping standby servers must be running during this shutdown so they receive all changes\&.
549 .RE
550 .sp
551 .RS 4
552 .ie n \{\
553 \h'-04' 9.\h'+01'\c
554 .\}
555 .el \{\
556 .sp -1
557 .IP "  9." 4.2
558 .\}
559 Prepare for standby server upgrades: If you are upgrading standby servers using methods outlined in section
560 Step 11, verify that the old standby servers are caught up by running
561 pg_controldata
562 against the old primary and standby clusters\&. Verify that the
563 \(lqLatest checkpoint location\(rq
564 values match in all clusters\&. Also, make sure
565 \fIwal_level\fR
566 is not set to
567 minimal
568 in the
569 postgresql\&.conf
570 file on the new primary cluster\&.
571 .RE
572 .sp
573 .RS 4
574 .ie n \{\
575 \h'-04' 10.\h'+01'\c
576 .\}
577 .el \{\
578 .sp -1
579 .IP "  10." 4.2
580 .\}
581 Run pg_upgrade: Always run the
582 pg_upgrade
583 binary of the new server, not the old one\&.
584 pg_upgrade
585 requires the specification of the old and new cluster\*(Aqs data and executable (bin) directories\&. You can also specify user and port values, and whether you want the data files linked, cloned, or swapped instead of the default copy behavior\&.
586 .sp
587 If you use link mode, the upgrade will be much faster (no file copying) and use less disk space, 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\&. (Tablespaces and
588 pg_wal
589 can be on different file systems\&.) Clone mode provides the same speed and disk space advantages but does not cause the old cluster to be unusable once the new cluster is started\&. Clone mode also requires that the old and new data directories be in the same file system\&. This mode is only available on certain operating systems and file systems\&. Swap mode may be the fastest if there are many relations, but you will not be able to access your old cluster once the file transfer step begins\&. Swap mode also requires that the old and new cluster data directories be in the same file system\&.
590 .sp
591 Setting
592 \fB\-\-jobs\fR
593 to 2 or higher allows pg_upgrade to process multiple databases and tablespaces in parallel\&. A good starting point is the number of CPU cores on the machine\&. This option can substantially reduce the upgrade time for multi\-database and multi\-tablespace servers\&.
594 .sp
595 For Windows users, you must be logged into an administrative account, and then run
596 pg_upgrade
597 with quoted directories, e\&.g\&.:
598 .sp
599 .if n \{\
600 .RS 4
601 .\}
602 .nf
603 pg_upgrade\&.exe
604         \-\-old\-datadir "C:/Program Files/PostgreSQL/12/data"
605         \-\-new\-datadir "C:/Program Files/PostgreSQL/18/data"
606         \-\-old\-bindir "C:/Program Files/PostgreSQL/12/bin"
607         \-\-new\-bindir "C:/Program Files/PostgreSQL/18/bin"
608 .fi
609 .if n \{\
610 .RE
611 .\}
612 .sp
613 Once started,
614 \fBpg_upgrade\fR
615 will verify the two clusters are compatible and then do the upgrade\&. You can use
616 \fBpg_upgrade \-\-check\fR
617 to perform only the checks, even if the old server is still running\&.
618 \fBpg_upgrade \-\-check\fR
619 will also outline any manual adjustments you will need to make after the upgrade\&. If you are going to be using link, clone, copy\-file\-range, or swap mode, you should use the option
620 \fB\-\-link\fR,
621 \fB\-\-clone\fR,
622 \fB\-\-copy\-file\-range\fR, or
623 \fB\-\-swap\fR
624 with
625 \fB\-\-check\fR
626 to enable mode\-specific checks\&.
627 \fBpg_upgrade\fR
628 requires write permission in the current directory\&.
629 .sp
630 Obviously, no one should be accessing the clusters during the upgrade\&.
631 pg_upgrade
632 defaults to running servers on port 50432 to avoid unintended client connections\&. You can use the same port number for both clusters when doing an upgrade because the old and new clusters will not be running at the same time\&. However, when checking an old running server, the old and new port numbers must be different\&.
633 .sp
634 If an error occurs while restoring the database schema,
635 \fBpg_upgrade\fR
636 will exit and you will have to revert to the old cluster as outlined in
637 Step 17
638 below\&. To try
639 \fBpg_upgrade\fR
640 again, you will need to modify the old cluster so the pg_upgrade schema restore succeeds\&. If the problem is a
641 contrib
642 module, you might need to uninstall the
643 contrib
644 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\&.
645 .RE
646 .sp
647 .RS 4
648 .ie n \{\
649 \h'-04' 11.\h'+01'\c
650 .\}
651 .el \{\
652 .sp -1
653 .IP "  11." 4.2
654 .\}
655 Upgrade streaming replication and log\-shipping standby servers: If you used link mode and have Streaming Replication (see
656 Section\ \&26.2.5) or Log\-Shipping (see
657 Section\ \&26.2) standby servers, you can follow these steps to quickly upgrade them\&. You will not be running
658 pg_upgrade
659 on the standby servers, but rather
660 rsync
661 on the primary\&. Do not start any servers yet\&.
662 .sp
663 If you did
664 \fInot\fR
665 use link mode, do not have or do not want to use
666 rsync, or want an easier solution, skip the instructions in this section and simply recreate the standby servers once
667 pg_upgrade
668 completes and the new primary is running\&.
669 .sp
670 .RS 4
671 .ie n \{\
672 \h'-04' 1.\h'+01'\c
673 .\}
674 .el \{\
675 .sp -1
676 .IP "  1." 4.2
677 .\}
678 Install the new PostgreSQL binaries on standby servers: Make sure the new binaries and support files are installed on all standby servers\&.
679 .RE
680 .sp
681 .RS 4
682 .ie n \{\
683 \h'-04' 2.\h'+01'\c
684 .\}
685 .el \{\
686 .sp -1
687 .IP "  2." 4.2
688 .\}
689 Make sure the new standby data directories do \fInot\fR exist: Make sure the new standby data directories do
690 \fInot\fR
691 exist or are empty\&. If
692 initdb
693 was run, delete the standby servers\*(Aq new data directories\&.
694 .RE
695 .sp
696 .RS 4
697 .ie n \{\
698 \h'-04' 3.\h'+01'\c
699 .\}
700 .el \{\
701 .sp -1
702 .IP "  3." 4.2
703 .\}
704 Install extension shared object files: Install the same extension shared object files on the new standbys that you installed in the new primary cluster\&.
705 .RE
706 .sp
707 .RS 4
708 .ie n \{\
709 \h'-04' 4.\h'+01'\c
710 .\}
711 .el \{\
712 .sp -1
713 .IP "  4." 4.2
714 .\}
715 Stop standby servers: If the standby servers are still running, stop them now using the above instructions\&.
716 .RE
717 .sp
718 .RS 4
719 .ie n \{\
720 \h'-04' 5.\h'+01'\c
721 .\}
722 .el \{\
723 .sp -1
724 .IP "  5." 4.2
725 .\}
726 Save configuration files: Save any configuration files from the old standbys\*(Aq configuration directories you need to keep, e\&.g\&.,
727 postgresql\&.conf
728 (and any files included by it),
729 postgresql\&.auto\&.conf,
730 pg_hba\&.conf, because these will be overwritten or removed in the next step\&.
731 .RE
732 .sp
733 .RS 4
734 .ie n \{\
735 \h'-04' 6.\h'+01'\c
736 .\}
737 .el \{\
738 .sp -1
739 .IP "  6." 4.2
740 .\}
741 Run rsync: When using link mode, standby servers can be quickly upgraded using
742 rsync\&. To accomplish this, from a directory on the primary server that is above the old and new database cluster directories, run this on the
743 \fIprimary\fR
744 for each standby server:
745 .sp
746 .if n \{\
747 .RS 4
748 .\}
749 .nf
750 rsync \-\-archive \-\-delete \-\-hard\-links \-\-size\-only \-\-no\-inc\-recursive old_cluster new_cluster remote_dir
751 .fi
752 .if n \{\
753 .RE
754 .\}
755 .sp
756 where
757 \fBold_cluster\fR
758 and
759 \fBnew_cluster\fR
760 are relative to the current directory on the primary, and
761 \fBremote_dir\fR
762 is
763 \fIabove\fR
764 the old and new cluster directories on the standby\&. The directory structure under the specified directories on the primary and standbys must match\&. Consult the
765 rsync
766 manual page for details on specifying the remote directory, e\&.g\&.,
767 .sp
768 .if n \{\
769 .RS 4
770 .\}
771 .nf
772 rsync \-\-archive \-\-delete \-\-hard\-links \-\-size\-only \-\-no\-inc\-recursive /opt/PostgreSQL/12 \e
773       /opt/PostgreSQL/18 standby\&.example\&.com:/opt/PostgreSQL
774 .fi
775 .if n \{\
776 .RE
777 .\}
778 .sp
779 You can verify what the command will do using
780 rsync\*(Aqs
781 \fB\-\-dry\-run\fR
782 option\&. While
783 rsync
784 must be run on the primary for at least one standby, it is possible to run
785 rsync
786 on an upgraded standby to upgrade other standbys, as long as the upgraded standby has not been started\&.
787 .sp
788 What this does is to record the links created by
789 pg_upgrade\*(Aqs link mode that connect files in the old and new clusters on the primary server\&. It then finds matching files in the standby\*(Aqs old cluster and creates links for them in the standby\*(Aqs new cluster\&. Files that were not linked on the primary are copied from the primary to the standby\&. (They are usually small\&.) This provides rapid standby upgrades\&. Unfortunately,
790 rsync
791 needlessly copies files associated with temporary and unlogged tables because these files don\*(Aqt normally exist on standby servers\&.
792 .sp
793 If you have tablespaces, you will need to run a similar
794 rsync
795 command for each tablespace directory, e\&.g\&.:
796 .sp
797 .if n \{\
798 .RS 4
799 .\}
800 .nf
801 rsync \-\-archive \-\-delete \-\-hard\-links \-\-size\-only \-\-no\-inc\-recursive /vol1/pg_tblsp/PG_12_201909212 \e
802       /vol1/pg_tblsp/PG_18_202307071 standby\&.example\&.com:/vol1/pg_tblsp
803 .fi
804 .if n \{\
805 .RE
806 .\}
807 .sp
808 If you have relocated
809 pg_wal
810 outside the data directories,
811 rsync
812 must be run on those directories too\&.
813 .RE
814 .sp
815 .RS 4
816 .ie n \{\
817 \h'-04' 7.\h'+01'\c
818 .\}
819 .el \{\
820 .sp -1
821 .IP "  7." 4.2
822 .\}
823 Configure streaming replication and log\-shipping standby servers: Configure the servers for log shipping\&. (You do not need to run
824 \fBpg_backup_start()\fR
825 and
826 \fBpg_backup_stop()\fR
827 or take a file system backup as the standbys are still synchronized with the primary\&.) If the old primary is prior to version 17\&.0, then no slots on the primary are copied to the new standby, so all the slots on the old standby must be recreated manually\&. If the old primary is version 17\&.0 or later, then only logical slots on the primary are copied to the new standby, but other slots on the old standby are not copied, so must be recreated manually\&.
828 .RE
829 .RE
830 .sp
831 .RS 4
832 .ie n \{\
833 \h'-04' 12.\h'+01'\c
834 .\}
835 .el \{\
836 .sp -1
837 .IP "  12." 4.2
838 .\}
839 Restore pg_hba\&.conf: If you modified
840 pg_hba\&.conf, restore its original settings\&. It might also be necessary to adjust other configuration files in the new cluster to match the old cluster, e\&.g\&.,
841 postgresql\&.conf
842 (and any files included by it),
843 postgresql\&.auto\&.conf\&.
844 .RE
845 .sp
846 .RS 4
847 .ie n \{\
848 \h'-04' 13.\h'+01'\c
849 .\}
850 .el \{\
851 .sp -1
852 .IP "  13." 4.2
853 .\}
854 Start the new server: The new server can now be safely started, and then any
855 rsync\*(Aqed standby servers\&.
856 .RE
857 .sp
858 .RS 4
859 .ie n \{\
860 \h'-04' 14.\h'+01'\c
861 .\}
862 .el \{\
863 .sp -1
864 .IP "  14." 4.2
865 .\}
866 Post\-upgrade processing: 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:
867 .sp
868 .if n \{\
869 .RS 4
870 .\}
871 .nf
872 psql \-\-username=postgres \-\-file=script\&.sql postgres
873 .fi
874 .if n \{\
875 .RE
876 .\}
877 .sp
878 The scripts can be run in any order and can be deleted once they have been run\&.
879 .if n \{\
880 .sp
881 .\}
882 .RS 4
883 .it 1 an-trap
884 .nr an-no-space-flag 1
885 .nr an-break-flag 1
886 .br
887 .ps +1
888 \fBCaution\fR
889 .ps -1
890 .br
891 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\&.
892 .sp .5v
893 .RE
894 .RE
895 .sp
896 .RS 4
897 .ie n \{\
898 \h'-04' 15.\h'+01'\c
899 .\}
900 .el \{\
901 .sp -1
902 .IP "  15." 4.2
903 .\}
904 Statistics: Unless the
905 \fB\-\-no\-statistics\fR
906 option is specified,
907 \fBpg_upgrade\fR
908 will transfer most optimizer statistics from the old cluster to the new cluster\&. However, some statistics may not be transferred, such as those created explicitly with
909 CREATE STATISTICS (\fBCREATE_STATISTICS\fR(7))
910 or custom statistics added by an extension\&.
911 .sp
912 Because not all statistics are transferred by
913 \fBpg_upgrade\fR, you will be instructed to run commands to regenerate that information at the end of the upgrade\&. You might need to set connection parameters to match your new cluster\&.
914 .sp
915 First, use
916 \fBvacuumdb \-\-all \-\-analyze\-in\-stages \-\-missing\-stats\-only\fR
917 to quickly generate minimal optimizer statistics for relations without any\&. Then, use
918 \fBvacuumdb \-\-all \-\-analyze\-only\fR
919 to ensure all relations have updated cumulative statistics for triggering vacuum and analyze\&. For both commands, the use of
920 \fB\-\-jobs\fR
921 can speed it up\&. If
922 \fIvacuum_cost_delay\fR
923 is set to a non\-zero value, this can be overridden to speed up statistics generation using
924 \fBPGOPTIONS\fR, e\&.g\&.,
925 PGOPTIONS=\*(Aq\-c vacuum_cost_delay=0\*(Aq vacuumdb \&.\&.\&.\&.
926 .RE
927 .sp
928 .RS 4
929 .ie n \{\
930 \h'-04' 16.\h'+01'\c
931 .\}
932 .el \{\
933 .sp -1
934 .IP "  16." 4.2
935 .\}
936 Delete old cluster: Once you are satisfied with the upgrade, you can delete the old cluster\*(Aqs data directories by running the script mentioned when
937 \fBpg_upgrade\fR
938 completes\&. (Automatic deletion is not possible if you have user\-defined tablespaces inside the old data directory\&.) You can also delete the old installation directories (e\&.g\&.,
939 bin,
940 share)\&.
941 .RE
942 .sp
943 .RS 4
944 .ie n \{\
945 \h'-04' 17.\h'+01'\c
946 .\}
947 .el \{\
948 .sp -1
949 .IP "  17." 4.2
950 .\}
951 Reverting to old cluster: If, after running
952 \fBpg_upgrade\fR, you wish to revert to the old cluster, there are several options:
953 .sp
954 .RS 4
955 .ie n \{\
956 \h'-04'\(bu\h'+03'\c
957 .\}
958 .el \{\
959 .sp -1
960 .IP \(bu 2.3
961 .\}
962 If the
963 \fB\-\-check\fR
964 option was used, the old cluster was unmodified; it can be restarted\&.
965 .RE
966 .sp
967 .RS 4
968 .ie n \{\
969 \h'-04'\(bu\h'+03'\c
970 .\}
971 .el \{\
972 .sp -1
973 .IP \(bu 2.3
974 .\}
975 If neither
976 \fB\-\-link\fR
977 nor
978 \fB\-\-swap\fR
979 was used, the old cluster was unmodified; it can be restarted\&.
980 .RE
981 .sp
982 .RS 4
983 .ie n \{\
984 \h'-04'\(bu\h'+03'\c
985 .\}
986 .el \{\
987 .sp -1
988 .IP \(bu 2.3
989 .\}
990 If the
991 \fB\-\-link\fR
992 option was used, the data files might be shared between the old and new cluster:
993 .sp
994 .RS 4
995 .ie n \{\
996 \h'-04'\(bu\h'+03'\c
997 .\}
998 .el \{\
999 .sp -1
1000 .IP \(bu 2.3
1001 .\}
1002 If
1003 \fBpg_upgrade\fR
1004 aborted before linking started, the old cluster was unmodified; it can be restarted\&.
1005 .RE
1006 .sp
1007 .RS 4
1008 .ie n \{\
1009 \h'-04'\(bu\h'+03'\c
1010 .\}
1011 .el \{\
1012 .sp -1
1013 .IP \(bu 2.3
1014 .\}
1015 If you did
1016 \fInot\fR
1017 start the new cluster, the old cluster was unmodified except that, when linking started, a
1018 \&.old
1019 suffix was appended to
1020 $PGDATA/global/pg_control\&. To reuse the old cluster, remove the
1021 \&.old
1022 suffix from
1023 $PGDATA/global/pg_control; you can then restart the old cluster\&.
1024 .RE
1025 .sp
1026 .RS 4
1027 .ie n \{\
1028 \h'-04'\(bu\h'+03'\c
1029 .\}
1030 .el \{\
1031 .sp -1
1032 .IP \(bu 2.3
1033 .\}
1034 If you did start the new cluster, it has written to shared files and it is unsafe to use the old cluster\&. The old cluster will need to be restored from backup in this case\&.
1035 .RE
1036 .RE
1037 .sp
1038 .RS 4
1039 .ie n \{\
1040 \h'-04'\(bu\h'+03'\c
1041 .\}
1042 .el \{\
1043 .sp -1
1044 .IP \(bu 2.3
1045 .\}
1046 If the
1047 \fB\-\-swap\fR
1048 option was used, the old cluster might be destructively modified:
1049 .sp
1050 .RS 4
1051 .ie n \{\
1052 \h'-04'\(bu\h'+03'\c
1053 .\}
1054 .el \{\
1055 .sp -1
1056 .IP \(bu 2.3
1057 .\}
1058 If
1059 \fBpg_upgrade\fR
1060 aborts before reporting that the old cluster is no longer safe to start, the old cluster was unmodified; it can be restarted\&.
1061 .RE
1062 .sp
1063 .RS 4
1064 .ie n \{\
1065 \h'-04'\(bu\h'+03'\c
1066 .\}
1067 .el \{\
1068 .sp -1
1069 .IP \(bu 2.3
1070 .\}
1071 If
1072 \fBpg_upgrade\fR
1073 has reported that the old cluster is no longer safe to start, the old cluster was destructively modified\&. The old cluster will need to be restored from backup in this case\&.
1074 .RE
1075 .sp
1076 .RE
1077 .RE
1078 .SH "ENVIRONMENT"
1079 .PP
1080 Some environment variables can be used to provide defaults for command\-line options:
1081 .PP
1082 \fBPGBINOLD\fR
1083 .RS 4
1084 The old PostgreSQL executable directory; option
1085 \fB\-b\fR/\fB\-\-old\-bindir\fR\&.
1086 .RE
1087 .PP
1088 \fBPGBINNEW\fR
1089 .RS 4
1090 The new PostgreSQL executable directory; option
1091 \fB\-B\fR/\fB\-\-new\-bindir\fR\&.
1092 .RE
1093 .PP
1094 \fBPGDATAOLD\fR
1095 .RS 4
1096 The old database cluster configuration directory; option
1097 \fB\-d\fR/\fB\-\-old\-datadir\fR\&.
1098 .RE
1099 .PP
1100 \fBPGDATANEW\fR
1101 .RS 4
1102 The new database cluster configuration directory; option
1103 \fB\-D\fR/\fB\-\-new\-datadir\fR\&.
1104 .RE
1105 .PP
1106 \fBPGPORTOLD\fR
1107 .RS 4
1108 The old cluster port number; option
1109 \fB\-p\fR/\fB\-\-old\-port\fR\&.
1110 .RE
1111 .PP
1112 \fBPGPORTNEW\fR
1113 .RS 4
1114 The new cluster port number; option
1115 \fB\-P\fR/\fB\-\-new\-port\fR\&.
1116 .RE
1117 .PP
1118 \fBPGSOCKETDIR\fR
1119 .RS 4
1120 Directory to use for postmaster sockets during upgrade; option
1121 \fB\-s\fR/\fB\-\-socketdir\fR\&.
1122 .RE
1123 .PP
1124 \fBPGUSER\fR
1125 .RS 4
1126 Cluster\*(Aqs install user name; option
1127 \fB\-U\fR/\fB\-\-username\fR\&.
1128 .RE
1129 .SH "NOTES"
1130 .PP
1131 pg_upgrade
1132 creates various working files, such as schema dumps, stored within
1133 pg_upgrade_output\&.d
1134 in the directory of the new cluster\&. Each run creates a new subdirectory named with a timestamp formatted as per ISO 8601 (%Y%m%dT%H%M%S), where all its generated files are stored\&.
1135 pg_upgrade_output\&.d
1136 and its contained files will be removed automatically if
1137 pg_upgrade
1138 completes successfully; but in the event of trouble, the files there may provide useful debugging information\&.
1139 .PP
1140 pg_upgrade
1141 launches short\-lived postmasters in the old and new data directories\&. Temporary Unix socket files for communication with these postmasters are, by default, made in the current working directory\&. In some situations the path name for the current directory might be too long to be a valid socket name\&. In that case you can use the
1142 \fB\-s\fR
1143 option to put the socket files in some directory with a shorter path name\&. For security, be sure that that directory is not readable or writable by any other users\&. (This is not supported on Windows\&.)
1144 .PP
1145 All failure, rebuild, and reindex cases will be reported by
1146 pg_upgrade
1147 if they affect your installation; post\-upgrade scripts to rebuild tables and indexes will be generated automatically\&. If you are trying to automate the upgrade of many clusters, you should find that clusters with identical database schemas require the same post\-upgrade steps for all cluster upgrades; this is because the post\-upgrade steps are based on the database schemas, and not user data\&.
1148 .PP
1149 For deployment testing, create a schema\-only copy of the old cluster, insert dummy data, and upgrade that\&.
1150 .PP
1151 pg_upgrade
1152 does not support upgrading of databases containing table columns using these
1153 reg*
1154 OID\-referencing system data types:
1155 .RS 4
1156 regcollation
1157 .RE
1158 .RS 4
1159 regconfig
1160 .RE
1161 .RS 4
1162 regdictionary
1163 .RE
1164 .RS 4
1165 regnamespace
1166 .RE
1167 .RS 4
1168 regoper
1169 .RE
1170 .RS 4
1171 regoperator
1172 .RE
1173 .RS 4
1174 regproc
1175 .RE
1176 .RS 4
1177 regprocedure
1178 .RE
1179 (regclass,
1180 regrole, and
1181 regtype
1182 can be upgraded\&.)
1183 .PP
1184 If you want to use link mode and you do not want your old cluster to be modified when the new cluster is started, consider using the clone mode\&. If that is not available, make a copy of the old cluster and upgrade that in link mode\&. To make a valid copy of the old cluster, use
1185 \fBrsync\fR
1186 to create a dirty copy of the old cluster while the server is running, then shut down the old server and run
1187 \fBrsync \-\-checksum\fR
1188 again to update the copy with any changes to make it consistent\&. (\fB\-\-checksum\fR
1189 is necessary because
1190 \fBrsync\fR
1191 only has file modification\-time granularity of one second\&.) You might want to exclude some files, e\&.g\&.,
1192 postmaster\&.pid, as documented in
1193 Section\ \&25.3.4\&. If your file system supports file system snapshots or copy\-on\-write file copies, you can use that to make a backup of the old cluster and tablespaces, though the snapshot and copies must be created simultaneously or while the database server is down\&.
1194 .SH "SEE ALSO"
1195 \fBinitdb\fR(1), \fBpg_ctl\fR(1), \fBpg_dump\fR(1), \fBpostgres\fR(1)