CREATE TABLESPACE TABLESPACE_NAME
datafile ...
encryption
Using 'algorithm' ( optional )
defult storage ( ENCRYPT );
SQL> create tablespace new_encrypted
2 datafile 'D:\app\LG\data_file\new_encrypted.dbf' size 1m
3 encryption
4 default storage( encrypt );
테이블스페이스가 생성되었습니다.
SQL> create tablespace new_clear
2 datafile 'D:\app\LG\data_file\new_clear.dbf' size 1m
3 autoextend on next 1m;
테이블스페이스가 생성되었습니다.
SQL> create table scott.stage
2 as
3 select *
4 from all_objects;
테이블이 생성되었습니다.
SQL> create table scott.nonencrypted
2 tablespace new_clear
3 as
4 select *
5 from scott.stage
6 where 1=0;
테이블이 생성되었습니다.
SQL> alter table scott.nonencrypted add constraint nonencrypted_pk primary key( object_id )
2 using index
3 (create index scott.nonencrypted_pk on scott.nonencrypted( object_id )
4 tablespace new_clear
5 );
테이블이 변경되었습니다.
SQL> create table scott.encrypted
2 tablespace new_encrypted
3 as
4 select *
5 from scott.stage
6 where 1=0
7
SQL> /
테이블이 생성되었습니다.
SQL> alter table scott.encrypted add constraint encrypted_pk primary key( object_id )
2 using index
3 (create index scott.encrypted_pk on scott.encrypted( object_id )
4 tablespace new_encrypted
5 );
테이블이 변경되었습니다.
SQL>
SQL> create or replace procedure do_sql( p_sql in varchar2
2 , p_tname in varchar2
3 , p_truncate in boolean default true )
4 authid current_user -- SQL 인젝션 공격 보안 문제 회피
5 as
6 l_start_cpu number;
7 l_start_redo number;
8 l_total_redo number;
9 function get_stat_val( p_name in varchar2 ) return number
10 as
11 l_val number;
12 begin
13 select b.value
14 into l_val
15 from v$statname a, v$mystat b
16 where a.statistic# = b.statistic#
17 and a.name = p_name;
18
19 return l_val;
20 end;
21 begin
22 if( p_truncate )
23 then
24 execute immediate 'truncate table '||p_tname;
25 end if;
26
27 dbms_output.put_line( replace( p_sql, '#TNAME#', p_tname) );
28
29 l_start_cpu := dbms_utility.get_cpu_time;
30 l_start_redo := get_stat_val( 'redo size' );
31
32 execute immediate replace( p_sql, '#TNAME#', p_tname);
33
34 commit work write batch wait;
35
36 dbms_output.put_line( (dbms_utility.get_cpu_time - l_start_cpu ) || ' cpu hsecs' );
37
38 l_total_redo := round( ( get_stat_val('redo size') - l_start_redo ) / 1024 / 1024, 1 );
39
40 dbms_output.put_line( to_char( l_total_redo, '999,999,999,9')||' mbytes redo' );
41
42 end;
43 /
프로시저가 생성되었습니다.
SQL> ALTER TABLESPACE new_encrypted ADD DATAFILE 'D:\app\LG\data_file\new_encrypted01.dbf' SIZE 1M autoextend on next 1m;
테이블스페이스가 변경되었습니다.
SQL>
SQL> begin
2 do_sql( 'insert into #TNAME# SELECT * FROM SCOTT.STAGE', 'SCOTT.nonencrypted' );
3 do_sql( 'insert into #TNAME# SELECT * FROM SCOTT.STAGE', 'SCOTT.encrypted' );
4 end;
5 /
insert into SCOTT.nonencrypted SELECT * FROM SCOTT.STAGE
234 cpu hsecs
3,2 mbytes redo
insert into SCOTT.encrypted SELECT * FROM SCOTT.STAGE
396 cpu hsecs
3,2 mbytes redo
PL/SQL 처리가 정상적으로 완료되었습니다.
SQL>
-- CPU 활용 측면에서 영향도는 거의 없다는데 1.5정도 -_-
SQL> begin
2 do_sql( 'insert /*+ append */ into #TNAME# SELECT * FROM SCOTT.STAGE', 'SCOTT.nonencrypted' );
3 do_sql( 'insert /*+ append */ into #TNAME# SELECT * FROM SCOTT.STAGE', 'SCOTT.encrypted' );
4 end;
5 /
insert /*+ append */ into SCOTT.nonencrypted SELECT * FROM SCOTT.STAGE
207 cpu hsecs
2,0 mbytes redo
insert /*+ append */ into SCOTT.encrypted SELECT * FROM SCOTT.STAGE
326 cpu hsecs
2,0 mbytes redo
PL/SQL 처리가 정상적으로 완료되었습니다.
-- 음..ㅠ
SQL> declare
2 l_sql long := 'begin ' || 'for x in (select * from scott.stage) ' ||
3 'loop ' ||
4 'insert into #TNAME# values x; ' ||
5 'end loop; ' ||
6 'end; ';
7 begin
8 do_sql( l_sql, 'SCOTT.nonencrypted' );
9 do_sql( l_sql, 'SCOTT.encrypted' );
10 end;
11 /
begin for x in (select * from scott.stage) loop insert into SCOTT.nonencrypted
values x; end loop; end;
1408 cpu hsecs
5,2 mbytes redo
begin for x in (select * from scott.stage) loop insert into SCOTT.encrypted
values x; end loop; end;
1745 cpu hsecs
5,2 mbytes redo
SQL> declare
2 l_sql long := 'begin ' || 'for x in (select object_id from scott.stage) ' ||
3 'loop ' ||
4 'for y in (select * from #TNAME# where object_id = x.object_id ) ' ||
5 'loop ' ||
6 'null; ' ||
7 'end loop;' ||
8 'end loop; ' ||
9 'end; ';
10 begin
11 do_sql( l_sql, 'SCOTT.nonencrypted', false );
12 do_sql( l_sql, 'SCOTT.encrypted', false );
13 end;
14 /
begin for x in (select object_id from scott.stage) loop for y in (select * from
SCOTT.nonencrypted where object_id = x.object_id ) loop null; end loop;end loop;
end;
1120 cpu hsecs
0 mbytes redo
begin for x in (select object_id from scott.stage) loop for y in (select * from
SCOTT.encrypted where object_id = x.object_id ) loop null; end loop;end loop;
end;
1140 cpu hsecs
0 mbytes redo
PL/SQL 처리가 정상적으로 완료되었습니다.
ALTER SYSTEM FLUSH BUFFER_CACHE;
SQL> declare
2 l_sql long := 'begin ' || 'for x in (select object_id from scott.stage) ' ||
3 'loop ' ||
4 'for y in (select * from #TNAME# where object_id = x.object_id ) ' ||
5 'loop ' ||
6 'null; ' ||
7 'end loop;' ||
8 'end loop; ' ||
9 'end; ';
10 begin
11 do_sql( l_sql, 'SCOTT.nonencrypted', false );
12 -- do_sql( l_sql, 'SCOTT.encrypted', false );
13 end;
14 /
begin for x in (select object_id from scott.stage) loop for y in (select * from
SCOTT.nonencrypted where object_id = x.object_id ) loop null; end loop;end loop;
end;
1081 cpu hsecs
0 mbytes redo
PL/SQL 처리가 정상적으로 완료되었습니다.
ALTER SYSTEM FLUSH BUFFER_CACHE;
SQL> declare
2 l_sql long := 'begin ' || 'for x in (select object_id from scott.stage) ' ||
3 'loop ' ||
4 'for y in (select * from #TNAME# where object_id = x.object_id ) ' ||
5 'loop ' ||
6 'null; ' ||
7 'end loop;' ||
8 'end loop; ' ||
9 'end; ';
10 begin
11 -- do_sql( l_sql, 'SCOTT.nonencrypted', false );
12 do_sql( l_sql, 'SCOTT.encrypted', false );
13 end;
14 /
begin for x in (select object_id from scott.stage) loop for y in (select * from
SCOTT.encrypted where object_id = x.object_id ) loop null; end loop;end loop;
end;
1095 cpu hsecs
0 mbytes redo
SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS( 'SCOTT', 'nonencrypted' , METHOD_OPT => 'for columns object_name size 254' );
PL/SQL 처리가 정상적으로 완료되었습니다.
SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS( 'SCOTT', 'encrypted' , METHOD_OPT => 'for columns object_name size 254' );
PL/SQL 처리가 정상적으로 완료되었습니다.
SQL>
SQL>
SQL> set autotrace traceonly explain
SQL> select * from SCOTT.nonencrypted where object_name = 'ALL_OBJECT';
Execution Plan
----------------------------------------------------------
Plan hash value: 2348679572
--------------------------------------------------------------------------------
--
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
--
| 0 | SELECT STATEMENT | | 2 | 196 | 342 (1)| 00:00:05
|
|* 1 | TABLE ACCESS FULL| NONENCRYPTED | 2 | 196 | 342 (1)| 00:00:05
|
--------------------------------------------------------------------------------
--
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_NAME"='ALL_OBJECT')
SQL> select * from SCOTT.encrypted where object_name = 'ALL_OBJECT';
Execution Plan
----------------------------------------------------------
Plan hash value: 827516354
-------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2 | 196 | 342 (1)| 00:00:05 |
|* 1 | TABLE ACCESS FULL| ENCRYPTED | 2 | 196 | 342 (1)| 00:00:05 |
-------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_NAME"='ALL_OBJECT')
SQL>
- 강좌 URL : http://www.gurubee.net/lecture/4080
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.