PlanetScale + WorkersでPostgresおよびMySQLデータベースをデプロイ
本文の状態
日本語全文を表示中
詳細モードで約5分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
Cloudflare Blog
Cloudflareは、PlanetScaleとの提携により、Cloudflare WorkersからPostgresおよびMySQLデータベースに直接アクセスできるようにし、高速なフルスタックアプリケーションを実現する。さらに、CloudflareダッシュボードやAPIから直接PlanetScaleデータベースを作成し、Cloudflareアカウントで課金できるようにする。
Continue in AI NEW LAB
このニュースを、実務の判断につなげる
AI NEW LABで、試したことや先に確認したい条件を共有できます。まずはログインなしで読めます。
AI NEW LABで論点を見るSource Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
Cloudflareは昨年9月、Cloudflare WorkersがPostgresおよびMySQLデータベースに直接アクセスし、高速なフルスタックアプリケーションを構築できるようにするため、PlanetScaleとのパートナーシップを発表しました。
まもなく、両技術をさらに緊密に連携させます:CloudflareダッシュボードとAPIから直接PlanetScaleのPostgresおよびMySQLデータベースを作成し、それらの利用料金をCloudflareアカウントに請求できるようになります。

Workerアプリケーションのニーズに合ったデータストレージを選択でき、Cloudflareのセルフサービスまたはエンタープライズ顧客として、請求を単一のシステムで管理できます。スタートアッププログラムで付与されるものやCloudflareコミットメント支出などのCloudflareクレジットは、PlanetScaleデータベースにも利用できます。
Workers向けPostgres & MySQL
PostgresやMySQLといったSQLリレーショナルデータベースは、現代のアプリケーションの基盤です。特にPostgresは、豊富なツールエコシステム(ORM、GUIなど)や、AI駆動アプリケーションでベクター検索を構築するためのpgvectorなどの拡張機能により、開発者の間で人気が高まっています。強力で柔軟かつスケーラブルなデータベースをアプリケーションに求める大多数の開発者にとって、Postgresはデフォルトの選択肢となっています。
すでにPlanetScaleアカウントを接続し、Workers向けにCloudflareダッシュボードから直接Postgresデータベースを作成できます。来月からは、新たなCloudflareサブスクリプションにより、新規作成するPlanetScaleデータベースの利用料金が、セルフサービスまたはエンタープライズユーザーとして直接Cloudflareアカウントに請求されるようになります。

