Skip to content

Databases

Each organization can create independent SQLite databases and bind them to Workers using Wrangler’s d1_databases configuration. No MySQL or PostgreSQL server is involved. Databases persist on their selected service host across Worker deployments, database API restarts, and native shard restarts.

Create, migrate, and deploy

Use an organization read-write token after following Connect Wrangler. Tokens created before database permissions were introduced retain their original permissions; create a new token rather than expecting an existing credential to gain access silently.

npx wrangler d1 create my-database

Copy the returned ID into your Worker configuration:

[[d1_databases]]
binding = "DB"
database_name = "my-database"
database_id = "<returned-uuid>"

Add SQL files under the Worker’s migrations/ directory, then:

npx wrangler d1 migrations apply DB --remote
npx wrangler deploy

The supported CLI surface is create, list, info, delete, execute --command, and migrations list/apply. Wrangler bulk import (execute --file), Wrangler export, Time Travel, and replicas are not implemented; they are not silently emulated. Portable SQL import and export are available in the tenant console. Migration SQL and its bookkeeping execute in one transaction per migration. Do not put explicit BEGIN, COMMIT, or savepoints inside a migration.

Inside a Worker:

const session = env.DB.withSession("first-primary");
const row = await session.prepare("SELECT title FROM items WHERE id = ?")
  .bind(1).first();
const bookmark = session.getBookmark(); // synchronous, like the D1 interface

prepare, bind, first, all, raw, run, batch, exec, and sessions use the pinned upstream workerd D1 JavaScript client. The synchronous client lives inside the tenant isolate; a platform-owned capability transports queries to the database service. The service credential and organization scope are not application environment variables.

Use the database ID returned for your organization in your Wrangler configuration.

Console and access

Choose Databases in the organization sidebar. Create a database, open its details, copy its binding configuration, inspect lifecycle events, or run SQL from the Query tab. The initial query lists schema objects. The Backups tab creates and downloads portable SQL restore points and imports a SQL snapshot.

Database inventory in the tenant console

Queries default to read-only and SQLite enforces that restriction, including indirect writes. Observers cannot disable it. Members, admins, and owners can use the write path. SQL and parameters are intentionally absent from page URLs, metrics, logs, and spans. Database identity and the selected tab are deep-linkable.

Restoring or importing never rewrites the database ID. The service validates the SQL in an isolated SQLite database, creates a safety backup, restores a hidden native actor, compares its canonical digest and sequence, and only then switches the catalog. Existing Worker bindings therefore continue to name the same logical database. A failed restore leaves the current actor active.

Deleting a database is permanent and breaks existing bindings to it. The console requires typing the database name, and retained backups must be downloaded or deleted first. Database deletion does not silently delete restore points.

Isolation, capacity, and consistency

The database API owns organization catalogs, admission, and the D1-compatible surface. Databases are native SQLite-backed Durable Objects. The catalog records an explicit storage placement before initializing one serialized actor; a database is not a process, service, or runtime member of its own. New native databases use the platform’s clustered-storage member by default. During a platform rollout, native databases created before explicit placement are moved through a resumable, database-scoped migration. The provider freezes one database, snapshots its one actor, verifies the imported database bytes and sequence, switches the catalog, and only then retires the standalone source. Interrupted native migrations resume from their durable checkpoint. Older file-backed catalogs use the same portable snapshot and verified hidden-actor cutover. Ansible convergence migrates every active catalog and fails if any database remains on a file or standalone placement. The original file is moved out of the serving path as inert recovery evidence; the canonical migration backup is available from the Backups tab.

Both deployment-time binding checks and query-time lookup enforce organization ownership. The shard API is private and independently authenticated. Knowing another organization’s database UUID does not grant access.

SQLite authorization denies ATTACH, filesystem functions, extension loading, internal platform tables, transaction control, and unsafe PRAGMAs. SQL uses bound parameters. JSON functions and FTS5 are available. Native actor SQL is interrupted by the enforcing workerd runtime’s per-event CPU policy. An interrupted database object is reconstructed from its committed state while the shard process and neighboring databases remain available. Admission, result-row and result-byte limits, database size checks, and shard process budgets provide additional containment. These are shared-isolate guarantees, not VM isolation.

Database allowances follow the organization tier: Free permits 3 databases and 128 MiB of allocated pages, Standard permits 10 and 1 GiB, and Enterprise permits 25 and 4 GiB. Each database is limited to 1 GiB. Portable backup allowances are 10 restore points / 1 GiB on Free, 50 / 4 GiB on Standard, and 250 / 16 GiB on Enterprise. Platform-created migration backups do not consume those tenant allowances. Manual, import, and pre-restore backups do. These are separate from R2 bucket and static asset allowances. Quota growth is reserved inside the native storage transaction before it commits. Reservations are idempotent so a workerd transaction retry cannot double-count storage; a failed reservation rolls back the SQL transaction. Startup reconciliation repairs holdings from authoritative backend sizes. No-growth queries do not make a quota reservation.

Current execution limits: 100 KiB SQL, 100 statements per batch, 100 bound parameters, 1 MiB values, 10,000 result rows and 4 MiB results per call, a 2-second native execution CPU policy, and bounded admission waits. Organization operations are serialized at the API boundary; up to eight organizations can execute concurrently. SQL imports are streamed to bounded temporary storage and may be at most three times the 1 GiB database limit before materialization. Physical SQLite metadata consumes host disk beyond logical page quotas.

This single-region service has no replication, failover, lag, or eventual-consistency mode. The deployed cluster currently has one member. Clustered storage changes the persistence and recovery substrate; it does not make the database highly available. Adding members does not by itself remap or replicate a database; placement changes use the explicit migration above. Session bookmarks identify committed database sequence numbers and survive service restarts. Worker version rollback does not roll back database data or schema: use backward-compatible migrations. Database loss/restore is not masked as a new bookmark history.

Native SQLite reports engine rows read and written. These fields are operational evidence, not a Cloudflare billing guarantee.

Investigate an issue

Review database activity in the console and Usage & limits for quota enforcement. Query errors and slow application SQL do not establish a platform outage. Operators can inspect separate admission, execution, and commit signals through Platform observability.

The platform retains engine-enforced query interruption. The operator Runtime isolation guide documents that boundary and how it is evaluated when upgrading.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close