ORACLE 遷移到 PG 之 ora2pg


1       ORACLE 遷移到 PG

1.1   使用ora2pg 工具

 

1.1.1     ora2pg簡介

Ora2Pg是一個免費的工具,用於將Oracle數據庫遷移到PostgreSQL兼容的模式。它連接您的Oracle數據庫,自動掃描並提取它的結構或數據,然后生成可以裝載到PostgreSQL數據庫的SQL腳本。Ora2Pg可以從逆向工程Oracle數據庫到大型企業數據庫遷移,或者簡單地將一些Oracle數據復制到PostgreSQL數據庫中。它非常容易使用,並且不需要任何Oracle數據庫知識,而不需要提供連接到Oracle數據庫所需的參數。

Ora2Pg 由一個 Perl 腳本(ora2pg)以及一個 Perl 模塊(Ora2Pg.pm)組成,唯一需要做的事情就是修改它的配置文件 ora2pg.conf,設置連接 Oracle 數據庫的 DSN 和一個可選的模式名稱。完成之后,只需要設置導出的類型:TABLE(包括約束)、VIEW、MVIEW、TABLESPACE、SEQUENCE、INDEXES、TRIGGER、GRANT、FUNCTION、PROCEDURE、PACKAGE、PARTITION、TYPE、INSERT 或 COPY、FDW、QUERY、KETTLE 以及 SYNONYM。

默認情況下,Ora2Pg 導出一個文件,可以通過 psql 客戶端將文件加載到 PostgreSQL 數據庫;但是也可以在配置文件中設置一個數據庫的 DSN,直接導入 PostgreSQL 數據庫。通過 ora2pg.conf 中的配置選項,可以控制導出的內容和方式。

對象

ora2pg是否支持

view

trigger

是,某些情況下需要手工修改腳本

package

是,某些情況下需要手工修改腳本

sequence

function

procedure

是,某些情況下需要手工修改腳本

type

是,某些情況下需要手工修改腳本

materialized view

是,某些情況下需要手工修改腳本

 

 

1.1.2     環境描述

本實驗以ORACLE 11.2.0.3 on LINUX  sample 數據為例,遷移psql (11.2) on LINUX .

內容

源端

目標端

IP

10.85.10.6

10.85.10.5

數據庫

oracle 11.2.3

postgres 11.2

實例名

PROD1

orcl

操作系統

redhat 5.4

redhat 7.4

遷移數據

SH SCOTT HR

SH SCOTT HR

 

1.1.3     依賴環境安裝

perl版本5.10以上

 

[root@test01 ~]# yum install -y perl perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker

 

[root@test01 ~]# perl -v

 

This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi

(with 33 registered patches, see perl -V for more detail)

 

Copyright 1987-2012, Larry Wall

 

Perl may be copied only under the terms of either the Artistic License or the

GNU General Public License, which may be found in the Perl 5 source kit.

 

Complete documentation for Perl, including FAQ lists, should be found on

this system using "man perl" or "perldoc perl".  If you have access to the

Internet, point your browser at http://www.perl.org/, the Perl Home Page.

 

 

安裝oracle 客戶端

1.下載所需的Instant Client RPM軟件包。所有安裝都需要基本或基本輕型RPM。

2.安裝包yum。請注意,從19.3開始,默認情況下,一次只能安裝一個版本的Instant Client RPM庫。

 
[root@test01 soft]# rpm -ivh oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm

[root@test01 soft]#rpm -ivh oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm

[root@test01 soft]#rpm -ivh oracle-instantclient12.2-jdbc-12.2.0.1.0-1.x86_64.rpm

[root@test01 soft]# rpm -ivh oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm

 

3.在19.3之前,如果Instant Client是此系統上安裝的唯一Oracle軟件,則更新運行時鏈接路徑,例如:

 

[root@test01 bin]# echo /usr/lib/oracle/18.3/client64/lib > /etc/ld.so.conf.d/oracle-instantclient.conf

 

使用ldconfig舊版本的替代方法是LD_LIBRARY_PATH在運行應用程序之前在每個shell中設置環境變量。例如:

[root@test01 bin]# export LD_LIBRARY_PATH=/usr/lib/oracle/18.3/client64/lib:$LD_LIBRARY_PATH export PATH=/usr/lib/oracle/18.3/client64/bin:$PATH

 

 

 

安裝DBI

下載地址:https://metacpan.org/release/DBI


# tar -zxvf DBI-1.642.tar.gz

# cd DBI-1.642

