# Storage backends

SQLite, MySQL and MongoDB, what each plugin stores, and how writes are handled.

Both plugins use the same storage engine and the same `storage.yml` format. Each has its own file and its own database name.

## Choosing a backend

| Backend | Use it when |
| --- | --- |
| `sqlite` | One server. No setup, stored in `storage.db` |
| `mysql` | Several servers share data, or you already run MySQL or MariaDB |
| `mongodb` | You already run MongoDB |

```yaml
backend: mysql

sqlite:
  file: storage.db

mysql:
  host: localhost
  port: 3306
  database: glacierstaff
  username: root
  password: ""
  use-ssl: false
  pool-size: 6

mongodb:
  connection-uri: ""
  host: localhost
  port: 27017
  database: glacierstaff
  username: ""
  password: ""
  auth-database: admin
  pool:
    max-size: 20
    min-size: 0
    max-idle-time: 10m
  timeouts:
    connect: 10s
    read: 30s
    server-selection: 10s
```

For MongoDB, a full `connection-uri` (`mongodb://` or `mongodb+srv://`) replaces the individual fields below it.

> [!NOTE]
> Changing the backend does not move existing data. Switch before you go live, or migrate the data yourself.

## What's stored

| Plugin | Data |
| --- | --- |
| GlacierHub | Points, cosmetics, login streaks, parkour times, friends, shop purchases, vote data, the maintenance switch |
| GlacierStaff | Punishment cases, reports and Helpop requests, inventory restore records, notes and the watchlist, and the other modules' saved data |

Each plugin keeps everything in one table, `glacierhub_storage` or `glacierstaff_storage`, or the matching MongoDB database.

## How writes work

- Writes go to one background thread, in order, and are retried if they fail.
- Reads wait for queued writes first, so a module never reads stale data it just wrote.
- Modules load their data when enabled and keep it in memory. Gameplay never waits on the database.
- On shutdown, both plugins stop their modules first, then wait up to 30 seconds for pending writes before closing the connection.

## When the database is down

If the backend can't be reached at startup, the modules that need storage fail to enable with a short console warning. Everything else keeps running. Fix the connection and run `/glacierhub reload all` or `/glacierstaff reload all`.

## Sharing across servers

For GlacierStaff on a network, point every server at the same MySQL or MongoDB database. That's what keeps report and Helpop queues, native punishment cases and inventory restore records consistent. Redis then tells the other servers when something changed. See [Redis](/docs/network/redis).

Keep reason settings and permission groups the same on every server that shares a database.
