drop table mcustsum purge;
create table mcustsum as
select rownum custno,
'2025' || lpad(ceil(rownum / 100000), 2, '0') salemm,
decode(mod(rownum, 12), 1, 'A', 'B') salegb,
round(dbms_random.value(1000, 100000), -2) saleamt
from dual
connect by level <= 120000;
๐ก scott A ์ธ์ ์ด select๋ฅผ ํ๋๋ฐ 15๋ถ ๋๊ฒ select๋ฅผ ํ๊ณ ์๋ ์ค์ ๋๋ค. ๊ทธ๋ฐ๋ฐ ๊ทธ ์ฌ์ด์ scott B ์ธ์ ์ด mucustsum์ 120๋ง๋ฒ์งธ ๋ฐ์ดํฐ์ธ salegb๋ฅผ B์ K๋ก ๋ณ๊ฒฝํ์ต๋๋ค. ๊ทธ๋ฌ๋ฉด B๋ UNDO segment์ ๋ค์ด๊ฐ๊ณ scott A๋ update ๋ณด๋ค ๋จผ์ ํ select๋ฌธ์ด๊ณ selectํ๊ธฐ ์ง์ ์ ์ต์ข ์ ์ผ๋ก commit ๋ ๋ฐ์ดํฐ๋ B์ด๊ธฐ ๋๋ฌธ์ B๋ฅผ ๋ด์ผํฉ๋๋ค.
๊ทธ๋ฐ๋ฐ 15๋ถ์ด ์ง๋ฌ๊ณ update ๋ฌธ์ commit์ ํ๊ธฐ ๋๋ฌธ์ B๊ฐ ์๋ undo segment ์๋ฆฌ๋ฅผ ๋ค๋ฅธ ํธ๋์ญ์ ์์ ์ํด์ ๋ฎ์ด์จ์ง ํฉ๋นํ ์ด์ ๊ฐ ์๊ฒผ์ต๋๋ค. ๊ทธ๋์ ๋ฎ์ด์ ธ๋ฒ๋ฆฌ๋ฉด scott A ์ธ์ ์ 120๋ง๋ฒ์งธ ๋ฐ์ดํฐ๋ฅผ ๋ณผ ๋ ์๋ฌ๊ฐ ๋๊ณ select๊ฐ ์คํจํ๊ฒ ๋๋ ๊ทธ ์๋ฌ๊ฐ ๋ฐ๋ก ORA-01555 snap shot too old ์๋ฌ์ ๋๋ค.
์ค๋ผํด์์ ๊ฐ์ฅ ๊ธธ๊ฒ ๋๋ ์ฟผ๋ฆฌ๋ฌธ์ ์๊ฐ์ ๋ง์ถฐ์ undo_retention์ ์ง์ ํ๋ผ๊ณ ๊ถ์ฅํ๊ณ ์์
์ค์ต. ORA-01555 snap shot too old ์๋ฌ๋ฅผ ์ผ์ผ์ผ ๋ณด์์ค !
#1. 10m ์ง๋ฆฌ ์ธ๋ ํ
์ด๋ธ ์คํ์ด์ค๋ฅผ ์์ฑํฉ๋๋ค.
create undo tablespace small_undo
datafile '/home/oracle/small_undo.dbf' size 10m autoextend off;
SYS @ ORA19 > show parameter undo_tablespace
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace string UNDOTBS1
#2. 10m ์ธ๋ ํ
์ด๋ธ ์คํ์ด์ค๋ฅผ ํ์ฌ ์ฌ์ฉ์ค์ธ undo tablespace ๋ก ๋ณ๊ฒฝํฉ๋๋ค.
alter system set undo_tablespace=small_undo;
SYS @ ORA19 > show parameter undo_tablespace
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace string SMALL_UNDO
SYS @ ORA19 >
#3. ํ
์ด๋ธ์ ์์ฑํ๊ณ ๋ฐ์ดํฐ๋ฅผ 10000 ๊ฑด์ ์
๋ ฅํฉ๋๋ค.
create table t1(c1 int, c2 char(300));
insert /*+ append */ into t1
select level, 'dummy'
from dual
connect by level <= 10000;
commit;
#4. ์ธ๋ฑ์ค๋ฅผ ์์ฑํฉ๋๋ค.
create index t1_n1 on t1(c1);
#5. ์ฌ์ฉ์ ์ ์ ํจ์๋ฅผ ์์ฑํฉ๋๋ค.
create or replace function fsleep(v1 int, vsleep int)
return number
is
begin
dbms_lock.sleep(vsleep);
return 1;
end;
/
# 6. ๋ฒํผ ์บ์ฌ ์ฌ์ด์ฆ๋ฅผ 1m ๋ก ๋ณ๊ฒฝํฉ๋๋ค.
alter system set db_cache_size = 1m;
#7. ์์ ๊ฐ์ด ํ๊ฒฝ๊ตฌ์ฑ์ ํ๊ณ ์๋์ ์ฟผ๋ฆฌ๋ฅผ ์ํํ๋ค.
select /*+ index(t1) */
c1, substr(c2,1,10)
from t1
where fsleep(c1, 0.01) = 1
and c1 > 0;
-- session 2 -------
# 1. ํ์ฌ ์ธ๋ ์ธ๊ทธ๋จผํธ๊ฐ ๋ญ๊ฐ์๋์ง ํ์ธํฉ๋๋ค.
-- get rollback segment name
col rollback_seg new_value v_rollback_seg
select '_SYSSMU'||max(segment_id)||'$' as rollback_seg
from dba_rollback_segs
where segment_name <> 'SYSTEM';
-- do very frequent commit on t1
#2. t1 ํ
์ด๋ธ์ update ๋ฅผ ๊ณ์ ๋ฐ๋ณต
begin
for idx in 1 .. 1000 loop
for idx2 in 1 .. 10000 loop
set transaction use rollback segment "&v_rollback_seg";
update t1 set c2 = 'dummy'||idx
where c1 = idx2;
commit;
end loop;
end loop;
end;
/
SYS @ ORA19 > alter system set undo_tablespace=undotbs1;
์์คํ
์ด ๋ณ๊ฒฝ๋์์ต๋๋ค.
SYS @ ORA19 > show parameter undo_tablespace
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace string UNDOTBS1
SYS @ ORA19 >
SYS @ ORA19 > alter system set db_cache_size=50m;
์์คํ
์ด ๋ณ๊ฒฝ๋์์ต๋๋ค.
SYS @ ORA19 > drop tablespace owi_tbs including contents and datafiles cascade constraints;