xiaohongshu
xiaohongshu
configuring-connection-pools
Configure connection pool sizing for optimal performance. Use when configuring DATABASE_URL or deploying to production.
Full skill instructions
Configure Prisma Client connection pools for optimal performance and resource utilization.
Standard environments: connection_limit = (num_cpus × 2) + 1
Examples: 4 CPU → 9, 8 CPU → 17, 16 CPU → 33 connections
Configure in DATABASE_URL:
DATABASE_URL="postgresql://user:pass@host:5432/db?connection_limit=9&pool_timeout=20"
Configure in schema.prisma:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
previewFeatures = ["metrics"]
}
Always use connection_limit=1 per instance: Serverless platforms scale horizontally; total connections = instances × limit. Example: 100 Lambda instances × 1 = 100 DB connections (safe) vs. 100 × 10 = 1,000 (exhausted).
AWS Lambda / Vercel / Netlify:
DATABASE_URL="postgresql://user:pass@host:5432/db?connection_limit=1&pool_timeout=0&connect_timeout=10"
Additional optimizations:
pool_timeout=0: Fail fast instead of waiting for connectionsconnect_timeout=10: Timeout initial DB connectionpgbouncer=true: Use PgBouncer transaction modeDeploy external pooler when: >100 application instances, unpredictable serverless scaling, multiple apps sharing one database, connection exhaustion, frequent P1017 errors
Configuration:
[databases]
mydb = host=postgres.internal port=5432 dbname=production
[pgbouncer]
pool_mode = transaction
max_client_conn = 1000
default_pool_size = 20
reserve_pool_size = 5
reserve_pool_timeout = 3
**Prisma with
PgBouncer:**
DATABASE_URL="postgresql://user:pass@pgbouncer:6432/db?pgbouncer=true&connection_limit=10"
Avoid in transaction mode: Prepared statements (disabled with pgbouncer=true), persistent SET variables, LISTEN/NOTIFY, advisory locks, temporary tables
P1017 Error (Connection pool timeout): "Can't reach database server at localhost:5432"
Causes: connection_limit too low, slow queries holding connections, missing cleanup, database at max_connections limit
Diagnosis:
import { Prisma } from '@prisma/client';
const prisma = new Prisma.PrismaClient({
log: [{ emit: 'event', level: 'query' }],
});
prisma.$on('query', (e) => {
console.log('Query duration:', e.duration);
});
const metrics = await prisma.$metrics.json();
console.log('Pool metrics:', metrics);
Check pool status:
SELECT count(*) as connections, state, wait_event_type, wait_event
FROM pg_stat_activity WHERE datname = 'your_database'
GROUP BY state, wait_event_type, wait_event;
SHOW max_connections;
SELECT count(*) FROM pg_stat_activity;
| Parameter | Standard | Serverless | PgBouncer | Notes |
|---|---|---|---|---|
connection_limit | num_cpus × 2 + 1 | 1 | 10–20 | Total connections = instances × limit |
pool_timeout | 20–30 sec | 0 (fail fast) | — | Wait time for available connection |
connect_timeout | 5 sec | 10 sec | — | Initial connection timeout; 15–30 for network issues |
Complete URL example:
postgresql://user:pass@host:5432/db?connection_limit=9&pool_timeout=20&connect_timeout=10&socket_timeout=0&statement_cache_size=100
connection_limit based on CPU/instance countpool_timeout appropriately for environmentslow queries
Environment-specific settings:
| Environment | URL Pattern |
|---|---|
| Traditional servers | postgresql://user:pass@host:5432/db?connection_limit=17&pool_timeout=20 |
| Containers with PgBouncer | postgresql://user:pass@pgbouncer:6432/db?pgbouncer=true&connection_limit=10 |
| Serverless functions | postgresql://user:pass@host:5432/db?connection_limit=1&pool_timeout=0 |
Default limit in serverless: Each Lambda instance uses ~10 connections, exhausting DB with 50+ concurrent functions. Fix: connection_limit=1
High pool_timeout in serverless: Functions wait 30s for connections, hitting timeout. Fix: pool_timeout=0
No PgBouncer with high concurrency: 200+ application instances with direct connections = exhaustion. Fix: Deploy PgBouncer with transaction pooling.
Connection_limit exceeds database max_connections: Setting connection_limit=200 when DB max is 100. Fix: Use PgBouncer or reduce limit below database maximum.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience