Oracle

게시글 보기
작성자 유건데이타 등록일 2015-12-02
제목 특정 테이블 제외하고 export 받기
expdp 면


EXCLUDE=TABLE:\"IN \(\'테이블1\', \'MASTER\',\'BILLMP\' , \'BILTAIL\' , \'BILTEM\'\)\"


exp 면


8I) 특정 테이블을 제외(SKIP)하고 EXPORT 하는 방법
====================================

PURPOSE
--------
Fine-Grained Access (FGAC) control이 특정 테이블을 제외하고 Export하는데
사용이 되는데 여기서는 FGAC에 대한 설명은 하지 않을것이며 자세한 사항은 관련
문서들을 참고하기 바란다.

Explanation & Example
----------------------
이 방법은 FGAC을 지원하는 Oracle Version에서만 가능하다. Oracle 8i에서부터
FGAC을 지원하며 Standard Edition을 제외한 Enterprise Edition 과 Personal
Edition에서 지원한다.
아래는 Scott User에서 EMP,DEPT 테이블을 제외하고 export받는 예제이다.

1. SYSTEM user로 database에 접속한다.

SQL> connect system/manager
Connected.

2. 새로운 DBA user를 만든다. 이 User로 export을 받을 것이다.

SQL> Create user EXP_DB identified by EXP_DB;

User created.

( default tablespace가 필요하다면 명시한다.)

SQL> Grant DBA to EXP_DB;

Grant succeeded.

3. Fine-Grained Access Control.

3.1. 2에서 만든 EXP_DB user로 접속한다.

SQL> connect exp_db/exp_db
Connected.

3.2 predicate function을 만든다.

CREATE or REPLACE FUNCTION exclude_table
(obj_schema VARCHAR2, obj_name VARCHAR2)
RETURN VARCHAR2 IS d_predicate VARCHAR2(2000);

BEGIN
if sys_context ('USERENV', 'SESSION_USER') = 'EXP_DB' THEN
d_predicate := '1=2';
else
d_predicate := '';
end if;
RETURN d_predicate;
END exclude_table;
/

( 1=2 조건은 EXP_DB user에게 항상 어떤 row도 return하지 않도록 하기 위한 것이다)

3.2 EXPORT에서 제외하기를 TABLE에 대해 각각의 Policy를 만든다.

execute dbms_rls.add_policy ('SCOTT','EMP','POL_EMP','EXP_DB','EXCLUDE_TABLE')
execute dbms_rls.add_policy ('SCOTT','DEPT','POL_DEPT','EXP_DB','EXCLUDE_TABLE')

참고 : 'SCOTT' --> 제외하고자 하는 테이블의 Owner.
'EMP' --> 제외하고자 하는 테이블.
'POL_EMP' --> policy의 이름(임의).
'EXP_DB' --> predicate function의 Owner(3.2에서 만듬).
'EXCLUDE_TABLE' --> predicate function.

ex) 위와 같이 policy에 add하면 그때부터 EXP_DB user는 emp table을 query할때
어떤 row도 return하지 않는다.

SQL> execute dbms_rls.add_policy ('SCOTT','EMP','POL_EMP','EXP_DB','EXCLUDE_TABLE')

PL/SQL procedure successfully completed.

SQL> select * from scott.emp;

no rows selected

SQL> execute dbms_rls.add_policy ('SCOTT','DEPT','POL_DEPT','EXP_DB','EXCLUDE_TABLE')

PL/SQL procedure successfully completed.

SQL> select * from scott.dept;

no rows selected

SQL> connect scott/tiger
Connected.
SQL> select count(*) from scott.emp;

COUNT(*)
----------
14

SQL> select count.
(*) from scott.dept;

COUNT(*)
----------
4


4. EXP_DB user로 database 또는 schema level로 export한다.

여기서 우리는 제외하고자 하는 각가의 테이블에서는 아래와 같은 warnings
을 발견할 것이다.

EXP-00079: Data in table "EMP" is protected. Conventional path may only be
exporting partial table.


ex) exp exp_db/exp_db file=scott.dmp owner=scott

. .
. .
. . exporting table CHESS_SAVE_CAPTURED 0 rows exported
. . exporting table CHESS_SAVE_PLAYER 0 rows exported
. . exporting table CITIES 205 rows exported
. . exporting table CLOB_TEST 1 rows exported
. . exporting table CODE 2 rows exported
. . exporting table COMPANY_SUMMARY 3 rows exported
. . exporting table CONCLASS 9 rows exported
. . exporting table CONLABEL 6 rows exported
. . exporting table CONTAINERS 169 rows exported
. . exporting table CREATE$JAVA$LOB$TABLE 1 rows exported
. . exporting table CUST 6 rows exported
. . exporting table CUSTOMER 9 rows exported
. . exporting table CUSTOMERS 14 rows exported
. . exporting table C_TEST1 8 rows exported
. . exporting table DAYS 7 rows exported
EXP-00079: Data in table "DEPT" is protected. Conventional path may only be expo
rting partial table.
. . exporting table DEPT 0 rows exported
. . exporting table DEPT2 4 rows exported
. . exporting table DTEST 0 rows exported
. . exporting table DUMMY 1 rows exported
EXP-00079: Data in table "EMP" is protected. Conventional path may only be expor
ting partial table.
. . exporting table EMP 0 rows exported
EXP-00091: Exporting questionable statistics.
. . exporting table EMP1 14 rows exported
. . exporting table EMPTEST 12 rows exported
. . exporting table EMP_UNRECOVER 15 rows exported
. . exporting table EMP_GQ1[ 26 rows exported
. . exporting table ESJO_DEPT 3 rows exported
. . exporting table EXECUTABLES 1 rows exported
. . exporting table FLRPEOPLE 65 rows exported
. . exporting table FUNDS 5 rows exported
. . exporting table FUND_CONTRIB 16 rows exported
. . exporting table
. .
. .
Export terminated successfully with warnings.


5. 제외하거나 다시 export list에 더하거나 할때.

5.1 다시 export list에 넣으려면

execute dbms_rls.drop_policy ('SCOTT','EMP','POL_EMP');

참고 : 'SCOTT' --> 제외하고자 했던 테이블의 Owner.
'EMP' --> 제외하고자 했던 테이블.
'POL_EMP' --> policy의 이름.

5.2 제외하고자 하는 table list에 있는지 알아보고자 할때는 DBA/USER/ALL_POLICIES
view을 이용한다.

SQL> select POLICY_NAME, OBJECT_NAME, FUNCTION
from DBA_POLICIES
where PF_OWNER='EXP_DB';

POLICY_NAME OBJECT_NAME
------------------------------ ------------------------------
FUNCTION
------------------------------
POL_DEPT DEPT
EXCLUDE_TABLE

POL_EMP EMP
EXCLUDE_TABLE
Comment
등록된 코멘트가 없습니다.