OpenAICloudflareApr 16, 2026, 1:00 PM

Deploy Postgres and MySQL databases with PlanetScale + Workers

A condensed section focused on the key takeaways first.

Original Post

Quick Digest

Summary

A condensed section focused on the key takeaways first.

openaienmodel: gpt-5-mini-2025-08-07

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)

  1. Connect your PlanetScale account in the Cloudflare dashboard.
  2. Create a Postgres or MySQL database from the dashboard or API.
  3. Add a Hyperdrive binding to your Worker config (wrangler.jsonc):
{
  "hyperdrive": [
    { "binding": "DATABASE", "id": <AUTO_CREATED_ID> }
  ]
}
  1. 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.

Full Translation

Translations

A translation section that keeps the flow of the original article.

openaijamodel: gpt-5-mini-2025-08-07

PlanetScale + WorkersでPostgresとMySQLのデータベースをデプロイする

PlanetScale + WorkersでPostgresとMySQLのデータベースをデプロイする

Cloudflareは昨年9月にPlanetScaleとのパートナーシップを発表し、Cloudflare Workersから直接PostgresとMySQLデータベースにアクセスして、高速なフルスタックアプリケーションを構築できるようにしました。さらに密接に統合され、CloudflareダッシュボードおよびAPIから直接PlanetScaleのPostgresおよびMySQLデータベースを作成し、Cloudflareアカウントで課金できるようになります。これにより、Workerアプリケーションのニーズに合ったデータストレージを選びつつ、セルフサーブまたはエンタープライズ顧客としてCloudflareで一元的に課金管理が可能になります。Cloudflareのクレジット(スタートアッププログラムやCloudflareの確約支出など)をPlanetScaleデータベースの支払いに利用できます。

Postgres & MySQL for Workers

SQLリレーショナルデータベース(PostgresやMySQL)は、モダンなアプリケーションの基盤です。特にPostgresは、ORMやGUIといった豊富なツール群や、AI駆動アプリでのベクター検索構築に使われるpgvectorのような拡張により、開発者に人気があります。柔軟でスケーラブルな強力なデータベースを必要とする多くの開発者にとって、Postgresはデフォルトの選択肢です。

現在、PlanetScaleアカウントを接続して、Cloudflareダッシュボードから直接Postgresデータベースを作成できます。来月からは、新しいCloudflareのサブスクリプションにより、作成したPlanetScaleデータベースの課金をCloudflareアカウントへ直接請求できるようになります。

Cloudflareダッシュボード経由でPlanetScaleデータベースを作成する方法

PlanetScaleアカウントを接続した後、CloudflareダッシュボードからPlanetScaleデータベースを作成できます。Cloudflare課金機能は来月提供開始予定です。

組み込みの統合により、PlanetScaleデータベースはHyperdrive(Cloudflareのデータベース接続サービス)を通じてWorkersで自動的に動作します。Hyperdriveはデータベース接続プールとクエリキャッシュを管理し、クエリを高速かつ信頼性の高いものにします。Workerの設定ファイルにバインディングを追加するだけです。

// wrangler.jsonc file
{
  "hyperdrive": [
    {
      "binding": "DATABASE",
      "id": <AUTO_CREATED_ID>
    }
  ]
}

その後、お好みのPostgresクライアントを使ってWorker内でSQLクエリを実行できます:

import { Client } from "pg";
export default {
  async fetch(request, env, ctx) {
    const client = new Client({ connectionString: env.DATABASE.connectionString });
    await client.connect();
    const result = await client.query("SELECT * FROM pg_tables");
    ...
  }
}

PlanetScaleの開発者体験

PlanetScaleは、パフォーマンスと信頼性において他に類を見ないため、Workersコミュニティ向けの提供先として自然な選択でした。開発者はPostgresまたはVitess MySQLという、二つの人気のリレーショナルデータベースから選べます。PlanetScaleは、Cloudflareが開発者プラットフォームの重要な機能と位置付ける「パフォーマンス」と「信頼性」を満たします。

クエリインサイトやSQLクエリ性能改善のためのエージェント駆動ワークフロー、データベース変更を含む安全なデプロイのためのブランチングなどの機能により、PlanetScaleのデータベース開発者体験は一流です。Cloudflareユーザーは同等のPlanetScaleデータベース開発者体験を得られます。PlanetScaleデータベースはCloudflareから直接デプロイでき、接続はHyperdriveで管理されます。これにより既存のリージョナルデータベースがグローバルなWorkersで高速に動作します。

同一のPlanetScaleデータベースクラスターへアクセスでき、クエリインサイトや使用量とコストの詳細内訳といったすべての機能を含む標準のPlanetScale料金で利用できます。PlanetScale Postgresのシングルノードは $5/month から始まります。

Workersのプレースメント

中央集約型データベースを使う場合、明示的なプレースメントヒントを使ってWorkerをプライマリデータベースの近くで実行させ、レイテンシを削減できます。デフォルトではWorkerはユーザーリクエストに最も近い場所で実行されるため、中央データベースへクエリを投げる際にネットワークレイテンシが発生します(特に複数クエリの場合)。代わりに、WorkerをPlanetScaleデータベースに最も近いCloudflareデータセンターで実行するよう設定できます。将来的には、CloudflareがPlanetScaleデータベースの場所に基づいて自動的にプレースメントヒントを設定し、ネットワークレイテンシを一桁ミリ秒にまで低減できるようになります。

{
  "placement": {
    "region": "aws:us-east-1"
  }
}

今後の予定

今日から、Cloudflareダッシュボード経由でPlanetScale Postgresデータベースをデプロイするか、既存のPlanetScaleデータベースをWorkersに接続できます。現状では課金は引き続きPlanetScale経由です。来月開始予定のローンチにより、新しいPlanetScaleデータベースをCloudflareアカウントに請求できるようになります。

PlanetScaleパートナーとともにさらに多くの機能(例: Cloudflare API統合)を構築しています。ぜひ、次に何を見たいか教えてください。

Cloudflareのコネクティビティクラウドは企業ネットワーク全体を保護し、顧客がインターネット規模のアプリケーションを効率的に構築できるよう支援し、あらゆるウェブサイトやインターネットアプリケーションを高速化し、DDoS攻撃を抑止し、ハッカーの脅威から守り、Zero Trustへの道を支援します。あらゆるデバイスから 1.1.1.1 を訪問して、インターネットをより速く安全にする無料アプリを始めてください。より良いインターネット構築に向けた我々のミッションの詳細はここから始めてください。新しいキャリアをお探しなら、オープンポジションもご確認ください。