http://powergres.sra.co.jp/s/ja/tech/plus/experience/vol4/oracle_migration2.php http://blog.livedoor.jp/loopus/archives/50311640.html !!!準備 !!Perl perlを使える状態にしておく !!Ora2pg !ダウンロード http://pgfoundry.org/projects/ora2pg から Ora2pg をダウンロードするして解凍する {{ref ora2pg-6.3.tar.bz2}} !コンパイル?(必要ないかも) 解凍したディレクトリで perl Makefile.PL を実行する。 Ora2Pg.pm が出来上がればOK. !!移行用のスクリプトを作成 #!/usr/bin/perl BEGIN { $ENV{ORACLE_HOME}='C:\oraclexe\app\oracle\product\10.2.0\server'; $ENV{NLS_LANG} = 'JAPANESE_JAPAN.JA16SJISTILDE'; } use strict; use Ora2Pg; my $schema=new Ora2Pg ( datasource=>'dbi:Oracle:host=localhost;sid=xe;port=1521', user=>'system', password=>'manager', schema=>'orauser', type=>'TABLE', debug=>1 ); $schema->export_schema('C:\temp\schema.sql'); exit(0); 見たいな感じのを作る。 :$ENV{ORACLE_HOME}:Oracleをインストールしたディレクトリ。Linuxだと{{br}}$ENV{ORACLE_HOME}='/home/oracle/app/oracle/product/10.1.0/db_1';{{br}}とか。 : $ENV{NLS_LANG} :Oracleの文字コード :datasource:Oracleに接続するための情報 :user:Oracleへ接続するためのユーザー。 dba_usersなどにアクセス出来るユーザ。 :password:上記ユーザのパスワード :schema:移行対象のスキーマ :type: ,TABLE, "Extract all tables with indexes, primary keys, unique keys,foreign keys and check constraints." ,VIEW, "Extract only views." ,GRANT, "Extract roles converted to Pg groups, users and grants on all objects." ,SEQUENCE, "Extract all sequence and their last position." ,TABLESPACE, "Extract storage space, need PostgreSQL >= v8." ,TRIGGER," Extract triggers defined following actions." ,FUNCTION," Extract functions." ,PROCEDURES," Extract procedures." ,PACKAGE," Extract packages and package bodies." ,DATA," Extract datas as INSERT statement." ,COPY," Extract datas as COPY statement." ,PARTITION," Extract range and list Oracle partitioning." ,TYPE, "Extract user defined Oracle type." {{word 個人的には、DATA より COPY の方がファイルのサイズが小さくなるのでオススメ。,red}} :export_schema('パス');:スキーマの出力先。{{br}}/home/oracle/data_for_migrate/schema.sql{{br}}とか。 !!!移行作業 !!1.Oracleからエクスポート 準備作業で作成した移行用スクリプトを実行する。 !!2.「5C問題」の対応(Oracleの文字コードがSJISの場合) Oracleの文字コードがSJISの場合、5C問題の関係で出力ファイルに不要な「\」が 出力される。 use Encode; my $file = shift; open(IN, $file) or die "Can't open $file: $!\n"; while(){ $tmp = $_; # $tmp =~ s/\\\\/\\/g; $tmp =~ s/([\x81-\x9f\xe0-\xfc]\\)\\/\1/g; Encode::from_to($tmp, "shiftjis", "utf8" ); print $tmp; } close(IN); こんなスクリプトを書いて、convert.pl として保存する。 1.で出力したファイルを data.sql とした場合 perl convert.pl data.sql > data_utf8.sql と実行して、不要な「\」を取り除いてUTF8に変換。 {{word インポートを行う環境がUTF8じゃなければ、utf8への変換は不要,red}} !!3.Postgresqlへインポート psql -h ホスト名 -U ユーザー -f インポートファイル データベース名 または、psql 内で psql => \i インポートファイル でインポート。 !!!orafce http://orafce.projects.postgresql.org/index-ja.html orafce の目的は Oracle Database で使用できる関数と互換性のある関数を PostgreSQL に実装することです。 個人的な感想としては意外と{{word 使えない,red}}。 !!インストール http://pgfoundry.org/frs/?group_id=1000113 から rpm をダウンロード。 {{ref orafce-3.0.1-1.pg84.rhel5.x86_64.rpm}} rpm -ihv orafce-xxxxxx.rpm でインストール。終わったら psql -U postgres testdb < orafunc.sql でスクリプト実行。 orafunc.sql は、/usr/share/pgsql/contrib あたりにあるはず。 無ければ、find で検索。 {{category2 データベース,Postgresql}} {{category2 データベース,Oracle}}