Migrating DigitalOcean database to AWS
Published: 2021-10-14 12:54:40

Video Version: https://youtu.be/3zLWCNn0Vqk

In this article, we’ll look at how to migrate an existing Postgres database on DigitalOcean created through their "managed database" function to a Relational Database Service (RDS) instance on AWS.

For an introduction to RDS, you can read my previous article on [migrating a local database to RDS](https://blog.tinystacks.com/migrate-local-database-on-docker-container-to-aws), or [watch the video](https://youtu.be/87G3iUl-tj0).


Prerequisites:

- Managed database on DigitalOcean with some data in it
- AWS account
- (optional) TablePlus or any other tool to manage a Postgresql DB

Steps: 

- Check DigitalOcean and download the connection certificate
- Install [TablePlus](https://tableplus.com/) (GUI tool for managing relational databases)
- Check DigitalOcean database
- Create RDS instance
- Test empty RDS instance
- Backup DigitalOcean DB
- Restore RDS database
- Final Test

## Check DigitalOcean and Download CA certificate 

First, let's visit our DigitalOcean account’s Database page. We should see something like this:

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633850207069/bJ5X7ICQ0.png)

Download the CA certificate locally. We need this because managed databases on DigitalOcean don't allow insecure connections.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633851982852/yF_CJYDBs.png)

## TablePlus

To access the DB, we can use whatever tool we want (command line interface, Pgadmin, etc.). In this demo, we will use [TablePlus](https://tableplus.com/) (available on Mac/Windows), so if you want to follow along exactly I suggest you download it. We’ll use the free version. 



![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633852039662/y2m5aTO47.png)

## Check DigitalOcean Database

Let's create a new connection on TablePlus:

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633852186650/fqlnJcPa4.png)

Add the details for your DigitalOcean database:

- Host
- Port
- Username
- Password
- Database name
- SSL mode: REQUIRED

Remember also to add the certificate we just downloaded.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633853428664/qxJUIfj-M.png)

Click **Connect** and you will see the database with your data. In this case, we have just 2 tables and 3 inserts.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633854766934/p15NHXHXZ.png)

## Create RDS Instance

Go on AWS Console and search "RDS"

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633854992204/u_6qS-0Ko.png)

Click **Create Database**.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633855372747/W6VD6mhCQ.png)

Select **Postgres** and **version 12**, so we will have access to a free Tier (read the conditions before accepting).

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633855452315/Z-MLOn7Rl.png)

Choose a name for the database, as well as a username and password to access the DB.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633856460380/7LNyYT_oh.png)

Make the instance accessible from the Internet:

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633856712642/358bqiea2.png)

Double-check that this is a Free Tier (with limitations- please read them)Then, click **Create Database**. 

This will take a few minutes to complete.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633856792367/c9c-1v6Jh.png)

Let's check that our security group is configured correctly. Our machine should have access to the instance:

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633880449214/wAktrFH55j.png)

Specifically, check if the inbound rules are set properly. In our case, they’re as follows:

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633880804639/IX_-9ACpf.png)

## Test Empty RDS Instance

Now let's test connecting to the RDS instance using TablePlus:

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633859248130/_osJpwFrW.png)

Click **Connect**. As you can see, the DB is empty for now:

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633859374216/4tX-PILYV.png)

## Backup DigitalOcean DB

Now let’s use Tableplus to make a backup of the DigitalOcean database:

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633873953447/2pWysYQln.png)

Choose a folder and save the file called defaultdb.dump (it will have the name of your database):

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633873793413/O_v_gbkEw.png)

If you see this, it worked:

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633874000509/9VXsAtPp8.png)

## Restore RDS Database

To restore the database, click **Restore**.

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633874050280/pOhriVRy-.png)

Select the `aws` database. Then, select the `postgres` database and click **Start restore**:

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633874100962/WsFln0TVx.png)

Select the dump file, in our case `defaultdb.dump`:

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633875156759/UEULTNmb6.png)

### Final Test

As a final test, let's access the RDS database again:

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633876573537/UPdSzUQ8o.png)

And here we can see our tables and inserts again:

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1633876619400/qmtVNr-0O.png)

And we’re done!

Video Version: https://youtu.be/3zLWCNn0Vqk