CliDeck

SQLite Deletion: Database Pages, WAL and Backups

← Back to Blog

Short answer

Deleting a row from SQLite is not the same as erasing every copy of its former content. Data can remain in reusable database space, a write-ahead log, a journal, or a separate backup. Start by naming the files and copies included in the deletion decision.

secure_delete and VACUUM address database-level remnants within their documented scope. A WAL checkpoint manages committed database changes and log reuse. None of these operations, by itself, proves physical sanitization of the underlying HDD or SSD, or deletion of snapshots and exported copies.

Who this is for

This guide is for application owners and administrators reviewing SQLite data removal before transferring a database file or retiring its storage. It separates three outcomes: a row no longer appears in queries, deleted content is removed from the maintained database representation, and the storage medium meets an approved sanitization requirement.

The SQL examples target ordinary SQLite tables. Record the actual engine version and application build. Embedded applications may bundle a different SQLite engine from the command-line tool on the same machine. The schema-qualified VACUUM syntax shown below requires SQLite 3.15.0 or later; use a supported, patched build approved for the application.

Verification note: No customer database, application logs or physical media were examined or altered for this article. The SQL examples are prospective maintenance steps requiring application-specific review. They are not transcripts of completed sanitization tests.

When to use this

Use this review when a deletion request is closed after a successful DELETE, when a smaller database file is described as wiped, or when a proposed transfer includes only the main file while related copies remain unaccounted for.

It also helps distinguish an approved data export from storage retirement. A file intended for another party needs a content review; a drive leaving custody needs a media-specific disposition decision. One does not automatically satisfy the other.

When not to use this

Do not perform maintenance on evidence under preservation, on a database you do not own, or on an application-managed file without the application owner's procedure. Bypassing the application can violate its retention rules, triggers, relationships or consistency assumptions.

Do not manually remove -wal, -shm or journal files from an active database. If access, version support, file identity or transaction state is unclear, stop. Resolve those conditions before executing a write operation.

Workflow

1. Define the deletion boundary

Record the main database path and all databases attached by the application. List snapshots, backups, exports, synchronization destinations and working copies. Give each retained copy an owner and a decision: keep under an authorized retention rule, delete through its own supported process, or investigate.

An important distinction is between a consistency backup and a sanitized transfer artifact. A backup deliberately preserved for recovery remains a data copy. Do not create a new sensitive backup automatically just because maintenance is planned; agree on preservation and disposition first.

Include temporary storage in the review. SQLite can create rollback journals, WAL files, temporary databases and transient working files. Their use depends on configuration and can change between versions. Treat filesystem snapshots and backup software as additional layers outside those SQLite file types.

2. Inspect the engine and schema context

Run informational queries through the authorized application connection or a controlled maintenance connection to the verified target:

SELECT sqlite_version();
PRAGMA database_list;
PRAGMA main.journal_mode;
PRAGMA main.secure_delete;
PRAGMA main.freelist_count;
SELECT type, name, tbl_name
FROM main.sqlite_master
ORDER BY type, name;

Keep the results internal. Paths and schema names can expose application details. These queries identify context; they do not demonstrate that old content is absent. In particular, a freelist count measures free database pages, not a quantity of recoverable personal data.

Review the schema for virtual tables, application-maintained history and duplicate representations of the target information. A row can disappear from one table while its value remains legitimately stored in another. Database-space cleanup does not decide which live records are authorized to remain.

3. Choose the ordinary-table deletion behavior

For an approved deletion on ordinary tables, enable the intended setting before the application performs the delete or update:

PRAGMA main.secure_delete = ON;
PRAGMA main.secure_delete;

ON causes deleted content to be overwritten with zeros within SQLite's ordinary-table handling. FAST is a weaker compromise that can leave traces on freelist pages. Do not assume the default: it depends on the build. Enabling the setting after deletion does not retroactively process old free space.

Virtual tables need separate attention. FTS3 and FTS5 shadow tables can retain traces even with the core pragma enabled. Review the particular extension and version instead of treating the setting as universal coverage.

Use the application's reviewed deletion routine and verify its exact selection criteria. This article intentionally supplies no generic table-wide DELETE: a valid predicate depends on the real schema, authorization and retention decision. Record errors and affected records without copying personal content into a public report.

4. Review rebuilding as a separate maintenance step

For previously deleted content, VACUUM rebuilds the database representation and removes deleted-content remnants from it. After committing the authorized transaction and closing unfinished statements, a supported maintenance connection can run:

VACUUM main;

