Move your database to Nife
This guide moves a database from your current platform to Nife. You create a database on Nife, copy your data into it, point a test copy of your app at it, then switch over. Your old database keeps running until you are sure.
Before you start
- A Nife account and an organization.
- Access to your current database and its admin credentials.
- The database tools for your engine installed on your own computer (for example pg_dump for PostgreSQL).
- A short window where your app can pause writes. Plan one for the final copy.
Databases Nife supports
Nife lists these engines: PostgreSQL, MySQL, MariaDB, MongoDB and Redis.
Step 1: Note your current database settings
- Write down the engine and its version.
- Write down how big the data is, so you can choose a volume size on Nife.
- Write down which apps connect to it and the variable each one uses, such as DATABASE_URL.
Step 2: Create the database on Nife
You can create a database from the Nife dashboard or with nifectl. With nifectl, use the built-in runtime for your engine. The commands below follow Nife's own database guides.
PostgreSQL:
nifectl init --name your-database-name --builtin postgres --org your-organization-name --volume-size 1 --volume-path /var/lib/postgresql/data/pgdata --port 5432 --external 5432 --replica 1 --routing-policy Latency --request-cpu 0.5 --limit-cpu 1
nifectl deploy -e POSTGRES_PASSWORD=your-secret-password -e PGDATA=/var/lib/postgresql/data/pgdata/postgres
MySQL (for MariaDB, use --builtin mariadb):
nifectl init --name your-database-name --builtin mysql --org your-organization-name --volume-size 1 --volume-path /var/lib/mysql --port 3306 --external 3306 --replica 1 --routing-policy Latency --request-cpu 0.5 --limit-cpu 1
nifectl deploy -e MYSQL_ROOT_PASSWORD=your-secret-password
Redis:
nifectl init --name your-database-name --builtin redis --org your-organization-name --volume-size 1 --volume-path /data --port 6379 --external 6379 --replica 1 --routing-policy Latency --request-cpu 0.5 --limit-cpu 1
nifectl deploy -e REDIS_PASSWORD=your-secret-password
Set --volume-size (in GB) to fit your data. The volume is what keeps your data when the database restarts. Choose your own strong password and keep it in a password manager.
Step 3: Copy your data
Export from your current database with its standard tool, then import into the Nife database using the host, port and password you set in Step 2.
- PostgreSQL: run
pg_dump -Fc -f backup.dump YOUR_OLD_CONNECTION_STRING, thenpg_restore --no-owner -d YOUR_NIFE_CONNECTION_STRING backup.dump. - MySQL and MariaDB: run
mysqldump --single-transaction YOUR_DATABASE > backup.sql, then load it withmysqlagainst the Nife database. - MongoDB: run
mongodumpagainst the old database, thenmongorestoreagainst the Nife database. - Redis: if you use Redis only as a cache, start empty. If you need the data, use your source platform's export and the Redis tools to load it.
Check the row counts or document counts on both sides before you go on.
Step 4: Point a test copy of your app at the new database
- Set your app's database variable to the Nife database address. See Move your environment variables.
- Deploy and test on the Nife URL.
- Check that reads and writes work, and that your migrations run.
Step 5: Switch over
- Pause writes on the old app for a short time.
- Run the final export and import from Step 3 so the new database has the latest data.
- Point your live app at the Nife database.
- Watch the logs with
nifectl logs.
Keep the old database for a few days before you delete it.
What this guide does not cover
Automatic database backups, replication, point-in-time restore and database upgrades. If you depend on any of these, contact Nife support at support@nife.io before you migrate, and we will help you plan it.
Troubleshooting
- Cannot connect from your app: check the host, the port and the password. Confirm the database finished deploying with
nifectl status. - Import fails on permissions: for PostgreSQL, use the --no-owner flag shown above.
- Data looks short: compare counts on both sides and run the import again into an empty database.
Need help? Email support@nife.io.