Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> script to show who is using temp. tablespaces.
I've been contacting Oracle support about finding a script to display
who is using up
the temporary tablespace. They have replied that someone sent them the
following
script. They did state that it has not been tested. I have had some luck
running
it to show who is using the space but not how much space they are using.
If you have better luck please email me.
type temp_seg_number_array is table of number index by binary_integer;
temp_seg_file_no temp_seg_number_array; temp_seg_block_no temp_seg_number_array; temp_seg_owner temp_seg_number_array;
loop_cnt number; temp_tmp_flag number; perm_tmp_flag number; temp_table_dba number; temp_table_block_no number; temp_table_file_no number; temp_table_nblocks number; temp_table_nextents number; temp_table_tbs_num number; sess_id number; sess_addr varchar2(50);
kssob_type_flag varchar2(50); kssob_own_ptr varchar2(50); kssob_nxt_link varchar2(50); kssob_prv_link varchar2(50);
function to_decimal (hex_str_in in varchar2) return number as
hex_str varchar2(50) :=hex_str_in;
result number;
hex_char number;
begin
if ( sga_word_size = 8 ) then
hex_str := lpad(upper(nvl(ltrim(hex_str,'0'),'0')),16,'0');
result := 0;
for i in 1..16 loop
hex_char := ascii(substr(hex_str,i,1));
if (hex_char - 64 > 0 ) then
hex_char := hex_char - 64 + 9;
else
hex_char := hex_char - 48 ;
end if;
result := result + ( hex_char * power(2, ( 64 - (i*4) ) ) );
end loop;
return (trunc(result));
else
hex_str := lpad(upper(nvl(ltrim(hex_str,'0'),'0')),8,'0');
result := 0;
for i in 1..8 loop
hex_char := ascii(substr(hex_str,i,1));
if (hex_char - 64 > 0 ) then
hex_char := hex_char - 64 + 9;
else
hex_char := hex_char - 48 ;
end if;
result := result + ( hex_char * power(2, ( 32 - (i*4) ) ) );
end loop;
return (trunc(result));
end if;
end;
procedure get_base_address as
hex_address varchar2(40);
begin
select rawtohex(addr)
into hex_address
from x$ksmmem
where indx = 0;
sga_base_address := to_decimal(hex_address);
sga_base_address_hex := hex_address;
end;
function get_sga_index(sga_address in varchar2) return number as
begin
return trunc((to_decimal(sga_address)-sga_base_address)/sga_word_size );
end;
function get_sga_index_rem (sga_address in varchar2) return number as
begin
return (mod((to_decimal(sga_address)-sga_base_address),sga_word_size));
end;
function get_sga_value (hex_address in varchar2,adjustment in number
default 0)
return varchar2 as
sga_index number;
local_value varchar2(50);
begin
sga_index := get_sga_index(hex_address) + adjustment;
if (debug) then
dbms_output.put_line('. get_sga_value '||hex_address||' '||
to_char(adjustment));
dbms_output.put_line('. get_sga_value get_sga_index '||sga_index);
end if;
select rawtohex(ksmmmval) into local_value from x$ksmmem
where indx = sga_index;
return local_value;
end;
function get_temp_table_state_object(state_name in varchar2) return number as
local_state_object number;
hex_str varchar2(50);
state_object_address varchar2(50);
state_object_offset number;
sga_structure boolean;
sga_col_count number;
c1 integer;
rc integer;
sql_stmt varchar2(255);
begin
select count(*) into sga_col_count from x$kqfta a, x$kqfco b
where a.kqftanam = 'X$KSMFSV' and a.indx = b.KQFCOTAB
and b.KQFCONAM = 'KSMFSADR';
if ( sga_col_count = 1 ) then
sga_structure := false;
else
sga_structure := true;
end if;
if ( sga_structure ) then
c1 := dbms_sql.open_cursor;
sql_stmt := 'select KSMFSOFF from x$ksmfsv
where KSMFSNAM like '''||state_name||'''';
dbms_sql.parse(c1,sql_stmt,dbms_sql.native);
dbms_sql.define_column(c1,1,state_object_offset);
rc := dbms_sql.execute(c1);
rc := dbms_sql.fetch_rows(c1);
dbms_sql.column_value(c1,1,state_object_offset);
dbms_sql.close_cursor(c1);
local_state_object:=to_decimal(
get_sga_value(sga_base_address_hex,
state_object_offset/sga_word_size));
else
c1 := dbms_sql.open_cursor;
sql_stmt := 'select rawtohex(KSMFSADR) from x$ksmfsv
where KSMFSNAM like '''||state_name||'''' ;
dbms_sql.parse(c1,sql_stmt,dbms_sql.native);
dbms_sql.define_column(c1,1,state_object_address,50);
rc := dbms_sql.execute(c1);
rc := dbms_sql.fetch_rows(c1);
dbms_sql.column_value(c1,1,state_object_address); dbms_sql.close_cursor(c1); dbms_output.put_line('state_object_address '||state_object_address);
function state_object_initialised(flags in varchar2) return boolean
is
begin
if ( sga_word_size = 8 and byte_swapped ) then
if ( to_decimal(substr(flags,14,1)) = 1 ) then
return true;
else
return false;
end if;
else
if ( byte_swapped ) then
if ( to_decimal(substr(flags,6,1)) = 1 ) then
return true;
else
return false;
end if;
else
if ( to_decimal(substr(flags,4,1)) = 1 ) then
return true;
else
return false;
end if; end if; end if;
function match_flag(state_flag in number,flags in out varchar2) return
boolean
is
begin
if ( byte_swapped ) then
if ( sga_word_size = 8 ) then
flags:=lpad(upper(nvl(ltrim(flags,'0'),'0')),16,'0');
if (debug) then
dbms_output.put_line('. '||
to_decimal(substr(flags,15,2))||
'?='||state_flag);
end if;
if ( to_decimal(substr(flags,15,2)) = state_flag ) then
return true;
else
return false;
end if;
else
if ( to_decimal(substr(flags,7,2)) = state_flag ) then
return true;
else
return false;
end if;
end if;
else
if ( to_decimal(substr(flags,1,2)) = state_flag ) then
return true;
else
return false;
end if;
end if;
end;
procedure build_active_temp_segments as
cursor c1 is select file#,block# from seg$ where type=3;
local_file_no number;
local_block_no number;
begin
open c1;
no_of_temp_segments := 0 ;
loop
fetch c1 into local_file_no,local_block_no;
exit when c1%notfound;
no_of_temp_segments := no_of_temp_segments + 1;
temp_seg_file_no(no_of_temp_segments) := local_file_no ; temp_seg_block_no(no_of_temp_segments) := local_block_no; temp_seg_owner(no_of_temp_segments) := (-1);end loop;
function valid_temp_seg_dba (t_file_no number, t_block_no number,
sess_id number ) return boolean
is
begin
for i in 1..no_of_temp_segments loop
if ( temp_seg_file_no(i) = t_file_no and
temp_seg_block_no(i)= t_block_no ) then
temp_seg_owner(i) := sess_id ;
return true;
end if;
end loop;
return false;
end;
begin
get_base_address;
dbms_output.put_line('SGA base '||sga_base_address); temp_tmp_flag:=get_temp_table_state_object('%ktstud%'); perm_tmp_flag:=get_temp_table_state_object('%ktatlt%'); dbms_output.put_line('temp tmp state '||temp_tmp_flag); dbms_output.put_line('perm tmp state '||perm_tmp_flag);build_active_temp_segments;
:=dbms_utility.data_block_address_block(temp_table_dba);
if (valid_temp_seg_dba(temp_table_file_no,temp_table_block_no,
sess_id) ) then
sys.dbms_output.put_line(
'Session '||rpad(to_char(sess_id),6,' ')|| ' DBA '||rpad(temp_table_dba,10,' ')|| ' File No '||rpad(temp_table_file_no,6,' ')||' Block No '||rpad(temp_table_block_no,10,' '));
'Session '||rpad(to_char(sess_id),6,' ')|| ' TS id # :'||temp_table_tbs_num|| ' Blocks used :'||temp_table_nblocks|| ' Exetents used :'||temp_table_nextents);end if;