neon-postgres: Best Practices for Agents with Neon Serverless Postgres

Introduction

In AI-assisted coding scenarios, database-related tasks often lead to mistakes such as selecting the wrong connection string, using pooled connections for migrations, or conflating Neon branching with general Postgres tuning. Neon separates compute and storage, providing features like autoscaling, branching, and scale-to-zero, which differ slightly from the operational habits of standard self-hosted Postgres. The following introduces the neon-postgres Skill maintained by Neon: it codifies practices for connections, migrations, branching, diagnostics, and search for Lakebase Postgres (Neon’s core database) via Neon access paths into guidelines that Agents can follow, reducing the need to repeatedly consult documentation during conversations.

What is this

neon-postgres is an Agent Skill provided by Neon in the agent-skills repository. Its metadata identifies the parent Skill as neon, sourced from the same GitHub path.

The Skill’s description summarizes its scope: centered on Lakebase Postgres on Neon, it covers connections (pooled and direct), schema migrations, branching, autoscaling, scale-to-zero, point-in-time recovery, read replicas, IP allowlists, logical replication, and Lakebase Search. It should be activated when there is existing DATABASE_URL, SQL, schema, inspect, or search-related work. New backends, Auth, files, Functions, and LLM calls should be delegated to the parent Skill neon; real-time queries, reactive UIs, and real-time data should be handled by neon-realtime.

The documentation states: Lakebase Postgres runs on the lakebase architecture with decoupled storage and compute, is compatible with standard Postgres, and can be accessed via any Postgres-supporting language, framework, or ORM. This Skill only covers the access path via Neon; for login and user sessions, refer to neon-auth.

Core Features

Official guidance: First, use the parent Skill neon to understand the Neon overview, getting started guide, and development best practices. If neon is not installed, obtain it from https://neon.com/docs/ai/skills/neon/SKILL.md or run:

neon skills -s neon -y

neon-postgres focuses on the usage of the database itself on Neon; for detailed branch creation workflows, refer to neon-postgres-branches (installable via neon skills -s neon-postgres-branches -y).

Setup and Connection

The Setup Flow consists of four steps. The Agent should check existing context to avoid creating duplicate projects:

  1. Select Organization and Project: If a prompt, environment variable, or repository already contains a DATABASE_URL, or if .neon points to a project, use it directly. Do not list organizations or create a second project for schema work; otherwise, use the CLI (default) or MCP to list and let the user select or create one.
  2. Obtain Connection String: If a DATABASE_URL exists, do not pull it again via CLI/MCP; otherwise, use CLI, neon env pull, or MCP. Write to DATABASE_URL in .env. Read the file before modifying to avoid overwriting.
  3. Choose Connection Mode and Driver: Keep existing ORM/drivers; for TypeScript schema work without a established choice, refer to Drizzle documentation. Select the driver based on the runtime environment (see Neon’s “choose connection” docs); e.g., for serverless/edge, use @neondatabase/serverless (HTTP for single queries, WebSocket for transactions). Scenarios for Vercel, Cloudflare, Neon Functions, etc., have corresponding driver instructions in the Skill.
  4. Schema: Manage schema and migrations as code to avoid hard-to-trace ad-hoc DDL on the database.

Selection between Pooled (-pooler) and direct (excerpt from official table):

Scenario Connection Type
Web applications, serverless functions Pooled
Schema migrations Direct
pg_dump / pg_restore Direct
Logical replication Direct
Long-running analytics with temp tables Direct
Admin tasks requiring SET or session state Direct
LISTEN / NOTIFY Direct

Branching and Migration

Branches are instant, copy-on-write clones, each with an independent compute endpoint; they are suitable for isolated environments, validating migrations on preview data, preview deployments, or branch lifecycle automation. For more detailed branch types and CLI/MCP workflows, see neon-postgres-branches.

Migrations should be validated on a production branch with production-like data before being applied to production; migrations must be executed using a direct (non-pooled) connection. neon connection-string returns a direct connection by default, and the hostname should not have the -pooler suffix.

Diagnostics and Neon-side Performance

Before writing manual catalog queries, prioritize Neon’s built-in read-only diagnostics: the CLI’s neon inspect db and the MCP’s inspect_database run the same set of checks. Correspondences between symptoms and checks include: storage usage (table-sizes, index-sizes), unused indexes and sequential scans (unused-indexes, seq-scans), long queries and locks (long-running-queries, locks), total duration and call frequency (outliers, calls), compute cache and working set (lfc-hit-rate, working-set), vacuum and bloat (vacuum-stats, bloat), etc. If evidence points to general Postgres optimization (query changes, indexes, planner nodes), the Skill instructs to load postgres-best-practices and continue with diagnostic results.

CLI Example (when authenticated and Neon context is resolvable):

neon inspect db <check>

Overrides are available via --project-id, --branch, --database-name; using only --db-url indicates a direct connection to Postgres rather than resolution via the Neon API.

Search and Trigger Words

The Skill instructions also apply to @neondatabase/serverless, @neondatabase/neon-js, neon inspect db, as well as Lakebase Search-related work such as semantic / vector / full-text / BM25 / hybrid search.

Installation and Activation

The installation method listed on officialskills.sh is:

npx skills add https://github.com/neondatabase/agent-skills --skill neon-postgres

You can also provide the Skill directory link to your coding assistant and request installation:
https://github.com/neondatabase/agent-skills/tree/main/skills/neon-postgres

The parent Skill neon is recommended to be installed as well (see neon skills -s neon -y above). If the documentation does not differentiate installation specifics for Cursor, Codex CLI, or Claude Code, follow npx skills add and the Neon CLI’s neon skills.

Typical Usage (Agent-side Behavior)

When the conversation involves an existing DATABASE_URL, writing SQL, modifying schema, inspecting the database, or performing search, the Agent should load this Skill and operate according to the Setup Flow: do not recreate projects; use direct connections for migrations and pg management tools; use pooled connections or @neondatabase/serverless for Web/serverless queries.

Branching and CI: Use the neon CLI or MCP to create, view, and compare branches; run migrations on branches before merging to the production branch.

Troubleshooting: Select the check name for neon inspect db based on the symptom, or use MCP inspect_database; switch to neon-postgres-branches for detailed branch workflow needs.

Scenarios summarized by officialskills.sh include: creating isolated branches for PR previews, point-in-time recovery after a bad migration, connecting to Postgres via HTTP on Vercel Edge, independently scaling read replicas for analytics, and using neonctl to automate branch lifecycles in CI/CD (consistent with the official Skill description, not separate user cases).

Scenarios and Notes

Suitable for: Postgres workloads already using or planning to use Neon; teams where Agents need to stably follow the rules of “pooled vs direct, testing migrations on branches, using inspect before digging deeper.”

Notes:

  • This Skill does not replace neon (platform overview, Auth/Functions, etc.), neon-realtime (real-time UI), or neon-auth (login and sessions).
  • Do not run schema changes on production that have not been validated on a branch.
  • If diagnostics are truncated, you may increase the limit for the MCP inspect_database (only when the results indicate truncation).

Serverless Postgres and AI applications often go hand-in-hand; Neon uses official Skills to integrate database vendor best practices into the Agent Skills ecosystem, with neon-postgres being the specific entry for Lakebase Postgres via Neon paths.

Conclusion

neon-postgres consolidates guidelines for connections, migrations, branching, platform diagnostics, and search into an executable process for Agents, clearly defining boundaries with the parent Skill, branch sub-Skills, and general Postgres best practice Skills. Official Skill Directory:

https://github.com/neondatabase/agent-skills/tree/main/skills/neon-postgres

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye