Database too many clients crashes
Given the nature of my software, whenever a user uses it, they must make dozens of requests to the database to incrementally decrease a number (the amount of funds in their account).
The result of this is that the database just crashes.
I am not super familiar with databases in general btw, just enough to do CRUD
Thanks!
15 Replies
Project ID:
7ca80dd7-b76f-4860-8cd5-add39d3a162c
7ca80dd7-b76f-4860-8cd5-add39d3a162c
your app should be using a database pool, not opening a new connection for every query you make to the database
Oh okay thanks. I will look into that.
In the meantime, how can I uncrash my database?
well its not crashed, just not accepting any more connections, you can redeploy it to close the connections
@Brody Wait, I'm actually not opening a new connection each time... I don't think. Becuase I open it once and then make it a global variable called db.
I then use the global db object throughout code
is there anything else connecting to yoour database?
No, only one app
ChatGPT said to add
Do you think this is the solution? Or should have pooling alone fixed the problem?
is that even valid code?
Project code or postgres code?
I put ... inside the postgres code, I assume I shouldn't make it public
code for
github.com/lib/pq
Oh
Good question let me check
https://pkg.go.dev/database/sql#DB.SetMaxIdleConns
then cant hurt to try
Okay I'll try
Also, is it the constant reading from the database that's the issue or the constant changing of a value? Or it doesn't matter?
it would be too many connections being open to the database, but i honestly dont know why that would happen