prisma migrate: P1017 Server has closed the connection.
See original GitHub issueBug description
I am connecting to a supabase.io postresql database. I have 2 databases with the exact same schema. For one of them, prisma migrate dev
works fine, for the other I suddenly get the following P1017 error message.
yarn run v1.22.15
$ yarn prisma migrate dev
$ /xxx/xxxxxx/node_modules/.bin/prisma migrate dev
prisma:loadEnv project root found at /xxx/xxxxxx/packages/platform/package.json +0ms
prisma:tryLoadEnv Environment variables not found at null +0ms
prisma:tryLoadEnv Environment variables not found at undefined +1ms
prisma:tryLoadEnv No Environment variables loaded +0ms
prisma:engines using Node API: false +0ms
prisma:engines binaries to download query-engine, migration-engine, introspection-engine, prisma-fmt +0ms
Prisma schema loaded from prisma/schema.prisma
prisma:getConfig Using Query Engine Binary at: /xxx/xxxxxx/node_modules/@prisma/engines/query-engine-rhel-openssl-1.1.x +0ms
Datasource "db": PostgreSQL database "postgres", schema "public" at "db.xxxxxxxxxxxxxxxxxxxx.supabase.co:5432"
prisma:getDMMF Using Query Engine Binary at: /xxx/xxxxxx/node_modules/@prisma/engines/query-engine-rhel-openssl-1.1.x +0ms
prisma:getConfig Using Query Engine Binary at: /xxx/xxxxxx/node_modules/@prisma/engines/query-engine-rhel-openssl-1.1.x +127ms
prisma:getConfig Using Query Engine Binary at: /xxx/xxxxxx/node_modules/@prisma/engines/query-engine-rhel-openssl-1.1.x +30ms
prisma:migrateEngine:rpc starting migration engine with binary: /xxx/xxxxxx/node_modules/@prisma/engines/migration-engine-rhel-openssl-1.1.x +0ms
prisma:migrateEngine:rpc SENDING RPC CALL {"id":1,"jsonrpc":"2.0","method":"devDiagnostic","params":{"migrationsDirectoryPath":"/xxx/xxxxxx/packages/platform/prisma/migrations"}} +5ms
prisma:migrateEngine:stderr {"timestamp":"2021-10-28T17:45:58.967826886+00:00","level":"INFO","fields":{"message":"Starting migration engine RPC server","git_hash":"89facabd0366f63911d089156a7a70125bfbcd27"},"target":"migration_engine"} +0ms
prisma:migrateEngine:stderr {"timestamp":"2021-10-28T17:46:00.944393975+00:00","level":"ERROR","fields":{"message":"Error in PostgreSQL connection: Error { kind: Closed, cause: None }"},"target":"quaint::connector::postgres"} +2s
prisma:migrateEngine:stderr {"timestamp":"2021-10-28T17:46:00.948060137+00:00","level":"ERROR","fields":{"message":"Error in PostgreSQL connection: Error { kind: Closed, cause: None }"},"target":"quaint::connector::postgres"} +4ms
prisma:migrateEngine:rpc {
prisma:migrateEngine:rpc jsonrpc: '2.0',
prisma:migrateEngine:rpc error: {
prisma:migrateEngine:rpc code: 4466,
prisma:migrateEngine:rpc message: 'An error happened. Check the data field for details.',
prisma:migrateEngine:rpc data: {
prisma:migrateEngine:rpc is_panic: false,
prisma:migrateEngine:rpc message: 'Server has closed the connection.',
prisma:migrateEngine:rpc meta: null,
prisma:migrateEngine:rpc error_code: 'P1017'
prisma:migrateEngine:rpc }
prisma:migrateEngine:rpc },
prisma:migrateEngine:rpc id: 1
prisma:migrateEngine:rpc } +2s
Error: Error: P1017
Server has closed the connection.
I tried the following without any luck:
- connecting from another machine / location
- switching off connection pooling
- retrying over serveral hours
Interestingly, regular database connections work as expected (query, mutate, etc.), it’s only with prisma migrate
that I see this error.
Any hints are welcome on how to further debug the issue.
How to reproduce
I can’t provide a reproduction example for the moment, as the db connection is private.
Expected behavior
No error.
Prisma information
I am adding the following lines to an existing schema:
model Member {
id String @default(cuid())
userId String
projectId String
email String
name String?
newsletter Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id])
project Project @relation(fields: [projectId], references: [id])
@@id([id, userId])
@@unique([userId, projectId, email])
@@index([userId, projectId, email])
}
Environment & setup
- OS: Linux/Fedora
- Database: PostgreSQ
- Node.js version: v16.10.0
Prisma Version
prisma : 2.28.0
@prisma/client : 2.28.0
Current platform : rhel-openssl-1.1.x
Query Engine : query-engine 89facabd0366f63911d089156a7a70125bfbcd27 (at node_modules/@prisma/engines/query-engine-rhel-openssl-1.1.x)
Migration Engine : migration-engine-cli 89facabd0366f63911d089156a7a70125bfbcd27 (at node_modules/@prisma/engines/migration-engine-rhel-openssl-1.1.x)
Introspection Engine : introspection-core 89facabd0366f63911d089156a7a70125bfbcd27 (at node_modules/@prisma/engines/introspection-engine-rhel-openssl-1.1.x)
Format Binary : prisma-fmt 89facabd0366f63911d089156a7a70125bfbcd27 (at node_modules/@prisma/engines/prisma-fmt-rhel-openssl-1.1.x)
Default Engines Hash : 89facabd0366f63911d089156a7a70125bfbcd27
Studio : 0.417.0
Migration SQL (generated when applied to working database)
-- CreateTable
CREATE TABLE "Member" (
"id" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"projectId" TEXT NOT NULL,
"email" TEXT NOT NULL,
"name" TEXT,
"newsletter" BOOLEAN NOT NULL DEFAULT true,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
PRIMARY KEY ("id","userId")
);
-- CreateIndex
CREATE INDEX "Member.userId_projectId_email_index" ON "Member"("userId", "projectId", "email");
-- CreateIndex
CREATE UNIQUE INDEX "Member.userId_projectId_email_unique" ON "Member"("userId", "projectId", "email");
-- AddForeignKey
ALTER TABLE "Member" ADD FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Member" ADD FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Migration status (for failing database)
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "db.xxxxxxxxxxxxxxxxxxx.supabase.co:5432"
32 migrations found in prisma/migrations
Following migration have not yet been applied:
20211028160538_member
To apply migrations in development run prisma migrate dev.
To apply migrations in production run prisma migrate deploy
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Prisma: Error: P1017 Server has closed the connection
Error: P1017 Server has closed the connection. I am sure that the postgres database works because all queries and mutations requests are work....
Read more >Error message reference - Prisma
Prisma Client, Migrate, Introspection error message reference. ... P1017. "Server has closed the connection." Prisma Client (Query Engine). P2000.
Read more >PostgreSQL connection errors in release_command - Fly.io
I'm running a Prisma migration in the release_command section of the config for my app. ... I'm getting a P1017 “Server has closed...
Read more >please make sure your database server is running at ...
I am trying to down migrate by following the document https://www.prisma.io/docs ... If you want to access the database from another container, which...
Read more >Running into issues connecting with Prisma to PlanetScale An | Orm ...
Running into issues connecting with Prisma to PlanetScale Anyone else Is this a ... at "localhost:3306" Error: P1017: Server has closed the connection....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Update: I was able to apply the missing migration
20211028160538_member
withprisma migrate deploy
. However,prisma migrate dev
still throws the same error.Problem was on supabase side. They had to kill dangling connections and now everything is working again as expected.