How to upgrade postgreSQL

Hello,

Today I install postgresql16 with an installed postgresql15, looking how to do pg_upgrade, found that all distro except openSUSe have a folder with the data version (/usr/lib/postgresql{15,16}/data or /var/lib/pgsql/data{15,16}).

following the command structure:

pg_upgrade --old-bindir=BINDIR \
           --new-bindir=BINDIR \
           --old-datadir=DATADIR \
           --new-datadir=DATADIR \

So, following this with openSUSe installation, we will have:

pg_upgrade --old-bindir=/usr/lib/postgresql15/bin \
           --new-bindir=/usr/lib/postgresql16/bin \
           --old-datadir=/var/lib/pgsql/data (default) \
           --new-datadir=/var/lib/pgsql/data (replace itself?) \

don’t know if this is safe to do or which will be the best approach to this.

maybe cp -r /var/lib/pgsql/data /var/lib/pgsql/data.old and do:

pg_upgrade --old-bindir=/usr/lib/postgresql15/bin \
           --new-bindir=/usr/lib/postgresql16/bin \
           --old-datadir=/var/lib/pgsql/data.old \
           --new-datadir=/var/lib/pgsql/data \

Which one is the best practice to do the upgrade?

On what?
You tagged this as “other”. That makes us even more curious on what unsupported version of openSUSE you are trying to do this.

Leap 15.6.

someone, can tell me if doing pg_upgrade is safe?, when openSUSE share the data folder between versions.

Do you have a recent backup of your database (and did you check that you can restore from it)?