Changing the Database Password¶
The exact steps depend on your deployment type, and — for native/PM2 — whether encryption at rest is already set up. Pick the right tab below.
Order matters
In every path, update the app's stored credential before changing Postgres's actual password, then restart immediately after the Postgres change. That way the only window where the two are out of sync is the few seconds between the ALTER ROLE/ALTER USER and the restart — not the (potentially much longer) time between editing a config file and remembering to restart.
Use this if backend/.env already has a DB_PASSWORD_ENC line (see Secrets & Encryption).
Don't just re-run install-onprem.sh
Re-running the installer reconciles Postgres to whatever password is already encrypted — it doesn't generate or accept a new one. It's the right tool for keeping things in sync during an upgrade, not for rotating the password.
- Generate a new strong password and encrypt it with the existing master key:
cd backend NEW_PASSWORD=$(head -c 32 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9' | head -c 32) node dist/scripts/encrypt-env-value.js encrypt /etc/itsm/env-master.key "$NEW_PASSWORD" # copy the printed iv:authTag:ciphertext value - Replace the
DB_PASSWORD_ENC=line inbackend/.envwith the new ciphertext (keepENV_MASTER_KEY_FILEunchanged). - Apply the same password to the Postgres role:
(replace
sudo -u postgres psql -c "ALTER ROLE itsm_user WITH PASSWORD '${NEW_PASSWORD}';"itsm_userwith your actualDB_USER) - Restart immediately:
pm2 restart itsm-backend pm2 logs itsm-backend --lines 50 # confirm a clean startup, no auth errors curl -sf http://localhost:3001/api/health - Clear
$NEW_PASSWORDfrom your shell history / unset it.
Use this if backend/.env still has a plaintext DB_PASSWORD= line. Consider setting up encryption first — it takes one command and this becomes the encrypted flow above.
- Generate a new strong password.
- Update
DB_PASSWORD=in both.env(root) andbackend/.env—install-onprem.shcopies root → backend on every future run, so leaving them out of sync will silently revert the backend's copy on the next upgrade. - Apply it to the Postgres role:
sudo -u postgres psql -c "ALTER ROLE itsm_user WITH PASSWORD 'NewStrongPassword';" - Restart immediately:
pm2 restart itsm-backend pm2 logs itsm-backend --lines 50 curl -sf http://localhost:3001/api/health
The db container's POSTGRES_PASSWORD only takes effect the first time it initializes an empty volume — editing .env alone does not change an already-running database's password. You have to change both.
- Generate a new strong password.
- Change the live Postgres role's password inside the running container:
docker exec -it itsm-db-prod psql -U ${DB_USER} -c "ALTER USER ${DB_USER} WITH PASSWORD 'NewStrongPassword';" - Update
DB_PASSWORDin.envto the same value. - Recreate the
backendcontainer so it picks up the newDATABASE_URL(a plainrestartreuses the old, already-baked-in environment — it won't see the.envchange):docker compose -f docker-compose.prod.yml up -d backend - Verify:
docker compose -f docker-compose.prod.yml logs --tail=50 backend curl -sf http://localhost/api/health
After rotating¶
- If you use encryption at rest, the master key itself never changes during a password rotation — only the encrypted value does.
- Update your password manager / secrets vault entry for this environment.
- If you have an offsite backup of
.envfrom before the rotation, note that restoring it would reintroduce the old password — see Backups & Disaster Recovery.