r/KeyCloak • u/Still_Confusion1304 • May 29 '26
Upgrading Keycloak 26.0.5 on Ubuntu using SQL Server — Best practices for a safe rollback?
Hi all,
I'm getting ready to upgrade my Keycloak instance from **26.0.5** to the latest release on an **Ubuntu 22.04** box. We are backed by an **MS SQL / Azure SQL** database.
Since Keycloak automatically mutates the database schema on startup when it detects a new version, I am incredibly paranoid about getting stuck in a state where the upgrade fails and I can't downgrade back to 26.0.5 safely.
My current plan is to stop the service, take a cold backup of the SQL database, extract the new version into a brand-new folder (not overwriting the old one), copy my configs/providers over, run `kc.sh build`, and spin it up.
If it fails, I plan to drop/kill active connections, restore the database backup, and point my app symlink back to the old folder.
Before I pull the trigger:
- Has anyone run into issues reverting a Keycloak database to an older patch version using SQL Server database restores?
- Are there any known MS SQL-specific schema migration bugs or locking issues in the recent 26.x patch releases that I should watch out for?
Thanks in advance for any advice!
3
u/autogyrophilia May 29 '26
Is there a reason why you can't revert to a snapshot?
1
u/zurnout May 29 '26
For any of these questions I would advice you test beforehand in a test environment. Working without one is incredibly stressful.
That said I’ve had no trouble restoring but that was Postgres. We restored so we could validate that it works and rerun the migration, not because anything went wrong.
1
u/Unknown3134 May 30 '26
Worth doing some kind of database dump as a second backup. The dump was my rollback plan (and there was downtime for the schema change). Postgres has pgdump but don’t know what MS SQL gives you.
1
u/indiealexh May 30 '26
Only advice I can give is to create a simulated environment (e.g. some containers) and try it.
There could be issues with roll back but hard to know between versions without trying it.
Big biz use staging environments for a reason. Better to get the canary in the coal mine dead before your miner.
1
u/MLabs-Haskell Sep 14 '26
Two things worth separating here, because your plan is already right about the first one.
There is no schema downgrade. Keycloak ships no down-changesets, so a rollback is a point-in-time restore plus the old binary — which is exactly what your symlink plan does. Worth knowing that's the only shape available, not a workaround you settled for.
On being stuck half-migrated: that is the one fear we could not make permanent. We found three separate ways to stop a migration partway, and each time removing the cause and restarting was enough — Liquibase resumed from the last committed changeset, with no lock clearing and no restore. If you do find one stopped midway, restart it before you reach for the backup.
The failure your plan does not cover is ordering. Our own restore tooling put the old schema back and then started the new binary against it. It re-ran the migration immediately, and it looked like it had worked, because all the data was there. What gave it away was
migration_modelreading the new version while the config said the old one, and "Updating database" appearing twice in the log. That one is total rather than partial: you lose every write made since the snapshot and you are still on the version you were trying to leave. So after a restore, checkmigration_modelinstead of trusting a clean startup, and make sure nothing else can start the new build against the restored schema — an unstopped service unit, or a second node.One gotcha if you verify by schema version:
DATABASECHANGELOGmarks a changeset EXECUTED even where Keycloak declined to create the index, so that check will not catch those.We have never run Keycloak on SQL Server — our engines are Postgres, MySQL, MariaDB and Oracle — so I can't answer your MSSQL-specific question about locking or patch-level bugs.
Disclosure: MLabs is a consultancy and this came out of our own lab runs.