# perl Makefile.PL

# make

# make install

 

 

安裝DBD-Oracle

下載地址:https://sourceforge.net/projects/ora2pg/

設置環境變量; 加載環境變量;因為必須定義ORACLE_HOME環境變量;本例在postgres用戶下配置環境變量

export LD_LIBRARY_PATH=/usr/lib/oracle/18.3/client64/lib:$LD_LIBRARY_PATH

export ORACLE_HOME=/usr/lib/oracle/18.3/client64

 

 

# tar -zxvf DBD-Oracle-1.76.tar.gz # source /home/postgres/.bashrc

# cd DBD-Oracle-1.76

# perl Makefile.PL

# make

# make install

 

安裝DBD-PG(可選)

下載地址:https://metacpan.org/release/DBD-Pg/

設置環境變量:

export POSTGRES_HOME=/opt/pgsql/11.2

 

# tar -zxvf DBD-Pg-3.80.tar.gz

# source /home/postgres/.bashrc

# cd DBD-Pg-3.8.0

# perl Makefile.PL

# make

# make install

 

 

 

1.1.4     安裝Ora2pg

下載地址:https://sourceforge.net/projects/ora2pg/

 

[root@Test01 ~]# tar -xjf  ora2pg-20.0.tar.bz2

[root@Test01 ~]# cd ora2pg-xx/

[root@Test01 ~]# perl Makefile.PL  PREFIX=<your_install_dir>

 

[root@Test01 ora2pg-18.2]# make && make install

 

 

默認安裝在/usr/local/bin/目錄下

檢查軟件環境:

[root@Test01 ~]# vi check.pl

#!/usr/bin/perl

use strict;

use ExtUtils::Installed;

my $inst= ExtUtils::Installed->new();

my @modules = $inst->modules();

foreach(@modules)

{

        my $ver = $inst->version($_) || "???";

        printf("%-12s --  %s\n", $_, $ver); 

}

exit;

 

[root@test01 bin]# perl check.pl

DBD::Oracle  --  1.76

DBD::Pg      --  3.8.0

DBI          --  1.642

Ora2Pg       --  20.0

Perl         --  5.16.3

 

    

設置環境變量

export PERL5LIB=<your_install_dir>

#export PERL5LIB=/usr/local/bin/

 

 

1.1.5   源端准備工作

更新oracle統計信息 提高性能

 

BEGIN

DBMS_STATS.GATHER_SCHEMA_STATS('SH');

DBMS_STATS.GATHER_SCHEMA_STATS('SCOTT');

DBMS_STATS.GATHER_SCHEMA_STATS('HR');

DBMS_STATS.GATHER_DATABASE_STATS ;

DBMS_STATS.GATHER_DICTIONARY_STATS;

END;
/

 

查詢源端對像對類型

 

SYS@PROD1>set pagesize 200

SYS@PROD1>select distinct OBJECT_TYPE from  dba_objects where OWNER in ('SH','SCOTT','HR') ;

OBJECT_TYPE

-------------------

INDEX PARTITION

TABLE PARTITION

SEQUENCE

PROCEDURE

LOB                                X

TRIGGER

DIMENSION                          X

MATERIALIZED VIEW

TABLE

INDEX

VIEW

11 rows selected.

 

 

1.1.6   ora2pg導出表結構

 配置ora2pg.conf:

默認情況下,Ora2Pg會查找/etc/ora2pg/ora2pg.conf配置文件,如果文件存在,您只需執行:/usr/local/bin/ora2pg

cat /etc/ora2pg/ora2pg.conf.dist  | grep -v ^# |grep -v ^$ >ora2pg.conf

vi ora2pg.conf

 

[root@test01 ora2pg]# cat ora2pg.conf

ORACLE_HOME     /usr/lib/oracle/18.3/client64

ORACLE_DSN      dbi:Oracle:host=10.85.10.6 ;sid=PROD1;port=1521

ORACLE_USER     system

ORACLE_PWD      oracle

SCHEMA          SH

EXPORT_SCHEMA  1         # 將用戶導入到PostgreSQL數據庫中 DISABLE_UNLOGGED  1       #避免將NOLOGGING屬性設為UNLOGGED

SKIP  fkeys ukeys checks      #跳過外鍵 唯一 和檢查約束

 

TYPE            TABLE,VIEW,GRANT,SEQUENCE,TABLESPACE,PROCEDURE,TRIGGER,FUNCTION,PACKAGE,PARTITION,TYPE,MVIEW,QUERY,DBLINK,SYNONYM,DIRECTORY,TEST,TEST_VIEW

