Data migration from Oracle 10g to Postgres db

a 夏天 提交于 2019-12-24 08:23:49

问题


I want to migrate the data from Oracle 10g database to Postgres db. Oracle SQL developer has data migration option but it seems its only for migrating non oracle db to oracle. Please let me know other options.


回答1:


There's a dedicated tool for that written in Perl: Ora2Pg.

Most databases provide tools for importing from other databases but not exporting to other databases.




回答2:


I have tried using ORA2PG before but it was too complicated so I found my own way to migrate from sql developer to postgres.

Here's a step by step, let me know if you have any questions.

HOW TO MIGRATE DATA FROM THE ORACLE DATABASE TO THE POSTGRES DATABASE!

Tools to download before migration: SQL Developer, WINSCP

SQL Developer

  • Step 1: Login into the Oracle server using SQL Developer
  • Step 2: Right click on the schema name > Export > Change for the format to CSV and the encoding to UTF-8. (Make sure Export DDL is unchecked) (Make sure the filename is finished with .csv )
  • Step 3: Click next > next > Finish (Wait till the exporting is done)

ONCE THE FILE FROM SQL DEVELOPER IS EXPORTED

  • Right click on the csv file, click on open with and open it with Notepad. Click File > Save as > Change encoding to UTF-8 and save it.

Open WINSCP

  • STEP 1: Before logging in into your server, click on edit > Advanced > Turn ON ‘UTF-8 encoding for filenames’.
  • STEP 2: Login into your server
  • STEP 3: Click on Settings > Internal Editors > Change the Default encoding to UTF-8 > Click Ok
  • STEP 4: Create a new directory anywhere on your server and drag your file to that directory into WINSCP

Now the file should be on your server with the UTF-8 encoding.

Open putty

Before logging in into your server with Putty, click on Translation and change the Received data assumed to be in which character set to UTF-8 then click on DATA and change the Terminal-type string to Putty then login into your server.

Once you logged in into your server with Putty, Run the command:

Locale charmap

This command will show you the default encoding of the server.

Run that command after:

 grep -Rw '/home/pgadmin/data1/1234.csv' -e 'fre' 
  • data1 = Directory created on the server
  • 1234.csv = Csv file inside the data1 Directory

This command will show you if the French word in your document are still lost or not. The '/home/pgadmin/data1/1234.csv' in that command is where your file is located on your server and ‘1234.csv’ is the name of the CSV file. If everything is good after running that command, now we’re able to put it on the Postgres database.

After entering the postgres database with the command “psql”

  • Step 1: Make sure you have created your own database, schema and table (if you don’t know how, Scroll down to the end of the document).
  • Step 2: After creating your own database, schema and table, we can run the copy command.
\Copy joe.data01 FROM ‘home/pgadmin/data1/1234.csv’  DELIMITER ‘,’ CSV HEADER encoding ‘UTF-8’  ;

If the file already has column names on the csv file, add “HEADER” in the command. joe.data01= Name of table created home/pgadmin/data1/1234.csv = Location of the file on the server

To view if the schema was copied, simply run the command select * from joe.data01;

To view if French words are not lost, run the command select * from joe.data01 where isa = ‘fre’ ;

  • How to create a Database on Postgres: CREATE DATABASE name_of_database ;
  • How to create a Schema on Postgres: CREATE SCHEMA name_of_schema;
  • How to create a Table on Postgres: create table joe.data01 (ccca CHAR(50) NOT NULL, isa CHAR(70) NOT NULL, co CHAR(150) NOT NULL) ;



回答3:


We ended up migrating a fairly large database (~100 schema, with >1000 tables) from Oracle to Postgres using the approach outlined at: https://github.com/MIT-LCP/oracle-to-postgres.

You can install the package with pip install oracle2postgres. More information is at: https://pypi.org/project/oracle2postgres/

A Jupyter Notebook demonstrating the approach is at: https://github.com/MIT-LCP/oracle2postgres/blob/master/migration.ipynb.

Our general approach was to mirror the source database; convert data types where necessary; create the target database; copy across the data in chunks. It's a slightly hacky solution, but it worked well for us.

# import the package
import oracle2postgres

# create the logfile
oracle2postgres.create_logfile()

# get source database settings
source_config = oracle2postgres.get_source_config()

# get target database settings
target_config = oracle2postgres.get_target_config()

# get settings for migration
migration_config = oracle2postgres.get_migration_config()

# check the schema exist on the source database
source_engine = oracle2postgres.connect_to_source(source_config)
oracle2postgres.check_schema_exist(source_engine,source_config['schema_list'])

# check for null characters in strings in the source database
# if found, they can be removed as explained in the documentation
oracle2postgres.check_for_nulls(source_engine,source_config['schema_list'])

# create a new database on the target database
target_engine = oracle2postgres.connect_to_target(target_config)
oracle2postgres.create_database(target_config['database'],target_engine)

# create schema on the target database
target_engine = oracle2postgres.connect_to_target(target_config,target_config['database'])
oracle2postgres.create_target_schema(source_config['schema_list'],source_engine,target_engine)

# run the migration
oracle2postgres.migrate(source_config,target_config,migration_config)

If you hit problems when reusing the code, feel free to raise an issue if so and we'll do our best to help.




回答4:


  • expand the tables section,
  • then select tables you want to export
  • right click, select export,
  • then select format and export (preferably insert statements or csv)


来源:https://stackoverflow.com/questions/14837191/data-migration-from-oracle-10g-to-postgres-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!