Database resource limits hit

When performing a certain request to my server which accesses my db i get the following error on the server side:

2025-03-03T18:15:34.412 app[d890426c46e328] ams [info] PrismaClientKnownRequestError:

2025-03-03T18:15:34.412 app[d890426c46e328] ams [info] Invalid `prisma.salesData.findMany()` invocation:

2025-03-03T18:15:34.412 app[d890426c46e328] ams [info] Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 3)

2025-03-03T18:15:34.412 app[d890426c46e328] ams [info] at Ln.handleRequestError (/app/node_modules/@prisma/client/runtime/library.js:121:7753)

2025-03-03T18:15:34.412 app[d890426c46e328] ams [info] at Ln.handleAndLogRequestError (/app/node_modules/@prisma/client/runtime/library.js:121:7061)

2025-03-03T18:15:34.412 app[d890426c46e328] ams [info] at Ln.request (/app/node_modules/@prisma/client/runtime/library.js:121:6745)

2025-03-03T18:15:34.412 app[d890426c46e328] ams [info] at async l (/app/node_modules/@prisma/client/runtime/library.js:130:9633)

2025-03-03T18:15:34.412 app[d890426c46e328] ams [info] at <anonymous> (/app/src/actions/getUserTrackedProds.ts:70:25)

2025-03-03T18:15:34.412 app[d890426c46e328] ams [info] at async Promise.all (index 26)

2025-03-03T18:15:34.412 app[d890426c46e328] ams [info] at getTrackedProductStats$2 (/app/src/actions/getUserTrackedProds.ts:68:17)

2025-03-03T18:15:34.412 app[d890426c46e328] ams [info] at <anonymous> (/app/.wasp/build/server/src/middleware/operations.ts:14:24)

2025-03-03T18:15:34.412 app[d890426c46e328] ams [info] at <anonymous> (/app/.wasp/out/sdk/wasp/server/utils.ts:26:5)

2025-03-03T18:15:34.415 app[d890426c46e328] ams [info] POST /operations/get-tracked-products 500 10191.014 ms - 148

2025-03-03T18:15:34.415 app[d890426c46e328] ams [info] PrismaClientKnownRequestError:

2025-03-03T18:15:34.415 app[d890426c46e328] ams [info] Invalid `prisma.user.findUnique()` invocation:

2025-03-03T18:15:34.415 app[d890426c46e328] ams [info] Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 3)

2025-03-03T18:15:34.415 app[d890426c46e328] ams [info] at Ln.handleRequestError (/app/node_modules/@prisma/client/runtime/library.js:121:7753)

2025-03-03T18:15:34.415 app[d890426c46e328] ams [info] at Ln.handleAndLogRequestError (/app/node_modules/@prisma/client/runtime/library.js:121:7061)

2025-03-03T18:15:34.415 app[d890426c46e328] ams [info] at Ln.request (/app/node_modules/@prisma/client/runtime/library.js:121:6745)

2025-03-03T18:15:34.415 app[d890426c46e328] ams [info] at async l (/app/node_modules/@prisma/client/runtime/library.js:130:9633)

2025-03-03T18:15:34.415 app[d890426c46e328] ams [info] at getAuthUserData (/app/.wasp/out/sdk/wasp/auth/session.ts:55:16)

2025-03-03T18:15:34.415 app[d890426c46e328] ams [info] at getSessionAndUserFromSessionId (/app/.wasp/out/sdk/wasp/auth/session.ts:50:11)

2025-03-03T18:15:34.415 app[d890426c46e328] ams [info] at <anonymous> (/app/.wasp/out/sdk/wasp/core/auth.ts:28:26)

2025-03-03T18:15:34.415 app[d890426c46e328] ams [info] at <anonymous> (/app/.wasp/out/sdk/wasp/server/utils.ts:26:5)

and this is happening on the db side:

2025-03-03T18:13:37.560 health[080e513b2946e8] ams [info] Health check for your postgres database is now passing.

2025-03-03T18:14:57.696 health[080e513b2946e8] ams [info] Health check for your postgres vm is now passing.

2025-03-03T18:15:27.974 health[080e513b2946e8] ams [error] Health check for your postgres vm has failed. Your instance has hit resource limits. Upgrading your instance / volume size or reducing your usage might help. [✗] cpu: system spent 1.78s of the last 10 seconds waiting on cpu (32.17µs)

What is happening and how can i fix this issue? Update: increasing ram to 1gb and cpu to 2x works a bit better but still doesnt pass health check and says for some queries that i exceed resource limits.

I’m not familiar with Prisma. Is that a web or application server and Postgres bundled together in one container? If so, I’d be mildly inclined to give it more RAM, but not more CPU. 1GB isn’t a lot these days.

A few more thoughts. What kind of load are you putting your web app under? Do you have a rough req/sec to give readers an idea?

Finally I don’t know how configurable Postgres is when it is bundled into Prisma. However you might be able to reconfigure it for a low-memory environment (e.g. reduce max listeners etc). I did this with Apache, but since I was using it stand-alone, it was pretty easy.

it might be the connection limit, if this is from production usage you can increase limit or use pgbouncer to manage connections. If this was from localhost usage then you can cache prisma instance because hmr creates a new connection every time might be causing this issue

see how to set the limit: Connection pool | Prisma Documentation

Thanks for the reply, i increased ram already and cpu amount. Should i then decrease cpu amount or is it okay like this?


Attatched images of metrics, i use wasp framework and not sure if it is in one container as one of the replies asked…

Would you have any recommendationz?

connection limit formula is: num_physical_cpus * 2 + 1

1 shared cpu is not great for a database (assuming its postgres)

I would recommend using pgbouncer or managed db solution with connection pooling like neondb / turso

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.