> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Database

> Create a database instance hosted on Square Cloud.

<ParamField header="Authorization" type="string" placeholder="API Key" required>
  The API key for your account. You can find this in your [account settings](https://squarecloud.app/en/account/security).
</ParamField>

Provisions a managed database on Square Cloud (MongoDB, MySQL, PostgreSQL or Redis), picks the cluster with the most available RAM, and allocates a public DNS record (`square-cloud-db-<id>.squareweb.app`) pointing to it. The `password` and `certificate` in the response are shown only once, save them immediately since neither can be retrieved again later, only reset via [Reset Credentials](/en/api-reference/endpoint/databases/credentials/reset).

Database hosting requires a Standard, Pro or Enterprise plan. The requested `memory` must be at least the engine's minimum (512 MB for Redis, 1024 MB for MongoDB, MySQL and PostgreSQL) and cannot exceed your account's available memory. Rate limited to 1 creation every 3 seconds per user.

Once created, use [Edit Database](/en/api-reference/endpoint/databases/edit) to rename it or resize its memory, and [Create Snapshot](/en/api-reference/endpoint/databases/snapshots/create) to back it up.

### Parameters

<ParamField body="name" type="string" placeholder="database name" required>
  The name of the database. 1–32 characters — letters, numbers, underscores (`_`), hyphens (`-`) and spaces — and must include at least one letter, number or underscore.
</ParamField>

<ParamField body="memory" type="int" placeholder="RAM(in MB)" required>
  The RAM allocated to it. Redis minimum is 512 and Mongo, 1024.
</ParamField>

<ParamField body="type" type="string" placeholder="database(mongo,redis)" required>
  The database type, mongo, redis, postgres, mysql.
</ParamField>

<ParamField body="version" type="string" placeholder="Version number" required>
  The version of the database.\\
  Postgres 17, MySQL 9, Mongo 8, Redis 7.
</ParamField>

### Response

<ResponseField name="status" type="string">
  Indicates whether the call was successful.. `success` if successful, `error` if not.
</ResponseField>

<ResponseField name="response" type="object">
  The contents of the response.

  <Expandable title="Toggle object">
    <ResponseField name="id" type="string">
      The ID of the database.
    </ResponseField>

    <ResponseField name="name" type="string">
      The name you chose for the database
    </ResponseField>

    <ResponseField name="memory" type="int">
      The memory allocated to the database
    </ResponseField>

    <ResponseField name="cpu" type="int">
      The number of vCPUs allocated to the database
    </ResponseField>

    <ResponseField name="type" type="string">
      The type of the database.
    </ResponseField>

    <ResponseField name="password" type="string">
      The password for the database.
    </ResponseField>

    <ResponseField name="certificate" type="string">
      The certificate needed to connect to it. You can save it in a `.pem` file.
    </ResponseField>

    <ResponseField name="connection_url" type="string">
      The url to connect to the database.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```json theme={null}
  {
    "status":"success",
    "response": {
      "id": "a14b8d5e1cb7405a851eb4c075506121",
      "name": "test",
      "memory": 1024,
      "cpu": 2,
      "type": "mongo",
      "password": "PASSWORD",
      "certificate": "CERTIFICATE_IN_BASE_64_FORMAT",
      "connection_url": "mongodb://default:PASSWORD@square-cloud-db-ID.squareweb.app:PORT"
      }
  }
  ```
</ResponseExample>

### Common errors

| Code                            | HTTP      | Meaning                                                                                         |
| ------------------------------- | --------- | ----------------------------------------------------------------------------------------------- |
| `INVALID_NAME`                  | 400       | The name fails the 1-32 character validation.                                                   |
| `INVALID_DATABASE_TYPE`         | 400       | `type` is not one of `mongo`, `mysql`, `redis`, `postgres`.                                     |
| `INVALID_DATABASE_VERSION`      | 400       | `version` is not a supported version for the chosen `type`.                                     |
| `INSUFFICIENT_MEMORY`           | 400       | The requested `memory` is below the engine's minimum or exceeds the account's available memory. |
| `CLUSTER_SELECTION_FAILED`      | 400       | No cluster with enough capacity could be selected.                                              |
| `DATABASE_CREATION_FAILED`      | 400 / 500 | Provisioning failed, or the cluster response was incomplete.                                    |
| `UPGRADE_REQUIRED`              | 403       | The active plan does not include database hosting.                                              |
| `CLUSTER_MAINTENANCE_TRY_LATER` | 503       | Database provisioning is temporarily unavailable due to maintenance.                            |
