Description
Do you use Amazon RDS for PostgreSQL?
First, what is max_connections?
Determines the maximum number of concurrent connections to the database server.
max_connections on PostgreSQL Documentation
When running a standby server, you must set this parameter to the same or higher value than on the master server. Otherwise, queries will not be allowed in the standby server.
Do you know that, by default, each instance comes with a different number of max_connections
?
Grab a PSQL console to your Postgres database and check now with show max_connections;
.
According to this answer on StackExchange (for MySQL), this is how it scales:
MODEL | max_connections |
---|---|
t1.micro | 34 |
m1-small | 125 |
m1-large | 623 |
m1-xlarge | 1263 |
m2-xlarge | 1441 |
m2-2xlarge | 2900 |
m2-4xlarge | 5816 |
The numbers in the max_connections
column looks slightly awkward because they are actually calculated from a formula DBInstanceClassMemory/magic_number
where magic_number
differs according to the class of your instance.
To know exactly what's the magic_number
for an instance, head over to "Parameter Groups" in your Amazon console:
Click on the default Parameter Group and search for max_connections
and you'll see the formula.
In my case, it's {DBInstanceClassMemory/31457280}
.
Fortunately, unlike Heroku Postgres where you can't change any of the Postgres configuration,
you actually can modify Amazon RDS's configuration options!
This means, you can, e.g., increase the max_connections
for a t1.micro
instance from 34 to 100!
To do that, you can create a new Parameter Group:
And update the max_connections
to 100:
Then, modify your existing instance's DB Parameter Group to use your new Parameter Group:
Save and restart your instance, and it should now have 100 connections.
Finally, remember to update your Rails app (database.yml) to make use of these 100 connections.
Resources:
- "Tune your Postgres RDS instance via parameter groups"
- "Should I increase max_connections in AWS RDS t1-micro for MySQL?"
Thanks for reading!
About Jolly Good Code
We specialise in Agile practices and Ruby, and we love contributing to open source.
Speak to us about your next big idea, or check out our projects.