How to Destroy 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.


Deleting a database cluster permanently and irreversibly destroys the cluster, its contents, and its automated backups.

Destroy a Database Cluster Using the CLI or API

How to create a Database using the DigitalOcean CLI

To create a Database 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, create a Database with doctl databases delete. The basic usage looks like this, but you'll want to read the usage docs for more details:

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

    The following example deletes the database cluster with the ID f81d4fae-7dec-11d0-a765-00a0c91e6bf6

                       doctl databases delete f81d4fae-7dec-11d0-a765-00a0c91e6bf6
                    
How to destroy a database cluster using the DigitalOcean API

To destroy 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 DELETE request to https://api.digitalocean.com/v2/databases/{database_cluster_uuid}

    cURL

    To destroy a database cluster with cURL, call:

    
                    curl -X DELETE \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
    "https://api.digitalocean.com/v2/databases/9cc10173-e9ea-4176-9dbc-a4cee4c4ff30" 

    Go

    Go developers can use Godo, the official DigitalOcean V2 API client for Go. To destroy 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()
    
        _, err := client.Databases.Delete(ctx, "9cc10173-e9ea-4176-9dbc-a4cee4c4ff30")
    }

    Python

    
                    import os
    from pydo import Client
    
    client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
    
    delete_resp = client.databases.destroy_cluster(database_cluster_uuid="a7abba8")

Destroy a Database Cluster Using the Control Panel

To destroy a database cluster from the control panel, open the cluster’s More menu. Click Destroy to go to the cluster’s Settings page.

Screenshot of cluster settings page

In the Destroy this database cluster section at the bottom of the page, click the Destroy button. This opens a Destroy database cluster confirmation window.

Screenshot of the destroy cluster warning

To permanently destroy the cluster, type or copy and paste the name of the database cluster into the text field, then click Destroy.

Warning
Destroying a database cluster destroys the backups of that database. Make sure you download any important data before you destroy a cluster.