# List of  QuestDB Error Codes

> **For AI agents:** the complete documentation index is at [llms.txt](https://questdb.com/docs/llms.txt). Every page is available as markdown by appending `.md` to its URL, or by sending an `Accept: text/markdown` request header.

A list of error codes that QuestDB may generate, with explanations and suggested actions.

## Replication Errors

Error codes may appear during start-up if an instance is misconfigured.

When a primary instance is running, QuestDB checks that other primary instances are not running. 

It does so by keeping a rolling ID locally and in the object store in sync. 

If these two IDs are out of sync, the primary instance will raise an error.

For additional information, refer to the [replication overview](/docs/high-availability/overview), the [replication setup guide](/docs/high-availability/setup), and the [disaster recovery guide](/docs/high-availability/disaster-recovery/).

### ER001

Raised at startup when a node that has just completed a
[point-in-time recovery](/docs/operations/point-in-time-recovery/) is
configured with `replication.role=primary` while its
`replication.object.store` points at a non-empty location.

A recovered node is a new cluster, so the configured location may contain WAL data from a different replication "timeline".

**As such, this error is raised to prevent an overwrite of the existing data.**

To resolve, shut down the database and reconfigure the `replication.object.store` to point to a new empty location. 

Once restarted, if the old location is no longer needed, you can delete it.

### ER002

The database cannot read or write its local copy of the replication sync ID stored in the `_replication_sync_id.d` file.

If you recently recovered the database from a backup, check that the file permissions of the restored directory (and its contents recursively) are readable and writable.

If the error indicates a "Could not read" error, perform a primary migration to recreate it. 

To do so, place an empty `_migrate_primary` file into your databases installation directory - for example, the parent of `conf` and `db` directories.

This will trigger the database instance to resync with the latest state in the object store and restart as primary.

### ER003

When you create a replica from a snapshot that is too old, this error may occur. 

The workflow to enable replication on the primary instance and create replicas is:
* Reconfigure the primary instance with `replication.role=primary` and configure its `replication.object.store` to point to the object store and start it.
* While running, snapshot the primary instance and copy the snapshot and restore it on the replica instance.
* Reconfigure the replica instance with `replication.role=replica` and ensure its `replication.object.store` points to the same object store as the primary. Also, set a new and unique value to the `cairo.snapshot.instance.id` configuration.
* Start the replica instance.

See the [checkpointing](/docs/query/sql/checkpoint/) page for more details
on how to create and restore snapshots.

### ER004

This error is very similar to ER003. 

It indicates that the transactions in the object store and the replica are out of sync.

This can happen if you created the replica from a database that replicated on a different timeline or from a database unrelated to the primary instance.

To resolve this, recreate the replica using a recent primary instance snapshot. 

Use a snapshot you created after enabling replication on the primary instance. 

See the workflow in ER003 for detailed steps.

### ER005

A primary instance started which is not in sync with the configured object store.

Verify the `replication.object.store` configuration and ensure that the object store is not in use by another primary instance.

If this instance was the primary before an unplanned failover, do not use
`_migrate_primary` in its existing installation directory. It may contain
committed transactions that never reached the object store, even if the
current primary has since advanced beyond its transaction numbers. Retire it
or [rebuild it from the current primary](/docs/high-availability/failover/#rebuild-the-failed-primary).
`_migrate_primary` downloads missing transactions; it does not repair
divergent local data.

For a replica that has remained on the current replication stream, verify
that the configuration is correct and no other primary is running before
performing a primary migration. Place an empty `_migrate_primary` file in its
installation directory, the parent of `conf` and `db`, and start it with
`replication.role=primary`. This downloads the latest state from the object
store before taking over as primary. See
[Emergency primary migration](/docs/high-availability/disaster-recovery/#emergency-primary-migration).

An in-place promotion with
[`SWITCH ROLE TO PRIMARY`](/docs/high-availability/failover/#promote-a-replica-after-a-primary-loss)
runs the same check before it changes anything. A replica that has not yet
applied everything in the object store is refused: it stays a replica and
keeps replicating, `GET /lifecycle` reports the `replication` component as
`DEGRADED`, and the reason is in the server log. Promote it again once it has
caught up.

### ER006

This error occurs when you start a primary instance and discover another instance is already acting as the primary.

This typically happens after an emergency primary migration, usually due to a network partition that separated your database instances.

Before proceeding, check your infrastructure to determine which instance is
the intended primary. The node halted by ER006 may be the intended primary.
Stop the unintended primary and prevent it from restarting automatically.

If the intended primary was halted, restart it with `replication.role=primary`
only after establishing that the unintended primary committed no competing
writes and the intended primary retains the authoritative data. No promotion
is needed. Startup can still be refused with [ER005](#er005), because even an idle
unintended primary can advance the object-store ownership token. If either
condition is uncertain, contact QuestDB support before resuming replication.

Retire the extra instance or rebuild it as a new replica from a fresh backup
or snapshot of the current primary. Changing `replication.role` alone does
not make its existing data safe to reuse after an unplanned failover. See
[Rebuild the failed primary](/docs/high-availability/failover/#rebuild-the-failed-primary).

This error can also occur when a node that successfully completed a planned
demotion with [`SWITCH ROLE`](/docs/query/sql/switch-role/) is restarted while
`server.conf` still says `replication.role=primary`. Inspect its server logs
from startup until it stopped for evidence of local writes, but the absence
of write entries does not prove that no writes committed. Restart it with
`replication.role=replica` only if you can establish that it committed no local
writes since its successful demotion; otherwise rebuild it from the current
primary. Update the configuration before any restart, as described in
[Restarts](/docs/high-availability/failover/#restarts).

### ER007

This error indicates a Data ID mismatch between the local database and the backup or replication object store.

Each QuestDB database has a unique Data ID (stored in `<install_root>/db/.data_id`) that identifies it for backup and replication purposes. This error occurs when:

* Attempting to back up to an object store that contains backups from a different database instance
* A replication object store contains data from a different primary instance

To resolve:

* **For backup creation**: Verify the `backup.object.store` points to the correct location for this database instance. If intentionally backing up to a new location, the location must be empty.
* **For replication**: Verify the `replication.object.store` configuration matches the primary instance that owns the data.

Note: Restore operations check for an empty database separately. If the target
database already has a Data ID, restore fails with: "The local database is not
empty. It already has an associated data ID."

#### Starting fresh with a new Data ID

A Data ID is automatically generated when QuestDB first starts with an empty
database. To intentionally start fresh:

**Recommended**: Create a new, empty database directory and configure QuestDB
to use it.

**Alternative**: Delete the existing `.data_id` file (stop QuestDB first):

```bash
# Stop QuestDB first!
rm <install_root>/db/.data_id
# Restart QuestDB - a new Data ID will be generated
```

:::warning

Changing the Data ID on a database with existing data will:
- Break any existing replication configuration
- Make existing backups incompatible for restore
- Cause ER007 errors when connecting to the original object store

:::

See the [Backup and Restore guide](/docs/operations/backup/) for more information.

## Operating system error codes

Refer to the [OS error codes](/docs/troubleshooting/os-error-codes/) page for any
file or network related errors that QuestDB may raise.
