Database
The backend database is Postgres and it's running as a container.
Connectivity
By default, containers must be connectable only within the Docker network. For debugging reasons, instances publish their IP.
| Container name | Env | Port |
|---|---|---|
| simops-db | Prod | 35433 |
| simops-db-dev | Dev | 35431 |
Use ufw to block ports when containers are normally not accessible from the public network.
sudo ufw allow 35433/tcp
sudo ufw deny 35433/tcp
See also Database as a datastore for Simops API.
Local Database Upgrade
For the local instance of database, say from PostgreSQL 16 to 17, the steps was:
- With DataGrip, do an export using
pg_dump(pg_dumpcan be installed via the Enterprise DB Postgres Downloads and selecting only Command-line tools in wizard)pg_dump --dbname=simops \--file=D:/path/to/pg_dump/simops-dump.sql \--username=postgres --host=localhost --port=5432 - Stop the current container, not removing it.
- Start a new container with a new volume. The volume is using the version in its name (ie:
_17)docker run -d --name simops-db-local-17 -p 5432:5432 --restart=always \-e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=simops \-e PGDATA=/var/lib/postgresql/data/pgdata \-v simops-api_simops-db-data_17:/var/lib/postgresql/data \postgres:17.2 - Connect to database and import the dump file with
psql(can also do that in DataGrip).psql --file=D:/simops/dump.sql \--username=postgres --host=localhost --port=5432 simops - Check if all is working correctly, including running API and Web client
- If working correctly, we can delete old container and rename the new one
Dev instance upgrade
- Do a backup of the dev database:
pg_dump --dbname=simops \--file=./simops-dump.sql \--username=simopsdb --host=localhost --port=35431
- Remove container and volume (check which volume it's using with
docker inspect). - Change version of Postgre service on docker compose file and push changes.
- Run Development pipeline
- Check if container is up and running with correct version of image.
- Restore data from SQL file/backup.
psql --file=./simops_dump.sql \--username=simopsdb --host=localhost --port=35431 simops
Prod instance upgrade
- Change Postgre image version in docker compose and push changes
- Do a backup of the prod database:
pg_dump --dbname=simops \--file=./dump.sql \--username=simopsdb --host=localhost --port=35433
- Remove container and volume (check which volume it's using with
docker inspect). - Run production pipeline
- Check if container is up and running with correct version of image.
- Restore data from SQL file/backup.
psql --file=./dump.sql \--username=simopsdb --host=localhost --port=35433 simops