---
title: Migration to PostgreSQL
description: "Guide for migrating data from MongoDB (`agenta <v0.18`) to PostgreSQL (`agenta >=v0.19`)."
---

:::caution
  As of version `0.19.0`, Agenta is transitioning from MongoDB to PostgreSQL.
  Users need to migrate their MongoDB databases to this latest version, as this
  will be the only version receiving feature updates and patches.
:::

This guide provides step-by-step instructions for migrating your agenta instance from MongoDB to PostgreSQL version.

### Prepare for Migration

Before starting the migration, ensure that you have backed up your production data.

While the migration will not modify any data in your MongoDB instance, it is highly recommended that you create a [backup](https://www.mongodb.com/docs/manual/tutorial/backup-and-restore-tools/) of your database in the MongoDB instance before running the migration script. This ensures you have a recovery point in case of any issues.

### Start the Migration

1. Start the local instance of Agenta using the dedicated migration Docker Compose file, and ensure that both the MongoDB and PostgreSQL instances are active.
```
cd agenta-backend/agenta_backend/migrations/mongo_to_postgres
docker compose -f docker-compose.migration.yml up
```
2. Use the following commands to initiate the migration:

```bash
docker ps
```

The above command will list the running docker containers that you have. Copy the backend container id and execute bash.

```bash
docker exec -it {backend-container-id} bash
```

Next, navigate to the `mongo_to_postgres` folder to execute the migration script.

```bash
cd /app/agenta_backend/migrations/mongo_to_postgres
python3 migration.py
```

### Post Migration

After completing the migration, ensure you check the data integrity in PostgreSQL by accessing Agenta on the web and verifying that your data is intact and everything works fine.

In the event that you encounter issues and need to revert the migration, rest assured that your data in the MongoDB instance is still intact. All you need to do to revert is to check out the last commit you were on before the PostgreSQL migration and create a Github [issue](https://github.com/Agenta-AI/agenta/issues/new?assignees=&labels=postgres,bug,Backend&projects=&template=bug_report.md&title=[Bug]+) describing the problem you encountered.