PlanetScaleアカウント接続後、Cloudflareダッシュボード経由でPlanetScaleデータベースを作成する方法。Cloudflare経由の請求は来月開始予定です。
当社の組み込み統合により、PlanetScaleデータベースは当社のデータベース接続サービスであるHyperdriveを利用して、自動的にWorkersと連携します。Hyperdriveサービスはデータベース接続プールとクエリキャッシングを管理し、データベースクエリを高速かつ信頼性高く実行します。Workerの設定ファイルにバインディングを追加するだけです:
// wrangler.jsoncファイル
{
"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という2つの最も人気のあるリレーショナルデータベースから選択できます。PlanetScaleは、Cloudflareが開発者プラットフォームの主要機能としてパフォーマンスと信頼性を扱う方針と一致しています。さらに、SQLクエリのパフォーマンス改善のためのクエリインサイトやエージェント駆動ワークフロー、データベース変更を含むコードの安全なデプロイのためのブランチングなどの機能により、PlanetScaleデータベースの開発者体験は最高水準です。
Cloudflareユーザーは、まったく同じPlanetScaleデータベースの開発者体験を得られます。お客様のPlanetScaleデータベースはCloudflareから直接デプロイでき、接続はHyperdrive経由で管理されます。これにより、既存のリージョナルデータベースがグローバルに展開されるWorkersによって高速化されます。これは、標準的なPlanetScaleの価格で同じPlanetScaleデータベースクラスターにアクセスでき、クエリインサイトや使用量・コストの詳細な内訳などの全機能が利用できることを意味します。

PlanetScale Postgresのシングルノードは月額5ドルから。
Workersの配置
集中型データベースでは、明示的な配置ヒントを使用してWorkersをプライマリデータベースの直近で実行し、レイテンシを削減できます。デフォルトでは、Workersはユーザーリクエストに最も近い場所で実行されるため、特に複数のクエリを実行する場合、中央データベースへの問い合わせ時にネットワークレイテンシが加算されます。代わりに、WorkerをPlanetScaleデータベースに最も近いCloudflareデータセンターで実行するように設定できます。将来的には、CloudflareがPlanetScaleデータベースの所在地に基づいて自動的に配置ヒントを設定し、ネットワークレイテンシを一桁ミリ秒に削減できるようになる予定です。
{
"placement": {
"region": "aws:us-east-1"
}
}近日公開予定
本日、PlanetScale Postgresデータベースをデプロイするか、既存のPlanetScaleデータベースをCloudflareダッシュボード経由でWorkersに接続できます。現在、すべての請求はPlanetScale経由で行われています。
来月開始予定で、新規のPlanetScaleデータベースの利用料金をCloudflareアカウントに請求できるようになります。
当社はPlanetScaleパートナーとさらに連携を深めており、例えばCloudflare API統合などを進めています。次にどのような機能を期待するか、ぜひお聞かせください。
原文を表示
Cloudflare announced our PlanetScale partnership last September to give Cloudflare Workers direct access to Postgres and MySQL databases for fast, full-stack applications.
Soon, we’re bringing our technologies even closer: you’ll be able to create PlanetScale Postgres and MySQL databases directly from the Cloudflare dashboard and API, and have them billed to your Cloudflare account.
image
You choose the data storage that fits your Worker application needs and keep a single system for billing as a Cloudflare self-serve or enterprise customer. Cloudflare credits like those given in our startup program or Cloudflare committed spend can be used towards PlanetScale databases.
Postgres & MySQL for Workers
SQL relational databases like Postgres and MySQL are a foundation of modern applications. In particular, Postgres has risen in developer popularity with its rich tooling ecosystem (ORMs, GUIs, etc) and extensions like pgvector for building vector search in AI-driven applications. Postgres is the default choice for most developers who need a powerful, flexible, and scalable database to power their applications.
You can already connect your PlanetScale account and create Postgres databases directly from the Cloudflare dashboard for your Workers. Starting next month, a new Cloudflare subscription will bill for new PlanetScale databases direct to your Cloudflare account as a self-serve or enterprise user.
image
How to create PlanetScale databases via Cloudflare dashboard after your PlanetScale account is connected. Cloudflare billing is coming next month.
With our built-in integration, PlanetScale databases automatically work with Workers using Hyperdrive, our database connectivity service. Hyperdrive service manages database connection pools and query caching to make database queries fast and reliable. You just add a binding to your Worker’s config file:
// wrangler.jsonc file
{
"hyperdrive": [
{
"binding": "DATABASE",
"id": <AUTO_CREATED_ID>
}
]
}
And start running SQL queries via your Worker with your Postgres client of choice:
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 developer experience
PlanetScale was the obvious choice to provide to the Workers community due to it’s unrivaled performance and reliability. Developers can choose from two of the most popular relational databases with Postgres or Vitess MySQL. PlanetScale matches how Cloudflare treats performance and reliability as key features of a developer platform. And with features like query insights and agent driven workflows for improving SQL query performance and branching for deploying code safely, including database changes, the PlanetScale database developer experience is first-class.
Cloudflare users get the exact same PlanetScale database developer experience. Your PlanetScale databases can be deployed directly from Cloudflare with connections managed via Hyperdrive, which already makes your existing regional databases fast with global Workers. This means access to the same PlanetScale database clusters at standard PlanetScale pricing with all features included like query insights and detailed breakdown of usage and costs.
image
A single node on PlanetScale Postgres starts at $5/month.
Workers placement
With centralized databases, Workers can run right next to your primary database to reduce latency with an explicit placement hint. By default, Workers execute closest to a user request, which adds network latency when querying a central database especially for multiple queries. Instead, you can configure your Worker to execute in the closest Cloudflare data center to your PlanetScale database. In the future, Cloudflare can automatically set a placement hint based on the location of your PlanetScale database and reduce network latency to single digit milliseconds.
{
"placement": {
"region": "aws:us-east-1"
}
}
Coming soon
You can deploy a PlanetScale Postgres database or connect an existing PlanetScale database to Workers today via the Cloudflare dashboard. Everything today is still billed via PlanetScale.
Launching next month, new PlanetScale databases can be billed to your Cloudflare account.
We are building more with our PlanetScale partners, such as Cloudflare API integration, so tell us what you’d like to see next.
関連記事
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み