{"name":"neon-postgres","url":"https://github.com/neondatabase/agent-skills","install":"npx skills add neondatabase/agent-skills","sdk":"neon","key":"neon/neon-postgres","description":"Guides and best practices for working with Neon Serverless Postgres. Covers setup, connection methods, branching, autoscaling, scale-to-zero, read replicas, connection pooling, Neon Auth, and the Neon CLI, MCP server, REST API, TypeScript SDK, and Python SDK. Use when users ask about \"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\", or \"Neon connection pooling\".","hasContent":true,"content":"---\nname: neon-postgres\ndescription: >-\n  Guides and best practices for working with Neon Serverless Postgres.\n  Covers setup, connection methods, branching, autoscaling, scale-to-zero,\n  read replicas, connection pooling, Neon Auth, and the Neon CLI, MCP server,\n  REST API, TypeScript SDK, and Python SDK.\n  Use when users ask about \"Neon setup\", \"connect to Neon\", \"Neon project\",\n  \"DATABASE_URL\", \"serverless Postgres\", \"Neon CLI\", \"neon\", \"Neon MCP\",\n  \"Neon Auth\", \"@neondatabase/serverless\", \"@neondatabase/neon-js\",\n  \"scale to zero\", \"Neon autoscaling\", \"Neon read replica\", or\n  \"Neon connection pooling\".\n---\n\n# Neon Serverless Postgres\n\nGuide the user through any Neon-related task: setup, connections, branching, and advanced features. Deliver a working Neon connection, a completed feature configuration, or a specific answer from the official Neon docs.\n\nNeon is a serverless Postgres platform that separates compute and storage 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.\n\n## Neon Documentation\n\nThe Neon documentation is the source of truth for all Neon-related information. Always verify claims against the official docs before responding. Neon features and APIs evolve, so prefer fetching current docs over relying on training data.\n\n### Fetching Docs as Markdown\n\nAny Neon doc page can be fetched as markdown in two ways:\n\n1. **Append `.md` to the URL** (simplest): https://neon.com/docs/introduction/branching.md\n2. **Request `text/markdown`** on the standard URL: `curl -H \"Accept: text/markdown\" https://neon.com/docs/introduction/branching`\n\nBoth return the same markdown content. Use whichever method your tools support.\n\n### Finding the Right Page\n\nThe docs index lists every available page with its URL and a short description:\n\n```\nhttps://neon.com/docs/llms.txt\n```\n\nCommon doc URLs are organized in the topic links below. If you need a page not listed here, search the docs index: https://neon.com/docs/llms.txt. Don't guess URLs.\n\n## What Is Neon\n\nUse this for architecture explanations and terminology (organizations, projects, branches, endpoints) before giving implementation advice.\n\nLink: https://neon.com/docs/introduction/architecture-overview.md\n\n## Getting Started\n\nUse this section when guiding a user through first-time Neon setup.\n\n### Check Status Quo\n\nBefore starting setup, inspect the user's codebase and environment:\n\n- Existing database connection code\n- Existing Neon MCP server or Neon CLI configuration\n- Existence of a `.env` file and `DATABASE_URL` environment variable\n- Existing ORM (Prisma, Drizzle, TypeORM) configuration\n\n### Self-Driving Setup With Neon's CLI or MCP Server\n\nOffer to inspect existing connected Neon projects or create new ones using the Neon CLI or MCP server. If neither is set up yet, run init with the `--agent` flag. Use `npx -y` to skip the package install prompt. Auth is handled automatically. If the user is not logged in, it opens their browser for OAuth and waits for completion before proceeding.\n\n```bash\nnpx -y neon@latest init --agent <agent-name>\n```\n\nSupported `--agent` values: `cursor`, `copilot`, `claude`, `claude-desktop`, `codex`, `opencode`, `cline`, `gemini-cli`, `goose`, `zed`.\n\nThis installs the Neon extension (for Cursor/VS Code) or MCP server (for other agents), creates an API key, and adds the `neon-postgres` agent skill to the project.\n\nIf `init` is not suitable, the individual steps can be run non-interactively:\n\n- **Extension:** `cursor --install-extension databricks.neon-local-connect`\n- **MCP server:** `npx -y add-mcp https://mcp.neon.tech/mcp -g -n Neon -y -a <agent-name>`\n- **Agent skill:** `npx skills add neondatabase/agent-skills --skill neon-postgres --agent <agent-name> -y`\n\nFor full CLI installation options, see https://neon.com/docs/cli/install.md\n\n### Setup Flow\n\n**1. Select Organization and Project**\n\nUse MCP server or CLI to list organizations and projects. Let the user select an existing project or create a new one.\n\n**2. Get Connection String**\n\nUse MCP server or CLI to get the connection string. Store it in `.env` as `DATABASE_URL`. Read the file first before modifying to avoid overwriting existing values.\n\n**3. Pick Connection Method & Driver**\n\nRefer to the connection methods guide to pick the correct driver based on deployment platform: https://neon.com/docs/connect/choose-connection.md\n\n**4. User Authentication with Neon Auth (if needed)**\n\nSkip for CLI tools, scripts, or apps without user accounts. If the app needs auth: use MCP server `provision_neon_auth` tool, then see the auth overview (https://neon.com/docs/auth/overview.md) for setup. For auth + database queries, see the JavaScript SDK reference (https://neon.com/docs/reference/javascript-sdk.md).\n\n**5. ORM Setup (optional)**\n\nCheck for existing ORM (Prisma, Drizzle, TypeORM). If none, ask if they want one. For Drizzle integration, see https://neon.com/docs/guides/drizzle.md.\n\n**6. Schema Setup**\n\n- Check for existing migration files or ORM schemas\n- If none: offer to create an example schema or design one together\n\n### Resume Support\n\nIf resuming setup, check what's already configured (MCP connection, `.env` with `DATABASE_URL`, dependencies, schema) and continue from the next incomplete step.\n\n### Security Reminders\n\nRemind users to use environment variables for credentials, never commit connection strings, and use least-privilege database roles.\n\n## Connection Methods & Drivers\n\nUse this when you need to pick the correct transport and driver based on runtime constraints (TCP, HTTP, WebSocket, edge, serverless, long-running).\n\nLink: https://neon.com/docs/connect/choose-connection.md\n\n### Recommended: Drizzle + the right driver for your runtime\n\nAlways pair Neon with an ORM such as **Drizzle** for easy schema management and migrations. Pick the driver based on how the runtime treats your code:\n\n- **Long-running or shared-runtime environments → node-postgres (`pg`).** Neon Functions, and any host where the function runtime is shared across requests / runs on fluid compute (e.g. **Vercel** with Fluid compute), keep a module-scope process alive across many requests. Open a `pg` pool **once at module scope** and reuse it across requests.\n- **Fully isolated serverless (Lambda-style) → Neon's serverless driver (`@neondatabase/serverless`).** Hosts like **Netlify** spin up a fresh, isolated instance per request, so a persistent TCP pool can't be reused; the serverless driver queries over HTTP and is built for this.\n\n**Neon Functions / Vercel / fluid compute — Drizzle + node-postgres:**\n\n```typescript\nimport { drizzle } from \"drizzle-orm/node-postgres\";\nimport { Pool } from \"pg\";\nimport * as schema from \"./schema\";\n\n// Created once at module scope; reused by every request the instance handles.\nconst pool = new Pool({ connectionString: process.env.DATABASE_URL, max: 5 });\nconst db = drizzle({ client: pool, schema });\n```\n\nOn **Vercel** (Fluid compute) also attach the pool with `attachDatabasePool` from `@vercel/functions`, so the function runtime drains idle connections before an instance suspends:\n\n```typescript\nimport { drizzle } from \"drizzle-orm/node-postgres\";\nimport { Pool } from \"pg\";\nimport { attachDatabasePool } from \"@vercel/functions\";\nimport * as schema from \"./schema\";\n\nconst pool = new Pool({ connectionString: process.env.DATABASE_URL });\nattachDatabasePool(pool); // let the Vercel runtime manage the pooled connections\nconst db = drizzle({ client: pool, schema });\n```\n\n**Netlify and other fully-isolated serverless — Drizzle + Neon serverless driver:**\n\n```typescript\nimport { drizzle } from \"drizzle-orm/neon-http\";\nimport { neon } from \"@neondatabase/serverless\";\n\nconst sql = neon(process.env.DATABASE_URL!);\nconst db = drizzle({ client: sql });\n```\n\n### Serverless Driver\n\nUse this for `@neondatabase/serverless` patterns, including HTTP queries, WebSocket transactions, and runtime-specific optimizations.\n\nLink: https://neon.com/docs/serverless/serverless-driver.md\n\n### Neon JS SDK\n\nUse this for combined Neon Auth + Data API workflows with PostgREST-style querying and typed client setup.\n\nLink: https://neon.com/docs/reference/javascript-sdk.md\n\n## Developer Tools\n\nUse this for local development enablement with `npx -y neon@latest init --agent <agent-name>`, VSCode extension setup, and Neon MCP server configuration.\n\n| Tool             | URL                                             |\n| ---------------- | ----------------------------------------------- |\n| CLI Init Command | https://neon.com/docs/cli/init.md               |\n| VSCode Extension | https://neon.com/docs/local/vscode-extension.md |\n| MCP Server       | https://neon.com/docs/ai/neon-mcp-server.md     |\n| Neon CLI         | https://neon.com/docs/cli.md                    |\n\n### Neon CLI\n\nUse this for terminal-first workflows, scripts, and CI/CD automation with `neon`.\n\nLink: https://neon.com/docs/cli.md\n\n## Neon Admin API\n\nThe Neon Admin API can be used to manage Neon resources programmatically. It is used behind the scenes by the Neon CLI and MCP server, but can also be used directly for more complex automation workflows or when embedding Neon in other applications.\n\n### Neon REST API\n\nUse this for direct HTTP automation, endpoint-level control, API key auth, rate-limit handling, and operation polling.\n\nLink: https://neon.com/docs/reference/api-reference.md\n\n### Neon TypeScript SDK\n\nUse this when implementing typed programmatic control of Neon resources in TypeScript via `@neon/sdk` (the fetch-based, zero-dependency successor to `@neondatabase/api-client`). For the full API surface — client config, the `{ data, error }` result model, typed errors, readiness/workflow helpers (`createAndConnect`, `createWithCompute`), pagination, every resource namespace, and the raw layer — see [references/neon-sdk.md](https://neon.com/docs/ai/skills/neon-postgres/references/neon-sdk.md).\n\nLink: https://neon.com/docs/reference/typescript-sdk.md\n\n### Neon Python SDK\n\nUse this when implementing programmatic Neon management in Python with the `neon-api` package.\n\nLink: https://neon.com/docs/reference/python-sdk.md\n\n## Neon Auth\n\nUse this for managed user authentication setup, UI components, auth methods, and Neon Auth integration pitfalls in Next.js and React apps.\n\nLink: https://neon.com/docs/auth/overview.md\n\nNeon Auth is also embedded in the Neon JS SDK. Depending on your use case, you may want to use the Neon JS SDK instead of Neon Auth alone. See https://neon.com/docs/connect/choose-connection.md for more details.\n\n## Neon Infrastructure as Code (`neon.ts`)\n\n`neon.ts` is Neon's branch config and infrastructure-as-code file: declare which services your branches have, get type-safe env vars, and program per-branch compute — all in TypeScript (see the `neon` skill for the full reference). Postgres always exists on every branch, so you never declare the database itself; what you codify here is the Postgres-adjacent surface — Neon Auth, the Data API, and per-branch compute settings (autoscaling and scale-to-zero).\n\nAdd it with `@neon/config`:\n\n```bash\nnpm i @neon/config\n```\n\n```typescript\n// neon.ts\nimport { defineConfig } from \"@neon/config/v1\";\n\nexport default defineConfig({\n  auth: true, // Neon Auth (adds NEON_AUTH_* env vars)\n  dataApi: true, // Data API (adds NEON_DATA_API_URL); requires auth: true (or an external IdP)\n  // Postgres exists on every branch; tune its compute per branch:\n  branch: (branch) => {\n    if (branch.exists) return {}; // leave existing branches untouched\n    if (branch.isDefault) return { protected: true }; // prod keeps default compute\n    return {\n      ttl: \"7d\", // non-prod branches auto-expire (max 30d)\n      postgres: {\n        computeSettings: {\n          autoscalingLimitMinCu: 0.25, // scale to zero\n          autoscalingLimitMaxCu: 1, // keep dev/preview cheap\n          suspendTimeout: \"5m\",\n        },\n      },\n    };\n  },\n});\n```\n\nReconcile the declaration from the CLI — the Neon equivalent of `terraform plan` / `apply`:\n\n```bash\nneon config status   # print the branch's live config\nneon config plan     # dry-run diff of what apply would change\nneon config apply    # provision the declared services / settings\nneon deploy          # alias for `neon config apply`\n```\n\nBecause `neon checkout` applies the policy as it **creates** a branch, a fresh branch comes up with these compute settings (and Auth / Data API) already in place. Checking out an _existing_ branch never reconciles it — run `neon deploy` to apply changes.\n\nSince `neon.ts` is TypeScript, invalid combinations fail to compile with an actionable message: the Data API verifies requests with Neon Auth by default, so `dataApi: true` without `auth: true` is a type error (the fix — `auth: true`, or `authProvider: 'external'` with a `jwksUrl` — is in the message). See the `neon` skill's type-safe config note.\n\nRead the resulting env back, typed and validated against the policy, with `parseEnv` from `@neon/env`:\n\n```typescript\nimport { parseEnv } from \"@neon/env\";\nimport config from \"./neon\";\n\nconst env = parseEnv(config);\nenv.postgres.databaseUrl; // typed; enabling auth / dataApi above surfaces env.auth / env.dataApi\n```\n\n## Branching\n\nUse this when the user is planning isolated environments, schema migration testing, preview deployments, or branch lifecycle automation.\n\nKey points:\n\n- Branches are instant, copy-on-write clones (no full data copy).\n- Each branch has its own compute endpoint.\n- Use the neon CLI or MCP server to create, inspect, and compare branches.\n\nLink: https://neon.com/docs/introduction/branching.md\n\nFor detailed branch creation workflows (normal vs schema-only branches, reset-from-parent, CLI/MCP selection), use the `neon-postgres-branches` skill if available\n\nOr fetch the full branching skill from the following URL:\n\nhttps://neon.com/docs/ai/skills/neon-postgres-branches/SKILL.md\n\nIf this skill is not installed you can use the following command to install it:\n\n```bash\nnpx skills add neondatabase/agent-skills --skill neon-postgres-branches\n```\n\n## Autoscaling\n\nUse this when the user needs compute to scale automatically with workload and wants guidance on CU sizing and runtime behavior.\n\nLink: https://neon.com/docs/introduction/autoscaling.md\n\n## Scale to Zero\n\nUse this when optimizing idle costs and discussing suspend/resume behavior, including cold-start trade-offs.\n\nKey points:\n\n- Idle computes suspend automatically (default 5 minutes, configurable) (unless disabled - launch & scale plan only)\n- First query after suspend typically has a cold-start penalty (around hundreds of ms)\n- Storage remains active while compute is suspended.\n\nLink: https://neon.com/docs/introduction/scale-to-zero.md\n\n## Instant Restore\n\nUse this when the user needs point-in-time recovery or wants to restore data state without traditional backup restore workflows.\n\nKey points:\n\n- History windows for instant restore depend on plan limits.\n- Users can create branches from historical points-in-time.\n- Time Travel queries can be used for historical inspection workflows.\n\nLink: https://neon.com/docs/introduction/branch-restore.md\n\n## Read Replicas\n\nUse this for read-heavy workloads where the user needs dedicated read-only compute without duplicating storage.\n\nKey points:\n\n- Replicas are read-only compute endpoints sharing the same storage.\n- Creation is fast and scaling is independent from primary compute.\n- Typical use cases: analytics, reporting, and read-heavy APIs.\n\nLink: https://neon.com/docs/introduction/read-replicas.md\n\n## Connection Pooling\n\nUse this when the user is in serverless or high-concurrency environments and needs safe, scalable Postgres connection management.\n\nKey points:\n\n- Neon pooling uses PgBouncer.\n- Add `-pooler` to endpoint hostnames to use pooled connections.\n- Pooling is especially important in serverless runtimes with bursty concurrency.\n\nLink: https://neon.com/docs/connect/connection-pooling.md\n\n## IP Allow Lists\n\nUse this when the user needs to restrict database access by trusted networks, IPs, or CIDR ranges.\n\nLink: https://neon.com/docs/introduction/ip-allow.md\n\n## Logical Replication\n\nUse this when integrating CDC pipelines, external Postgres sync, or replication-based data movement.\n\nKey points:\n\n- Neon supports native logical replication workflows.\n- Useful for replicating to/from external Postgres systems.\n\nLink: https://neon.com/docs/guides/logical-replication-guide.md\n","contentSource":"skills.sh/api/download/neondatabase/agent-skills/neon-postgres","contentFetchedAt":"2026-07-27T08:59:29.257Z"}