NLS_LANG    AMERICAN_AMERICA.UTF8

OUTPUT     sh.sql

 

注:1. 只能同時執行一種類型的導出,因此TYPE指令必須是唯一的。如果您有多個,則只會在文件中找到最后一個。但我測試就可以同時導出多個類型的。

     2. 請注意,您可以通過向TYPE指令提供以逗號分隔的導出類型列表來鏈接多個導出,但在這種情況下,您不能將COPY或INSERT與其他導出類型一起使用。

3. 某些導出類型不能或不應該直接加載到PostgreSQL數據庫中,仍然需要很少的手動編輯。GRANT,TABLESPACE,TRIGGER,FUNCTION,PROCEDURE,TYPE,QUERY和PACKAGE導出類型就是這種情況,特別是如果您有PLSQL代碼或Oracle特定SQL。

4.對於TABLESPACE,您必須確保系統上存在文件路徑,對於SYNONYM,您可以確保對象的所有者和模式對應於新的PostgreSQL數據庫設計。

5. 建議導出表結構時,一個類型一個類型的操作,避免其它錯誤相互影響。

 

測試連接

設置Oracle數據庫DSN后,您可以執行ora2pg以查看它是否有效:

[root@test01 ora2pg]#  ora2pg -t SHOW_VERSION -c config/ora2pg.conf

WARNING: target PostgreSQL version must be set in PG_VERSION configuration directive. Using default: 11

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0

 

遷移成本評估

估算從Oracle到PostgreSQL的遷移過程的成本並不容易。為了獲得對此遷移成本的良好評估,Ora2Pg將檢查所有數據庫對象,所有函數和存儲過程,以檢測是否仍有一些對象和PL / SQL代碼無法由Ora2Pg自動轉換。

Ora2Pg具有內容分析模式,該模式檢查Oracle數據庫以生成有關Oracle數據庫包含的內容和無法導出的內容的文本報告。

[root@test01 ora2pg]# ora2pg -t SHOW_REPORT --estimate_cost  -c ora2pg.conf

WARNING: target PostgreSQL version must be set in PG_VERSION configuration directive. Using default: 11

[========================>] 11/11 tables (100.0%) end of scanning.                       

[========================>] 11/11 objects types (100.0%) end of objects auditing.              

-------------------------------------------------------------------------------

Ora2Pg v20.0 - Database Migration Report

-------------------------------------------------------------------------------

Version Oracle Database 11g Enterprise Edition Release 11.2.0.3.0

Schema  SH

Size    287.25 MB

 

-------------------------------------------------------------------------------

Object  Number  Invalid Estimated cost  Comments        Details

-------------------------------------------------------------------------------

DATABASE LINK   0       0       0       Database links will be exported as SQL/MED PostgreSQL's Foreign Data Wrapper (FDW) extensions using oracle_fdw.

DIMENSION       5       0       0

GLOBAL TEMPORARY TABLE  0       0       0       Global temporary table are not supported by PostgreSQL and will not be exported. You will have to rewrite some application code to match the PostgreSQL temporary table behavior.

INDEX   20      0       3.4     14 index(es) are concerned by the export, others are automatically generated and will do so on PostgreSQL. Bitmap will be exported as btree_gin index(es) and hash index(es) will be exported as b-tree index(es) if any. Domain index are exported as b-tree but commented to be edited to mainly use FTS. Cluster, bitmap join and IOT indexes will not be exported at all. Reverse indexes are not exported too, you may use a trigram-based index (see pg_trgm) or a reverse() function based index and search. Use 'varchar_pattern_ops', 'text_pattern_ops' or 'bpchar_pattern_ops' operators in your indexes to improve search with the LIKE operator respectively into varchar, text or char columns.      11 bitmap index(es). 1 domain index(es). 2 b-tree index(es).

INDEX PARTITION 196     0       0       Only local indexes partition are exported, they are build on the column used for the partitioning.

JOB     0       0       0       Job are not exported. You may set external cron job with them.

MATERIALIZED VIEW       2       0       6       All materialized view will be exported as snapshot materialized views, they are only updated when fully refreshed.

SYNONYM 0       0       0       SYNONYMs will be exported as views. SYNONYMs do not exists with PostgreSQL but a common workaround is to use views or set the PostgreSQL search_path in your session to access object outside the current schema.

