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

# Database

> This guide covers database deployment in `ale`, service connectivity, and database management tool configuration using TCP connections.

<Info>
  `ale` offers pre-configured database options as built-in applications. For unsupported databases, you can create custom plugins through our plugin system. See our [plugin guides](/en/developers/database) for details.
</Info>

<Warning>
  Stopping or updating a database retains all data, but deleting the database will permanently erase the data.
</Warning>

***

## Deploying a Database

<Frame>
  <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/developers/images/en/07_01.png" />
</Frame>

> On the dashboard, click <Icon icon="circle-plus" iconType="solid" size={15} color="2396F1" /> or `⌘ + K` to open the deployment modal. Select the **database** you want to deploy and fill in the configuration fields.

<AccordionGroup>
  <Accordion title="Basic Configuration">
    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/developers/images/en/07_02.png" />
    </Frame>

    > Specify the version and root password credentials.

    <Info>
      Basic Configuration options are **service-specific.** Set the required values based on the deployment requirements.
    </Info>
  </Accordion>

  <Accordion title="More Options">
    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/developers/images/en/07_03.png" />
    </Frame>

    > Set database name, timezone, and service-specific parameters.

    <Info>
      **Additional Options are service-specific.** Configure the settings based on the selected database service and deployment requirements.
    </Info>
  </Accordion>

  <Accordion title="Resource Settings and Deployment">
    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/developers/images/en/07_04.png" />
    </Frame>

    * **Resource Type**: Select between [On-demand or Spot instance types](/en/developers/resource#on-demand-spot)
    * **CPU**: Maximum vCPU resource for the service. Minimum vCPU means 0.1 vCPU
    * **Memory**: Maximum memory size the service can use
    * **Disk**: Database disk capacity
    * **Deploy**: Click `Deploy`
  </Accordion>
</AccordionGroup>

<Info>
  If deployment fails due to resource limitations, see the [Space and Resource Management page](/en/operations/spaces#allocate-resources) to add resources to the space.
</Info>

<Tip>
  The auto-generated or previously configured Root Password can be found in the [Secrets section of the Environments Settings.](/en/developers/database#root-password)
</Tip>

## Database Connectivity

<Frame>
  <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/developers/images/en/07_06.png" />
</Frame>

> **the connection info (hostname: port)** is in the resources tab of the service page.

### Internal Services

<Frame>
  <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/developers/images/en/07_05.png" />
</Frame>

> Services displayed on the same screen can communicate using the private network address, **service name and port number.**

<Info>
  Services shown together belong to the same environment (namespace). Since each environment is isolated within its own network, there's no need for firewall rules, minimizing communication latency.
</Info>

<Tip>
  For more details on ale's workspace structure, see the [Environments page.](/en/developers/environment)
</Tip>

### External and Cross-env Services

<Frame>
  <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/developers/images/en/07_07.png" />
</Frame>

> Services can connect to services in other environments or external systems using the ingress address (hostname:port).
> In this case, as shown below, you'll need to **allow external connections** in the Settings tab of the environment where the database is deployed.

<AccordionGroup>
  <Accordion title="TCP External Connections" defaultOpen={true}>
    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/developers/images/en/03_11.png" />
    </Frame>

    > You can allow TCP external connections in the settings tab of the environment where the database you want to connect to is located.

    <Tip>
      TCP external access is configured at the environment level and affects all services within that environment. This setting cannot be configured for individual services.
    </Tip>
  </Accordion>
</AccordionGroup>

### Database Client Tools

> You can use [the ingress address](/en/developers/database#external-and-cross-env-services) to connect to your database from DB client tools via TCP.

<AccordionGroup>
  <Accordion title="MariaDB - MySQL Workbench">
    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/developers/images/en/07_08.png" />
    </Frame>

    > Enter the ingress address, then in the next screen, enter [the Root Password](/en/developers/database#root-password) you set during deployment.

    <Info>
      [MySQL Workbench Download](https://dev.mysql.com/downloads/workbench/)
    </Info>
  </Accordion>

  <Accordion title="PostgreSQL - pgAdmin">
    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/developers/images/en/07_10.png" />
    </Frame>

    > In the Connection tab, enter the ingress address, the Username (default is **root**), and [the Root Password](/en/developers/database#root-password) you set during deployment.

    <Info>
      [pgAdmin Download](https://www.pgadmin.org/download/)
    </Info>
  </Accordion>

  <Accordion title="MongoDB - MongoDB Compass">
    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/developers/images/en/07_11.png" />
    </Frame>

    > Click `New Connection`, then in the **Advanced Connection Options** section, enter the **hostname including the port number** in the Host field.

    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/developers/images/en/07_12.png" />
    </Frame>

    > In the Authentication tab, enter the Username (default is **admin**) and [the Root Password](/en/developers/database#root-password) you set during deployment.

    <Info>
      [MongoDB CompassDownload](https://www.mongodb.com/try/download/compass)
    </Info>
  </Accordion>

  <Accordion title="Redis - Redis Insight">
    <Frame>
      <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/developers/images/en/07_13.png" />
    </Frame>

    > Click `Add Redis Database` and enter the ingress address.

    <Info>
      [Redis Insight Download](https://redis.io/insight/)
    </Info>
  </Accordion>
</AccordionGroup>

<Tip>
  [Allow TCP external connections](/en/developers/database#tcp-external-connections) to enable the DB management tool to connect to the database.
</Tip>

## Database Management

### Disk Space

<Frame>
  <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/developers/images/en/07_14.png" />
</Frame>

> You can modify the Disk Resource in the Settings tab of the service page. Click `Deploy` to apply the new disk capacity.

<Info>
  When you deploy with new resource configurations, the disk capacity will be updated while preserving all existing data.
</Info>

### Root Password

<Frame>
  <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/developers/images/en/07_16.png" />
</Frame>

> The Root Password can be viewed and managed in **the Secrets section of environment settings.**

### Database Deletion

<Frame>
  <img className="block rounded-md" src="https://files.cloudtype.io/ale-docs/developers/images/en/07_15.png" />
</Frame>

> You can delete your database service by clicking `Remove Service` in the Settings tab of the service page.

<Warning>
  Removing a database service is irreversible and will permanently delete all data stored on its disk. Make sure you have backed up any important data before proceeding with the deletion.
</Warning>
