Skip to content

docs(sqlite): clarify WAL sidecar cleanup behavior after close#27915

Open
ssing2 wants to merge 1 commit intooven-sh:mainfrom
ssing2:fix-27481-sqlite-wal-docs
Open

docs(sqlite): clarify WAL sidecar cleanup behavior after close#27915
ssing2 wants to merge 1 commit intooven-sh:mainfrom
ssing2:fix-27481-sqlite-wal-docs

Conversation

@ssing2
Copy link
Contributor

@ssing2 ssing2 commented Mar 8, 2026

Fixes #27481

Documents that WAL sidecar files (.db-wal, .db-shm) cleanup behavior
varies by platform and SQLite configuration after db.close():

  • Linux: sidecar files typically cleaned up after close
  • macOS: sidecar files may persist after close
  • Windows: behavior varies by version and configuration

Provides guidance for manual cleanup when needed.

Changes

  • Added Important note about WAL sidecar file behavior
  • Clarified platform-specific cleanup differences
  • Provided example for manual cleanup when needed

Fixes oven-sh#27481

Documents that WAL sidecar files (.db-wal, .db-shm) cleanup behavior
varies by platform and SQLite configuration after db.close():

- Linux: sidecar files typically cleaned up after close
- macOS: sidecar files may persist after close
- Windows: behavior varies by version and configuration

Provides guidance for manual cleanup when needed.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 8, 2026

Walkthrough

Documentation update to docs/runtime/sqlite.mdx clarifying WAL sidecar file (.db-wal, .db-shm) cleanup behavior. Added notes explaining platform-specific cleanup variations after database close and provided code examples for manual sidecar file removal.

Changes

Cohort / File(s) Summary
SQLite WAL Cleanup Documentation
docs/runtime/sqlite.mdx
Added documentation notes explaining that WAL mode creates sidecar files whose cleanup behavior varies by platform. Includes code snippets demonstrating manual removal of .db-wal and .db-shm files using rmSync in two locations within the documentation.
🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The PR partially addresses issue #27481 by documenting platform-specific WAL sidecar cleanup behavior, but does not include the suggested deterministic cleanup code example using fileControl(constants.SQLITE_FCNTL_PERSIST_WAL, 0). Review whether the deterministic cleanup option (fileControl with SQLITE_FCNTL_PERSIST_WAL) should be documented as mentioned in issue #27481, or if manual cleanup guidance is sufficient.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change - it clarifies WAL sidecar cleanup behavior documentation, matching the core objective of the PR.
Description check ✅ Passed The description addresses the required template sections and provides detailed context about platform-specific WAL cleanup behavior, linking to issue #27481.
Out of Scope Changes check ✅ Passed All changes in the PR are directly related to documenting WAL sidecar cleanup behavior as specified in linked issue #27481 - no out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/runtime/sqlite.mdx`:
- Around line 146-152: The rmSync calls can throw ENOENT if the WAL/SHM sidecar
files are absent; update the cleanup to call rmSync("mydb.sqlite-wal", { force:
true }) and rmSync("mydb.sqlite-shm", { force: true }) after db.close() so
removal is idempotent and safe across platforms — locate the calls to rmSync in
the snippet and add the { force: true } option.
- Around line 136-153: Update the "WAL sidecar files" Important note to
recommend using the deterministic SQLite API before suggesting manual deletion:
explain and show using Database and
db.fileControl(constants.SQLITE_FCNTL_PERSIST_WAL, 0) after enabling WAL (e.g.,
after db.run("PRAGMA journal_mode = WAL;")) so SQLite will clean up sidecar
files on db.close(), then present manual rmSync deletion as a fallback and use
rmSync("mydb.sqlite-wal", { force: true }) and rmSync("mydb.sqlite-shm", {
force: true }) to avoid errors when removing files.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5d2b3b62-95a3-4eca-8695-7df976ca7695

📥 Commits

Reviewing files that changed from the base of the PR and between 06b2ba7 and eb4572e.

📒 Files selected for processing (1)
  • docs/runtime/sqlite.mdx

Comment on lines +136 to +153
<Important title="WAL sidecar files">
When using WAL (Write-Ahead Logging) mode with a file-based database, SQLite creates additional sidecar files:
`-wal` (write-ahead log) and `-shm` (shared memory). The cleanup behavior of these files after calling `.close()`
varies by platform and SQLite configuration:

