本文只介紹如何使用Ora2Pg從Oracle導(dǎo)出數(shù)據(jù)到PostgreSQL,但是在操作前需要先安裝先決軟件DBD::Oracle、DBI、Ora2Pg。
成都創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比紅花崗網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式紅花崗網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋紅花崗地區(qū)。費(fèi)用合理售后完善,十年實(shí)體公司更值得信賴。安裝參考:Linux下安裝DBD::Oracle、DBI和Ora2Pg
安裝Ora2Pg完成會(huì)在/etc目錄下生成一個(gè)ora2pg目錄里面有使用Ora2Pg的配置文件。
1、在Oracle上創(chuàng)建測(cè)試用戶并創(chuàng)建測(cè)試表
sys@ORCL>create user zhaoxu identified by zhaoxu; User created. sys@ORCL>grant dba to zhaoxu; Grant succeeded. sys@ORCL>conn zhaoxu/zhaoxu; Connected. zhaoxu@ORCL>create table emp as select * from scott.emp; Table created. zhaoxu@ORCL>select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ------------------------------ --------------------------- ---------- ------------------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 1980-12-17 00:00:00 800 20 7499 ALLEN SALESMAN 7698 1981-02-20 00:00:00 1600 300 30 7521 WARD SALESMAN 7698 1981-02-22 00:00:00 1250 500 30 7566 JONES MANAGER 7839 1981-04-02 00:00:00 2975 20 7654 MARTIN SALESMAN 7698 1981-09-28 00:00:00 1250 1400 30 7698 BLAKE MANAGER 7839 1981-05-01 00:00:00 2850 30 7782 CLARK MANAGER 7839 1981-06-09 00:00:00 2450 10 7788 SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 20 7839 KING PRESIDENT 1981-11-17 00:00:00 5000 10 7844 TURNER SALESMAN 7698 1981-09-08 00:00:00 1500 0 30 7876 ADAMS CLERK 7788 1987-05-23 00:00:00 1100 20 7900 JAMES CLERK 7698 1981-12-03 00:00:00 950 30 7902 FORD ANALYST 7566 1981-12-03 00:00:00 3000 20 7934 MILLER CLERK 7782 1982-01-23 00:00:00 1300 10 14 rows selected.2、修改參數(shù)文件
[oracle@rhel6 ora2pg]$ cp /etc/ora2pg/ora2pg.conf /home/oracle/ora2pg/ [oracle@rhel6 ora2pg]$ cd /home/oracle/ora2pg/ [oracle@rhel6 ora2pg]$ vi ora2pg.conf [oracle@rhel6 ora2pg]$ cat ora2pg.conf ORACLE_HOME /u02/app/oracle/product/11.2.4/db1 ORACLE_DSN dbi:Oracle:host=192.168.56.2;sid=orcl ORACLE_USER zhaoxu ORACLE_PWD zhaoxu SCHEMA zhaoxu USER_GRANTS 0 DEBUG 0 ORA_INITIAL_COMMAND EXPORT_SCHEMA 0 CREATE_SCHEMA 1 COMPILE_SCHEMA 0 TYPE TABLE,INSERT OUTPUT output.sql3、使用上面修改的參數(shù)導(dǎo)出數(shù)據(jù)
[oracle@rhel6 ora2pg]$ ora2pg -c ora2pg.conf [========================>] 1/1 tables (100.0%) end of scanning. [> ] 0/1 tables (0.0%) end of scanning. [========================>] 1/1 tables (100.0%) end of table export. [========================>] 14/1 rows (1400.0%) Table EMP (14 recs/sec) [========================>] 14/1 total rows (1400.0%) - (0 sec., avg: 14 recs/sec). [========================>] 1/1 rows (100.0%) on total estimated data (1 sec., avg: 1 recs/sec) [oracle@rhel6 ora2pg]$ cat output.sql -- Generated by Ora2Pg, the Oracle database Schema converter, version 17.6b -- Copyright 2000-2016 Gilles DAROLD. All rights reserved. -- DATASOURCE: dbi:Oracle:host=192.168.56.2;sid=orcl SET client_encoding TO 'UTF8'; \set ON_ERROR_STOP ON CREATE TABLE emp ( empno smallint, ename varchar(10), job varchar(9), mgr smallint, hiredate timestamp, sal decimal(7,2), comm decimal(7,2), deptno smallint ) ; -- Generated by Ora2Pg, the Oracle database Schema converter, version 17.6b -- Copyright 2000-2016 Gilles DAROLD. All rights reserved. -- DATASOURCE: dbi:Oracle:host=192.168.56.2;sid=orcl SET client_encoding TO 'UTF8'; \set ON_ERROR_STOP ON BEGIN; INSERT INTO emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) VALUES (7369,E'SMITH',E'CLERK',7902,'1980-12-17 00:00:00',800,NULL,20); INSERT INTO emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) VALUES (7499,E'ALLEN',E'SALESMAN',7698,'1981-02-20 00:00:00',1600,300,30); INSERT INTO emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) VALUES (7521,E'WARD',E'SALESMAN',7698,'1981-02-22 00:00:00',1250,500,30); INSERT INTO emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) VALUES (7566,E'JONES',E'MANAGER',7839,'1981-04-02 00:00:00',2975,NULL,20); INSERT INTO emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) VALUES (7654,E'MARTIN',E'SALESMAN',7698,'1981-09-28 00:00:00',1250,1400,30); INSERT INTO emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) VALUES (7698,E'BLAKE',E'MANAGER',7839,'1981-05-01 00:00:00',2850,NULL,30); INSERT INTO emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) VALUES (7782,E'CLARK',E'MANAGER',7839,'1981-06-09 00:00:00',2450,NULL,10); INSERT INTO emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) VALUES (7788,E'SCOTT',E'ANALYST',7566,'1987-04-19 00:00:00',3000,NULL,20); INSERT INTO emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) VALUES (7839,E'KING',E'PRESIDENT',NULL,'1981-11-17 00:00:00',5000,NULL,10); INSERT INTO emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) VALUES (7844,E'TURNER',E'SALESMAN',7698,'1981-09-08 00:00:00',1500,0,30); INSERT INTO emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) VALUES (7876,E'ADAMS',E'CLERK',7788,'1987-05-23 00:00:00',1100,NULL,20); INSERT INTO emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) VALUES (7900,E'JAMES',E'CLERK',7698,'1981-12-03 00:00:00',950,NULL,30); INSERT INTO emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) VALUES (7902,E'FORD',E'ANALYST',7566,'1981-12-03 00:00:00',3000,NULL,20); INSERT INTO emp (empno,ename,job,mgr,hiredate,sal,comm,deptno) VALUES (7934,E'MILLER',E'CLERK',7782,'1982-01-23 00:00:00',1300,NULL,10); COMMIT;4、把生成的output.sql傳到PostgreSQL服務(wù)器上
[oracle@rhel6 ora2pg]$ scp output.sql pguser@192.168.56.25:/home/pguser/ pguser@192.168.56.25's password: output.sql 100% 2599 2.5KB/s 00:005、在PostgreSQL數(shù)據(jù)庫上創(chuàng)建對(duì)應(yīng)的數(shù)據(jù)庫、用戶和Schema
#創(chuàng)建數(shù)據(jù)庫 zhaoxu postgres=# create database zhaoxu; CREATE DATABASE postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+--------+----------+-------------+-------------+------------------- postgres | pguser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | pguser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/pguser + | | | | | pguser=CTc/pguser template1 | pguser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/pguser + | | | | | pguser=CTc/pguser zhaoxu | pguser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | zx | pguser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (5 rows) #創(chuàng)建用戶 zhaoxu postgres=# create user zhaoxu superuser; CREATE ROLE postgres=# \dg List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- lx | Superuser, Cannot login | {} pguser | Superuser, Create role, Create DB, Replication, Bypass RLS | {} sq | Superuser, Create role, Create DB | {} zhaoxu | Superuser | {} zx | Superuser | {} #在zhaoxu庫下創(chuàng)建Schema zhaoxu postgres=# \c zhaoxu zhaoxu You are now connected to database "zhaoxu" as user "zhaoxu". zhaoxu=# create schema zhaoxu; CREATE SCHEMA zhaoxu=# \dn List of schemas Name | Owner --------+-------- public | pguser zhaoxu | zhaoxu (2 rows)6、使用output.sql導(dǎo)入從Oracle導(dǎo)出的數(shù)據(jù)
[pguser@rhel7 ~]$ psql zhaoxu zhaoxu < output.sql SET CREATE TABLE SET BEGIN INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 1 COMMIT [pguser@rhel7 ~]$ psql zhaoxu zhaoxu psql (9.6.1) Type "help" for help. zhaoxu=# \d List of relations Schema | Name | Type | Owner --------+------+-------+-------- zhaoxu | emp | table | zhaoxu (1 row) zhaoxu=# select * from emp; empno | ename | job | mgr | hiredate | sal | comm | deptno -------+--------+-----------+------+---------------------+---------+---------+-------- 7369 | SMITH | CLERK | 7902 | 1980-12-17 00:00:00 | 800.00 | | 20 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 00:00:00 | 1600.00 | 300.00 | 30 7521 | WARD | SALESMAN | 7698 | 1981-02-22 00:00:00 | 1250.00 | 500.00 | 30 7566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975.00 | | 20 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 00:00:00 | 1250.00 | 1400.00 | 30 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 00:00:00 | 2850.00 | | 30 7782 | CLARK | MANAGER | 7839 | 1981-06-09 00:00:00 | 2450.00 | | 10 7788 | SCOTT | ANALYST | 7566 | 1987-04-19 00:00:00 | 3000.00 | | 20 7839 | KING | PRESIDENT | | 1981-11-17 00:00:00 | 5000.00 | | 10 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 00:00:00 | 1500.00 | 0.00 | 30 7876 | ADAMS | CLERK | 7788 | 1987-05-23 00:00:00 | 1100.00 | | 20 7900 | JAMES | CLERK | 7698 | 1981-12-03 00:00:00 | 950.00 | | 30 7902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000.00 | | 20 7934 | MILLER | CLERK | 7782 | 1982-01-23 00:00:00 | 1300.00 | | 10 (14 rows)數(shù)據(jù)導(dǎo)入完成。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
分享題目:使用Ora2Pg工具把數(shù)據(jù)從Oracle導(dǎo)入到PostgreSQL-創(chuàng)新互聯(lián)
網(wǎng)站網(wǎng)址:http://aaarwkj.com/article22/cocjjc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)、手機(jī)網(wǎng)站建設(shè)、外貿(mào)建站、虛擬主機(jī)、建站公司、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容