简体   繁体   中英

Migrate data from SQL Server to PostgreSQL

I have a stored procedure function as well as table in the SQL Server enterprise 2014. I also have data in the table. Now I need same table and data in PostgreSql(pgAdmin4).

Can anyone suggest to me the idea to migrate data to POSTGRESQL or any idea on creating the SQL script so that I can use psql to run the script?

Depending on how much data you have, you could script out the table and data. Then you could tweak the script as needed for PostgreSQL:

  1. Right click on the SQL database > Tasks > Generate Scripts
  2. On the "Choose Objects" screen, select your specific table then select "Next>"
  3. On the "Set Scripting Options" screen, select "Advanced"
  4. Find the option called "Types of data to script", then select "Schema and data" and select "OK"
  5. Set the filename and continue through the dialog until the file is generated
  6. Tweak the sql script for any specific PostgreSQL syntax

If there is a larger amount of data, you might look into some type of data transfer tool like SSIS.

Exporting the table structure and data as Josh Jay describes will likely require some fixes where the syntax doesn't match, but it should be doable if not tedious. Luckily there are existing conversion tools available to help.

You could also try using a foreign data wrapper to map the tables in SQL Server to a running instance of PostgreSQL. Then it's just a matter of copying tables. Depends on your needs and where each database server is located relative to one another.

The stored procedures will be far more difficult to handle unfortunately. While Oracle's pl/sql language is substantially similar to PostgreSQL's pl/pgsql, MS SQL Server/Sybase's TransactSQL dialect on the other hand is different enough to require rewrites. If the TransactSQL functions also access .Net objects, the migration task may end up far more difficult as you reimplement dependencies or find logical equivalents.

You can use Navicate a powerful GUI tool for working with various databases including Postgres and SQL Server. You can transfer both schema and data easily as follows:

  1. Create two connection for source and target database

在此处输入图片说明

  1. Go to Tools -> Data Transfer

Select source database and target database with its IP, database name and schema在此处输入图片说明

as you can see in the option, if target table is not exist, it would create

Tada, it takes 10 mins to transfer whole my 63 tables and its data from Postgres to SQL Server.

Enjoy it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM