一、查看表空间使用情况
Sql代码
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 4 DESC;
二、给表空间添加数据文件
Sql代码
alter tablespace 空间名 add datafile
‘/dev/rdata_1g_21′ size 1000M autoextend off,
‘/dev/rdata_1g_25′ size 1000M autoextend off,
‘/dev/rdata_1g_22′ size 1000M autoextend off;
三、查看某表是否被锁
Sql代码
select c.inst_id, b.object_name, a.session_id, c.serial#, c.machine,
c.PROGRAM,c.username,c.status, c.osuser, c.logon_time ,a.*
from gv$locked_object a, dba_objects b, gv$session c
where a.object_id=b.object_id and b.object_name=’TOAD_PLAN_TABLE’
and c.sid=a.session_id and schemaname<>’SYS’ ;
四、查看资源回滚情况
Sql代码
Select a.Osuser,
a.Sid,
a.Program,
b.Start_Time,
b.Used_Ublk,
b.Used_Urec,
b.Xidusn || ‘.’ || b.Xidslot || ‘.’ || b.Xidsqn Trans_Id
From V$session a, V$transaction b
Where a.Taddr = b.Addr
–And a.Sid = 4361
Order By Sid
五、查询Oracle正在执行的sql语句及执行该语句的用户
SELECT b.sid oracleID,
b.username 登录Oracle用户名,
b.serial#,
spid 操作系统ID,
paddr,
sql_text 正在执行的SQL,
b.machine 计算机名
FROM v$process a, v$session b, v$sqlarea c
WHERE a.addr = b.paddr
AND b.sql_hash_value = c.hash_value
六、查看正在执行sql的发起者的发放程序
SELECT OSUSER 电脑登录身份,
PROGRAM 发起请求的程序,
USERNAME 登录系统的用户名,
SCHEMANAME,
B.Cpu_Time 花费cpu的时间,
STATUS,
B.SQL_TEXT 执行的sql
FROM V$SESSION A
LEFT JOIN V$SQL B ON A.SQL_ADDRESS = B.ADDRESS
AND A.SQL_HASH_VALUE = B.HASH_VALUE
ORDER BY b.cpu_time DESC
七、查出oracle当前的被锁对象
SELECT l.session_id sid,
s.serial#,
l.locked_mode 锁模式,
l.oracle_username 登录用户,
l.os_user_name 登录机器用户名,
s.machine 机器名,
s.terminal 终端用户名,
o.object_name 被锁对象名,
s.logon_time 登录数据库时间
FROM v$locked_object l, all_objects o, v$session s
WHERE l.object_id = o.object_id
AND l.session_id = s.sid
ORDER BY sid, s.serial#;
八、kill掉当前的锁对象可以为
alter system kill session ‘sid, s.serial#‘;
九、利用oracle的闪存恢复数据
alter table b_zdrygk_mhbkzl enable row movement;
flashback table b_zdrygk_mhbkzl to timestamp to_timestamp(’2011-11-28 09:30:00′,’yyyy-mm-dd hh24:mi:ss’);
(短时间的用。长时间的就别用了)