Cloudflare D1 vs Postgres for App Migrations

Keep Postgres for the first release if the app depends on Postgres extensions, complex existing queries, or other services writing to the same tables. Consider D1 when the data fits SQLite and you can demonstrate that the app reads and writes the same records after a rehearsal.

Which database fits your migration?

Your app needsFirst choiceWhat to verify
Postgres extensions or Postgres-specific SQLKeep PostgresRun the queries your app depends on through the new Worker connection.
Several services writing to the same databaseKeep Postgres for cutoverConfirm every service can still connect when the web app moves.
A small Worker-backed form or app with SQLite-compatible queriesConsider D1Rehearse the import and check IDs, defaults, dates, indexes, and a new submission.

Check the D1 documentation and Hyperdrive documentation for the two connection options.

Start with a query your customer relies on

Pick a real task, such as retrieving an inquiry by ID or listing this month’s submissions in date order. Gather the schema, indexes, and SQL for that task. If it depends on a Postgres extension, removing that dependency is a separate engineering project. A Worker can reach an existing supported Postgres database through Hyperdrive. Verify that the database will remain accessible after you change hosting or cancel a plan. Cloudflare storage options · Hyperdrive FAQ.

Why D1 fit our inquiry form

Our contact form moved from the original Postgres-backed app to a Worker with a D1 binding. We kept text IDs and the inquiry fields, and the Worker now inserts one row per accepted submission. The schema has separate indexes for looking up an email and sorting submissions by creation time. That made it possible to check the same operations before and after the move.

In the original migration, report data needed a different test. The source represented parts of an audit as nested objects. The import script serialized those fields and preserved the original IDs. Simply counting the rows would have missed a report that existed but could no longer be read by the app.

Rehearse the import before choosing

  1. Use an authorized snapshot and a separate staging database. Include a row with an optional field missing, a message containing an apostrophe, a timestamp near midnight, and a parent record with children.
  2. Translate the schema explicitly. Check date representation, defaults, uniqueness, foreign keys, and any Postgres-specific operators. Import parent records before their children. D1 import and export · D1 foreign keys.
  3. Compare counts against the same source snapshot. Then open a known record through the app, compare its displayed values, and create a new one through the normal form. Run your common queries against a representative amount of data.

For a leads table like ours, these are two read-only staging checks. Run them against both copies with the same time cutoff. A difference in totals signals a mismatch. Equal totals still leave room for a missing ID and an extra one, so compare the full ID lists before cutover. The second query shows whether the same five recent inquiries surface in the same order.

SELECT COUNT(*) AS rows, COUNT(DISTINCT id) AS ids
FROM leads WHERE created_at < '2026-11-01';

SELECT id, created_at FROM leads
WHERE created_at < '2026-11-01'
ORDER BY created_at DESC, id DESC LIMIT 5;

If the D1 rehearsal passes, plan a final sync and name the person responsible for reconciling late writes. If a critical Postgres query still needs redesign, keep the database in place for the hosting move. Follow the Replit to Cloudflare cutover checklist to plan the rest of the migration.