# store-failed

The database **has failed** and refuses writes, or reads and writes, **until it is restarted**.

- **Routes:** `write-events`, `read-events`, `observe-events`, `run-eventql-query`, `register-event-schema`, `read-subjects`, `read-event-types`, `read-event-type`, `create-backup`, `restore-backup`, `import-events`, `export-events`, `verify-store`, and `audit-history`
- **Descriptions:** `store has failed: it refuses writes until it is restarted` after storing a write failed, and `store has failed: it refuses reads and writes until its data directory is emptied and the server is restarted` after a restore or an import failed and could not empty the database again
- **Details:** **`operation`**, the operation that the database refuses: `read`, `write`, or `observe`.

## Why It Happens

When EventSourcingDB **fails to store a write**, for example because the disk is failing, it **stops taking writes** until it is restarted, since storage that failed once cannot be trusted with the next write. The same happens when it cannot move stored writes into its data files while the writes waiting for that fill the memory it allows. Reads go on and see everything that was stored before the failure, see **[Read-Only Mode After a Storage Failure](/docs/eventsourcingdb/read-only-mode#read-only-mode-after-a-storage-failure)**.

If a **restore or an import fails and EventSourcingDB cannot empty the database again**, what is left is partly restored or imported, so it refuses **reads as well**, with the second text, see **[When a Restore Fails](/docs/eventsourcingdb/backup-and-restore#when-a-restore-fails)**.

An **[export](/docs/eventsourcingdb/api/export-events)** answers with this error as a single envelope, with the content type `application/json`, since an export carries no error items.

A failure outranks every other reason to refuse a request except **[`server-shutting-down`](/docs/eventsourcingdb/errors/server-shutting-down)**: a failed database in read-only mode, for example, reports `store-failed`.

## How to Fix It

Find the cause in the log, fix it, and **restart the server**; until then, sending the request again fails the same way. A write refused with this error was not stored. After a failed restore, with the second text, a restart alone is not enough: EventSourcingDB refuses to start on that data directory until it is emptied, so **empty the data directory**, start EventSourcingDB, and restore the backup again, or register the schemas and import the events again.

## Example

For a write after an earlier write failed to be stored, EventSourcingDB answers with this error, as a line of the stream, and then ends the stream with its `end` item:

```json
{
  "type": "error",
  "data": {
    "code": "https://docs.eventsourcingdb.io/errors/store-failed",
    "description": "store has failed: it refuses writes until it is restarted",
    "details": {
      "operation": "write"
    }
  }
}
```
