# Database Installer

> Install MongoDB, PostgreSQL, MySQL or MariaDB in Docker on a server of your installation in one click, with its API Maker instance. A free port, a random password and a first database are filled in for you. Start, stop, restart, read the logs and remove the databases from the same page, or from API Maker Launchpad.

Source: https://docs.apimaker.dev/v4/docs/features/database-installer.html

Install MongoDB, PostgreSQL, MySQL or MariaDB on a server of your installation, in one click. API Maker runs it in a Docker container. It can make its instance too, so its APIs work at once.

You choose nothing you do not want to. The server finds a free name, a free port and a random password. It makes the first database. You can still change any of them under **Advanced**.

> **In short**
>
> - Pick an engine. Press **Install and create instance**. The page follows the install step by step.
> - The connection string goes into your default secret. The instance reads it from there, like any other key.
> - Start, stop, restart, read the logs, copy the connection strings, or remove a database from the same page.
> - On a server or a folder of [API Maker Launchpad](https://docs.apimaker.dev/v4/docs/getting-started/install-on-server.html), the databases are laid out as Launchpad lays out its own. Launchpad manages them too.

| | |
|---|---|
| Where | `Dashboard → Database → Database Installer`. In **Add Instance**, the button **New database**. |
| Who | The root user and admins. An admin sees and manages the databases of its own account. The root user sees every database. |
| Engines | MongoDB 7.0 to 8.3 (a replica set of one member, so transactions work), PostgreSQL 14 to 18, MySQL 8.4 to 26.7, MariaDB 10.6 to 13.0. |
| Needs | Docker on the server. The page says when a server has none. |
| Data | A Docker volume, or a folder of the server on a server of Launchpad. It stays when the container goes, unless you choose to delete it. |
| Reach | This server and its sandboxes only. With several servers, choose **Every server**, and open the port in the firewall. |

## Install a database

1. Open **Database Installer** from the dashboard. Or press **New database** in **Add Instance**.
2. Pick **MongoDB**, **PostgreSQL**, **MySQL** or **MariaDB**.
3. Check the name and the version. With several servers, pick the server.
4. Keep **Create its API Maker instance** on to make the instance at the same time.
5. Press **Install and create instance**.

The dialog shows each step : the image is downloaded, the container is made, the database starts, the first database is made, then the instance. You can close the dialog. The install goes on, and the page shows it.

> **Tip : Your first instance**
>
> Until your account has an instance, **Add Instance** offers the four engines at its top. One click installs the database and makes the instance.

## What is filled in for you

| Value | What the server picks |
|---|---|
| Name | The name of the engine (`postgres`, `mysql`, `mongo`, `mariadb`), then `_2`, `_3`… No other database and no instance has it. It names the container, its data and the instance. |
| Port | The first free port from 27018 (MongoDB), 5433 (PostgreSQL), 3307 (MySQL) or 3308 (MariaDB). Nothing of the server listens on it. |
| Password | 24 random letters and digits. Nothing to escape in a URL. |
| User | `root` for MongoDB, MySQL and MariaDB. `postgres` for PostgreSQL. |
| First database | `app_db`. |

## Instances made in one click

The installer writes the connection string into a block of your default secret, under `installedDatabases.<name>.connectionString`. The instance names that key. Your connection string never sits in the instance or in your code.

A database has one instance at most. Press **Create instance** again and you get the same instance back. A second install under a name that is taken is refused.

## Manage the databases

The table lists the databases of every server : the engine and version, the server, the port, the state and the instance.

| Action | What it does |
|---|---|
| Start, Stop, Restart | The container. Its data stays. |
| Connect | The password, the connection string of API Maker, a URI with the first database, JDBC, and the shell inside the container. |
| Logs | The last lines the database printed. |
| Create instance | Its instance, when it has none yet. |
| Remove | The container. Choose to delete its data and to remove its instance too. |

> **Warning : Removing the data**
>
> **Also delete its data** removes the Docker volume or the folder of the database. This can not be undone.

## With API Maker Launchpad

The databases follow the layout of [API Maker Launchpad](https://docs.apimaker.dev/v4/docs/getting-started/install-on-server.html), so Launchpad can manage them too.

- **A server of Launchpad (Cloud mode)** : the container is `db_<name>` and its data is in `/root/docker-data/db_<name>`. The **Services** tab of the server shows it as **from API Maker**, with its start, stop, restart, logs and shell.
- **A folder of Launchpad (Local mode)** : the container and the Docker volume are the ones Launchpad gives a database of that name. Launchpad takes the database into the folder a few seconds later. It shows in its **Databases** tab, with the same data, port, password and instance.

API Maker lists its databases in `config/api_maker_databases.json` of Launchpad. That is how Launchpad finds them.

## By hand, with Docker

Every container has the labels `dev.apimaker.db-installer.*` and the Docker Compose project `amdb_<name>` :

```bash
docker compose -p amdb_postgres ps
```

```bash
docker logs -f --tail 200 db_postgres
```
