Neonの背後にあるLakebase Postgresデータベース(データ保存・管理用システム)の使い方とベストプラクティス(実績のある効果的な方法)ガイドです。セットアップ、接続方法とドライバ(ソフトウェア部品)、接続プーリング(複数の接続をまとめて管理すること)と直接接続、ブランチ機能、スキーママイグレーション(テーブル構造の変更)、自動スケーリング、スケール・トゥ・ゼロ(使わない時は自動で停止)、インスタントリストア(即座のデータ復元)、読み取り専用レプリカ(複製)、接続プーリング、IPアドレス制限リスト、論理レプリケーション(データベース間の同期)などをカバーしています。 次のような場合に使用: ユーザーが「Lakebase Postgres」「Neonのセットアップ」「Neonへの接続」「Neonプロジェクト」「DATABASE_URL」「サーバーレスPostgres」「Neon CLI」「neon」「Neon MCP」「Neon Auth」「@neondatabase/serverless」「@neondatabase/neon-js」「スケール・トゥ・ゼロ」「Neon自動スケーリング」「Neon読み取りレプリカ」「Neon接続プーリング」または「スキーママイグレーション」について質問している場合。
Guides and best practices for working with Lakebase Postgres, the database behind Neon. Covers setup, connection methods and drivers, pooled vs direct connections, branching, schema migrations, autoscaling, scale-to-zero, instant restore, read replicas, connection pooling, IP allow lists, and logical replication. Use when users ask about "Lakebase Postgres", "Neon setup", "connect to Neon", "Neon project", "DATABASE_URL", "serverless Postgres", "Neon CLI", "neon", "Neon MCP", "Neon Auth", "@neondatabase/serverless", "@neondatabase/neon-js", "scale to zero", "Neon autoscaling", "Neon read replica", "Neon connection pooling", or "schema migrations".
最初に確認: Neon の全般的な概要、使用開始方法、開発のベストプラクティスなどについては、親スキルの neon を使用してください。
neon スキルがインストールされていない場合は、https://neon.com/docs/ai/skills/neon/SKILL.md から取得するか、以下のコマンドでインストールしてください:
npx skills add neondatabase/agent-skills --skill neon
Lakebase Postgres は Neon の中核となるデータベースです。lakebase アーキテクチャ(クラウドオブジェクトストレージの上に直接構築された OLTP)で動作し、ストレージとコンピュート(処理能力)を分離することで、自動スケーリング、ブランチング、インスタント復元、スケール・ツー・ゼロ(未使用時にリソースをゼロまで削減)を実現します。Postgres と完全互換であり、Postgres をサポートする任意の言語、フレームワーク、ORM で動作します。
Neon を経由してアクセスしても Databricks を経由してアクセスしても、同じデータベースです。このスキルでは Neon 経由のアクセスについて説明します。
CLI(デフォルト)または MCP サーバを使用して、組織とプロジェクトを一覧表示します。ユーザーが既存のプロジェクトを選択するか、新規作成できるようにします。既にリンク済みのプロジェクトやブランチがあれば、.neon ファイルを確認してください。
CLI(デフォルト)、neon env pull、または MCP サーバを使用して接続文字列を取得します。これを .env ファイルに DATABASE_URL として保存します。既存の値を上書きしないよう、修正する前にファイルを読み込んでください。
| 用途 | 接続タイプ |
|---|---|
| Web アプリケーション、サーバーレス関数 | プール済み(-pooler 付き) |
| スキーママイグレーション | 直接接続 |
| pg_dump / pg_restore | 直接接続 |
| 論理レプリケーション | 直接接続 |
| テンポラリテーブル を使用する長時間分析 | 直接接続 |
| SET やセッション状態が必要な管理作業 | 直接接続 |
| LISTEN / NOTIFY | 直接接続 |
スキーマ管理とマイグレーション(データベース構造の変更)を簡単にするため、常に Neon を Drizzle などの ORM(オブジェクト・リレーショナル・マッピング:データベースをプログラムで操作するツール)と組み合わせて使用してください。接続方法ガイドを参照して、ランタイム(実行環境)がコードをどう扱うかに基づいて正しいドライバを選択してください: https://neon.com/docs/connect/choose-connection.md
推奨事項:
node-postgres(npm install pg)を使用し、import { attachDatabasePool } from "@vercel/functions"; をインポートするnode-postgres を使用するnode-postgres を使用する(関数は長時間実行され、リクエスト間でプールが再利用される)@neondatabase/serverless ドライバを使用する — HTTP トランスポート(単発クエリ用)、WebSocket(トランザクション対応): https://neon.com/docs/serverless/serverless-driver.mdスキーマとマイグレーションをコードとして管理します。データベースに対してその場限りのスキーママイグレーションを実行することは避けてください。管理が困難になるためです。
ORM を使用している場合は、その ORM のベストプラクティスに従ってスキーマとマイグレーションを管理してください。例えば Drizzle を使用している場合、特別な指示がない限り、スキーマとマイグレーション管理には Drizzle のみを使用してください。
次のような場合に使用: ユーザーが独立した環境、スキーママイグレーションのテスト、プレビューデプロイメント、またはブランチのライフサイクル自動化を計画している場合。
要点:
参考資料: https://neon.com/docs/introduction/branching.md
ブランチ作成の詳細なワークフロー(通常ブランチとスキーマのみブランチ、親からのリセット、CLI/MCP の選択)については、neon-postgres-branches スキルを使用してください。インストールされていない場合は、https://neon.com/docs/ai/skills/neon-postgres-branches/SKILL.md から取得するか、以下のコマンドでインストールしてください:
npx skills add neondatabase/agent-skills --skill neon-postgres-branches
本番環境に適用する前に、本番データに近いデータを用いて本番ブランチでマイグレーションをテストします。
マイグレーション実行時は、プール済みではなく 直接接続(非プール) の接続文字列を使用してください。neon connection-string はデフォルトで直接接続文字列を返します。ホスト名に -pooler サフィックスが含まれていないことを確認してください。
次のような場合に使用: ユーザーがワークロードに応じてコンピュートを自動的にスケールさせる必要があり、CU(コンピュートユニット:処理能力の単位)のサイジングとランタイム動作についてのガイダンスが必要な場合。
参考資料: https://neon.com/docs/introduction/autoscaling.md
次のような場合に使用: アイドル時のコストを最適化し、サスペンド(一時停止)・レジューム(再開)の動作、コールドスタート(初回起動の遅延)のトレードオフについて検討する場合。
要点:
参考資料: https://neon.com/docs/introduction/scale-to-zero.md
次のような場合に使用: ユーザーがポイント・イン・タイム・リカバリ(特定の時点へのデータ復元)が必要な場合、または従来のバックアップ復元ワークフローなしでデータ状態を復元したい場合。
要点:
参考資料: https://neon.com/docs/introduction/branch-restore.md
次のような場合に使用: ストレージを重複させずに読み取り専用のコンピュートが必要な、読み取り負荷の高いワークロード。
要点:
参考資料: https://neon.com/docs/introduction/read-replicas.md
次のような場合に使用: ユーザーがサーバーレスまたは高い同時接続環境にいて、安全でスケーラブルな Postgres 接続管理が必要な場合。
要点:
-pooler を追加します。参考資料: https://neon.com/docs/connect/connection-pooling.md
次のような場合に使用: ユーザーが信頼されたネットワーク、IP アドレス、または CIDR 範囲(ネットワークアドレス表記)によってデータベースアクセスを制限する必要がある場合。
参考資料: https://neon.com/docs/introduction/ip-allow.md
次のような場合に使用: CDC(変更データキャプチャ:データベースの変更を追跡する)パイプライン、外部 Postgres 同期、またはレプリケーションベースのデータ移動を統合する場合。
要点:
参考資料: https://neon.com/docs/guides/logical-replication-guide.md
Neon は同じデータベースに対して 2 つの接続文字列を提供します: プール済み(ホスト名に -pooler サフィックス付き)と 直接接続/非プール(-pooler サフィックスなし)。neon env pull はこれらを DATABASE_URL と DATABASE_URL_UNPOOLED として出力します。正しいものを選択してください:
DATABASE_URL) — アプリケーションの通常のクエリトラフィック。特にサーバーレスとリクエストごとの接続ワークロード。DATABASE_URL_UNPOOLED) — スキーママイグレーション(Prisma Migrate、Drizzle Kit、Alembic など)、pg_dump / pg_restore、論理レプリケーション、LISTEN/NOTIFY、SET やその他のセッション状態に依存するもの。プール済み接続を経由したマイグレーション、ダンプ、レプリケーション実行は失敗することがあり、プーリングだとは名前から分からない形で失敗します。Prisma Migrate の prepared statement "s0" already exists エラー、次のクエリが relation "mytable" does not exist と報告するように持続しない SET search_path、またはプール済みバックエンド(以前のクライアントから引き継いだ読み取り専用トランザクション)が偶発的に書き込みに失敗する SQLSTATE 25006 などです。マイグレーションツールは通常両方の文字列を一度に受け取ります。Prisma の directUrl を url と一緒に使う場合は、DATABASE_URL と直接接続を入れ替えてアプリケーションのプーリングを失わないよう、そこを直接接続に指定してください。https://neon.com/docs/connect/connection-pooling.md を参照。
FIRST: Use the parent neon skill for a Neon overview, getting started with Neon, Neon development best practices, and more.
If the neon skill is not installed, fetch it from https://neon.com/docs/ai/skills/neon/SKILL.md or install it with:
npx skills add neondatabase/agent-skills --skill neon
Lakebase Postgres is the database at the core of Neon. It runs on the lakebase architecture — OLTP built directly on cloud object storage — which decouples storage from compute to offer autoscaling, branching, instant restore, and scale-to-zero. It's fully compatible with Postgres and works with any language, framework, or ORM that supports Postgres.
It is the same database whether you reach it through Neon or through Databricks; this skill covers the Neon access path.
Use the CLI (default) or MCP server to list organizations and projects. Let the user select an existing project or create a new one. Check the .neon file for an existing linked project or branch.
Use the CLI (default), neon env pull, or the MCP server to get the connection string. Store it in .env as DATABASE_URL. Read the file first before modifying it, to avoid overwriting existing values.
| Use case | Connection type |
|---|---|
| Web applications, serverless functions | Pooled (-pooler) |
| Schema migrations | Direct |
| pg_dump / pg_restore | Direct |
| Logical replication | Direct |
| Long-running analytics with temp tables | Direct |
| Admin tasks needing SET or session state | Direct |
| LISTEN / NOTIFY | Direct |
Always pair Neon with an ORM such as Drizzle for easy schema management and migrations. Refer to the connection methods guide to pick the correct driver based on how the runtime treats your code: https://neon.com/docs/connect/choose-connection.md.
Recommendations:
node-postgres (npm install pg) with Vercel Fluid compute and import { attachDatabasePool } from "@vercel/functions";node-postgres with Cloudflare Hyperdrivenode-postgres, as the functions are long-running and reuse the pool across requests.@neondatabase/serverless driver for serverless and edge environments (for example, when using Netlify) — HTTP transport for one-shot queries, WebSocket for transaction support. Link: https://neon.com/docs/serverless/serverless-driver.mdManage schemas and migrations as code. Avoid running ad hoc schema migrations against your database, since they're hard to manage.
If you're using an ORM, follow your ORM's best practices to manage schemas and migrations. For example, if using Drizzle, only use Drizzle for schema and migration management unless instructed otherwise.
Use this when the user is planning isolated environments, schema migration testing, preview deployments, or branch lifecycle automation.
Key points:
Link: https://neon.com/docs/introduction/branching.md
For detailed branch creation workflows (normal vs schema-only branches, reset-from-parent, CLI/MCP selection), use the neon-postgres-branches skill. If it isn't installed, fetch it from https://neon.com/docs/ai/skills/neon-postgres-branches/SKILL.md or install it with:
npx skills add neondatabase/agent-skills --skill neon-postgres-branches
Test a migration on a branch of production, against production-like data, before applying it to production.
Use a direct (non-pooled) connection string when you run the migration, not a pooled one. neon connection-string returns the direct string by default; make sure the hostname does not include the -pooler suffix.
Use this when the user needs compute to scale automatically with workload and wants guidance on CU sizing and runtime behavior.
Link: https://neon.com/docs/introduction/autoscaling.md
Use this when optimizing idle costs and discussing suspend/resume behavior, including cold-start trade-offs.
Key points:
Link: https://neon.com/docs/introduction/scale-to-zero.md
Use this when the user needs point-in-time recovery or wants to restore data state without traditional backup restore workflows.
Key points:
Link: https://neon.com/docs/introduction/branch-restore.md
Use this for read-heavy workloads where the user needs dedicated read-only compute without duplicating storage.
Key points:
Link: https://neon.com/docs/introduction/read-replicas.md
Use this when the user is in serverless or high-concurrency environments and needs safe, scalable Postgres connection management.
Key points:
-pooler to endpoint hostnames to use pooled connections.Link: https://neon.com/docs/connect/connection-pooling.md
Use this when the user needs to restrict database access by trusted networks, IPs, or CIDR ranges.
Link: https://neon.com/docs/introduction/ip-allow.md
Use this when integrating CDC pipelines, external Postgres sync, or replication-based data movement.
Key points:
Link: https://neon.com/docs/guides/logical-replication-guide.md
Neon gives you two connection strings for the same database: a pooled one (hostname with the -pooler suffix) and a direct/unpooled one (no -pooler suffix). neon env pull writes them as DATABASE_URL and DATABASE_URL_UNPOOLED. The pooled connection routes through PgBouncer in transaction mode, which doesn't support session-level operations. Choose the right one:
DATABASE_URL) — your application's normal query traffic, especially serverless and connection-per-request workloads.DATABASE_URL_UNPOOLED) — schema migrations (Prisma Migrate, Drizzle Kit, Alembic, and others), pg_dump / pg_restore, logical replication, LISTEN/NOTIFY, and anything relying on SET or other session state.Running migrations, dumps, or replication over the pooled connection can fail, and never in a way that names pooling: prepared statement "s0" already exists from Prisma Migrate, a SET search_path that doesn't persist past its own transaction so the next query reports relation "mytable" does not exist, or a write intermittently hitting a read-only transaction (SQLSTATE 25006) that a pooled backend inherited from an earlier client. Migration tools generally take both strings at once — Prisma's directUrl alongside url — so point that at the direct one rather than swapping DATABASE_URL and losing pooling for the application. See https://neon.com/docs/connect/connection-pooling.md.
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。