Deploy Postgres and MySQL databases with PlanetScale + Workers
Key Points
- Create PlanetScale DBs from Cloudflare
- Cloudflare billing for new databases next month
- Hyperdrive manages DB connections for Workers
Summary
Cloudflare and PlanetScale now let you create PlanetScale Postgres and MySQL databases directly from the Cloudflare dashboard and API and (starting next month) bill them to your Cloudflare account. PlanetScale databases integrate with Workers via Hyperdrive, which manages connection pools and query caching so your Workers can run fast, reliable SQL queries using standard Postgres/MySQL clients.
Key Points
- Create PlanetScale Postgres or MySQL databases from the Cloudflare dashboard/API once your PlanetScale account is connected.
- New PlanetScale databases can be billed to your Cloudflare account starting next month (self-serve and enterprise); existing billing remains with PlanetScale until then.
- Hyperdrive provides managed connection pools and query caching; add a binding in your wrangler config to expose the DB to your Worker.
- You can place Workers near your PlanetScale primary database with an explicit placement hint to reduce latency; future automatic placement hints are planned.
- PlanetScale features (query insights, branching, usage breakdown) and standard pricing apply; Postgres single node starts at $5/month.
How to use (practical)
- Connect your PlanetScale account in the Cloudflare dashboard.
- Create a Postgres or MySQL database from the dashboard or API.
- Add a Hyperdrive binding to your Worker config (wrangler.jsonc):
{
"hyperdrive": [
{ "binding": "DATABASE", "id": <AUTO_CREATED_ID> }
]
}
- Use your preferred client in the Worker (example with node-postgres):
import { Client } from "pg";
export default {
async fetch(request, env) {
const client = new Client({ connectionString: env.DATABASE.connectionString });
await client.connect();
const result = await client.query("SELECT * FROM pg_tables");
// handle result
}
}
Practical notes for engineers
- Expect Cloudflare billing for new PlanetScale DBs after launch next month; migrate billing considerations accordingly.
- Use placement hints to cut DB query latency for multi-query workloads.
- Hyperdrive removes the need to manually manage global connection pools inside Workers.