Skip to content

Keep live data when a backup restore fails - #444

Merged
ArnavAgrawal03 merged 1 commit into
mainfrom
arnav/iy2r5
Sep 30, 2026
Merged

ArnavAgrawal03 merged 1 commit into
mainfrom
arnav/iy2r5

Conversation

@ArnavAgrawal03

@ArnavAgrawal03 ArnavAgrawal03 commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Restoring a backup with more than about 10,000 chunks failed while pg_restore rebuilt the IVFFlat index (1536-dimension vectors need 65 MB of maintenance_work_mem, PostgreSQL defaults to 64 MB), and because restore had already dropped the live database, the deployment came back empty. A customer hit this on a 359k-chunk install.
Restore and verify now both run with 512 MB (MORPHIK_RESTORE_MAINTENANCE_WORK_MEM overrides it), so verify can no longer pass a backup that restore rejects.
Restore loads into a morphik_restore database, checks it against the manifest, and only then renames it over the live database in one transaction, so a failed pg_restore leaves the current data as it was.
scripts/test_backup_restore.sh now seeds 10,500 vectors at 1536 dimensions and checks the failure path; it fails on main with the customer's exact error and passes on this branch (run with MORPHIK_BACKUP_TEST_S3=0).

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Restoring a backup with more than about 10,000 chunks failed while
pg_restore rebuilt the IVFFlat index: 1536-dimension vectors need 65 MB
of maintenance_work_mem and PostgreSQL defaults to 64 MB. verify ran
with 256 MB, so it passed backups that restore then rejected. Because
restore dropped the live database before pg_restore, the failure left
the deployment empty.

Restore and verify now both use 512 MB (MORPHIK_RESTORE_MAINTENANCE_WORK_MEM
overrides it). Restore loads into a morphik_restore database, checks it
against the manifest, and only then renames it over the live database in
one transaction, so a failed pg_restore leaves the current data as it
was.

The Docker test now seeds 10,500 vectors at 1536 dimensions and checks
that a pg_restore failure leaves the live database and files unchanged.
@ArnavAgrawal03
ArnavAgrawal03 merged commit 3b71932 into main Sep 30, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant