Compare commits
3 commits
a3944d3867
...
f20697a85c
Author | SHA1 | Date | |
---|---|---|---|
f20697a85c | |||
99241d0061 | |||
16ff239ea9 |
1 changed files with 59 additions and 42 deletions
101
doc/manual.md
101
doc/manual.md
|
@ -1,61 +1,78 @@
|
|||
# Manual and Help
|
||||
|
||||
## Upgrade Postgrs to newer Version (i.e. 15 to 16)
|
||||
[Source](https://helgeklein.com/blog/upgrading-postgresql-in-docker-container/)
|
||||
|
||||
|
||||
### 1. Copy Service
|
||||
|
||||
1.1 Copy whole service definition in docker-compose.yaml
|
||||
1.2 Rename old service to *-old
|
||||
1.3 Move path from new service to i.e postgres16
|
||||
1.4 Set postgres version explicit to new version
|
||||
|
||||
Example:
|
||||
### 1. Stopp application conatiner
|
||||
```
|
||||
databasedb-old:
|
||||
image: postgres:${POSTGRES_VERSION}
|
||||
volumes:
|
||||
- ${VOLUMES_PATH}/databasedb:/var/lib/postgresql/data
|
||||
environment:
|
||||
- POSTGRES_DB=${POSTGRES_DB}
|
||||
- POSTGRES_USER=${POSTGRES_USER}
|
||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
||||
|
||||
databasedb:
|
||||
image: postgres:16
|
||||
volumes:
|
||||
- ${VOLUMES_PATH}/databasedb16:/var/lib/postgresql/data
|
||||
environment:
|
||||
- POSTGRES_DB=${POSTGRES_DB}
|
||||
- POSTGRES_USER=${POSTGRES_USER}
|
||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
||||
docker compose down APP_CONTAINER_NAME
|
||||
```
|
||||
|
||||
### 2. Move data
|
||||
Backup data from service one to new servic with the following command:
|
||||
|
||||
### 2. Create a Full DB Dump
|
||||
Look up the name of your PostgreSQL user in your Docker configuration. Sometimes postgres or something
|
||||
|
||||
```
|
||||
docker exec old-service pg_dumpall -U dbuser | docker exec -i new-service psql -U dbuser -d database
|
||||
docker exec -it POSTGRESQL_CONTAINER_NAME pg_dumpall -U postgres > dump.sql
|
||||
```
|
||||
|
||||
### 3. Set password
|
||||
### 3. Stop the PostgreSQL Container
|
||||
```
|
||||
docker exec -i monitoring-databasedb-1 psql -U dbuser -d database -c "ALTER USER \"dbuser\" PASSWORD 'secret';"
|
||||
docker stop POSTGRESQL_CONTAINER_NAME # with compose
|
||||
docker compose stop POSTGRESQL_SERVICE_NAME # with compose
|
||||
docker compose down # all
|
||||
```
|
||||
|
||||
### 4. Test
|
||||
```docker compose up -d``` and check if service is correctly running.
|
||||
### 4. Move the DB Data Directory
|
||||
Use root priveleges to move data dir. Backup old one.
|
||||
```
|
||||
mv db/ db-old/
|
||||
mkdir db
|
||||
```
|
||||
|
||||
### 5. Cleanup
|
||||
5.1 Remove old service in docker-compose.yaml
|
||||
5.2 Set explicit version again to ${POSTGRES_VERSION} and adopt .env file
|
||||
5.4 remove old volume dir
|
||||
### 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
|
||||
|
||||
|
||||
### 6. May be move Data dir
|
||||
6.1. ```docker compose down```
|
||||
6.2 ```mv /mnt/dockervolumes/databasedb16 /mnt/dockervolumes/databasedb```
|
||||
6.3 docker-compose.yaml anpassen
|
||||
6.1. ```docker compose up -d```
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue