-
Oracle FDW카테고리 없음 2019. 11. 22. 15:47
개요
Postgresql 에서 Oracle에 있는 데이터를 가져오기 위해서는 FDW를 이용할 수 있다.
FDW는 Foreign Data Wrapper 의 약자로 이기종 데이터베이스의 외래테이블 간에 연결하여 사용할 수 있는 솔루션이다.
FDW를 이용하여 내부 레거시 연계작업을 단순화할 수 있는 장점이 있다.
그 중에서도 Oracle과 PostgreSQL 데이터베이스 간에 외래테이블에 대한 연결작업에 대해서 알아보고자 한다.
실행 방법
Oracle_FDW module compile
아래 url 에 접근 하여 oracle_fdw를 다운로드 한다. (현 예제는 linux에 설치할 예정이므로 source code 파일을 다운로드 받는다.)
https://github.com/laurenz/oracle_fdw/releases/tag/ORACLE_FDW_1_3_0
oracle페이지에서 Instant Client Package – Basic/SDK 를 다운로드 받는다.
http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
instantclient-basic-linux.x64-12.1.0.2.0.zip 설정
압축 해제
# unzip instantclient-basic-linux.x64-12.1.0.2.0.zip
라이브러리 설정
# ln -s libclntsh.so.12.1 libclntsh.so
환경변수 설정
.bash_profile
export LD_LIBRARY_PATH=/root/Desktop/instantclient_12_1
export oracle_home=/root/Desktop/instantclient_12_1
PATH=$LD_LIBRARY_PATH:$PATH:$HOME/bin
instantclient-sdk-linux.x64-12.1.0.2.0.zip 설정
# unzip instantclient-sdk-linux.x64-12.1.0.2.0.zip
위에서 압축을 푼 파일 하단에 sdk라는 디렉토리가 생성됨
Oracle FDW 컴파일
우선 Postgresql 의 pg_env.sh 파일을 실행시켜준 후 (# souce ./pg_env.sh)
# make
# make install
oracle_fdw Module을 EXTENSION 시킴
# CREATE EXTENSION oracle_fdw;
oracle 데이터 베이스 연결서버 생성
# create server ora foreign data wrapper oracle_fdw options(dbserver '//172.21.22.236:1521/orcl');
Oracle이 설치되어있는 서버의 /etc/host 파일과 postgresql이 설치되어 있는 서버의 /etc/hosts 파일에 각 통신하는 서버의 IP와 hostname 을 설정해 준다.
oracle 데이터베이스와 연결 할 유저 생성
# create user test5 password 'test5' login;
# grant usage on foreign server ora to test5;
# create user mapping for test5 server ora options(user 'scott', password 'tiger');
외래테이블 생성
# create foreign table emp_test(
empno numeric,
ename text,
job text,
mgr numeric,
hiredate date,
sal numeric,
comm numeric,
deptno numeric
)server ora options(schema 'SCOTT', table 'EMP');
외래테이블 확인
# select * from emp_test;