TABLE   11      0       1.1     1 external table(s) will be exported as standard table. See EXTERNAL_TO_FDW configuration directive to export as file_fdw foreign tables or use COPY in your code if you just want to load data from external files.     Total number of rows: 1063384. Top 10 of tables sorted by number of rows:. sales has 918843 rows. costs has 82112 rows. customers has 55500 rows. supplementary_demographics has 4500 rows. times has 1826 rows. promotions has 503 rows. products has 72 rows. countries has 23 rows. channels has 5 rows. sales_transactions_ext has 0 rows. Top 10 of largest tables:.

TABLE PARTITION 56      0       5.6     Partitions are exported using table inheritance and check constraint. Hash and Key partitions are not supported by PostgreSQL and will not be exported.  56 RANGE partitions..

VIEW    1       0       1       Views are fully supported but can use specific functions.

-------------------------------------------------------------------------------

Total   291     0       17.10   17.10 cost migration units means approximatively 1 man-day(s). The migration unit was set to 5 minute(s)

 

-------------------------------------------------------------------------------

Migration level : A-1

-------------------------------------------------------------------------------

 

Migration levels:

    A - Migration that might be run automatically

    B - Migration with code rewrite and a human-days cost up to 5 days

    C - Migration with code rewrite and a human-days cost above 5 days

Technical levels:

    1 = trivial: no stored functions and no triggers

    2 = easy: no stored functions but with triggers, no manual rewriting

    3 = simple: stored functions and/or triggers, no manual rewriting

    4 = manual: no stored functions but with triggers or views with code rewriting

    5 = difficult: stored functions and/or triggers with code rewriting

-------------------------------------------------------------------------------

 

導出SH表構

 

[root@test01 ora2pg]#  ora2pg  -c ora2pg.conf              

WARNING: target PostgreSQL version must be set in PG_VERSION configuration directive. Using default: 11

[========================>] 11/11 tables (100.0%) end of scanning.                       

[========================>] 12/12 tables (100.0%) end of table export.              

[========================>] 1/1 views (100.0%) end of output.        

[========================>] 0/0 sequences (100.0%) end of output.

[========================>] 0/0 procedures (100.0%) end of procedures export.

[========================>] 0/0 triggers (100.0%) end of output.            

[========================>] 0/0 functions (100.0%) end of functions export.

[========================>] 0/0 packages (100.0%) end of output.          

[========================>] 56/56 partitions (100.0%) end of output.               

[========================>] 0/0 types (100.0%) end of output.      

[========================>] 2/2 materialized views (100.0%) end of output.                

[========================>] 0/0 dblink (100.0%) end of output.           

[========================>] 0/0 synonyms (100.0%) end of output.

[========================>] 2/2 directory (100.0%) end of output.        

Fixing function calls in output files....

 

 

導出SH用戶數據

 

配置ora2pg.conf 的TYPE 為COPY  或 INSERT

[root@test01 ora2pg]# cp ora2pg.conf sh_data.conf

[root@test01 ora2pg]# vi sh_data.conf

 

ORACLE_HOME     /usr/lib/oracle/18.3/client64

ORACLE_DSN      dbi:Oracle:host=10.85.10.6 ;sid=PROD1;port=1521

ORACLE_USER     system

ORACLE_PWD      oracle

SCHEMA          SH

EXPORT_SCHEMA  1

DISABLE_UNLOGGED  1

SKIP  fkeys ukeys checks

TYPE           COPY

NLS_LANG    AMERICAN_AMERICA.UTF8

OUTPUT     sh_data.sql

 

 

導出數據

 

[root@test01 ora2pg]# ora2pg  -c sh_data.conf

WARNING: target PostgreSQL version must be set in PG_VERSION configuration directive. Using default: 11

[========================>] 11/11 tables (100.0%) end of scanning.                       

[========================>] 5/5 rows (100.0%) Table CHANNELS (5 recs/sec)

[>                        ]       5/1063384 total rows (0.0%) - (0 sec., avg: 5 recs/sec).

[>                        ]     0/82112 rows (0.0%) Table COSTS_1995 (0 recs/sec)                       

[>                        ]       5/1063384 total rows (0.0%) - (0 sec., avg: 5 recs/sec).

[>                        ]     0/82112 rows (0.0%) Table COSTS_H1_1997 (0 recs/sec)     

[>                        ]       5/1063384 total rows (0.0%) - (0 sec., avg: 5 recs/sec).

[>                        ]     0/82112 rows (0.0%) Table COSTS_1996 (0 recs/sec)        

