Skip to content

Commit f80f349

Browse files
Upgrade PostgreSQL from 12.0 to 16.14
Signed-off-by: Atharva Vaish <atharva.vaish240@gmail.com>
1 parent 1e229bc commit f80f349

6 files changed

Lines changed: 148 additions & 9 deletions

File tree

README.md

Lines changed: 142 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ If environment is prepared, then we can start cello service.
6767
```bash
6868
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6969
57df1462c7f1 cello/hyperledger-fabric-agent:local "python manage.py r…" 4 seconds ago Up 2 seconds 0.0.0.0:5001->8080/tcp, :::5001->8080/tcp cello-docker-agent
70-
04367ab6bd5e postgres:16.8 "docker-entrypoint.s…" 4 seconds ago Up 2 seconds 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp cello-postgres
70+
04367ab6bd5e postgres:16.14 "docker-entrypoint.s…" 4 seconds ago Up 2 seconds 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp cello-postgres
7171
29b56a279893 cello/api-engine:latest "/bin/sh -c 'bash /e…" 4 seconds ago Up 2 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp cello-api-engine
7272
a272a06d8280 cello/dashboard:latest "bash -c 'nginx -g '…" 4 seconds ago Up 2 seconds 0.0.0.0:8081->8081/tcp, :::8081->8081/tcp cello-dashboard
7373
```
@@ -101,6 +101,147 @@ If environment is prepared, then we can start cello service.
101101

