From:       To:      
Home > Documentation > SQL Server to Postgres

Open-source SQL Server to Postgres Converters

Database migration between advanced DBMS is non-trivial task that requires a lot of time and efforts. This article explores different tools for database migration from SQL Server or Azure SQL to PostgreSQL.

First open-source solution is pgloader, a well-known tool that migrates schemas, data, indexes, and foreign keys from SQL Server into PostgreSQL.

Features:

Simplest example of running SQL Server to Postgres migration via pgloader is illustrated by the following command line:

$ pgloader mssql://mssql_user@mssql_host/mssql_dbname pgsql://pgs_user@pgs_host/pgs_dbname

where mssql_user, mssql_host, mssql_dbname, pgs_user, pgs_host, pgs_dbname must be replaced by actual SQL Server and PostgreSQL username, host and database name.

Sqlserver2pgsql

Next open-source solution to automate database migration from Microsoft SQL Server to Postgres is Sqlserver2pgsql script written in Perl.

Features:

Although Sqlserver2pgsql is a cross-platform tool, it is recommended to run it inside a Docker container to simplify distribution of the required environment. So, here are the key statements for building proper container for SQL Server to Postgres migration using Sqlserver2pgsql:

Now you can run the migration through the following command line statement:

docker run --name sqlserver2psql --rm -e SRC_HOST= \
  -e SRC_USER= -e SRC_PWD="" \
  -e SRC_DB= -e DEST_HOST= \
  -e DEST_PORT=5432 -e DSET_USER= \
  -e DEST_PWD= -e DEST_DB=""
  --mount type=bind,source="$(pwd)"/conf,target=/opt/data_migration/conf \
  sqlserver2psql /scripts/migrate.sh

Both of these tools do not migrate views (as CREATE VIEW statements), stored procedures, triggers and have no advanced capabilities on customization of metadata and migration rules. Besides, pgloader and Sqlserver2pgsql are only available in form of console tools that may be not comfortable for users not so familiar with command line.

For those who look for easy way of running SQL Server to Postgres migration or need to deeply customize the process, the most reasonable option is dedicated commercial software with intuitive graphical interface. One of those tools is SQL Server to PostgreSQL converter.