1、查看表空间文件占用比例
select b.file_id
as 文件ID,
b.tablespace_name
as 表空间,
b.file_name
as 物理文件名,
b.bytes/1024/1024/1024
as 总字节数,
(b.bytes-sum(nvl(a.bytes,0)))/1024/1024/1024
as 已使用,
sum(nvl(a.bytes,0))/1024/1024/1024
as 剩余,
sum(nvl(a.bytes,0))/(b.bytes)*100
as 剩余百分比
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.file_id,b.bytes
order by b.tablespace_name ;
2、一键查询有表分区的表
SELECT TABLE_NAME,PARTITION_NAME,TABLESPACE_NAME
FROM USER_TAB_PARTITIONS;
3、查询oracle当前被锁对象
select a.session_id, c.serial#, a.locked_mode, a.oracle_username, a.os_user_name, c.machine,
c.terminal, b.object_name, c.logon_time
from v$locked_object a, all_objects b, v$session c
where a.object_id = b.object_id and a.session_id = c.sid
order by c.sid, c.serial#;
根据查出来的数据KILL掉
alter system kill session '24,111';
-4.察看TAXI用户的TAXIIDXTBS表空间有什么数据段
select * from DBA_SEGMENTS where owner = 'TAXI' and tablespace_name = 'TAXIIDXTBS' order by header_block desc;
--5.收缩数据文件
select a.file#,a.name,a.bytes/1024/1024 CurrentMB,
ceil(HWM * a.block_size)/1024/1024 ResizeTo,
(a.bytes - HWM * a.block_size)/1024/1024 ReleaseMB,
'alter database datafile '''||a.name||''' resize '||
ceil(HWM * a.block_size/1024/1024) || 'M;' ResizeCMD
from v$datafile a,
(select file_id,max(block_id+blocks-1) HWM
from dba_extents
group by file_id) b
where a.file# = b.file_id(+)
and (a.bytes - HWM *block_size)>0
order by 5
--6.增加表空间
ALTER TABLESPACE "SMCXKH" ADD DATAFILE 'F:\APP\ADMINISTRATOR\ORADATA\ORCL\testdbf1' SIZE 100M AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED
给SMCXKH表空间,增加testdbf1的数据文件,初始100M,每次增长100M,最大长到32G