Plan the operation before running it. Rebuilding may need substantial temporary space, can fail because of locks or an open transaction, and may change row identifiers in tables without an explicit integer primary key. Preserve the application's assumptions and inspect any failure before retrying.

VACUUM INTO instead creates a rebuilt output database and leaves the original unchanged. A reviewed output can therefore be useful for a transfer, but it adds an artifact whose identity and custody must be tracked. It does not dispose of the original. Do not accept an interrupted or incomplete output.

A successful rebuild is not a claim about old filesystem extents, controller-managed flash, retained snapshots or existing backup files. Avoid broadening a database-level result into media sanitization.

5. Treat WAL completion as its own result

In WAL mode, changed pages are appended to a separate log and checkpoints copy committed changes back into the database. Readers can prevent completion of later checkpoint work. A normal checkpoint does not necessarily shorten or remove the WAL; log storage can be reused.

Under an approved maintenance window, after the application has released relevant transactions, a supported WAL connection can request:

PRAGMA main.wal_checkpoint(TRUNCATE);

This is a write-side maintenance operation, not a passive status query. On successful completion, the truncate mode reduces the WAL file to zero bytes. Preserve the three returned integers and interpret them with the active journal mode: a busy result means the requested checkpoint did not complete; negative frame counts can indicate that there is no WAL for that connection.

Do not silently accept a blocked result. Identify the legitimate readers or writers and coordinate their completion. Do not force-kill an application or delete its log to make a checklist pass. A zero-length log is also only a filesystem observation; it is not evidence of physical erasure of its former storage.

6. Close the copy and media decisions

After the reviewed database operation, reconcile the full inventory again. A stale export or pre-deletion backup can defeat a statement that the information was removed everywhere, even when the current application query is correct.

If the requirement concerns release of the storage device, use an approved device-specific sanitization process and its completion evidence. The SSD translation-layer guide explains why changing host-visible data is a narrower claim than treating all physical flash locations.

Verification checklist

Keep the following findings distinct:

  • The application no longer returns the targeted records through the relevant queries.
  • The intended ordinary-table deletion setting was active before the operation, or a reviewed rebuild completed afterward.
  • Virtual tables, shadow data and other live representations were assessed separately.
  • Any required WAL maintenance completed without an unresolved busy or error result.
  • Retained originals, outputs, backups and snapshots have explicit dispositions.
  • The release decision states whether it concerns query visibility, a database artifact or a physical device.

A database integrity check can support a consistency review, but it does not prove absence of deleted information. Likewise, a search that fails to find a known string is limited by its encoding, representation and search coverage. Do not label either result as a forensic proof of erasure.

Resale and evidence checklist

Consider a hypothetical application that deletes a person's record and produces a rebuilt database for an authorized recipient. The recipient receives only the reviewed artifact, while an old recovery backup remains under a separate retention rule. The record should say which artifact was transferred and which copy was retained. It must not say that every copy was erased.

If the same machine is later sold, reopen the physical-media decision. Evidence that a database file was rebuilt is insufficient for the drive's release record. Identify the device, apply the accepted method and preserve its result and exceptions.

What not to publish

Do not publish database paths, customer identifiers, recovered fragments, private schema details or screenshots containing real records. Use synthetic examples to explain the procedure. Keep approved internal evidence intact without duplicating sensitive values into an unnecessarily broad report.

Common mistakes

A smaller file is often mistaken for stronger deletion. File size describes the current artifact, not the fate of old copies or released filesystem space.

Another mistake is assuming the machine's standalone SQLite utility proves the version used by an embedded application. Capture version information from the connection that performs the work.

Finally, do not combine every operation into a universal erasure script. Deletion, rebuilding, checkpointing and media sanitization solve different parts of the problem and have different preconditions. A failed stage remains an exception even if another stage succeeds.

CliDeck workflow fit

Use the evidence system your organization already maintains to connect the application decision with the later device decision. If CliDeck is part of that process, preserve those scopes separately. This article does not claim a SQLite cleanup integration, a completed database test or media-sanitization certification from CliDeck.

FAQ

Does secure_delete erase older backups?

No. A setting on the current database connection does not delete independently retained files or snapshots. Review those copies through their own authorized process.

Does truncating the WAL prove SSD sanitization?

No. It changes the current log file's length after successful checkpointing. Former physical locations and other copies lie outside that result.

Is an empty query result enough to close a deletion request?

It establishes only the tested query outcome. Closure also depends on the agreed scope, retained copies, extension behavior and applicable acceptance requirements.

Related guides