关于oracle:查询表空间使用率以及部分基础命令

7次阅读

共计 1299 个字符,预计需要花费 4 分钟才能阅读完成。

一、查看表所占空间大小

–1、查看用户表、索引、分区表占用空间

select segment_name, sum(bytes)/1024/1024 as Mbytes from user_segments group by segment_name order by Mbytes desc;

–2、表占用空间:

select segment_name, sum(bytes)/1024/1024 as Mbytes from user_segments where segment_type='TABLE' group by segment_name order by Mbytes desc;

–3、索引占用空间:

select segment_name ,sum(bytes)/1024/1024 as Mbytes from user_segments where segment_type ='INDEX' group by segment_name order by Mbytes desc;

–4、分区表 TABLE PARTITION 占用空间:

select segment_name,sum(bytes)/1024/1024 as Mbytes from user_segments where segment_type='TABLE PARTITION' group by segment_name order by Mbytes desc;


1、查问各个表空间使用率
SELECT a.tablespace_name “ 表空间名 ”,

   total/1024/1024  "表空间大小单位 M",

   free/1024/1024 "表空间残余大小单位 M",

   (total - free)/1024/1024 "表空间应用大小单位 M",

   Round((total - free) / total, 4) * 100 "使用率   [[%]]"FROM 

   (SELECT tablespace_name,Sum(bytes) free FROM DBA_FREE_SPACE GROUP BY tablespace_name) a,

   (SELECT tablespace_name,

           Sum(bytes) total FROM DBA_DATA_FILES GROUP BY tablespace_name) b WHERE a.tablespace_name = b.tablespace_name;

2、删除对应多的表数据

清理审计的数据,如果要保留局部 AUD$ 外面记录的审计数据,能够把想要的数据插入到一张长期表,而后间接 truncate 这张表就能够了,truncate 操作会间接回收 AUD$ 占用的空间。

truncate table AUD$;

3、删除
– 查问所有垃圾表


select * from recyclebin where type='TABLE';

– 删除回收站中所有的表


PURGE RECYCLEBIN ------- 这语句就能革除所有以 BIN 结尾的残留文件 

– 删除指定的垃圾表

PURGE TABLE TABLE_NAME

4. 表空间的扩大

alter tablespace MOF add datafile 'D:\Oracle\oradata\oracl\mofss.dbf' size 500M AUTOEXTEND on next 100m;

正文完
 0