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

Specify a user & password #34

Closed GoNzCiD closed 2 years ago

GoNzCiD commented 3 years ago

Hi, I'm trying to migrate from 12 to 13, but I have the error role "postgres" does not exist. It's normal because this database doesn't contain this role, is there any way to specifiy it?

I've tried with docker run --rm -v /docker/postgres:/var/lib/postgresql -e POSTGRES_PASSWORD=pas**rd -e POSTGRES_USER=us@r tianon/postgres-upgrade:12-to-13 --link but it seems to me that the environment variables ar not set. :(

GoNzCiD commented 3 years ago

Thanks to the combined workarounds found here I can go ahead but now I have another error......

...
Checking for presence of required libraries                 ok

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.
Failure, exiting
GoNzCiD commented 3 years ago

To not use the --link parameter works for me. After that have to copy/update the pg_hba.conf file to the new folder.

jooize commented 3 years ago

Thank you @GoNzCiD. I used docker-postgres-upgrade for a previously failed Matrix Synapse database upgrade from PostgreSQL 11 to 13 with the following final command. Your clues were valuable to me.

POSTGRES_USER="synapse"
POSTGRES_PASSWORD="synapse-password"
OLD=11
NEW=13
OLD_DATA="/matrix/postgres/data-auto-upgrade-backup"
NEW_DATA="/matrix/postgres/data"

sudo docker run --rm \
-e PGUSER="$POSTGRES_USER" \
-e POSTGRES_INITDB_ARGS="-U $POSTGRES_USER" \
-e POSTGRES_PASSWORD="$POSTGRES_PASSWORD" \
-v "$OLD_DATA":"/var/lib/postgresql/$OLD/data" \
-v "$NEW_DATA":"/var/lib/postgresql/$NEW/data" \
"tianon/postgres-upgrade:$OLD-to-$NEW"
cp -a /matrix/postgres/data-auto-upgrade-backup/pg_hba.conf /matrix/postgres/data/

If anyone else ends up where I did, also check the ownerships and permissions of /matrix/*.

Thank you, @tianon, for docker-postgres-upgrade!