tianon / docker-postgres-upgrade

a PoC for using "pg_upgrade" inside Docker -- learn from it, adapt it for your needs; don't expect it to work as-is!
https://hub.docker.com/r/tianon/postgres-upgrade/
MIT License
1.04k stars 114 forks source link

Upgrading from 14 to 15 failing with `"/var/lib/postgresql/14/data/PG_VERSION": No such file or directory` #68

Open TommyTran732 opened 1 year ago

TommyTran732 commented 1 year ago

This is a reoccurrence of https://github.com/tianon/docker-postgres-upgrade/issues/36

I am using the alpine postgres image if that matters

casalegno commented 1 year ago

I have the same problem. Have any solution?

casalegno commented 1 year ago

Reading and rereading the documentation I got an Idea: is not possible upgrade. This tool is for pg_upgrade that is not intended for major upgrade

squatica commented 1 year ago

@casalegno the first paragraph of pg_upgrade manual contradicts your statement:

https://www.postgresql.org/docs/9.5/pgupgrade.html

pg_upgrade (formerly called pg_migrator) allows data stored in PostgreSQL data files to be upgraded to a later PostgreSQL major version without the data dump/reload typically required for major version upgrades, e.g., from 8.4.7 to the current major release of PostgreSQL. It is not required for minor version upgrades, e.g., from 9.0.1 to 9.0.4.

manuelminca commented 9 months ago

Same problem here. The error makes sense since I don't have installed PG locally. I followed the documentation to use the volume to point to my data directory which contains PG_VERSION. But the docker container doesnt seem to use it.

I might try to install locally Postgres so it can find the file and the binary files.

manuelminca commented 9 months ago

Alright I found the way to solve it.

To give more context. My old data directory is mounted in a external disk in "/mnt/data/postgres" and I want to move the files to /mnt/data/postgres/16/postgres.

docker run --rm \
-v /mnt/data/postgres:/var/lib/postgresql/data \
-v /mnt/data/postgres/16/postgres:/var/lib/postgresql/16/data \
-e PGDATAOLD=/var/lib/postgresql/data \
-e PGDATANEW=/var/lib/postgresql/16/data \
tianon/postgres-upgrade:12-to-16 

The -v connects my local filesystem with the internal one in the docker container. And then, since PGDATAOLD and PGDATANEW env variables will be used inside the docker container, should point to the inner docker path.

That way works without setting --link option. With the --link option it complains about:

"could not create hard link between old and new data directories: Invalid cross-device link In link mode the old and new data directories must be on the same file system."

Update: The error makes sense since we are mounting 2 separate volumes. To use --link option, we have to only mount 1 volume and then reference properly in the ENV variables:

docker run --rm \
  -v /mnt/data/:/var/lib/postgresql/ \
  -e PGDATAOLD=/var/lib/postgresql/postgres \
  -e PGDATANEW=/var/lib/postgresql/postgres/16 \
  tianon/postgres-upgrade:12-to-16 --link

And it works as expected 😄

empereira commented 1 day ago

@manuelminca

Both containers need to be running, right?