library cache pin和lock的区别
这个问题在面试中曾被问倒过,网络上能找到的资料也比较少,后来和yyxup,久游的一个puber讨论了半天,总算搞懂了一点
library cache object在内存中是分成2部分来存储的,第一部分是头信息,叫做handle,头信息里保存了指向具体保存该对象的地址,这个叫做heap.一个对象可能分为很多个heap要访问或者修改一个对象,首先要锁住其头信息,也就是handle,以防止其他session同时访问或者修改该对象,这是library cache lock要做的事情而当实际的访问或者修改对象的内容时,则要根据头信息去访问或者修改具体的heap的,那么也要防止其他session同时访问或者修改这些heap,所以对heap需要加library cache pin来保护(Nigoo的描述)
下面是我这一年来比较常用的几个脚本,基本上处理问题就靠这些sql混了,现记录下来
1.查看用户的session信息
select * from v$session where username='ETL'
2.查看sid所对应的spid
select se.SID,se.SERIAL#,pr.SPID from v$session se,v$process pr where pr.ADDR=se.PADDR and se.SID=71
3.查看sid相应的执行sql
SELECT sql_text FROM v$sqltext a WHERE a.hash_value = (SELECT sql_hash_value FROM v$session b WHERE b.SID = '48') ORDER BY piece ASC
4.查看spid相应执行sql
4.查看spid相应执行sql
SELECT /*+ ORDERED */ sql_text FROM v$sqltext a WHERE (a.hash_value, a.address) IN
(SELECT DECODE(sql_hash_value, 0, prev_hash_value, sql_hash_value),
DECODE(sql_hash_value, 0, prev_sql_addr, sql_address)
FROM v$session b
WHERE b.paddr =
(SELECT addr FROM v$process c WHERE c.spid = '15125'))
ORDER BY piece ASC
5.查看block所在的表空间
(SELECT DECODE(sql_hash_value, 0, prev_hash_value, sql_hash_value),
DECODE(sql_hash_value, 0, prev_sql_addr, sql_address)
FROM v$session b
WHERE b.paddr =
(SELECT addr FROM v$process c WHERE c.spid = '15125'))
ORDER BY piece ASC
5.查看block所在的表空间
SELECT tablespace_name, segment_type, owner, segment_name FROM dba_extents WHERE file_id = 44 and 35245 between block_id AND block_id + blocks
6.产生批处理可以执行文件
6.产生批处理可以执行文件
begin
for i in -60..-1 loop
dbms_output.put_line('exec proc_tbl_sms_order_from(sysdate'||i||') ;');
end loop;
end ;
for i in -60..-1 loop
dbms_output.put_line('exec proc_tbl_sms_order_from(sysdate'||i||') ;');
end loop;
end ;
7.ALTER TABLE tbl_mt_succ DROP partition TBL_MT_SUCC_2006P9; --删除表分区
ALTER TABLE tbl_mt_succ ADD PARTITION TBL_MT_SUCC_2008P3 VALUES LESS THAN (TO_DATE('2008-04-01','YYYY-MM-DD') ) ; --增加分区
ALTER TABLE tbl_mt_succ ADD PARTITION TBL_MT_SUCC_2008P3 VALUES LESS THAN (TO_DATE('2008-04-01','YYYY-MM-DD') ) ; --增加分区
8.事务的uno
select used_ublk from v$transaction where addr = (select taddr from v$session where sid = (select sid from v$mystat where rownum = 1))
9.事务的redo
select my.SID, st.NAME, my.VALUE from v$mystat my, v$statname st where st.STATISTIC# = my.STATISTIC# and st.NAME = 'redo size'
select my.SID, st.NAME, my.VALUE from v$mystat my, v$statname st where st.STATISTIC# = my.STATISTIC# and st.NAME = 'redo size'