PSA: SQLite 不进行校验和 - blag

  • Default in SQLite: SQLite does not do checksums by default. If there is disk corruption, the database or application won't be able to know. A single bit flip can cause issues due to faulty disk, disk driver bug, or other application modifying database files.
  • Demonstration Script: A simple script was created to show this. It creates a sample bank database and adds a row for Alice with $83K. Then a single bit is flipped by a specific dd command, and Alice's balance becomes zero. It still passes PRAGMA integrity_check.
  • WAL and Checksums: SQLite has checksums for WAL frames. But when it detects a corrupt frame, it silently ignores it and subsequent frames without raising an error.
  • Checksum VFS Shim: Can be used but with an important caveat. Checksumming only works on databases with a reserve bytes value of exactly 8. The documentation of reserve bytes explains its use by extensions. If using an extension that uses reserve bytes, the Checksum shim can't be used.
  • Edit: A follow-up post was written.
阅读 22
0 条评论