How to upgrade PostgreSQL if the old version is removed?

Both archlinux-wiki and PostgreSQL Documentation provide guides on how to upgrade PostgreSQL from old version. But it seems that the prerequisite is that the old version still exists in the computer.

What troubles me is that in Manjaro, package managers such as yay and pacman would always remove the old version while auto-updating (of course the data for old version is still kept). Therefore, it is impossible for me to upgrade PostgreSQL properly.

The only way I can think up now is to reinstall the old version, migrate, and then remove it again. Any better idea?

Why would you need the old version if you still have the old database-data?
It is illogical that an old version would be able to support a new version, so installing the new version and then importing (migrating) the old database-data to the new version would seem the more logical way of operation.

Disclaimer: I’m not a databse user so i don’t know the specifics of this method.

All package managers of all distro’s always do that tobe able to install the new binaries, some (if not all) automatically migrate data files if they find old data that needs migration, but that could be done manually also depending on the package.

In anyway, make a backup of your database to be sure you don’t loose your data.

That’s how upgrading works, for any software.

It seems you’re talking about parallel versions installed. In which case:

:man_shrugging:

Indeed you need the old version, to upgrade. However Arch and Manjaro provide the postgresql-old-upgrade package which is basically the old version (it is binary you need to update).

Just make sure you stopped the postgres service before you update. After you stopped the DB service you can upgrade postgresql , postgresql-libs and postgresql-old-upgrade

The Arch wiki is very detailed you just need to follow the steps. Of course unfortunately PostgreSQL makes it very complicated to update to a new major version. So if you don’t need any feature that are only available in postgres you might be better of moving to a different database engine.

1 Like

My guess is, that there is a problem with postgresql-old-upgrade. If the new packages ar installed earlier than running postgresql-old-upgrade, there is a mess with the old-datadir:
Actual major version is 15, I guess @gigi314 is running 14, so he has
old-datadir=/…/data13
The update makes it
old-datadir=/…/data14
and after that $ pg_upgrade --check claims an error.
Therefore I delay the packages

#delay PostgreSQL for pg_upgrade
IgnorePkg   = postgresql
IgnorePkg   = postgresql-libs
IgnorePkg   = postgresql-old-upgrade
2 Likes

As long as you don’t forget it, because that will cause problems. Never mind it being unsupported.

I love this ignorepkg solution!

1 Like

In my opininion you should delay postgresql-old-upgrade, too (ref. here). I missed it in the beginning and it did not work.