# The store in your database

The record that reports read is kept in the server's own files, and that needs nothing from you: see [The store on disk](Reports-Store.md). This page is about an option beside it, for organisations whose own tools read from a database: the server can write the same record into a database that **you** run.

> [!NOTE]
> The server brings no database and no database driver, and does not need one. This is for writing into a database you already have. It needs an Enterprise licence.

## When to use it

| You want | Use |
|---|---|
| reports, dashboards, schedules, alerts | the files. Nothing else. |
| your own BI tool or data warehouse to read the record | **Both, reports read the files**: the server keeps its files for its reports and also writes to your database |
| the record only in your database | **Your database** |

For nearly everybody who needs a database at all, the middle one is right: the Reports app stays as fast as it is, and your tools get their tables.

Other ways to get the data out need no database: [exports](Reports-Running.md#export), [scheduled reports](Reports-Schedules.md) written to a folder as CSV, and the [API](API-Reports.md).

## Which databases

| Database | From version |
|---|---|
| MySQL | 8 |
| MariaDB | 10.6 |
| SQL Server | 2016 |
| Oracle | 12.2 |
| PostgreSQL | 12 |

No others, and no older versions.

## Setting it up

In [Preferences, Reporting](Prefs-Reporting.md#storage), under **Storage**:

1. Put your database's JDBC driver, a jar file from the database's maker, into `plugins/lib` in the server's folder and restart the server once.
2. Choose **Your database**, or **Both, reports read the files**.
3. Fill in:

| Field | Is |
|---|---|
| **Type** | MySQL, MariaDB, SQL Server, Oracle or PostgreSQL. Fills in the driver class. |
| **URL** | the JDBC address: `jdbc:postgresql://db.example.com:5432/crushftp` |
| **Driver class**, **Driver jar** | filled in from the type; the jar is the one you put into `plugins/lib` |
| **User**, **Password** | an account of the database |
| **Let the server create and upgrade its tables** | on: the server makes its tables itself. Off: it only checks them, and **Show the DDL** gives your database administrator the statements to run. |
| **Waiting on disk, at most** | how much the server keeps on its own disk while the database cannot be reached: 4,096 MB unless you change it |

4. **Test** connects and checks the tables.

Give the account its own schema or database, with the right to create tables there if the server shall manage them. It needs nothing else on the database server.

Without an Enterprise licence the choice has no effect: the server keeps using its files, says so once in its log, and the Storage part shows why.

## What the server writes

All names are upper case and begin with `CA_`.

| Table | Holds |
|---|---|
| `CA_<KIND>_<YYYYMM>` | the events of one kind and one month: `CA_FILE_202611`, `CA_AUTH_202611`. `ID` is the key, `TS` the time in milliseconds, then the columns of that kind of data. |
| `CA_<KIND>_KV_<YYYYMM>` | for columns that hold several named values, such as the fields of a form: `ID`, `K`, `V` |
| `CA_C_…` | the hourly and daily totals |
| `CA_META` | the version of the tables, and how far each server has written |
| `CA_V_<KIND>` | **a view over all months of a kind, with the time also as a timestamp. This is what your tools should read.** |

A table per month makes retention cheap: an old month is dropped as a table.

Text columns that people search by, the user, the file's name, the folder, have a second column in small letters (`USER_LC`, `NAME_LC`, `DIR_LC`), so that a search behaves the same on every database whatever its rules for capitals.

## It never loses an event to an outage

Events are always written to the server's own journal first, and from there to the database in batches. When the database cannot be reached, events wait on the server's disk and are written when it is back. Nothing is lost unless the wait fills the room you allowed for it; then the oldest waiting events are dropped and counted.

The [Data](Reports-Data.md) section shows **Database behind**: how many seconds the database is behind the server. A few seconds is normal. When it is more than 15 minutes the server writes a line `ACTIVITY: …` to its log; an alert of the type **Report Store Problem** in [Preferences, Alerts](Prefs-Alerts.md) tells someone.

A batch that was sent twice does no harm: each event has its own key.

## In a cluster

Every server writes to the same database. Each row carries the number of the server it came from.

## What changes for the Reports app

| Storage | Reports read |
|---|---|
| **Our own files** | the files |
| **Both, reports read the files** | the files. The database is for your tools. |
| **Your database** | the database: each report becomes statements against the month tables |

With **Your database**, how fast a report is depends on your database server and on what else it is doing.

## Things to know

- **Erasing a person** rewrites the database's rows too: see [Erase a person](Reports-Data.md#erase-a-person).
- **Retention** is the same as for the files: three years of events and ten of totals unless you change it. The server drops the month tables that are older.
- **Do not write to these tables**, and do not add columns to them. Build what you need as views of your own on top of `CA_V_…`.
- **An upgrade of the server** may add columns. With table management on, the server does that at its first start; with it off, **Show the DDL** gives the statements for the new version.
- **Going back to files** is a change of the Storage choice. What was written to the database while it was the only store is not copied back into files.
- **The history of CrushFTP 11** is brought in through the same import whichever store is used: [Bringing the history of CrushFTP 11](Reports-Import-from-11.md).
