Overview
Neon is a serverless PostgreSQL that scales to zero. It’s great for:- Development environments
- Cost optimization (pay only when active)
- Auto-scaling
Prerequisites
- Neon account
- A Neon project with logical replication enabled
Step 1: Create Neon Project
- Go to Neon Console
- Create a new project
- Important: Enable logical replication:
- Go to Project Settings → Logical Replication
- Enable it
Step 2: Get Connection String
From your Neon dashboard, copy the pooled connection string:Step 3: Configure Agent Diff
Create.env file in ops/:
Step 4: Start Agent Diff
Neon-Specific Configuration
Scale-to-Zero Support
Agent Diff’s on-demand services work well with Neon’s scale-to-zero:Connection Pooling
Neon uses PgBouncer for connection pooling. Agent Diff auto-detects this and disables its own pooling:Replication Slot Limits
Neon limits replication slots to 10 per project. Agent Diff uses a single global slot, so this is not a problem for normal usage.First Time Setup
On first run withSEED=true:
- Alembic migrations run
- Seed scripts create templates
- Pool schemas are pre-created
Subsequent Runs
After initial setup:Monitoring
Check Connection
View Logs
Check Replication
In Neon SQL Editor:diffslot_global.
Cost Optimization
Compute Hours
Neon bills for compute hours. To minimize costs:- Use short idle timeouts
- Clean up environments promptly
- Reduce pool targets if not needed
Storage
Neon bills for storage. Pooled schemas use storage. Balance between:- More pools = faster tests, more storage
- Fewer pools = slower tests, less storage
Troubleshooting
Connection Timeouts
Neon connections can drop on idle. Agent Diff handles this with:- Connection retries
- NullPool (no stale connections)
SSL SYSCALL error: EOF detected, it’s normal - retries should handle it.
Replication Not Working
Check that logical replication is enabled:Slow First Request
After Neon scales to zero, the first request takes 1-3 seconds to “wake up” the database. Subsequent requests are fast.Production Considerations
For production use:- Use dedicated compute: Disable scale-to-zero in Neon for consistent latency
- Increase pool targets: Minimize pool misses
- Monitor replication lag: Ensure diffs are captured in time
Next Steps
Configuration
All configuration options
API Reference
Complete API documentation
