l 建立表空间
create tablespace kaoyi_cq
logging
datafile 'E:appxuweioradataorclKAOYI_cq.DBF' --这里是物理表空间文件的物理路径
size 1024m
autoextend on
next 100m maxsize unlimited
extent management local;
l 查看表空间剩余容量
² 以sys或dba权限用户登录
主要从数据库的表dba_data_files,dba_segments两张表中获取。默认数据库保存的是byte单位,转换关系如下:
1024bytes = 1kb
1024KB = 1M
1024M = 1G
² 视图脚本
CREATE OR REPLACE VIEW V_GET_DISKSPACE AS
SELECT A.TABLESPACE_NAME,
A.USE "USED (MB)",
(B.TOTAL-A.USE) "FREE (MB)",
B.TOTAL "TOTAL (MB)",
round((B.TOTAL-A.USE)/B.TOTAL,5)*100||'%' "PER_FREE"
FROM
(
select TABLESPACE_NAME,sum(bytes)/(1024*1024) as USE from dba_segments
/*where tablespace_name NOT IN ('USERS','SYSAUX','UNDOTBS1','SYSTEM','UNDOTBS2')*/
GROUP BY TABLESPACE_NAME
) A ,
(
WITH TABLESPACE_TOTAL AS
(
SELECT tablespace_name,sum(MAXBYTES)/(1024*1024) TOTAL FROM DBA_DATA_FILES T
WHERE /*T.TABLESPACE_NAME NOT IN ('USERS','SYSAUX','UNDOTBS1','SYSTEM','UNDOTBS2')
AND*/ T.AUTOEXTENSIBLE='YES' group by tablespace_name
UNION ALL
SELECT tablespace_name,sum(bytes) TOTAL FROM DBA_DATA_FILES T
WHERE /*T.TABLESPACE_NAME NOT IN ('USERS','SYSAUX','UNDOTBS1','SYSTEM','UNDOTBS2')
AND*/ T.AUTOEXTENSIBLE='NO' group by tablespace_name
)
SELECT TABLESPACE_NAME,SUM(TOTAL) TOTAL FROM TABLESPACE_TOTAL GROUP BY TABLESPACE_NAME
) B
WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME;
² 在视图表中查看结果
l 扩充表空间
² 查询表空间在物理磁盘上的位置
SELECT tablespace_name,
file_id,
file_name,
round(bytes / (1024 * 1024), 0) total_space
FROM dba_data_files
ORDER BY tablespace_name;
² 给需要扩充的表空间进行扩容操作
alter tablespace kaoyi
add datafile 'E:APPXUWEIORADATAORCLKAOYI0211.DBF' size 5m autoextend on;