We're getting too many database connections and need to scale - what options are available?
db is locking due to too many connections. do I have options within railway to scale?
Solution:Jump to solution
okay well then pgbouncer isnt needed in this context.
as a temporary fix you can increase the limit by running
ALTER SYSTEM SET max_connections = 200;
then restart the deployment.
run SHOW MAX_CONNECTIONS;
to confirm the new limit after the redeploy.
...19 Replies
Project ID:
bb751571-dd10-43ee-8a83-386587f4256b
bb751571-dd10-43ee-8a83-386587f4256b
yes you can increase the connection limit, i think postgres has a default of 100 iirc, but counter question, do you need more conncetions or should you add in a connection pooler like pgbouncer?
unclear. any tricks to setting up the railway pgbouncer template?
can start there
my pgbouncer template assumes you already have a database service in the project thats named
Postgres
and as long as you have that it should not need any initial setup from a perspective of deploying the templateshould be good then
what needs to change on the django side?
well lets slow down a tad here, i had assumed you where connecting to the database from a serverless environment and that was causing you to exhaust the 100 connections, but this is just a django app on railway?
correct
do you have an idea of why you are hitting the 100 connection limit? how large are your pools? are you running replicas?
No replicas, not sure how large pools would be (if they exist at all). Default django app with default postgres instance, both on railway. We had sub-100 but close to that concurrent users and starting getting the connections dropped
oh then maybe your app is opening a database connection for each request? and you arent using a client pool at all?
I suppose not - I'm just using whatever is batteries included with django. So perhaps we're just opening too many connections
Solution
okay well then pgbouncer isnt needed in this context.
as a temporary fix you can increase the limit by running
ALTER SYSTEM SET max_connections = 200;
then restart the deployment.
run SHOW MAX_CONNECTIONS;
to confirm the new limit after the redeploy.
then i would work on getting an in client database pool goingthen i would work on getting an in client database pool goinghow would I go about doing this / where can I learn?
i cant see there not being django documentation for this, their docs are pretty good imo
got it, ty
happy to help!
is there a way to connect to a postgres instance directly through railway or does it need to happen via command line?
use the
DATABASE_URL
variable's value from the databases service variables