How to Resize PostgreSQL Database Clusters

PostgreSQL is an open source, object-relational database built for extensibility, data integrity, and speed. Its concurrency support makes it fully ACID-compliant, and it supports dynamic loading and catalog-driven operations to let users customize its data types, functions, and more.


You can resize existing PostgreSQL database clusters at any time to add more CPUs, RAM, and storage. To avoid data loss, you cannot decrease the size of database clusters.

Resize a Database Cluster Using the CLI

Note
To resize a database cluster using doctl, you need to provide a value for the --size flag, which specifies the cluster’s new configuration (number of CPUs, amount of RAM, and hard disk space). Use the doctl databases options slugs command to get a list of available values.
How to resize a Database Cluster using the DigitalOcean CLI

To resize a Database Cluster via the command-line, follow these steps:

  1. Install doctl, the DigitalOcean command-line tool.

  2. Create a personal access token, and save it for use with doctl.

  3. Use the token to grant doctl access to your DigitalOcean account.

                  doctl auth init
                
  4. Finally, resize a Database Cluster with doctl databases resize. The basic usage looks like this, but you'll want to read the usage docs for more details:

                  doctl databases resize <database-cluster-id> [flags]
                

    The following example resizes a PostgreSQL or MySQL database to have two nodes, 16 vCPUs, 64 GB of memory, and 2048 GiB of storage space

                       doctl databases resize ca9f591d-9999-5555-a0ef-1c02d1d1e352 --num-nodes 2 --size db-s-16vcpu-64gb --storage-size-mib 2048000
                    

Resize a Database Cluster Using the API

Note
To resize a database cluster using the API, you need to provide a value for the size field, which specifies the cluster’s configuration (number of CPUs, amount of RAM, and hard disk space). Use the /v2/databases/options endpoint to get a list of available values.
How to resize a Database Cluster using the DigitalOcean API

To resize a Database Cluster using the DigitalOcean API, follow these steps:

  1. Create a personal access token, and save it for use with the API.

  2. Send a PUT request to https://api.digitalocean.com/v2/databases/{database_cluster_uuid}/resize

    cURL

    To resize a Database Cluster with cURL, call:

    
                    curl -X PUT \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
    -d '{"size":"db-s-4vcpu-8gb", "num_nodes":3, "storage_size_mib":163840}' \
    "https://api.digitalocean.com/v2/databases/9cc10173-e9ea-4176-9dbc-a4cee4c4ff30/resize" 

    Go

    Go developers can use Godo, the official DigitalOcean V2 API client for Go. To resize a Database Cluster with Godo, use the following code:

    
                    import (
        "context"
        "github.com/digitalocean/godo"
    )
    
    func main() {
        pat := "mytoken"
    
        client := godo.NewFromToken(pat)
        ctx := context.TODO()
    
        resizeRequest := &godo.DatabaseResizeRequest{
            SizeSlug: "db-s-4vcpu-8gb",
            NumNodes: 3,
            StorageSizeMib: 163840,
        }
    }

    Python

    
                    import os
    from pydo import Client
    
    client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
    
    req = {
      "size": "db-s-4vcpu-8gb",
      "num_nodes": 3,
      "storage_size_mib": 163840
    }
    
    update_resp = client.databases.update_cluster_size(database_cluster_uuid="a7a8bas", body=req)

Resize a Database Cluster Using the Control Panel

To resize a PostgreSQL database cluster, click the name of the cluster in the control panel to go to its Overview page, then click the Settings tab.

Warning
Because of data integrity risks, you cannot reduce the amount of added storage in a cluster. If you need to downscale, you can instead fork the cluster and select a smaller storage size for the new cluster.

In the Cluster configuration section, click Edit. Select your cluster configuration and CPU option.

Cluster configuration section with additional nodes selected

Then, select your storage size.

Once you have selected your new configuration and size, click Save to provision the new configuration. The provisioning takes several minutes but the total time depends on the size of the cluster.

Your cluster’s state changes from Active to Resizing until the process is done. You can expect no downtime and do not need to take action.