Migrate Data from External MongoDB to External PostgreSQL
Starting from version v1.47, Appsmith uses PostgreSQL as the default primary database. If you're upgrading to a newer version, you need to migrate your data from External MongoDB to External PostgreSQL. This page provides the steps and guidance for the migration process.
Prerequisites
Before starting the migration, ensure the following requirements are met:
- Back up the Appsmith instance to ensure you can revert if necessary. For more information, see the Backup Appsmith instance guide.
- Take note of the external MongoDB URL that Appsmith connects to. If you don’t have it, retrieve the value from the
APPSMITH_DB_URL
environment variable in either thedocker.env
file for Docker or thevalues.yaml
file for Kubernetes. - Ensure you have PostgreSQL version 14 or higher.
- Use an existing PostgreSQL instance or set up a new one. For more information on creating a new PostgreSQL instance, see the How to set up external PostgreSQL guide.
- Verify that the external PostgreSQL instance has
CREATE SCHEMA
andCREATE EXTENSION
permissions granted to the user that Appsmith will use to connect.
Migrate Appsmith data
Before you begin the Appsmith update, ensure you have met all the prerequisites. Follow these steps to perform the migration:
-
Access the
appsmith
container to run migration commands. -
Run the following command to create a dump of your MongoDB data in JSONL format. Replace
<mongo_db_url>
with your MongoDB connection URL that you noted in the Prerequisites section:node /opt/appsmith/utils/bin/move-to-postgres.mjs --mongodb-url=<mongo_db_url>
This will store the MongoDB data in the
/appsmith-stacks/mongo-data
directory for transfer. -
Go to the directory containing the Appsmith configuration file, such as
docker.env
for Docker orvalues.yaml
for Kubernetes. -
Update the
APPSMITH_DB_URL
environment variable with your PostgreSQL connection details. An example update is shown below:APPSMITH_DB_URL=postgresql://{username}:{password}@{host}:{port}/{db_name}?options
-
Restart the Appsmith container to apply the changes. The migration process may take time depending on the data volume, so it’s advisable to schedule it during a maintenance window as Appsmith will be unavailable during this process.
-
Log into your Appsmith instance and verify the Apps and App data to confirm the migration is successful.
Troubleshooting
If issues arise during migration, consider these steps:
- Verify that the specified MongoDB URL in the migration command is accurate.
- Confirm that your PostgreSQL instance is accessible and has the necessary permissions.
- Roll back to the backup you created in the Prerequisites section. For more information, see Restore Appsmith instance.
If you continue to face issues, contact the support team using the chat widget at the bottom right of this page.