Prisma "P1017: Server has closed the connection" in CI
P1017 means the database closed a connection Prisma was using. In CI this comes from a service that restarted, an idle-timeout on a pooler, or the DB being killed before the step finished.
What this error means
A migrate or query step fails partway with "P1017: Server has closed the connection.", sometimes only under load or on slower runners.
Error: P1017: Server has closed the connection.Common causes
The database service restarted or was still stabilizing
A service container that restarts (or is under memory pressure) drops in-flight connections, surfacing as P1017.
A pooler closed an idle or capped connection
A connection pooler (PgBouncer) or the server closed a connection that exceeded an idle or lifetime limit.
How to fix it
Ensure the database is stable before use
- Wait for the health check to pass before running Prisma.
- Give the service enough memory so it does not restart under load.
- Retry the operation once if the drop is transient.
services:
postgres:
image: postgres:16
options: >-
--health-cmd="pg_isready" --health-interval=5s --health-retries=10Tune connection lifetime with a pooler
When routing through a pooler, keep connection limits and lifetimes consistent so Prisma is not handed a connection about to be closed.
DATABASE_URL=postgresql://user:pass@pooler:6432/app?pgbouncer=true&connection_limit=5How to prevent it
- Wait for a healthy database before running Prisma.
- Provision enough resources so the service does not restart.
- Align pool limits and lifetimes when using a pooler.