Created
October 21, 2022 08:10
-
-
Save xFuture603/274327680de3ff6630fe4fc5a3090d2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### upgrade your dockerized postgresql version in docker container | |
Background: I've wanted to upgrade the Postgresql version of one of my images from version 11 to version 14. | |
1. create a temp directory with some space left on the disk | |
```bash | |
mkdir $directory | |
``` | |
2. create a Dockerfile with 2 postgres versions in it. Example: | |
```bash | |
FROM postgres:11-alpine3.15 AS old | |
FROM postgres:14-alpine3.15@sha256:a00af33e23643f497a42bc24d2f6f28cc67f3f48b076135c5626b2e07945ff9c AS new | |
COPY --from=old /usr/local/ /usr/local_old | |
``` | |
Note: replace the images to your desired postgresql version. | |
3. enter the container and mount your postgres data directories: | |
```bash | |
docker run -it -v /$old_database_directory:/data_old -v /$new_database_directory/:/data_new -u 70:70 postgres_migration sh | |
``` | |
4. create a new PostgreSQL database cluster in the container: | |
```bash | |
/usr/local/bin/initdb -U $database_user -D /data_new/ | |
``` | |
5. perform a pg_upgrade to upgrade a PostgreSQL server instance: | |
```bash | |
/usr/local/bin/pg_upgrade -U $database_user -b /usr/local_old/bin/ -B /usr/local/bin/ -d /data_old/ -D /data_new/ | |
``` | |
6. exit the "postgres_migration" container and start your desired postgres container with the new image and the new database directory | |
Note: this is the manual documentation for doing this. I've tried it with tools like: https://github.com/tianon/docker-postgres-upgrade but found my way of doing this for a smaller database way better. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment