> ## Documentation Index
> Fetch the complete documentation index at: https://a5eb32f-docs-2.manicule.dev/llms.txt
> Use this file to discover all available pages before exploring further.
> For every page in one file, fetch https://a5eb32f-docs-2.manicule.dev/llms-full.txt (large).
> To search and read these docs as tools, connect the MCP server at https://a5eb32f-docs-2.manicule.dev/api/mcp.
> Every agent surface: https://a5eb32f-docs-2.manicule.dev/.well-known/llms-manifest.json

# Connect Your App to Neon Postgres (/databases/neon-postgres)

<!-- agent-signals: reading_time_min: 2 · est_tokens: 710 · updated: 2026-11-25 -->
Related: [Choose a Database for Your Project](/databases/overview.md), [Connect a Worker to Cloudflare D1](/databases/cloudflare-d1.md), [Connect Your App to Supabase](/databases/supabase-postgres.md), [Review and Apply Database Migrations](/databases/migrations.md)

> Connect to Neon from server-side code and test PostgreSQL schema changes on an isolated database branch.

Neon is serverless PostgreSQL with separate compute and storage. Use it when your app needs Postgres and you want a separate database branch for testing schema changes. The connection string selects the branch your code will query, so keep development and production values separate.

## Connect from server-side code

<Steps>
<Step title="Create or choose a database in Neon">Open Neon and choose the project and database branch for the environment you're setting up. A Neon entry in Studio doesn't create the database or provide its connection string.</Step>

<Step title="Set the connection string">Copy the connection string for that branch into the server-side `DATABASE_URL` environment variable. Use the pooled connection string for application traffic when your driver supports it, and use a direct connection for schema migrations. Treat both strings as credentials.</Step>

<Step title="Run a query from your server">Use `@neondatabase/serverless` from code that can read the server environment. Run a query against a table you expect on that branch; the example below assumes your schema already defines a `users` table with an `active` column.</Step>
</Steps>

```typescript
import { neon } from "@neondatabase/serverless";

const databaseUrl = process.env.DATABASE_URL;
if (!databaseUrl) throw new Error("Set DATABASE_URL on the server");

const sql = neon(databaseUrl);

export async function getActiveUsers() {
  return sql`SELECT id, name, email FROM users WHERE active = true`;
}
```

## Test migrations on a database branch

Create an isolated Neon branch for a feature and, if useful, give it the same name as the Git branch. Matching names helps you identify the pair, but it doesn't change `DATABASE_URL`. Point your development or test environment at the Neon branch before running a migration. Verify the schema and run the app against that branch before applying the reviewed migration to production.

## Plan for compute and extensions

Neon compute can scale up under load and scale to zero when idle. Account for a resume when testing the first query after an idle period. Neon supports PostgreSQL extensions such as `pgvector`, `uuid-ossp`, and `pg_trgm`. If your schema depends on one, include it in the migration you test on the branch.

## Check the branch when a query fails

If the example can't find `users`, verify that the running app loads the connection for the branch where you applied the migration. If the query runs but returns no rows, confirm that branch has test users marked active. Don't point a development app at production to get test data.

## Next

* [Review and apply database migrations](/databases/migrations).
* [Compare database engines and tooling](/databases/overview).
