How to Migrate MySQL to PostgreSQL in AWS?
Last Updated :
05 Jul, 2024
Compared to other database engines migration from MySQL to PostgreSQL can be challenging, especially if you want to minimize downtime or have a desire to preserve data integrity. AWS offers a variety of tools to help with database migration, such as the Database Migration Service (DMS).
In this article, we are going to explain in detail how to perform MySQL to PostgreSQL migration on AWS using DMS where for Amazon RDS we will be setting up the source and target environments and defining migration tasks. With this PostgreSQL migration guide at your side, your migration will be as swift and hassle-free as possible, whether you are simply taking advantage of PostgreSQL’s more complex functionalities or seeking to enhance your system’s capacity.
Prerequisites
- Amazon RDS Instances: Ensure you have two databases in Amazon RDS—one for MySQL and one for PostgreSQL.
- MySQL Table Creation: Use MySQL Workbench or any other MySQL client to create the necessary tables in your MySQL database.
How to migrate MySQL to PostgreSQL in AWS
We will be creating a DMS instance then we will be creating endpoints and then replication tasks with this replication will happen from source to destination database. So basically DMS service needs a platform or infrastructure on which these replication tasks will run. So we have to create a DMS instance and then create the endpoints for the source and target database and then replication task all rules we can define here.
Note: In AWS, in services, amazon RDS, create two databases named as a database of My SQL and database-1 of PostgreSQL. Make sure that you have created a table in MySQL Workbench.
Create DatabaseStep 1: Create a DMS Replication Instance
1. Open AWS DMS:
- Navigate to the AWS Management Console and select "Database Migration Service" from the services menu.
2. Create a Replication Instance:
- Click on "Replication Instances" in the left sidebar.
- Click on "Create replication instance".
Create Replication InstanceFill in the following details:
- Name: Give a unique name to your replication instance.
- Description: Provide a short description.
- Instance Class: Select dms.t3.micro.
- Engine Version: Choose 3.4.4.
- VPC: Select the appropriate Virtual Private Cloud (VPC).
- Click on the "Create" button to create the replication instance.
Fill DetailsFill up details:
Fill up detailsCreate Replication Instance:
Create Replication InstanceStep 2: Create Endpoints
Source Endpoint
1. Go to Endpoints:
- Click on "Endpoints" in the left sidebar.
- Click on "Create endpoint".
Create Endpoint2. Configure Source Endpoint:
- Endpoint Identifier: Enter a name for your source endpoint.
- Source Engine: Select "Microsoft SQL Server".
- Access Information: Check "Provide access information manually".
Fill in the details from your source database (MySQL). Go to your database-1 which is the source database and pick up the details from there like endpoint and port.
Database-1 details- Server Name: Copy the endpoint from your databse-1 and paste it here.
- Port: Enter the port number (default is 3306).
- Username: Enter your MySQL username.
- Password: Enter your MySQL password.
- Database Name: Enter the name of your MySQL database.
- Click "Create endpoint".
Target Endpoint
1. Go to Endpoints:
- Click on "Endpoints" in the left sidebar.
- Click on "Create endpoint".
2. Configure Target Endpoint:
- Endpoint Identifier: Enter a name for your target endpoint.
- Target Engine: Select "Amazon Aurora PostgreSQL" (if using Aurora PostgreSQL) or "PostgreSQL" for standard PostgreSQL.
- Access Information: Check "Provide access information manually".
- Fill in the details from your target database (PostgreSQL).
- Server Name: Enter the endpoint of your PostgreSQL RDS instance.
- Port: Enter the port number (default is 5432).
- Username: Enter your PostgreSQL username.
- Password: Enter your PostgreSQL password.
- Database Name: Enter the name of your PostgreSQL database.
- Click "Create endpoint".
Step 3: Test the Connections
1. Test Source Endpoint Connection:
- In the Endpoints section, select the source endpoint.
- Click on "Test connection" from the dropdown.
Test Connection
Run Test2. Test Target Endpoint Connection:
- In the Endpoints section, select the target endpoint.
- Click on "Test connection" from the dropdown.
- Click "Run test".
Step 4: Create a Database Migration Task
1. Go to Database Migration Tasks
- Click on "Database migration tasks" in the left sidebar.
- Click on "Create task".
2. Configure Migration Task
- Task Identifier: Provide a name for your migration task.
Database Migration TaskDatabase Migration Task:
Database Migration Task- Migration Type: Choose "Migrate existing data and replicate ongoing changes" for minimal downtime migration.
- Selection Roles: Fill in all the details. It contains the details of the source.
Fill details of Selection Roles- Transformation Roles: Fill in all the details. It contains the details of the target.
Fill details of Transformation Roles3. Start the Migration Task
- After creating the task, select it from the list.
- From the dropdown menu, click "Restart/Resume".
Click on the Restart/Resume ButtonStep 5: Verify the Migration
- Connect to your PostgreSQL database using a client like pgAdmin or psql.
- Verify that the data has been migrated correctly from MySQL to PostgreSQL.
- Perform data integrity checks to ensure all data is consistent.
Conclusion
Switching from MySql to PostgreSQL in AWS using the Database Migration Service is a well-sequenced and efficient approach that is not very disruptive and guarantees data consistency. Using the instructions provided in this guide—establishing a replication instance of DMS, generating and checking the endpoints, as well as configuring migration tasks—the migration to a PostgreSQL framework will appear effortless.
After migration is complete, it is necessary to check the correctness of data and further fine-tune the PostgreSQL database for the maximum response rate. Nevertheless, AWS DMS can become truly valuable to aid you in the migration process, as well as in leveraging all the features that PostgreSQL can offer in an AWS environment.
Similar Reads
How to Migrate from MySQL to PostgreSQL?
Migrating from MySQL to PostgreSQL has become a strategic move for businesses and developers seeking improved scalability, performance, and support for complex data types. PostgreSQLâs advanced features and SQL standards make it a preferred choice for high-performance database management. In this ar
4 min read
How to Migrate a PostgreSQL Database to MySQL
Moving a database from one platform to another can be tough, but with careful planning and execution, it can be done smoothly. In this article, we'll go over how to migrate a PostgreSQL database to MySQL, which are both popular RDBMS. We'll cover preparation, schema conversion, data migration, and t
5 min read
How to migrate Postgres to SQL?
When it comes to moving data from one database system to another, it is quite a tricky affair especially when one is transferring data from one DBMS, for instance, PostgreSQL to the other DBMS like SQL Server. SSIS is a very efficient data integration and migration tool where users can transfer data
5 min read
How to Migrate SQL Server Database to MySQL?
The migration of an SQL Server database to MySQL can be an intricate process, but using the ODBC driver facilitates the execution, so no worries for users with basic skills. This guide will take you through transferring the database called 'Work' from Microsoft SQL Server to MySQL, ensuring that all
5 min read
How to Migrate from MySQL to Oracle
Migrating a database from MySQL to Oracle can be a complex yet rewarding endeavor, especially when transitioning between relational database management systems (RDBMS). This guide will explore the step-by-step process of migrating from MySQL to Oracle, covering key concepts, tools, and best practice
4 min read
How to Migrate a MySQL Database to PostgreSQL using pgloader?
Database migration is a common task in software development when switching between different database management systems (DBMS). In this article, we'll explore how to migrate a MySQL database to PostgreSQL using a powerful tool called pgloader. We'll cover the concepts involved, and the steps requir
6 min read
How to Migrate an Oracle Database to MySQL
Migrating databases between different platforms is a common task in the world of data management. Whether you're consolidating databases, switching to a different database management system (DBMS), or moving to a more cost-effective solution, migrating from Oracle to MySQL can be a complex but rewar
5 min read
How to Migrate MySQL to MariaDB in Ubuntu?
Migrating data from MySQL to MariaDB is a straightforward process, given the close compatibility between the two database systems. MariaDB is a popular choice for many organizations due to its enhanced features and improved performance over MySQL. Hereâs a detailed guide on how to migrate your data
7 min read
How to Install PostgreSQL on a Mac with Homebrew
Homebrew is a popular manager that is used for the installation of different types of software in the Mac as well as Linux operating systems. we can use Homebrew for installing other software instead of running specific commands. This improves the security as compared to not using homebrew for the i
6 min read
How to Change the Default Port in PostgreSQL
PostgreSQL is one of the most powerful and widely used relational database management systems (RDBMS) in the world. By default, PostgreSQL listens for incoming connections on port 5432. In this article, we will describe the process of changing the default port for PostgreSQL in detailed and step-by-
6 min read