18th September 2021

Migrating from MS-SQL Server to PostgreSQL Database

First, we need a SQL Server with the “AdventureWorks2014” database. Secondly, we will need a Windows/Linux system with PostgreSQL 10/11/12/13 version installed. The database we will transfer is as shown in the picture below. Now, for a quick and easy migration, we will use the project ready from the link “https://github.com/isapir/Migrate2Postgres”. We download the project to our computer.

database to transfer
database to transfer

 

After downloading the project, we put the “migrate.bat” file in “examples > bin” and the “MsSqlAWT2Postgres.conf” file in “examples → conf” into the home directory of the same project.

Migrate2Postgre
Migrate2Postgre
MsSqlAWT2Postgres.conf
MsSqlAWT2Postgres.conf

 

Now we will edit the “Conf” file. When we open the “conf” file with a text editor, a ready-made template for “AdventureWorks” will appear. We will only be entering the necessary information here. You can see the screen below for the places to be fixed in the “conf” file.

 

LEARN MORE  "The license for ePolicy Orchestrator is invalid" and "Login failed. The login is from an untrusted domain and cannot be used with Integrated authentication" Error and Solution

Then we open our file on the command line (cmd).

And we enter the code. We are running our migration file.

migrate.bat ddl
migrate.bat DDL

 

It has created a sql file in the specified path using the “config” file written as specified in the field we marked with red. You need to open the resulting file with a text editor and run it in PostgreSQL. With this process, you create the “DDL” structure of the source database on the PostgreSQL side. After running the DDL Script, you can see that the “AdventureWorks” database is created on the PostgreSQL side without any errors.

The resulting file
The resulting file

 

Finally, we need to transfer the “DML” contents that exist in SQL Server, and it will be sufficient to run the “migrate.bat” file as follows.

When you check after the transfers are complete, you will see that your existing data in SQL Server will be transferred to PostgreSQL.

 

Leave a Reply

Your email address will not be published. Required fields are marked *