Keep a stable local connection while switching Neon branches
Local development
Neon · Const
Neon Local is a Docker proxy that exposes a local Postgres endpoint for a Neon cloud branch. It can target an existing branch or create and clean up an ephemeral branch automatically.
Neon Local runs as a Docker proxy between a local Postgres endpoint and a Neon cloud database. It authenticates and routes requests to either an existing branch identified by BRANCH_ID or a temporary branch based on PARENT_BRANCH_ID, keeping the application's connection endpoint unchanged when branches change.
docker run --rm -p 5432:5432 -e NEON_API_KEY=$NEON_API_KEY -e NEON_PROJECT_ID=$NEON_PROJECT_ID -e PARENT_BRANCH_ID=$PARENT_BRANCH_ID neonlocal/neon-local| Name | Type | Description |
|---|---|---|
PARENT_BRANCH_ID | environment variable | Branch used as the basis for an automatically created ephemeral branch. |
BRANCH_ID | environment variable | Existing Neon branch to which the proxy routes connections. |
DELETE_BRANCH | environment variable | Controls whether an automatically created branch is removed when the container stops. |
DRIVER | environment variable | Selects the database client mode used by the container. |
A local Postgres endpoint that routes connections to the selected Neon branch.
docker run --rm -p 5432:5432 -e NEON_API_KEY=$NEON_API_KEY -e NEON_PROJECT_ID=$NEON_PROJECT_ID -e PARENT_BRANCH_ID=br-main neonlocal/neon-localRun the proxy locally; the application can connect through the exposed Postgres endpoint while the container manages an ephemeral branch.
Local development
Automated testing
Client compatibility
Neon Local is a Docker proxy that exposes a local Postgres endpoint and routes traffic to a Neon branch. The application uses the local endpoint while Neon Local manages authentication and branch routing.
Follow-up: How can it target a specific existing branch? Set BRANCH_ID to the desired branch identifier instead of using the ephemeral-branch configuration.
Set PARENT_BRANCH_ID to choose the source branch for an automatically created ephemeral branch. The branch is created when the container starts and removed when the container stops by default.
Follow-up: How would you retain that branch? Configure DELETE_BRANCH=false so shutdown does not delete it.
Neon Local supports both the standard postgres driver and Neon’s serverless driver through one Docker configuration. This lets applications use either client while connecting through the same local endpoint.
Follow-up: What remains stable when switching branches? The application’s local connection string does not need to change.
Neon serverless driverpostgres driverDockerephemeral branchesBRANCH_IDPARENT_BRANCH_IDDELETE_BRANCH