從Ubuntu 換到 Mac 後,就不知道要寫什麼文章了,哈~~

已經好久沒發文了。

最近在看怎麼將Oracle 移轉到 PostgreSQL 。

聽宣瑋爸說他是用 Ora2Pg,所以我也來研究一下。

現在版本已經到 8.1 了。

聽宣瑋爸說 7.1 中文會有亂碼的問題。

所以我就來試試看最新的 8.1 。

在這裡,隨便記一下安裝的過程。

因為是灌完後,才來回想怎麼安裝。所以就…有點亂。

首先安裝 Ora2Pg:

# wget http://pgfoundry.org/frs/download.php/2983/ora2pg-8.1.tar.bz2
# tar -xvf ora2pg-8.1.tar.bz2
# cd ora2pg-8.1/
# perl Makefile.PL
# make
# make install

雖然安裝完了。但…執行

# /usr/local/bin/ora2pg -h

就會出現錯誤訊息。

照著他說的錯誤訊息,就開始亂找要裝什麼東西,

亂裝亂裝就好了~ @ @

我裝了些啥哩:

perl-DBD-Pg   ( 上圖的錯誤,裝這個就好了 zypper in per-DBD-Pg)

postgresql

oracle-instant-client

 

另外因為下圖中的錯誤,我還裝了 DBD-Oracle 1.28

DBD-Oracle 就沒辦法用 zypper 裝了,要自己去下載來裝

# wget http://search.cpan.org/CPAN/authors/id/P/PY/PYTHIAN/DBD-Oracle-1.28.tar.gz
# tar -zxvf DBD-Oracle-1.28.tar.gz
# cd DBD-Oracle-1.28/
# perl Makefile.PL -V 10.0.0 (直接指定Oracle 版本為10.0.0)
# make
# make install

# 環境變數可能也要加一下,ORACLE_HOME  LD_LIBRARY_PATH  etc...

這次再執行ora2Pg -h ,就正常執行了。

接著就要修改 /etc/ora2pg/ora2pg.conf

在這裡記錄幾個比較常改的地方:

# Set the Oracle home directory
ORACLE_HOME     /home/oracle

# Set Oracle database connection (datasource, user, password)
# Your SID should be declared on your tnsnames.ora file
ORACLE_DSN      dbi:Oracle:host=10.10.10.10;sid=dev;port=1521
ORACLE_USER     chingwei
ORACLE_PWD      xxxxxxx

# Type of export. Values can be the following keyword:
#       TABLE           Export tables
#       PACKAGE         Export packages
#       DATA            Export datas from table as INSERT statement
#       COPY            Export datas from table as COPY statement
#       VIEW            Export views
#       GRANT           Export grants
#       SEQUENCE        Export sequences
#       TRIGGER         Export triggers
#       FUNCTION        Export functions
#       PROCEDURE       Export procedures
#       TABLESPACE      Export tablespace (PostgreSQL >= 8 only)
#       TYPE            Export user defined Oracle types
#       PARTITION       Export range or list partition (PostgreSQL >= v8.4)
#       可以一次指定多種 TYPE
TYPE    TABLE

# Set which table to export from. By default export from all tables.
# Additionally the extraction will respect the table list order given
# here. This is usefull if you have lots of foreign key constraints.
# Value must be a list of table name separated by space.
#       可以一次指定多個 Table
TABLES  LOG

# Extract data by bulk of DATA_LIMIT tuples at once. Default 10000. If you set
# a high value be sure to have enougth memory if you have million of rows.
DATA_LIMIT      10000

# By default all output is dump to STDOUT if not send directly to postgresql
# database (see above). Give a filename to save export to it. If you want
# a Gzipped compressed file just add the extension .gz to the filename, you
# need perl module Compress::Zlib from CPAN. Add extension .bz2 to use Bzip2
# compression
#OUTPUT         output.sql.gz
#OUTPUT         output.sql.bz2
OUTPUT          output.sql

當然裡面還有很多設定可以改。

我只是大概記幾個。

改完後,就執行 ora2pg 就會執行了。輸出的檔案,就會放在你執行時的資料匣下。

如果要指定輸出的檔名就加上 -o xxxx.sql 即可。

-c 可以指定要使用的config file。

這些用 ora2pg -h 都看的到。

經過測試後,發現轉存到PostgreSQL後,中文也可以正常呈現,沒有亂碼。

太棒了,哈~~

接著就是要解決有時候在 Oracle 輸出時,或 PostgreSQL 匯入時,會有些語法上的錯誤。

希望接下來能順利解決這些問題~~

ps. PostgreSQL 匯入方式,可以下 psql  db < output.sql

 

arrow
arrow
    全站熱搜

    Ching-Wei 發表在 痞客邦 留言(0) 人氣()