- **Linux**: Sidecar files are typically cleaned up after close
- **macOS**: Sidecar files may persist after close due to platform-specific SQLite behavior
- **Windows**: Behavior varies by Windows version and SQLite configuration

If you need to ensure sidecar files are cleaned up, consider manually removing them after closing the database:
```ts
import { rmSync } from "node:fs";

db.close();
rmSync("mydb.sqlite-wal");
rmSync("mydb.sqlite-shm");
```
</Important>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Cross-reference the fileControl API for deterministic cleanup.

The linked issue (#27481) specifically requests documenting db.fileControl(constants.SQLITE_FCNTL_PERSIST_WAL, 0) as the deterministic cleanup option. This API is already documented at lines 647-658, but this Important note doesn't mention it. The fileControl approach is preferable to manual file deletion as it instructs SQLite itself to clean up the files on close.

Consider restructuring to recommend the fileControl approach first, with manual deletion as a fallback:

📝 Suggested documentation improvement
   If you need to ensure sidecar files are cleaned up, consider manually removing them after closing the database:
+  If you need deterministic cleanup of sidecar files, use the `fileControl` API before closing:
+  ```ts
+  import { Database, constants } from "bun:sqlite";
+
+  const db = new Database("mydb.sqlite");
+  db.run("PRAGMA journal_mode = WAL;");
+  // Disable WAL persistence - files will be cleaned up on close
+  db.fileControl(constants.SQLITE_FCNTL_PERSIST_WAL, 0);
+  // ... use database ...
+  db.close();
+  ```
+
+  Alternatively, you can manually remove the files after closing:
   ```ts
-  import { rmSync } from "node:fs";
+  import { rmSync } from "node:fs"; 
 
   db.close();
-  rmSync("mydb.sqlite-wal");
-  rmSync("mydb.sqlite-shm");
+  rmSync("mydb.sqlite-wal", { force: true });
+  rmSync("mydb.sqlite-shm", { force: true });
</details>

<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

```suggestion
<Important title="WAL sidecar files">
  When using WAL (Write-Ahead Logging) mode with a file-based database, SQLite creates additional sidecar files:
  `-wal` (write-ahead log) and `-shm` (shared memory). The cleanup behavior of these files after calling `.close()` 
  varies by platform and SQLite configuration:

  - **Linux**: Sidecar files are typically cleaned up after close
  - **macOS**: Sidecar files may persist after close due to platform-specific SQLite behavior
  - **Windows**: Behavior varies by Windows version and SQLite configuration

  If you need deterministic cleanup of sidecar files, use the `fileControl` API before closing:
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/runtime/sqlite.mdx` around lines 136 - 153, Update the "WAL sidecar
files" Important note to recommend using the deterministic SQLite API before
suggesting manual deletion: explain and show using Database and
db.fileControl(constants.SQLITE_FCNTL_PERSIST_WAL, 0) after enabling WAL (e.g.,
after db.run("PRAGMA journal_mode = WAL;")) so SQLite will clean up sidecar
files on db.close(), then present manual rmSync deletion as a fallback and use
rmSync("mydb.sqlite-wal", { force: true }) and rmSync("mydb.sqlite-shm", {
force: true }) to avoid errors when removing files.

Comment on lines +146 to +152
```ts
import { rmSync } from "node:fs";

db.close();
rmSync("mydb.sqlite-wal");
rmSync("mydb.sqlite-shm");
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add { force: true } to prevent errors when files don't exist.

The rmSync calls will throw ENOENT if the sidecar files don't exist (e.g., on Linux where they may already be cleaned up, or if WAL mode wasn't actually used). Adding { force: true } makes the cleanup idempotent and safe across platforms.

🛠️ Proposed fix
   ```ts
   import { rmSync } from "node:fs";

   db.close();
-  rmSync("mydb.sqlite-wal");
-  rmSync("mydb.sqlite-shm");
+  rmSync("mydb.sqlite-wal", { force: true });
+  rmSync("mydb.sqlite-shm", { force: true });
</details>

<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

```suggestion

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/runtime/sqlite.mdx` around lines 146 - 152, The rmSync calls can throw
ENOENT if the WAL/SHM sidecar files are absent; update the cleanup to call
rmSync("mydb.sqlite-wal", { force: true }) and rmSync("mydb.sqlite-shm", {
force: true }) after db.close() so removal is idempotent and safe across
platforms — locate the calls to rmSync in the snippet and add the { force: true
} option.

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.

docs(sqlite): clarify WAL sidecar cleanup behavior after close

1 participant