[>                        ]       5/1063384 total rows (0.0%) - (0 sec., avg: 5 recs/sec).

……………………………………………………………

[========================>] 4500/4500 rows (100.0%) Table SUPPLEMENTARY_DEMOGRAPHICS (4500 recs/sec)          

[=======================> ] 1061558/1063384 total rows (99.8%) - (45 sec., avg: 23590 recs/sec).   

[========================>] 1826/1826 rows (100.0%) Table TIMES (1826 recs/sec)                               

[========================>] 1063384/1063384 total rows (100.0%) - (45 sec., avg: 23630 recs/sec).

[========================>] 1063384/1063384 rows (100.0%) on total estimated data (45 sec., avg: 23630 recs/sec)

Fixing function calls in output files...

 

 

     查看導出的文件:      

 

[root@test01 ora2pg]# ls -lrt *.sql

-rw-r--r-- 1 root root 15716 Jul  2 21:21 TABLE_sh.sql

-rw-r--r-- 1 root root   858 Jul  2 21:21 VIEW_sh.sql

-rw-r--r-- 1 root root  2026 Jul  2 21:21 TABLESPACE_sh.sql

-rw-r--r-- 1 root root   345 Jul  2 21:21 SEQUENCE_sh.sql

-rw-r--r-- 1 root root  2382 Jul  2 21:21 GRANT_sh.sql

-rw-r--r-- 1 root root   344 Jul  2 21:21 TRIGGER_sh.sql

-rw-r--r-- 1 root root   346 Jul  2 21:21 PROCEDURE_sh.sql

-rw-r--r-- 1 root root   344 Jul  2 21:21 PACKAGE_sh.sql

-rw-r--r-- 1 root root   345 Jul  2 21:21 FUNCTION_sh.sql

-rw-r--r-- 1 root root  6771 Jul  2 21:21 PARTITION_sh.sql

-rw-r--r-- 1 root root   341 Jul  2 21:21 TYPE_sh.sql

-rw-r--r-- 1 root root   342 Jul  2 21:21 QUERY_sh.sql

-rw-r--r-- 1 root root   950 Jul  2 21:21 MVIEW_sh.sql

-rw-r--r-- 1 root root   344 Jul  2 21:21 SYNONYM_sh.sql

-rw-r--r-- 1 root root   926 Jul  2 21:21 DIRECTORY_sh.sql

-rw-r--r-- 1 root root   343 Jul  2 21:21 DBLINK_sh.sql

-rw-r--r-- 1 root root 55281235 Jul  2 17:11 sh_data.sql

 

 

以同樣的方法分別導出HR,SCOTT 用戶數據。

 

1.1.7   在PG環境中創建orcl庫

創建ORCL 數據庫

 

[root@test01 ~]# su - postgres

Last login: Tue Jul  2 20:04:30 CST 2019 on pts/3

[postgres@test01 ~]$ createdb orcl

[postgres@test01 ~]$ psql

psql (11.2)

Type "help" for help.

 

postgres=# \l

                                 List of databases

   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges  

-----------+----------+----------+------------+------------+-----------------------

 orcl      | postgres | UTF8     | en_US.utf8 | en_US.utf8 |

 pgdb      | postgres | UTF8     | en_US.utf8 | en_US.utf8 |

 postgres  | postgres | UTF8     | en_US.utf8 | en_US.utf8 |

 template0 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +

           |          |          |            |            | postgres=CTc/postgres

 template1 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +

           |          |          |            |            | postgres=CTc/postgres

(5 rows)

 

postgres=#

 

 

 

  創建SH,HR,SCOTT 用戶:

[postgres@test01 ~]$ psql orcl

psql (11.2)

Type "help" for help.

 

orcl=#

orcl=# create user sh with password 'sh';

CREATE ROLE

 

1.1.8     導入表結構

 

注意:由於有物化視圖,在TABLE_sh.sql 里包含了物化視圖的索引,會創建失敗。需先創建表,在創建物化視圖,最后創建索引。

取消物化視圖索引,后面單獨創建:

CREATE INDEX fw_psc_s_mv_chan_bix ON fweek_pscat_sales_mv (channel_id);

CREATE INDEX fw_psc_s_mv_promo_bix ON fweek_pscat_sales_mv (promo_id);

CREATE INDEX fw_psc_s_mv_subcat_bix ON fweek_pscat_sales_mv (prod_subcategory);

CREATE INDEX fw_psc_s_mv_wd_bix ON fweek_pscat_sales_mv (week_ending_day);

 

取消 tab.sql 中的文本搜索內容

