Skip to main content
c.Databases manages Square Cloud’s managed databases (MongoDB, MySQL, PostgreSQL and Redis). Every method takes ctx first and, except Create and StatusAll, the database id next. To list your databases, use c.Account.Me: its Databases slice has every database the key can see. Database hosting needs a Standard, Pro or Enterprise plan. Each snippet below runs on its own inside this program: paste one at a time into main and run goimports (see Running the examples).

Creating a database

The result is a DatabaseCreated with ID, Name, Memory, CPU (float64), Type, Password, Certificate (*string, nil when the API sends none), ConnectionURL (connection_url) and Cluster. The password and certificate are only returned by Create (and by ResetCredentials). Without a ctx deadline, the call waits at least 2 minutes before timing out.

Getting a database

Updating a database

Update(ctx, databaseID, squarecloud.DatabaseUpdate{Name, RAM}) renames or resizes a database. Zero fields are not sent; set at least one (400 NO_UPDATE_DATA otherwise).

Start and stop

Like app lifecycle calls, without a ctx deadline they wait at least 2 minutes, and a refusal is 409 with a code and an empty message: CONTAINER_ALREADY_STARTED, CONTAINER_ALREADY_STOPPED, CONTAINER_NOT_FOUND, CONTAINER_INSUFFICIENT_DISK_SPACE, CONTAINER_NETWORK_CONFLICT or ACTION_FAILED. While a snapshot restore runs, they are 403 RESTORE_IN_PROGRESS.

Status and metrics

Status(ctx, databaseID) returns formatted values; StatusRaw(ctx, databaseID) returns numbers. StatusAll(ctx) returns one summary per database. Metrics(ctx, databaseID) returns the last 24 hours, one point every 5 minutes, newest first.
The status fields are the same as app status.

Credentials

Certificate(ctx, databaseID) returns the TLS certificate as base64-encoded PEM. ResetCredentials(ctx, databaseID, reset) rotates the password (squarecloud.ResetPassword, returns the new one) or the certificate (squarecloud.ResetCertificate, returns ""). The database must be running (400 DATABASE_NOT_RUNNING).

Deleting a database

Deletion is permanent. Take a snapshot first if you may need the data again.

Snapshots

c.Databases.Snapshots has the same List, Create and Restore as apps. See Snapshots.

Next steps

Workspaces

Share apps with your team.

Database API reference

The REST endpoints behind these methods.

Databases from the CLI

The same actions from the terminal.