Inspecting SQLite 100-Byte Headers, WAL Logs, and Deleted Freelist Rows Locally in the Browser
If you have ever needed to inspect a .sqlite or .db file on a locked-down work laptop, you know the usual trade-off: either install desktop software like DB Browser for SQLite, or upload a potentially sensitive database
If you have ever needed to inspect a .sqlite or .db file on a locked-down work laptop, you know the usual trade-off: either install desktop software like DB Browser for SQLite, or upload a potentially sensitive database to a random online converter and hope the server actually deletes it.
Most browser-based SQLite viewers try to solve this by fetching a precompiled .wasm binary from a third-party CDNβwhich works fine on home Wi-Fi, then silently breaks under a strict corporate Content-Security-Policy (CSP). Even when they do load, almost all of them are strictly read-only, ignore companion -wal files, and miss unvacuumed deleted data hiding in freelist pages.
While building the SQLite & DuckDB Viewer, Editor, ERD & Forensic Studio on KivaroTools, I ended up going down the rabbit hole of SQLite 3's binary file format and building a zero-CDN TypeScript B-tree parser and serializer that runs 100% in browser memory. Here are the four SQLite internals and edge cases that catch engineers off guardβand how to inspect and fix them locally.
1. The 100-Byte Header Tells You More Than the File Extension
A .db, .sqlite, and .sqlite3 file are identical under the hood. Every valid SQLite 3 binary starts with a 100-byte header on Page 1 (bytes 0..99). Reading just five offsets tells you immediately whether a file is valid, whether it uses WAL mode, and whether deleted records are still sitting inside it:
| Offset (Size) | Header Field | Values | Why It Matters |
|---|---|---|---|
0..15 (16 B) |
Magic String | "SQLite format 3\0" |
Confirms a real SQLite 3 file (rules out Access, dBase .dbf, or SQLCipher-encrypted .crypt files). |
16..17 (2 B) |
Page Size |
512β65536 B |
Modern SQLite defaults to 4096 bytes per B-tree page. |
18..19 (2 B) |
Write/Read Version |
1 = Rollback, 2 = WAL |
2 means recent writes may live in a companion .db-wal file, not the main .db. |
32..39 (8 B) |
Freelist Pages | Two 32-bit uints | A non-zero count means unvacuumed deleted pages still exist on disk. |
56..59 (4 B) |
Text Encoding |
1 = UTF-8, 2/3 = UTF-16 |
Controls how TEXT payloads are decoded from B-tree leaf cells. |
If a .db file refuses to open in any SQLite tool, checking bytes 0..15 immediately tells you whether it is actually SQLite or a different binary format.
2. Missing Recent Rows from Uncheckpointed .db-wal Files
If your app runs in Write-Ahead Logging (WAL) mode (header bytes 18..19 equal 2), copying app.db off a container or server without checkpointing often leaves your most recent INSERT and UPDATE transactions behind in app.db-wal.
Before grabbing a snapshot from production or staging, flush the WAL log into the main database file:
PRAGMA wal_checkpoint(TRUNCATE);
If you already pulled both files separately, you need a viewer that can attach the companion .db-wal alongside the main .db fileβotherwise you are looking at stale state.
3. Deleted Rows Survive DELETE FROM Until You Run VACUUM
One of the easiest privacy mistakes when sharing a "cleaned" SQLite database for debugging or support is running DELETE FROM users WHERE ...; and sending the .sqlite file over Slack or email.
SQLite does not zero out deleted bytes on DELETE. It marks those B-tree pages as free and adds them to the freelist (tracked at header bytes 32..39). The raw stringsβemails, tokens, wire detailsβstay readable inside the binary file until you explicitly rebuild it:
VACUUM;
In our forensic test fixture (forensic_places_and_sms.sqlite), two deleted wire rows sit right inside freelist space until carved or wiped. If you share .sqlite dumps with teammates or clients, always inspect freelist pages and scrub PII before exporting.
4. Unindexed Foreign Keys and 17-Digit Browser/iOS Timestamps
Two other headaches pop up constantly when auditing real-world SQLite databases:
Unindexed Foreign Keys: SQLite automatically indexes
PRIMARY KEYcolumns, notFOREIGN KEYcolumns. As soon as a table grows,JOINqueries and cascading deletes fall back to full table scans. RunningPRAGMA foreign_key_check;catches orphaned child rows, and adding explicit indexes on every*_idforeign key fixes the query plan.Opaque Epoch Timestamps: If you inspect Chromium
History(WebKit 1601microsecond timestamps) or Apple iOSsms.db/chat.db(CoreData 2001nanosecond timestamps), raw 17-digit integers are unreadable without manual epoch math. Decoding them inline into UTC timestamps saves a lot of scratchpad SQL.
Putting It Together in a Browser-Local Studio
I wanted a single local workspace where I could drop a .sqlite, .db, .sqlite3, .db-wal, .duckdb, or .sql file without uploading anything to a serverβand actually edit and save binary .sqlite files rather than hitting a read-only wall.
In the KivaroTools SQLite & DuckDB Viewer, Editor, ERD & Forensic Studio, everything runs locally in browser memory across five tabs:
SQL & DuckDB Analytical Runner + Inline Editor: Edit cells inline, add rows or tables, run standard SQLite queries plus DuckDB analytical syntax (
SUMMARIZE orders;,SELECT * EXCLUDE (metadata_json) FROM orders WHERE status = 'PAID';,GROUP BY ALL), and automatically decode Chrome 1601 / Apple 2001 timestamps.Visual ER Diagrams & ORM Schemas: Generate interactive Vector
.svg, Mermaid, and DBML ER diagrams (mapping both declaredFOREIGN KEYconstraints and implicit*_idrelations) and compile directly to Drizzle ORM (schema.ts), Prisma (schema.prisma), or PostgreSQL migrations:
import { sqliteTable, integer, text } from 'drizzle-orm/sqlite-core';
export const users = sqliteTable('users', {
id: integer('id').primaryKey({ autoIncrement: true }),
organization_id: integer('organization_id')
.notNull()
.references(() => organizations.id),
full_name: text('full_name').notNull(),
plan_tier: text('plan_tier').notNull(),
});
12-Point Linter & Auto-Optimizer: Flags unindexed foreign keys, orphaned rows, and schema issues with a 1-click auto-fix.
100-Byte Header, WAL & Freelist Forensics: Inspects Page 1 binary headers, attaches
.db-wallogs, carves deleted freelist records, and runs 1-click PII anonymization and residue wiping.11-Format Export & Side-by-Side Diff (
sqldiff): Save modified binary.sqlitefiles (passingPRAGMA integrity_check), export CWE-1236 formula-safe Excel (.xlsx), RFC 4180 CSV, SQL dumps, or diff two SQLite databases locally to produceALTER TABLEmigration patches.
Honest Scope & Privacy Boundaries
Your database files stay inside local browser memory and are never uploaded to KivaroTools servers. Because processing happens in client RAM, files run smoothly up to roughly 100β250 MB. For multi-gigabyte databases, heavy batch ETL, or SQLCipher / WhatsApp .crypt encrypted files, desktop DB Browser for SQLite is still the right tool. (And if you need columnar .parquet, .avro, or .feather files instead of SQLite, we keep those in a separate Parquet, Avro & Feather Viewer.)
The Stack
Built with Next.js (App Router), React, TypeScript, and Tailwind CSS, deployed on Cloudflare Workers with a self-contained zero-CDN TypeScript B-tree parser so strict corporate firewalls and CSP rules do not break local file loading.
If you want to test it without grabbing a local .db file, there are three built-in sample databases (SaaS Prod, Forensic DB, and Chrome / iOS) you can load in one click. Curious what SQLite edge cases or export formats you run into most often in productionβlet me know in the comments.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.