ORM connection pooling help?

Author
Rohan Patel Author
|
1 hour ago Asked
|
1 Views
|
0 Replies
0

hey everyone, still struggling a bit with the database connections after a deploy, you know, from that last thread. i thought i had it figured out but looks like i'm still missing something crucial.

i've been trying to dig into how my full-stack framework (using a generic ORM, let's say it's like Prisma or SQLAlchemy) handles its database connections, especially after a new deploy or when the app sits idle for a while. it seems like the connections just... vanish. i'm really trying to understand database connection pooling better for this.

i tried looking at the ORM's documentation for connection pooling settings. i found things like pool_size and idle_timeout, and i've tried setting them in my config, but i'm honestly not sure if i'm even putting them in the right place or with the write values. it's all a bit confusing for a newbie.

the problem is, after a deploy, or sometimes after a few hours of low traffic, when a new request comes in, the app just throws a fit trying to talk to the database. it's like the existing connections are dead, and new ones aren't being established properly. restarting the app temporarily fixes it, but that's not a real solution.

here's what i sometimes see in my logs when it happens:

[2023-10-27 14:35:01] ERROR: sqlalchemy.pool.QueuePool - Connection 'psycopg2.connect' was closed by the database.
[2023-10-27 14:35:01] ERROR: my_app.database - Database connection lost. Attempting to reconnect...
[2023-10-27 14:35:02] CRITICAL: my_app.api - Unhandled exception: (psycopg2.OperationalError) server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
    (Background on this error at: https://sqlalche.me/e/20/e3q8)

i'm a complete noob with this stuff, so i'm probably making some really basic mistake. what's the correct way to set up and manage ORM connection pooling in a full-stack framework, especially to prevent these random disconnects after a deploy or during idle periods? any step-by-step guidance for someone totally new to this would be super helpful.

0 Answers

No answers yet.

Be the first to provide a helpful answer!

Your Answer

You must Log In to post an answer and earn reputation.