79 lines
1.8 KiB
Markdown
79 lines
1.8 KiB
Markdown
# Manual and Help
|
|
|
|
## Upgrade Postgrs to newer Version (i.e. 15 to 16)
|
|
[Source](https://helgeklein.com/blog/upgrading-postgresql-in-docker-container/)
|
|
|
|
### 1. Stopp application conatiner
|
|
```
|
|
docker compose down APP_CONTAINER_NAME
|
|
```
|
|
|
|
|
|
### 2. Create a Full DB Dump
|
|
Look up the name of your PostgreSQL user in your Docker configuration. Sometimes postgres or something
|
|
|
|
```
|
|
docker exec -it POSTGRESQL_CONTAINER_NAME pg_dumpall -U postgres > dump.sql
|
|
```
|
|
|
|
### 3. Stop the PostgreSQL Container
|
|
```
|
|
docker stop POSTGRESQL_CONTAINER_NAME # with compose
|
|
docker compose stop POSTGRESQL_SERVICE_NAME # with compose
|
|
docker compose down # all
|
|
```
|
|
|
|
### 4. Move the DB Data Directory
|
|
Use root priveleges to move data dir. Backup old one.
|
|
```
|
|
mv db/ db-old/
|
|
mkdir db
|
|
```
|
|
|
|
### 5. Increment the PostgreSQL Version
|
|
Edit the Docker compose file, incrementing the image version.
|
|
If image is set with postgres:${POSTGRES_VERSION} change .env file.
|
|
|
|
|
|
### 6. Start container with empty data directory
|
|
Start container and Verify logs
|
|
```
|
|
docker compose up -d POSTGRESQL_CONTAINER_NAME
|
|
docker compose logs -f
|
|
```
|
|
|
|
|
|
### 7. Import DB Dump
|
|
Backup data from service one to new servic with the following command
|
|
Use this:
|
|
```
|
|
docker compose exec -T POSTGRESQL_SERVICE_NAME psql -U POSTGRES_USER POSTGRES_DB < dump.sql
|
|
```
|
|
|
|
### 8. set password
|
|
```
|
|
docker exec -i POSTGRESQL_CONTAINER_NAME psql -U POSTGRES_USER -d database -c "ALTER USER \"POSTGRES_USER\" PASSWORD 'POSTGRES_PASSWORD';"
|
|
```
|
|
|
|
### 8. Start the Application Container
|
|
```
|
|
docker compose up -d APP_CONTAINER_NAME
|
|
```
|
|
|
|
### 9. Test
|
|
Check if service is working correctly.
|
|
Check logs:
|
|
```
|
|
docker compose logs -f
|
|
```
|
|
|
|
### 10. Clean Up
|
|
* Delete the backup directory: rm -rf db-old/
|
|
* Delete the dump file: rm dump.sql
|
|
* Delete the old PostgreSQL image: docker image prune -a
|
|
|
|
|
|
|
|
|
|
|
|
|