最简单的处理办法就是重启计算机。
或者就要在数据库里排查出发生问题的原因,然后对症解决。
top查看系统的checkpoint动作我们可以通过将LOG_checkpointS_TO_ALERT设置成TRUE来打开checkpoint的trace,这样就可以跟踪checkpoint的 *** 作了。
ALTER SYSTEM SET LOG_checkpointS_TO_ALERT=TRUE
这设置以后系统的checkpoint将会被记录alert_$SID.log文件中。
在V$DATAFILE_HEADER里面也保存了发生完全checkpoint的时候一些相关信息,包括checkpoint发生时间、对应SCN已经checkpoint的次数。
select file# NO, status, tablespace_name, name, dbms_flashback.get_system_change_number CUR_SCN,
to_char(resetlogs_time, 'YYYY-MM-DD HH24:MI:SS') RST_DT, resetlogs_change# RST_SCN,
to_char(checkpoint_time, 'YYYY-MM-DD HH24:MI:SS') CKPT_DT, checkpoint_change# CKPT_SCN, checkpoint_count CKPT_CNT
from v$datafile_header
/**
NO STATUS TABLESPACE_NAME CUR_SCN RST_DT RST_SCN CKPT_DT CKPT_SCN CKPT_CNT
--- ------- ---------------- -------- ------------------- -------- ------------------- --------- ---------
1 ONLINE SYSTEM 533541 2008-01-12 16:51:53 446075 2008-08-04 22:03:58 532354 65
2 ONLINE UNDOTBS1 533541 2008-01-12 16:51:53 446075 2008-08-04 22:03:58 532354 28
3 ONLINE SYSAUX 533541 2008-01-12 16:51:53 446075 2008-08-04 22:03:58 532354 65
4 ONLINE USERS 533541 2008-01-12 16:51:53 446075 2008-08-04 22:03:58 532354 64
5 ONLINE EXAMPLE 533541 2008-01-12 16:51:53 446075 2008-08-04 22:03:58 532354 24
1.查看临时表空间使用情况Select
f.tablespace_name
,sum(f.bytes_free + f.bytes_used)
/1024/1024/1024 "total GB"
,sum((f.bytes_free + f.bytes_used) - nvl(p.bytes_used, 0))
/1024/1024/1024 "Free GB"
,sum(nvl(p.bytes_used, 0))
/1024/1024/1024 "Used GB"
from sys.v_$temp_space_header f, dba_temp_files d, sys.v_$temp_extent_pool p
where f.tablespace_name(+) = d.tablespace_name
and f.file_id(+) = d.file_id
and p.file_id(+) = d.file_id
group by
f.tablespace_name
2.查看使用临时表空间的SQL
Select se.username,
se.sid,
su.extents,
su.blocks * to_number(rtrim(p.value)) as Space,
tablespace,
segtype,
sql_text
from v$sort_usage su, v$parameter p, v$session se, v$sql s
where p.name = 'db_block_size'
and su.session_addr = se.saddr
and s.hash_value = su.sqlhash
and s.address = su.sqladdr
order by se.username, se.sid
3.收缩临时表空间
alter tablespace temp shrink space
alter tablespace temp shrink tempfile ''
4.重建索引
alter index PK_CROSSRELATION rebuild
5.查看表空间使用情况
SELECT UPPER(F.TABLESPACE_NAME) "表空间名",
D.TOT_GROOTTE_MB "表空间大小(M)",
D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",
TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,2),'990.99') || '%' "使用比",
F.TOTAL_BYTES "空闲空间(M)",
F.MAX_BYTES "最大块(M)"
FROM (SELECT TABLESPACE_NAME,
ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES,
ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES
FROM SYS.DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME) F,
(SELECT DD.TABLESPACE_NAME,
ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB
FROM SYS.DBA_DATA_FILES DD
GROUP BY DD.TABLESPACE_NAME) D
WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME
ORDER BY 1
6.查询表空间的总容量
select tablespace_name, sum(bytes) / 1024 / 1024 as MB
from dba_data_files
group by tablespace_name
7. 查询表空间使用率
select total.tablespace_name,
round(total.MB, 2) as Total_MB,考试大论坛
round(total.MB - free.MB, 2) as Used_MB,
round((1 - free.MB / total.MB) * 100, 2) || '%' as Used_Pct
from (select tablespace_name, sum(bytes) / 1024 / 1024 as MB
from dba_free_space
group by tablespace_name) free,
(select tablespace_name, sum(bytes) / 1024 / 1024 as MB
from dba_data_files
group by tablespace_name) total
where free.tablespace_name = total.tablespace_name
8. 查找当前表级锁的SQL如下:
select sess.sid,
sess.serial#,
lo.oracle_username,
lo.os_user_name,
ao.object_name,
lo.locked_mode
from v$locked_object lo,
dba_objects ao,
v$session sess
where ao.object_id = lo.object_id and lo.session_id = sess.sid
杀掉锁表进程:
alter system kill session '436,35123'
9.监控当前数据库谁在运行什么SQL语句
select osuser, username, sql_text
from v$session a, v$sqltext b
where a.sql_address =b.address order by address, piece
10.找使用CPU多的用户session
select a.sid,spid,status,substr(a.program,1,40) prog, a.terminal,osuser,value/60/100 value
from v$session a,v$process b,v$sesstat c
where c.statistic#=12 and
c.sid=a.sid and
a.paddr=b.addr
order by value desc
11.查看死锁信息
SELECT (SELECT username
FROM v$session
WHERE SID = a.SID) blocker, a.SID, 'is blocking',
(SELECT username
FROM v$session
WHERE SID = b.SID) blockee, b.SID
FROM v$lock a, v$lock b
WHERE a.BLOCK = 1 AND b.request >0 AND a.id1 = b.id1 AND a.id2 = b.id2
12.具有最高等待的对象
SELECT o.OWNER,o.object_name, o.object_type, a.event,
SUM (a.wait_time + a.time_waited) total_wait_time
FROM v$active_session_history a, dba_objects o
WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE
AND a.current_obj# = o.object_id
GROUP BY o.OWNER,o.object_name, o.object_type, a.event
ORDER BY total_wait_time DESC
13.查看具有最高等待的对象
SELECT a.session_id, s.osuser, s.machine, s.program, o.owner, o.object_name,
o.object_type, a.event,
SUM (a.wait_time + a.time_waited) total_wait_time
FROM v$active_session_history a, dba_objects o, v$session s
WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE
AND a.current_obj# = o.object_id
AND a.session_id = s.SID
GROUP BY o.owner,
o.object_name,
o.object_type,
a.event,
a.session_id,
s.program,
s.machine,
s.osuser
ORDER BY total_wait_time DESC
14.查看等待最多的SQL
SELECT a.program, a.session_id, a.user_id, d.username, s.sql_text,
SUM (a.wait_time + a.time_waited) total_wait_time
FROM v$active_session_history a, v$sqlarea s, dba_users d
WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE
AND a.sql_id = s.sql_id
AND a.user_id = d.user_id
GROUP BY a.program, a.session_id, a.user_id, s.sql_text, d.username
15.显示正在等待锁的所有会话
SELECT * FROM DBA_WAITERS
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)