diff options
author | Nathan Bossart <nathan@postgresql.org> | 2025-03-25 16:02:35 -0500 |
---|---|---|
committer | Nathan Bossart <nathan@postgresql.org> | 2025-03-25 16:02:35 -0500 |
commit | 626d7236b65da50423df7de035e86f273cd36b49 (patch) | |
tree | caa5496310260ed60cb6da76c84f042a2802ae27 /doc/src | |
parent | 9c49f0e8cd7d59e240f5da88decf2d62d8a4ad0d (diff) | |
download | postgresql-626d7236b65da50423df7de035e86f273cd36b49.tar.gz postgresql-626d7236b65da50423df7de035e86f273cd36b49.zip |
pg_upgrade: Add --swap for faster file transfer.
This new option instructs pg_upgrade to move the data directories
from the old cluster to the new cluster and then to replace the
catalog files with those generated for the new cluster. This mode
can outperform --link, --clone, --copy, and --copy-file-range,
especially on clusters with many relations.
However, this mode creates many garbage files in the old cluster,
which can prolong the file synchronization step if
--sync-method=syncfs is used. To handle that, we recommend using
--sync-method=fsync with this mode, and pg_upgrade internally uses
"initdb --sync-only --no-sync-data-files" for file synchronization.
pg_upgrade will synchronize the catalog files as they are
transferred. We assume that the database files transferred from
the old cluster were synchronized prior to upgrade.
This mode also complicates reverting to the old cluster, so we
recommend restoring from backup upon failure during or after file
transfer. We did consider teaching pg_upgrade how to generate a
revert script for such failures, but we decided against it due to
the rarity of failing during file transfer, the complexity of
generating the script, and the potential for misusing the script.
The new mode is limited to clusters located in the same file
system. With some effort, we could probably support upgrades
between different file systems, but this mode is unlikely to offer
much benefit if we have to copy the files across file system
boundaries.
It is also limited to upgrades from version 10 or newer. There are
a few known obstacles for using swap mode to upgrade from older
versions. For example, the visibility map format changed in v9.6,
and the sequence tuple format changed in v10. In fact, swap mode
omits the --sequence-data option in its uses of pg_dump and instead
reuses the old cluster's sequence data files. While teaching swap
mode to deal with these kinds of changes is surely possible (and we
may have to deal with similar problems in the future, anyway), it
doesn't seem worth the effort to support upgrades from
long-unsupported versions.
Reviewed-by: Greg Sabino Mullane <htamfids@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Discussion: https://postgr.es/m/Zyvop-LxLXBLrZil%40nathan
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/ref/pgupgrade.sgml | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/doc/src/sgml/ref/pgupgrade.sgml b/doc/src/sgml/ref/pgupgrade.sgml index 5db761d1ff1..da261619043 100644 --- a/doc/src/sgml/ref/pgupgrade.sgml +++ b/doc/src/sgml/ref/pgupgrade.sgml @@ -244,7 +244,8 @@ PostgreSQL documentation <listitem> <para> Copy files to the new cluster. This is the default. (See also - <option>--link</option> and <option>--clone</option>.) + <option>--link</option>, <option>--clone</option>, + <option>--copy-file-range</option>, and <option>--swap</option>.) </para> </listitem> </varlistentry> @@ -263,6 +264,32 @@ PostgreSQL documentation </varlistentry> <varlistentry> + <term><option>--swap</option></term> + <listitem> + <para> + 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 <option>--link</option>, + <option>--clone</option>, <option>--copy</option>, and + <option>--copy-file-range</option>, especially on clusters with many + relations. + </para> + <para> + However, this mode creates many garbage files in the old cluster, which + can prolong the file synchronization step if + <option>--sync-method=syncfs</option> is used. Therefore, it is + recommended to use <option>--sync-method=fsync</option> with + <option>--swap</option>. + </para> + <para> + Additionally, once the file transfer step begins, the old cluster will + be destructively modified and therefore will no longer be safe to + start. See <xref linkend="pgupgrade-step-revert"/> for details. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><option>--sync-method=</option><replaceable>method</replaceable></term> <listitem> <para> @@ -530,6 +557,10 @@ NET STOP postgresql-&majorversion; 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. </para> <para> @@ -889,6 +920,32 @@ psql --username=postgres --file=script.sql postgres </itemizedlist></para> </listitem> + + <listitem> + <para> + If the <option>--swap</option> option was used, the old cluster might + be destructively modified: + + <itemizedlist> + <listitem> + <para> + If <command>pg_upgrade</command> aborts before reporting that the + old cluster is no longer safe to start, the old cluster was + unmodified; it can be restarted. + </para> + </listitem> + + <listitem> + <para> + If <command>pg_upgrade</command> 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. + </para> + </listitem> + </itemizedlist> + </para> + </listitem> </itemizedlist></para> </step> </procedure> |