To create a database cluster, send a POST request to /v2/databases
.
The response will be a JSON object with a key called database
. The value of this will be an object that contains the standard attributes associated with a database cluster. The initial value of the database cluster’s status
attribute will be creating
. When the cluster is ready to receive traffic, this will transition to online
.
The embedded connection
and private_connection
objects will contain the information needed to access the database cluster. For multi-node clusters, the standby_connection
and standby_private_connection
objects will contain the information needed to connect to the cluster’s standby node(s).
DigitalOcean managed PostgreSQL and MySQL database clusters take automated daily backups. To create a new database cluster based on a backup of an existing cluster, send a POST request to /v2/databases
. In addition to the standard database cluster attributes, the JSON body must include a key named backup_restore
with the name of the original database cluster and the timestamp of the backup to be restored. Creating a database from a backup is the same as forking a database in the control panel.
Note: Backups are not supported for Redis clusters.
import os
from pydo import Client
client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
create_req = {
"name": "backend",
"engine": "pg",
"version": "14",
"region": "nyc3",
"size": "db-s-2vcpu-4gb",
"num_nodes": 2,
"storage_size_mib": 61440,
"tags": [
"production"
]
}
create_resp = client.databases.create_cluster(body=create_req)
See the API spec for this endpoint to view additional detail on responses, headers, parameters, and more.