Skip to content

Migration of On-Prem Postgres DB in Ubuntu to Azure Postgres using DMS

Notifications You must be signed in to change notification settings

bijuthottathil/DMS-Migration-PostgresDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 

Repository files navigation

image

Intent is to migrate postgres DB Version 12 installed in Ubuntu System to Azure Postgres DB

1 st step, we need to install Postgres 12 in Ubuntu

image

Installing PostgreSQL 12 on Ubuntu

Run the following command to create the file repository configuration:

sudo usermod -aG sudo postgres sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' Import the repository signing key by running the following command

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - Update the package lists apt a.k.a Advanced Packaging Tool by running the following command

sudo apt update

sudo apt -y install postgresql-12

image

image

Add Postgres User to SUDO Group

sudo usermod -aG sudo postgres

Now we are ready with source postgres db in ubuntu

Now, enter the following command to into the PostgreSQL shell:

psql

image

image

CREATE DATABASE mytestdb;

CREATE USER mytestuser WITH ENCRYPTED PASSWORD 'postgres';

GRANT ALL PRIVILEGES ON DATABASE mytestdb to mytestuser;

image

sudo nano /etc/postgresql/12/main/postgresql.conf

image

sudo systemctl restart postgresql

image

image

image

Server is ready

image

image

image

DB server is ready now

Creating blank DB in Destination Server

image

image

Next we need to create Replicatio role

create role db_migrationuser with login superuser createdb createrole inherit replication connection limit -1 password 'postgres'

grant postgres to db_migrationuser

new role created in onprem DB

image

image

need to do some config changes

sudo nano /etc/postgresql/12/main/pg_hba.conf

image

Use pg_dump -s command to create a schema dump file for a database.

pg_dump -O -h 20.29.58.169 -U postgres -d mytestdb -s > mytestdb_schema.sql;

image This is the schema content

image

Deploying this schema to Azure destinatio database

psql -h vmpostgresazure.postgres.database.azure.com -U postgres -d mytestdb < mytestdb_schema.sql

image

you can see schema created in destination Azure DB

image

Remember, only schema is loaded

image

Next step is to create DMS for migration

image

image

image

Created a migration project in DMS image

image

image

I am migrating only one database

image

image

image

image

Migration initiated

image

image

image

Migration is successfully completed for one table

image

Now I am going to add new rows in Ubuntu Onprem DB

image

image

Immediately all new records migrated to Azure DB

image

image

Migration of table data and incriment load is working fine

Now I am going to edit this project and adding new table in ubuntu postgres DB

Created new table and added few records in source DB

image

image

We need to add new activity for the new migration and use pg_pump to push new schema changes to destination DB

image

for existing tables, you will get error message, but schema will copy to destination DB

image image

image

Now come back and proceed with new activity to include new table

image

If existing table, it will truncate data

image

Both tables are loaded fully in destination DB image

image

image

You can see list resources used for this live DB migration activities

image

About

Migration of On-Prem Postgres DB in Ubuntu to Azure Postgres using DMS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published