API Updates for PostgreSQL - Noteworthy at Compose

Published

This is your weekly summary of Compose news for those changes and updates which can make your life easier. In this October 30th, 2018 edition of Noteworthy on Compose we talk about an update to the Compose API for PostgreSQL deployments and we also go through the past week's Compose Articles.

API update for PostgreSQL

This week, we introduced a new /max_connections endpoint so that you can increase the number of connections in your PostgreSQL deployment beyond the 100 connection limit.

In order to raise the connection limit, PostgreSQL requires that you have the memory resources needed for the increased connections. This may require scaling up your PostgreSQL deployment, which would need to be increased by two units of scale for every 100 connections added.

However, before you scale up and increasing connection limits, consider whether you need to increase your connection limits at all. Since each PostgreSQL connection uses RAM, opening up more connections will indeed diminish the system's RAM that could be used to run your database. So, if you've hit your connection limits, consider using either a connection pooler like PgBouncer, or a PostgreSQL driver that pools connections. You also want to make sure that your application is not holding onto connections unnecessarily.

Nonetheless, in times where you need to scale up and increase connection limits, you can do that right from the API.

Scaling up with the API

Before scaling up, we first need to know how many connections we want to have. For each 100 connections, we need to scale up by two units.

For example, if we want 200 connections, we'd have to scale up to three units, or 3GB of disk storage and 306MB of RAM. And if we wanted 300 connections we'd add another two units, totaling 5 units, which would give us 5GB of disk storage and 510 MB of RAM, and so on.

With the Compose API, we can scale up with the /scalings endpoint. To scale up to to three units, we'd run something like:

curl -X POST 'https://api.compose.io/2016-07/deployments/[[deployment ID]]/scalings'  
-H "Authorization: Bearer $API_TOKEN"
-H "Content-Type: application/json; charset=utf-8" \
-d '{
  "deployment": {
    "units": 3
  }
}

And get a response:

{
  "id": "...",
  "account_id": "...",
...
  "name": "Scale database to 3GB Storage",
...
}

Increasing connections

Now, after scaling up, you can increase your connection limit to 200 connection with the /max_connections endpoint like:

curl -X PUT 'https://api.compose.io/2016-07/deployments/[[deployment ID]]/settings/max_connections' \  
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
  "deployment": {
      "max_connections": "200"
  }
}'

Then you'll get a response:

{
  "id": "...",
  "account_id": "...",
  ...
  "name": "Set connection count on Postgres to 200",
  ...
  "_embedded": {
    ...
  }
}

And that's all you need to do.

Consult the API Reference for more details on how to scale up and add more connections to your PostgreSQL database.

Compose Articles

We didn't see any new articles this week, but we want to remind you about last week's Noteworthy at Compose. JanusGraph got updated to 0.3.1 and we recommend that all users upgrade to the latest version of that database. You can do that right from the Compose console. After 30 days, version 0.1.1 will not be available for provisioning and 0.3.1 will be the default version.

In last week's NewsBits we covered MySQL releases and gRPC-Web's GA announcement, as well as other news around the web.

That's it for this week's Noteworthy at Compose. Onwards to next week!

Abdullah Alger
Abdullah Alger is a former University lecturer who likes to dig into code, show people how to use and abuse technology, talk about GIS, and fish when the conditions are right. Coffee is in his DNA. Love this article? Head over to Abdullah Alger’s author page to keep reading.

Conquer the Data Layer

Spend your time developing apps, not managing databases.