postgres pg_upgrade - ghdrako/doc_snipets GitHub Wiki

pg_upgrade --clone
pg_upgrade --link  # -k use hardlink to migration

instead of copying files to the new cluster NOTE: remove this option if you need to keep a local copy of the old cluster's data files. This will increase the time it takes the upgrade to run as well as the size of the cluster on disk. You can NOT go back after using -k.

Reflinks are like a snapshot of a file. The old cluster will be preseved and the new cluster have only a point to old data plus the changed data incrementaly. If you need to start old cluster again,no problem. To use, you need a filesystem that supports reflinks and use pg_upgrade –clone instead –link.

  • pg_upgrade with –link option, that use hardlinks.
  • pg_upgrade with –clone option uses reflinks, that are a different approach but requires that filesystem have reflinks enabled (mkfs.xfs -m reflink=1)
time /usr/pgsql-12/bin/pg_upgrade --old-bindir /usr/pgsql-11/bin --new-bindir /usr/pgsql-12/bin --old-datadir /var/lib/pgsql/11/data --new-datadir /var/lib/pgsql/12/data --link --check

You can use pg_upgrade --check to perform only the checks, even if the old server is still running.

Upgrade:

time /usr/pgsql-12/bin/pg_upgrade --old-bindir /usr/pgsql-11/bin --new-bindir /usr/pgsql-12/bin --old-datadir /var/lib/pgsql/11/data --new-datadir /var/lib/pgsql/12/data --link