CouchDB Upgrade Utility: Recovering from Mixed-State Databases After an Interrupted 3.x to 4.x Transition
0 reputation · 21 May 2026, 11:58 UTC
0 reputation · 21 May 2026, 11:58 UTC
When moving a CouchDB cluster from 3.x to 4.x, the _upgrader REST endpoint rewrites database files in place while the node is offline. If the process is interrupted—by power loss, a kill signal, or manual termination—some .couch files may already be in the new format while others remain pre-upgrade. The result is a mixed-state data directory that can prevent startup or trigger view rebuild errors.
The documented recovery path is to restore the entire data directory from a pre-upgrade backup, because the upgrade utility does not provide an automatic rollback or checkpoint mechanism. Operators without a backup face a manual, error-prone cleanup: identifying partially migrated files, removing stray temporary artifacts, and deciding whether to re-run the upgrade from scratch or attempt a targeted repair. There is currently no built-in detection of a previous incomplete run, leaving the resume-or-restore decision entirely to the administrator.
Given that CouchDB 3.x to 4.x migrations rely on the _upgrader endpoint with exclusive data-directory access, what is the safest supported procedure when no pre-upgrade backup exists and the upgrade was interrupted mid-run? Should administrators assume the utility will never resume automatically and always plan for full restoration, or are there documented safeguards for detecting partial migrations before restarting the node? How do release notes for the 4.x line address configuration files that the endpoint does not migrate automatically after an interrupted run?
32775 reputation · 21 May 2026, 14:45 UTC
When the _upgrader stops in the middle of a 3.x‑to‑4.x transition, CouchDB does not provide an automatic resume or checkpoint. The only supported recovery path is a full restore from a known‑good backup. If no backup exists, the safest option is to wipe the data directory and rebuild the cluster from scratch or from replication sources, because manual file‑level cleanup carries a high risk of permanent data loss.
The _upgrader performs an in‑place rewrite of each .couch file. It does not keep a per‑file or global migration state. Consequently:
There is no automated flag, but you can identify the problem by inspecting CouchDB logs and the file metadata:
couchdb -vv in debug mode) to avoid automatic startup.couchdb.log for errors such as bad file format or invalid version that reference specific .couch files.couchdb -vv or couchdb -vvv to print the version stored in the data directory’s couchdb.dir metadata. If the binary version (4.x) and the directory version differ, a partial upgrade is likely.find /var/lib/couchdb -name "*.couch" -exec stat -c "%n %y" {} \; | grep -i upgrade to spot files that were modified during the last upgrade run.Because manual repair can corrupt data, the following steps are the safest:
/var/lib/couchdb to a safe location. This preserves the data for forensic analysis or for incremental attempts.couchdb -C config.ini) and let the nodes bootstrap._replicate or couchdb‑backup tools to bring the data back into the new 4.x cluster.local.ini or default.ini. After the fresh install, manually copy any custom settings from the old local.ini into the new one, and restart the node to verify they are applied.Restore the backup exactly as it existed before the upgrade attempt. Verify the data directory’s couchdb.dir metadata shows the pre‑upgrade version. Then run the _upgrader again from a clean state; the process will now upgrade all files atomically.
_upgrader does not support resuming; a mixed‑state directory is considered unrecoverable without a backup.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.