> ## Documentation Index
> Fetch the complete documentation index at: https://docs.airys.chat/llms.txt
> Use this file to discover all available pages before exploring further.

# How to migrate AirysChat database?

> Learn how to migrate your AirysChat database from bundled PostgreSQL to managed database services like AWS RDS

## AirysChat database migration

Follow along If you started out with a bundled install of postgres, redis and airyschat in a single instance
and now wants to migrate to managed database service.

In this guide, we assume you want to migrate to AWS RDS. This guide should be equally applicable to any other
managed database service or even migrating data between different AirysChat installations.

### Step 1: Stop AirysChat service

Stop AirysChat service to stop database activity.

```bash theme={null}
sudo systemctl stop airyschat.target
```

### Step 2: Back up the database

Back up the database using `pg_dump` tool.

```bash theme={null}
pg_dump -Fc --no-acl --no-owner  -U postgres airyschat_production > /tmp/cw.dump
```

### Step 3: Create RDS instance

Create an RDS Postgres instance in your AWS account. Refer to the [AWS documentation](https://aws.amazon.com/getting-started/hands-on/create-connect-postgresql-db/).

### Step 4: Verify connectivity

Verify connectivity to the new RDS instance from your AirysChat installation.

```bash theme={null}
psql -h <hostname> -u <username> -d postgres
```

### Step 5: Restore the database

Restore the database from the backup file.

```bash theme={null}
pg_restore --verbose --clean --no-acl --no-owner --create -U postgres -d postgres /tmp/cw.dump
```

### Step 6: Update environment variables

Modify the Postgres related environment variables to use the new RDS credentials.

```bash theme={null}
sudo -i -u airyschat
cd airyschat
vi .env
```

### Step 7: Start AirysChat service

Start the AirysChat service.

```bash theme={null}
sudo systemctl start airyschat.target
```

<Note>
  If you are getting the AirysChat onboarding screen again on visiting your self-hosted AirysChat URL,
  login to the rails console and run the following:

  ```bash theme={null}
  sudo cwctl --console
  ::Redis::Alfred.delete(::Redis::Alfred::AIRYSCHAT_INSTALLATION_ONBOARDING)
  ```
</Note>
