by 구루비스터디 PGA UGA Process Global Area User Global Area [2018.09.27]
--run_query.sql
connect /
set serveroutput off
set echo on
column sid new_val SID
select sid from v$mystat where rownum = 1;
alter session set workarea_size_policy=manual;
alter session set sort_area_size = &1;
prompt run @reset_stat &SID and @watch_stat in another session here!
pause
set termout off
select * from t order by 1,2,3,4;
set termout on
prompt run @watch_stat in another session here!
Pause
and then run:
--2.관찰을 위한 작은 테이블을 리셋하고 SQL*Plus 변수에 SID를 설정
--reset_stat.sql
drop table sess_stats;
create table sess_stats
( name varchar2(64), value number, diff number);
variable sid number
exec :sid :=&1
--3.스크립트에 세션의 통계값을 INSERT하고 이후에 통계값을 갱신하기 위해
MERGE SQL문을 생성
--watch_stat.sql
merge into sess_stats
using
(
select a.name, b.value from v$statname a, v$sesstat b
where a.statistic# = b.statistic#
and b.sid = :sid
and (a.name like '%ga %' or a.name like '%direct temp%')
) curr_stats
on (sess_stats.name = curr_stats.name)
when matched then
update set diff = curr_stats.value - sess_stats.value,
value = curr_stats.value
when not matched then
insert (name, value, diff)
values (curr_stats.name, curr_stats.value, null)
/
select name,
case when name like '%ga %'
then round(value/1024,0)
else value
end kbytes_writes,
case when name like '%ga %'
then round(diff / 1024,0)
else value
end diff_kbytes_writes
from sess_stats
order by name;
SQL> @/oracle/test.sql 65536
SQL> column sid new_val SID
SQL> select sid from v$mystat where rownum = 1;
SID
----------
1038
SQL> alter session set workarea_size_policy=manual;
Session altered.
SQL> alter session set sort_area_size = &1;
old 1: alter session set sort_area_size = &1
new 1: alter session set sort_area_size = 65536
Session altered.
SQL> prompt run @/oracle/reset.sql &SID and @watch_stat in another session here!
run @/oracle/reset.sql 1038 and @watch_stat in another session here!
SQL> pause
SQL> @/oracle/reset.sql 1038
Table dropped.
Table created.
PL/SQL procedure successfully completed.
SQL> @/oracle/watch.sql
6 rows merged.
NAME KBYTES_WRITES
---------------------------------------------------------------- -------------
DIFF_KBYTES_WRITES
------------------
physical reads direct temporary tablespace 0
0
physical writes direct temporary tablespace 0
0
session pga memory 585
NAME KBYTES_WRITES
---------------------------------------------------------------- -------------
DIFF_KBYTES_WRITES
------------------
session pga memory max 585
session uga memory 170
session uga memory max 170
6 rows selected.
SQL>
- 강좌 URL : http://www.gurubee.net/lecture/4011
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.