Skip to content

feat(local): set WAL journal mode as default for local databases (fixes #1553) - #2280

Open
Aditya-9-6 wants to merge 2 commits into
tursodatabase:mainfrom
Aditya-9-6:fix/default-wal-mode
Open

feat(local): set WAL journal mode as default for local databases (fixes #1553)#2280
Aditya-9-6 wants to merge 2 commits into
tursodatabase:mainfrom
Aditya-9-6:fix/default-wal-mode

Conversation

@Aditya-9-6

Copy link
Copy Markdown

Resolves #1553.

Problem

Turso's server, platform, and embedded replicas all use Write-Ahead Logging (WAL) mode. However, standalone and local file-based database connections in the libsql Rust driver did not enable WAL mode by default, leaving databases in DELETE journal mode unless explicitly configured.

Solution

  • Automatically execute PRAGMA journal_mode = WAL upon establishing local file-based database connections in Connection::connect.
  • Safely skip setting WAL mode for:
    • In-memory databases (:memory: or temporary empty paths), which do not support WAL mode and will gracefully remain in memory journal mode.
    • Read-only databases (SQLITE_OPEN_READONLY), avoiding SQLITE_READONLY: attempt to write a readonly database errors when opening existing read-only database files.
  • Move the Unix-only dev-dependency pprof under [target.'cfg(not(windows))'.dev-dependencies] in libsql/Cargo.toml so Windows developers can build and run tests without compilation failures.
  • Add integration tests in libsql/tests/integration_tests.rs:
    • test_default_journal_mode_is_wal: asserts that both Builder::new_local and Database::open default to WAL mode.
    • test_memory_journal_mode_is_memory: verifies :memory: databases succeed and report "memory".
    • test_readonly_connection_succeeds: verifies opening databases with OpenFlags::SQLITE_OPEN_READ_ONLY succeeds and preserves WAL mode without attempting invalid header writes.

tursodatabase#1553)

- Sets SQLite journal mode to WAL (PRAGMA journal_mode = WAL) by default when opening local file-based database connections.

- Safely skips setting WAL mode for in-memory (:memory:) databases and read-only connections (SQLITE_OPEN_READONLY).

- Adds integration tests verifying default WAL mode, in-memory databases, and read-only connections.

- Gates pprof under cfg(not(windows)) in dev-dependencies to support building and testing on Windows.
…tabases

- Moves PRAGMA journal_mode = WAL execution to DbType::File after encryption cipher and key are set.

- Restores Connection::connect to avoid executing SQL before encryption keys are applied to raw SQLite handles, fixing 'file is not a database' on encrypted databases and embedded replicas.
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.

Use WAL as default everywhere

1 participant