SQLPLUS > create table t
2 as
3 select object_name unindexed,
4 object_name indexed
5 from all_objects
6 /
Table created.
SQLPLUS > create index i_idx on t(indexed);
Index created.
SQLPLUS > exec dbms_stats.gather_table_stats(user,'T');
PL/SQL procedure successfully completed.
SQLPLUS > select used_ublk
2 from v$transaction
3 where addr = ( select taddr
4 from v$session
5 where sid = ( select sid from v$mystat where rownum = 1 )
6 )
7 /
USED_UBLK
----------
69
SQLPLUS > commit ;
Commit complete.
-- UPDATE 가 언두를 저장하는데 69개 블록을 사용함.
-- commit 이후에는 해당 정보를 없애거나 해제하므로,
위 select 쿼리로 다시 조회하면 no rows selected 결과가 출력된다.
SQLPLUS >update t set indexed = lower(indexed) ;
17679 rows updated.
SQLPLUS >select used_ublk
from v$transaction
where addr = ( select taddr
from v$session
where sid = ( select sid from v$mystat where rownum = 1 )
)
/
USED_UBLK
----------
337
-- 3배가 넘는 언두가 생성됐다.
-- 세션 A
SQLPLUS > create undo tablespace undo_small
2 datafile '/tmp/undo.dbf' size 2m
3 autoextend off ;
Tablespace created.
SQLPLUS > alter system set undo_tablespace = undo_small ;
System altered.
SQLPLUS > create table t
2 as
3 select * from all_objects
4 order by dbms_random.random ;
Table created.
SQLPLUS > alter table t add constraint t_pk primary key (object_id) ;
Table altered.
SQLPLUS > exec dbms_stats.gather_table_stats(user,'T',cascade=>true);
PL/SQL procedure successfully completed.
SQLPLUS > begin
for x in ( select rowid rid from t )
loop
update t set object_name = lower(object_name) where rowid = x.rid ;
commit;
end loop ;
end;
/
SQLPLUS > declare
cursor c is
select /*+ first_rows */ object_name
from t
order by object_id ;
l_object_name t.object_name%type ;
l_rowcnt number := 0 ;
begin
open c;
loop
fetch c into l_object_name ;
exit when c%notfound ;
dbms_lock.sleep( 0.01 ) ;
l_rowcnt := l_rowcnt + 1 ;
end loop ;
close c ;
exception
when others then
dbms_output.put_line ( 'rows fetched = ' || l_rowcnt ) ;
raise;
end ;
/
rows fetched = 301
declare
*
ERROR at line 1:
ORA-01555: snapshot too old: rollback segment number 46 with name
"_SYSSMU46_2555494716$" too small
ORA-06512: at line 21
SQLPLUS > create undo tablespace undo_small
2 datafile '/tmp/undo.dbf' size 4m
3 autoextend off
4 /
Tablespace created.
SQLPLUS > create table big
2 as
3 select a.*, rpad ('*', 1000, '*') data
4 from all_objects a;
Table created.
SQLPLUS > alter table big add constraint big_pk
2 primary key (object_id);
Table altered.
SQLPLUS > exec dbms_stats.gather_table_stats(user, 'BIG') ;
PL/SQL procedure successfully completed.
SQLPLUS > create table small ( x int, y char(500) );
Table created.
SQLPLUS > insert into small select rownum , 'x' from all_users ;
44 rows created.
SQLPLUS > commit ;
Commit complete.
SQLPLUS > exec dbms_stats.gather_table_stats(user, 'SMALL') ;
PL/SQL procedure successfully completed.
SQLPLUS > alter system set undo_tablespace = undo_small ;
System altered.
-- 블록의 첫 번째 row id 를 찾아 temporary ( VARCHAR2(1) 필드를 수정한다 )
SQLPLUS > update big
set temporary = temporary
where rowid in
( select r from (
select rowid r, row_number() over ( partition by dbms_rowid.rowid_block_number(rowid) order by rowid) rn
from big ) where rn = 1
)
/
12014 rows updated.
SQLPLUS > commit ;
Commit complete.
- 강좌 URL : http://www.gurubee.net/lecture/4029
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.