Anyone know how to solve db connections to many? It worked fine until I closed the nestjs app. when i restarted I got this error.
[Nest] 20064 - 05/05/2023, 12:58:05 PM LOG [GraphQLModule] Mapped {/graphql, POST} route +135ms
Error: Error querying the database: db error: FATAL: too many connections for role "fgypyneu"
at \node_modules\@prisma\client\runtime\index.js:25336:20
Anyone know a workaround?
I've the following prisma.service.ts
import { INestApplication, Injectable, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
async onModuleInit() {
await this.$connect();
}
async enableShutdownHooks(app: INestApplication) {
this.$on('beforeExit', async () => {
await app.close();
await this.$disconnect();
});
}
}
Update: after waiting alittle while it work fine again. But if i close the app and restart the same error will occur.
[Nest] 22692 - 05/05/2023, 1:02:29 PM LOG [GraphQLModule] Mapped {/graphql, POST} route +140ms
[Nest] 22692 - 05/05/2023, 1:02:32 PM LOG [NestApplication] Nest application successfully started +2947ms