CREATE TEXT SEARCH CONFIGURATION en (COPY = pg_catalog.english);

ALTER TEXT SEARCH CONFIGURATION en ALTER MAPPING FOR hword, hword_part, word WITH unaccent, english_stem;

 

 

導入表結構

psql orcl  -f  tab.sql.sql

ALTER TABLE PARTITION sh.sales OWNER TO sh;

COMMENT

COMMENT

COMMENT

COMMENT

COMMENT

COMMENT

COMMENT

ALTER TABLE

ALTER TABLE

ALTER TABLE

………………………………

 

 

給對象授權:

cat psql orcl  -f  GRANT_sh.sql

 

由於用戶已存在需要取消這行

CREATE USER SH WITH PASSWORD 'change_my_secret' LOGIN;

由於物化視圖沒有創建,需提取出來,后面單獨授權

ALTER TABLE sh.fweek_pscat_sales_mv OWNER TO sh;

GRANT ALL ON  sh.fweek_pscat_sales_mv TO sh;

 

 

導入物化視圖結構:

物化視圖需要相關查詢權限,所以導入權限,注意這里要跟上用戶

 [postgres@test01 ora2pg]$  psql orcl sh -f  MVIEW_sh.sql  

SELECT 0

SELECT 0

CREATE INDEX

CREATE INDEX

CREATE INDEX

CREATE INDEX

 

導入視圖:

[postgres@test01 ora2pg]$  psql orcl  -f  VIEW_sh.sql

SET

SET

SET

CREATE VIEW

 

 

導入分區表:

[postgres@test01 ora2pg]$  psql orcl  -f  PARTITION_sh.sql

SET

SET

SET

CREATE TABLE

CREATE TABLE

CREATE TABLE

CREATE TABLE

CREATE TABLE

CREATE TABLE

 …………………………

 

導入數據:

 

[postgres@test01 ora2pg]$  psql orcl   -f   sh_data.sql

SET

COPY 0

SET

COPY 0

SET

COPY 0

SET

COPY 0

SET

COPY 0

SET

COPY 0

SET

COPY 0

SET

COPY 4500

SET

COPY 1826

COMMIT

 

 

1.1.9    數據驗證

源庫,目標端抽取部份對象對比:

SYS@PROD1>select count(*) from sh.products;

 

  COUNT(*)

----------

        72

 

orcl=#  select count(*) from sh.products;

 count

-------

    72

(1 row)

---------------------------------------------------------------------------

SYS@PROD1>select count(*) from sh.channels;

 

  COUNT(*)

----------

         5

 

orcl=#   select count(*) from sh.channels;

 count

-------

     5

(1 row)

 

--------------------------------------------------------------------------

SYS@PROD1>select count(*) from sh.customers ;

 

  COUNT(*)

----------

     55500

 

orcl=# select count(*) from sh.customers ;

 count

-------

 55500

(1 row)

 

1.1.10     生成遷移模板

 使用時,兩個選項--project_base和--init_project向ora2pg表明他必須創建一個項目模板,其中包含工作樹,配置文件和從Oracle數據庫導出所有對象的腳本。 生成通用配置文件。 1.創建腳本export_schema.sh以自動執行所有導出。2.創建腳本import_all.sh以自動執行所有導入。例:

mkdir -p  /ora2pg/migration

 

[root@test01 ora2pg-20.0]# ora2pg --project_base /ora2pg/migration/ --init_project test_project

Creating project test_project.

/ora2pg/migration//test_project/

        schema/

                dblinks/

                directories/

                functions/

                grants/

                mviews/

                packages/

                partitions/

                procedures/

                sequences/

                synonyms/

                tables/

                tablespaces/

                triggers/

                types/

                views/

        sources/

                functions/

                mviews/

                packages/

                partitions/

                procedures/

                triggers/

                types/

                views/

        data/

        config/

        reports/

 

Generating generic configuration file

Creating script export_schema.sh to automate all exports.

Creating script import_all.sh to automate all imports.

 

 

1.1.11     Ora2pg 小結

 在測試過程中,出現較多問題就是表的關聯問題和主外鍵問題。表結構的導入以及數據的導入,都需要按關聯順序進行操作。 感覺比較適合對象少,關聯少的環境操作,或者不導入主外鍵。

在創建授權的時候,最好是直接內容直接在pgsql 窗口執行。這樣有個別報錯,也會繼續執行后面的授權。然后在最后創建好所有對像后在單獨執行失敗的授權。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM