oracle 查看表空间使用情况以及删除表的几种方法

1、查询数据库中表空间的使用情况
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
    --and f.tablespace_name = upper('表空间名称')                       
  order by 使用比 desc;
--查看表空间中比较大的表
  SELECT owner,
         segment_name,
         segment_type,
         partition_name,
         bytes / 1024 / 1024 / 1024     "所占大小(G)",
         tablespace_name                "表空间名"
    FROM dba_segments
   WHERE tablespace_name = '表空间名称'
ORDER BY 5 DESC;
2、删除表结构和表数据
drop table 表名 [purge]  purge  表示不放入回收站
对于一些临时表[表示确定以及肯定不需要的表]的删除,建议使用此法删除
3、删除表数据
delete from 表名 [where ...]
  特点:高水位线不降;记录日志,速度慢,可以恢复(savepoint test; rollback to test;)
4、删除表数据
truncate table 表名
不记录日志,高水位线下降 
PS:此种删除模式可能会导致原表索引失效,建议truncate后 插入数据后看索引是否有效
5、drop table 表名 ;表进入回收站
 查询回收站所有的表:
    select * from recyclebin where type='TABLE';
  删除回收站中指定的表:
    purge table tablename;
  恢复回收站中指定的表及其数据:
    flashback table tablename to before drop;
  删除回收站中所有的表:
    用来删除回收站中所有的表 purge recyclebin;

posted on 2020-05-17 15:15  机器猫007  阅读(701)  评论(0)    收藏  举报

导航