Skip to content

Update Amazon RDS max_connections with Parameter Group #16

Open
@winston

Description

@winston

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:

screen shot 2016-01-28 at 11 05 39 pm

Click on the default Parameter Group and search for max_connections and you'll see the formula.
In my case, it's {DBInstanceClassMemory/31457280}.

screen shot 2016-01-28 at 11 06 10 pm

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:

screen shot 2016-01-28 at 11 11 21 pm

And update the max_connections to 100:

screen shot 2016-01-28 at 11 11 43 pm

Then, modify your existing instance's DB Parameter Group to use your new Parameter Group:

screen shot 2016-01-28 at 11 13 12 pm

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:

Thanks for reading!

@winston ✏️ Jolly Good Code

About Jolly Good Code

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions