Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

migrate data from MS SQL to PostgreSQL?

Tags:

I've looked around and can't seem to find anything that answers this specific question.

What is the simplest way to move data from an MS SQL Server 2005 DB to a Postgres install (8.x)?

I've looked into several utilities like "Full Convert Enterprise", etc, and they all fail for one reason or another, ranging from strange errors that make it blow up to inserting nulls rather than actual data (wth?).

I'm looking at a DB with all table except for a single view, no stored procs, functions, etc.

At this point I'm about to write a small utility to do it for me, I just can't believe that's necessary. Surely there's something somewhere that can do this? I'm not even too worried about cost, although free is preferable :)

like image 950
Fred Avatar asked Sep 02 '09 21:09

Fred


People also ask

Is MS SQL better than PostgreSQL?

From the above comparisons, PostgreSQL trumps SQL Server in several scenarios. Not only is it open-source and free, but it also has several features that are easily available and can be implemented automatically, unlike Microsoft SQL Server. Moreover, PostgreSQL has a more suitable concurrency management system.

What is the best way to transfer the data in a PostgreSQL?

If you really have two distinct PostgreSQL databases, the common way of transferring data from one to another would be to export your tables (with pg_dump -t ) to a file, and import them into the other database (with psql ).

Can we migrate MySQL to PostgreSQL?

To connect MySQL to PostgreSQL through Foreign Data Wrapper, you must take note of the following as this is what will be required to create the connection: CREATE EXTENSION command to create a MySQL Foreign Data Wrapper extension to the PostgreSQL host. CREATE SERVER command to define a connection to the MySQL Server.


2 Answers

I don't know why nobody has mentioned the simplest and easiest way using robust MS SQL Server Management Studio.

Simply you just need to use the built-in SSIS Import/export feature. You can follow these steps:

  1. Firstly, you need to install the PostgreSQL ODBC Driver for Windows. It's very important to install the correct version in terms of CPU arch (x86/x64).

  2. Inside Management Studio, Right click on your database: Tasks -> Export Data

  3. Choose SQL Server Native Client as the data source.

  4. Choose .Net Framework Data Provider for ODBC as the destination driver.

  5. Set the Connection String to your database in the following form:

    Driver={PostgreSQL ODBC Driver(UNICODE)};Server=;Port=;Database=;UID=;PWD=

  6. In the next page, you just need to select which tables you want to export. SQL Server will generate a default mapping and you are free to edit it. Probably you`ll encounter some Type Mismatch problems which take some time to solve. For example, if you have a boolean column in SQL Server you should export it as int4.

Microsoft Docs hosts a detailed description of connecting to PostgreSQL through ODBC.

PS: if you want to see your installed ODBC Driver, you need to check it via ODBC Data Source Administrator.

like image 80
Ehsan Mirsaeedi Avatar answered Sep 18 '22 06:09

Ehsan Mirsaeedi


Take a look at the Software Catalogue. Under Administration/development tools I see DBConvert for MS SQL & PostgreSQL. Probably there are other similar tools listed.

like image 37
Milen A. Radev Avatar answered Sep 18 '22 06:09

Milen A. Radev