Change SQLite backup to use VACUUM INTO query #37

Open
opened 2026-04-05 20:29:02 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @getaaron on 3/22/2026

https://github.com/dani-garcia/vaultwarden/pull/6279 introduced several great improvements, but replaced VACUUM INTO with serialize_database_to_buffer() which is less efficient and loads the whole DB into RAM. This may be contributing to an increase in OOM errors which I have noticed in small vaultwarden deployments with 256MB RAM.

This PR reverts the serialize_database_to_buffer() change back into a VACUUM INTO query while keeping the other improvements from that PR. I also used .bind::<Text, _>(&backup_file) instead of the previous format!("VACUUM INTO '{}'", backup_file) to prevent theoretical SQL injection (even though path is trusted), let me know if you prefer the format! approach and I can switch it

*Originally created by @getaaron on 3/22/2026* https://github.com/dani-garcia/vaultwarden/pull/6279 introduced several great improvements, but replaced `VACUUM INTO` with `serialize_database_to_buffer()` which is less efficient and loads the whole DB into RAM. This may be contributing to an increase in OOM errors which I have noticed in small vaultwarden deployments with 256MB RAM. This PR reverts the `serialize_database_to_buffer()` change back into a `VACUUM INTO` query while keeping the other improvements from that PR. I also used `.bind::<Text, _>(&backup_file)` instead of the previous `format!("VACUUM INTO '{}'", backup_file)` to prevent theoretical SQL injection (even though path is trusted), let me know if you prefer the `format!` approach and I can switch it
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/vaultwarden#37