> d1 & hyperdrive
D1 is Cloudflare's serverless SQLite database you create and own; Hyperdrive is a connection pooler and query cache that fronts an existing Postgres or MySQL you host elsewhere (RDS, Neon, Supabase). These commands cover the real day-to-day: provisioning a D1 database, running SQL and versioned migrations against local vs. remote, backing up and time-travel-restoring data, and wiring a Worker to your origin Postgres through Hyperdrive. The recurring trap is local vs. remote — most D1 commands default to the emulated local DB, so production stays untouched until you add --remote.
// d1 & hyperdrive
11 commands$ wrangler d1 create <name>$ wrangler d1 execute <database> --command "SELECT * FROM users LIMIT 5" --local$ wrangler d1 execute <database> --file ./schema.sql --remote$ wrangler d1 migrations create <database> "add_users_table"$ wrangler d1 migrations apply <database> --local$ wrangler d1 migrations list <database> --remote$ wrangler d1 export <name> --remote --output ./backup.sql$ wrangler d1 time-travel info <database>$ wrangler d1 list$ wrangler hyperdrive create <name> --connection-string="postgres://user:[email protected]:5432/postgres"$ wrangler hyperdrive list// faq
Why did my SQL or migration run locally instead of against production?
wrangler d1 execute and wrangler d1 migrations apply default to --local, the emulated database wrangler dev uses. The command reports success but touches nothing in production. Add --remote to run against the deployed D1 database.
D1 or Hyperdrive — which do I actually use?
D1 is a serverless SQLite database you create and own inside Cloudflare (wrangler d1 create). Hyperdrive owns no data — it pools connections and caches read queries in front of an existing Postgres/MySQL you host somewhere else, so a Worker reaches it fast without a fresh TLS+auth handshake per request. Use D1 for new edge-native data; use Hyperdrive to make a Worker talk to your existing Postgres.
How do I recover after a bad migration or an accidental DELETE?
D1 keeps a continuous 30-day history. wrangler d1 time-travel info gives you the current bookmark, and wrangler d1 time-travel restore rolls the whole database back to a timestamp or bookmark — no manual snapshot required.