Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating from Postgres to SQL Server 2008

I need to migrate a database from Postgres 7 to SQL Server 2008. I am familiar with the SSIS Import and Export wizard but I am stumped about how to define the data source or define the data provider.

What is the best way to migrate Postgres to SQL Server, and how do I define data sources/drivers for postgres?

like image 908
reach4thelasers Avatar asked Sep 14 '10 16:09

reach4thelasers


People also ask

Why use SQL Server instead of Postgres?

PostgreSQL supports index-based table organization, but the early versions didn't use automatic index updates. It also allows you to look up many indexes in a single search, which means that you can discover a lot of information. SQL Server provides rich automated functionality for index management.

Is PostgreSQL outdated?

The PostgreSQL Global Development Group supports a major version for 5 years after its initial release. After its five year anniversary, a major version will have one last minor release containing any fixes and will be considered end-of-life (EOL) and no longer supported.


1 Answers

I wish you the best of luck in trying to import from PostgreSQL into SQL Server using SQL Server Import and Export Wizard. However, I have read numerous message board threads with people having trouble getting it to work. For example:

  • Import Data from Postgresql to SQL Server 08 Error

Here is the most helpful thread that I have found on the topic:

  • Import data from postgreSQL into SQL server 2005

To help someone who might be trying to achieve similar goal as mine. Instead of selecting the “PostgreSQL OLE DB Provider” in the data source drop down menu of SQL Server Import and Export Wizard, select “.Net Framework Data Provider for Odbc”

Then you have to make a DSN and provide a ConnectionString. Following ConnectionString worked for me

Driver={PostgreSQL};Server=localhost;Port=5432;Database=TestMasterMap;Uid=postgres;Pwd=;

To make a DSN you have to go into Administrative Toolsà Data Sources (ODBC) and create a user DSN. Once this is done you can supply the DSN name in the DSN text box of SQL Server Import and Export Wizard.


One commenter claimed that it worked, but that he got "Out of memory while reading tuples" errors on big tables. So for tables with more than 3 million rows, he had to break the import up into 3 million row chunks.

Also, there's a link to the native .NET provider for PostgreSQL in that thread.

Personally, if this is something that I only had to do once, and if I understood the schema and the data fairly well, I would try:

  1. export the data from PostgreSQL as flat files
  2. create the schema in SQL Server (without PKs or constraints)
  3. use the SSIS Import/Export Wizard to import the flat files
  4. then create PKs and necessary constraints

It might take you less time to do the above than messing with SSIS Import/Export Wizard and PostgreSQL for days (but it would be nice if those tools worked!)

like image 91
JohnB Avatar answered Sep 20 '22 09:09

JohnB