102102
* Check [troubleshoot](https://github.com/hyperledger/cello/blob/main/docs/setup/server.md#3-troubleshoot) section if you get any question.
103103

104+
### PostgreSQL 12 → 16 Migration
105+
106+
#### Important
107+
108+
PostgreSQL major-version data directories cannot be directly reused between PG12 and PG16 due to internal storage format changes. Before performing the upgrade:
109+
* Preserve the existing PG12 data directory or Docker volume so rollback remains possible.
110+
* Create a separate PG16 volume or storage directory rather than overwriting existing PG12 storage.
111+
* Perform a full backup of all databases and PostgreSQL globals/roles using `pg_dumpall`.
112+
* Check PostgreSQL extensions used by the application and verify database driver (`psycopg2-binary`) compatibility.
113+
* Validate the restored database and application functionality before removing old PG12 data.
114+
115+
#### Development environment
116+
117+
For setups using `docker-compose.dev.yaml` with the named volume `cello-postgres`:
118+
119+
1. **Back up PG12 databases and globals:**
120+
```bash
121+
docker exec -t cello-postgres pg_dumpall -U postgres > cello_pg12_backup.sql
122+
```
123+
124+
2. **Stop the development environment:**
125+
```bash
126+
docker compose -f docker-compose.dev.yaml down
127+
```
128+
129+
3. **Preserve the existing PG12 volume for rollback:**
130+
```bash
131+
docker volume create cello-postgres-pg12-backup
132+
docker run --rm -v cello-postgres:/from -v cello-postgres-pg12-backup:/to alpine sh -c "cp -av /from/. /to/"
133+
```
134+
135+
4. **Recreate the volume and start the updated PG16 database container:**
136+
```bash
137+
docker volume rm cello-postgres
138+
docker compose -f docker-compose.dev.yaml up -d cello-postgres
139+
```
140+
141+
5. **Restore the database backup into the PG16 container:**
142+
```bash
143+
docker exec -i cello-postgres psql -U postgres < cello_pg12_backup.sql
144+
```
145+
146+
6. **Start all development services:**
147+
```bash
148+
docker compose -f docker-compose.dev.yaml up -d
149+
```
150+
151+
#### Deployment using /opt/cello/pgdata
152+
153+
For deployments using `bootup/docker-compose-files/docker-compose.dev.yml`, `docker-compose.server.dev.yml`, or `docker-compose-dev.yml` with host path `${CELLO_STORAGE_PATH:-/opt/cello}/pgdata`:
154+
155+
1. **Back up PG12 databases and globals:**
156+
```bash
157+
docker exec -t cello-postgres pg_dumpall -U postgres > cello_pg12_backup.sql
158+
```
159+
160+
2. **Stop running services:**
161+
```bash
162+
docker compose -f bootup/docker-compose-files/docker-compose.dev.yml down
163+
```
164+
165+
3. **Preserve existing PG12 storage directory:**
166+
```bash
167+
sudo mv /opt/cello/pgdata /opt/cello/pgdata_v12_backup
168+
sudo mkdir -p /opt/cello/pgdata
169+
```
170+
171+
4. **Start the upgraded PG16 database container:**
172+
```bash
173+
docker compose -f bootup/docker-compose-files/docker-compose.dev.yml up -d cello-postgres
174+
```
175+
176+
5. **Restore the database backup:**
177+
```bash
178+
docker exec -i cello-postgres psql -U postgres < cello_pg12_backup.sql
179+
```
180+
181+
6. **Start all services:**
182+
```bash
183+
docker compose -f bootup/docker-compose-files/docker-compose.dev.yml up -d
184+
```
185+
186+
#### Deployment using /opt/cello/postgres
187+
188+
For server deployments using `bootup/docker-compose-files/docker-compose.yml` with host path `/opt/cello/postgres`:
189+
190+
1. **Back up PG12 databases and globals:**
191+
```bash
192+
docker exec -t cello-postgres-server pg_dumpall -U ${POSTGRES_USER:-postgres} > cello_pg12_backup.sql
193+
```
194+
195+
2. **Stop running services:**
196+
```bash
197+
docker compose -f bootup/docker-compose-files/docker-compose.yml down
198+
```
199+
200+
3. **Preserve existing PG12 storage directory:**
201+
```bash
202+
sudo mv /opt/cello/postgres /opt/cello/postgres_v12_backup
203+
sudo mkdir -p /opt/cello/postgres
204+
```
205+
206+
4. **Start the upgraded PG16 database container:**
207+
```bash
208+
docker compose -f bootup/docker-compose-files/docker-compose.yml up -d postgres-server
209+
```
210+
211+
5. **Restore the database backup:**
212+
```bash
213+
docker exec -i cello-postgres-server psql -U ${POSTGRES_USER:-postgres} < cello_pg12_backup.sql
214+
```
215+
216+
6. **Start all services:**
217+
```bash
218+
docker compose -f bootup/docker-compose-files/docker-compose.yml up -d
219+
```
220+
221+
#### Validation
222+
223+
1. Verify PostgreSQL version inside the container:
224+
```bash
225+
docker exec -it cello-postgres psql -U postgres -c "SELECT version();"
226+
```
227+
2. Verify Django API Engine logs for successful migrations and database connectivity:
228+
```bash
229+
docker logs cello-api-engine
230+
```
231+
3. Run API integration tests:
232+
```bash
233+
make check-api
234+
```
235+
236+
#### Rollback
237+
238+
If issues arise during verification:
239+
1. Stop the PG16 environment (`docker compose down`).
240+
2. Revert the PostgreSQL image reference to `postgres:12.0`.
241+
3. Restore the preserved PG12 storage directory (`/opt/cello/pgdata_v12_backup` -> `/opt/cello/pgdata` or `/opt/cello/postgres_v12_backup` -> `/opt/cello/postgres`) or named volume (`cello-postgres-pg12-backup`).
242+
4. Restart services.
243+
5. Only remove old PG12 storage after the PG16 environment is fully verified.
244+
104245
## Main Features
105246

106247
* Manage the lifecycle of blockchains, e.g., create/start/stop/delete/keep health automatically.

bootup/docker-compose-files/docker-compose-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ services:
2020

2121
# pg database
2222
cello-postgres:
23-
image: postgres:16.8
23+
image: postgres:16.14
2424
container_name: cello-postgres
2525
restart: unless-stopped
2626
environment:

bootup/docker-compose-files/docker-compose.dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ services:
2222

2323
# pg database
2424
cello-postgres:
25-
image: postgres:16.8
25+
image: postgres:16.14
2626
container_name: cello-postgres
2727
restart: unless-stopped
2828
environment:

bootup/docker-compose-files/docker-compose.server.dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515

1616
# pg database
1717
cello-postgres:
18-
image: postgres:16.8
18+
image: postgres:16.14
1919
container_name: cello-postgres
2020
restart: unless-stopped
2121
environment:

bootup/docker-compose-files/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ services:
3030
- /opt/cello/api-engine/media:/var/www/media
3131

3232
postgres-server:
33-
image: postgres:16.8
33+
image: postgres:16.14
3434
hostname: cello-postgres-server
3535
container_name: cello-postgres-server
3636
restart: always

docker-compose.dev.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ services:
1313
- cello-api-engine
1414

1515
cello-postgres:
16-
image: postgres:16.8
16+
image: postgres:16.14
1717
container_name: cello-postgres
1818
restart: unless-stopped
1919
environment:
@@ -68,9 +68,7 @@ services:
6868
- /var/run/docker.sock:/var/run/docker.sock
6969
- cello-hyperledger-fabric-agent:/cello
7070
networks:
71-
cello-net:
72-
aliases:
73-
- cello-hyperledger-fabric-agent
71+
- cello-net
7472

7573
networks:
7674
cello-net:

0 commit comments

Comments
 (0)