---
layout: article
title: Databases
description: Configure the database backend for your self-hosted Appwrite instance. Learn about the supported database options and their configuration.
---

Appwrite supports PostgreSQL, MariaDB, and MongoDB as database backends. You select the database during [installation](/docs/advanced/self-hosting/installation) via the setup wizard and **cannot change it after installation**.

Regardless of which database you choose, the Appwrite API remains the same. Only the underlying storage engine differs.

**Default database**

PostgreSQL is the default database for new installations.

# CLI installation

If you prefer to skip the setup wizard, you can set the database directly using the `--database` flag:

**macOS and Linux**

```bash
docker run -it --rm \
    --volume /var/run/docker.sock:/var/run/docker.sock \
    --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \
    --entrypoint="install" \
    appwrite/appwrite:1.9.5 \
    --database=postgresql
```

**Windows (CMD)**

```cmd
docker run -it --rm ^
    --volume //var/run/docker.sock:/var/run/docker.sock ^
    --volume "%cd%"/appwrite:/usr/src/code/appwrite:rw ^
    --entrypoint="install" ^
    appwrite/appwrite:1.9.5 ^
    --database=postgresql
```

**Windows (PowerShell)**

```powershell
docker run -it --rm `
    --volume /var/run/docker.sock:/var/run/docker.sock `
    --volume ${pwd}/appwrite:/usr/src/code/appwrite:rw `
    --entrypoint="install" `
    appwrite/appwrite:1.9.5 `
    --database=postgresql
```

Accepted values are `postgresql`, `mariadb`, and `mongodb`.

# Supported databases

## PostgreSQL

PostgreSQL is a relational SQL database and the default option for new Appwrite installations.

- **Docker image:** `appwrite/postgres:0.1.0`
- **Container name:** `appwrite-postgresql`
- **Default port:** `5432`

## MariaDB

MariaDB is a relational SQL database. It was the default database in Appwrite versions prior to 1.9.0.

- **Docker image:** `mariadb:10.11`
- **Container name:** `appwrite-mariadb`
- **Default port:** `3306`

## MongoDB

MongoDB is a document-based database and was the default in Appwrite 1.9. The installer configures it as a replica set (`rs0`) and places two helper files that the container needs next to `docker-compose.yml`: `mongo-init.js` and `mongo-entrypoint.sh`.

- **Docker image:** `mongo:8.2.5`
- **Container name:** `appwrite-mongodb`
- **Default port:** `27017`

# Environment variables

All database backends use the same environment variables. The values differ depending on which database you selected during installation.

| Variable | Description | PostgreSQL default | MariaDB default | MongoDB default |
|---|---|---|---|---|
| `_APP_DB_ADAPTER` | Database adapter type | `postgresql` | `mariadb` | `mongodb` |
| `_APP_DB_HOST` | Database server hostname | `postgresql` | `mariadb` | `mongodb` |
| `_APP_DB_PORT` | Database server port | `5432` | `3306` | `27017` |
| `_APP_DB_SCHEMA` | Database name | `appwrite` | `appwrite` | `appwrite` |
| `_APP_DB_USER` | Database user | `user` | `user` | `user` |
| `_APP_DB_PASS` | Database user password | `password` | `password` | `password` |
| `_APP_DB_ROOT_PASS` | Database root password | `rootsecretpassword` | `rootsecretpassword` | `rootsecretpassword` |

The installer writes only the selected database's service into your `docker-compose.yml`, so the other database containers never run.

**Change default passwords**

Always change the default database passwords before deploying to production. Update both the environment variables and the database credentials.

# Backups

For database backup procedures, see the [Backups](/docs/advanced/self-hosting/production/backups) guide.
