Oracle系列---【表空间常用命令】
1.创建表空间
#创建大小为30G且开启自增的表空间
CREATE TABLESPACE TEST_COM_SMM_FRONT DATAFILE '/oradata/ORA19/datafile/TEST_COM_SMM_FRONT_01.dbf' SIZE 30024M AUTOEXTEND ON;
2.查看表空间使用情况
#表空间数据文件维度使用率查询
SELECT
b.TABLESPACE_NAME,
b.FILE_NAME,
SUBSTR(b.BYTES/1024/1024/1024,1,5) 总大小G,
SUBSTR(b.BYTES-SUM(NVL(a.BYTES,0)))/1024/1024/1024,1,5) 已使用G,
SUBSTR(b.BYTES-SUM(NVL(a.BYTES,0)))/b.BYTES*100,1,5) 使用率
FROM
SYS.DBA_FREE_SPACE a
INNER JOIN
SYS.DBA_DATA_FILES b
ON
a.FILE_ID = b.FILE_ID
GROUP BY
b.TABLESPACE_NAME,b.FILE_NAME,b.BYTES
ORDER BY SUBSTR((b.BYTES-SUM(NVL(a.BYTES,0)))/b.BYTES*100,1,5) DESC;
#表空间维度
SELECT
b.TABLESPACE_NAME,
SUBSTR(b.BYTES/1024/1024/1024,1,5) 总大小G,
SUBSTR((b.BYTES-SUM(NVL(a.BYTES,0)))/1024/1024/1024,1,5) 已使用G,
SUBSTR((b.BYTES-SUM(NVL(a.BYTES,0)))/b.BYTES*100,1,5) 使用率
FROM
SYS.DBA_FREE_SPACE a
INNER JOIN
SYS.DBA_DATA_FILES b
ON
a.FILE_ID = b.FILE_ID
GROUP BY
SUBSTR((b.BYTES-SUM(NVL(a.BYTES,0)))/b.BYTES*100,1,5) DESC;
3.表空间新增数据文件
ALTER tablespace TEST_COM_SC
ADD DATAFILE '/oradata/ORA19/datafile/TEST_COM_SMM_FRONT_02.dbf'
SIZE 20480M
AUTOEXTEND ON NEXT 5000M;
ALTER DATABASE DATAFILE '/oradata/ORA19/datafile/TEST_COM_SMM_FRONT_01.dbf'
AUTOEXTEND ON NEXT 500M;
4.用户表空间查询
SELECT
DISTINCT a.TABLESPACE_NAME
FROM
DBA_TABLES a
LEFT JOIN DBA_TABLESPACES b ON
a.TABLESPACE_NAME = b.TABLESPACE_NAME
WHERE
OWNER LIKE 'TEST_%';
5.关闭表空间自增
#查看已开启自增的表空间
SELECT FILE_NAME,
TABLESPACE_NAME,
AUTOEXTENSIBLE,
'ALTER DATABASE DATAFILE '''||FILE_NAME||''' AUTOEXTEND OFF;',
FROM DBA_DATA_FILES
WHERE
AUTOEXTENSIBLE ='YES'
AND TABLESPACE_NAME LIKE 'TEST%';
#关闭表空间自增
ALTER DATABASE DATAFILE '/oradata/ORA19/datafile/TEST_COM_SMM_FRONT_01.dbf' AUTOEXTEND OFF;
6.删除oracle用户
DROP USER YOUR_USERNAME CASCADE;
ALTER TABLESPACE YOUR_TABLESPACE_NAME SHRINK SPACE;
7.修改表中表分区的表空间
ALTER TABLE `TEST_NEW_DS.BANK_OPER` MOVE PARTITION `SYS_P1706` TABLESPACE `TEST_NEW_DS`;
愿你走出半生,归来仍是少年!