侧边栏壁纸
博主头像
学海无涯博主等级

有疑问可发邮件[email protected]

  • 累计撰写 326 篇文章
  • 累计创建 85 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

ORACLE表空间操作基础命令

利刃
2020-06-23 / 0 评论 / 0 点赞 / 9 阅读 / 3180 字
温馨提示:
本文最后更新于 2024-08-13,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

一、创建临时表空间

create temporary tablespace USER_TEMP tempfile '/Project/DB/USER_TEMP.DBF' size 200m autoextend on next 100m maxsize 20480m extent management local;

二、创建表空间

create  tablespace USER DATAFILE '/Project/DB/USER.DBF' size 200m autoextend on next 100m maxsize 20480m extent management local;

三、扩展表空间

alter tablespace USER add datafile '/u01/app/oracle/oradata/USER02.DBF' size 200m autoextend on next 100m maxsize 20480m;

四、扩展临时表空间

alter tablespace USER add tempfile '/u01/app/oracle/oradata/orcl/USER.DBF' size 200m REUSE autoextend on next 100m maxsize 20480m;

五、查看表空间的名字及文件所在位置

select tablespace_name,
       file_id,
       file_name,
       round(bytes / (1024 * 1024), 0) total_space
  from sys.dba_data_files
 order by tablespace_name

六、查看临时表空间的名字及文件所在位置

 select tablespace_name,
       file_id,
       file_name,
       round(bytes / (1024 * 1024), 0) total_space
  from sys.dba_TEMP_files
 order by tablespace_name

七、查询表空间信息

select username,default_tablespace,t.* from dba_users t

八、查询当前表空间下使用情况

select a.tablespace_name,
       a.bytes / 1024 / 1024 "sum MB",
       (a.bytes - b.bytes) / 1024 / 1024 "used MB",
       b.bytes / 1024 / 1024 "free MB",
       round(((a.bytes - b.bytes) / a.bytes) * 100, 2) "used%"
  from (select tablespace_name, sum(bytes) bytes
          from dba_data_files
         group by tablespace_name) a,
       (select tablespace_name, sum(bytes) bytes, max(bytes) largest
          from dba_free_space
         group by tablespace_name) b
 where a.tablespace_name = b.tablespace_name
 order by ((a.bytes - b.bytes) / a.bytes) desc;

九、查看临时表空间

SELECT D.TABLESPACE_NAME,SPACE "SUM_SPACE(M)",BLOCKS SUM_BLOCKS,
USED_SPACE "USED_SPACE(M)",ROUND(NVL(USED_SPACE,0)/SPACE*100,2) "USED_RATE(%)",
NVL(FREE_SPACE,0) "FREE_SPACE(M)"
FROM
(SELECT TABLESPACE_NAME,ROUND(SUM(BYTES)/(1024*1024),2) SPACE,SUM(BLOCKS) BLOCKS
FROM DBA_TEMP_FILES
GROUP BY TABLESPACE_NAME) D,
(SELECT TABLESPACE_NAME,ROUND(SUM(BYTES_USED)/(1024*1024),2) USED_SPACE,
ROUND(SUM(BYTES_FREE)/(1024*1024),2) FREE_SPACE
FROM V$TEMP_SPACE_HEADER
GROUP BY TABLESPACE_NAME) F
WHERE  D.TABLESPACE_NAME = F.TABLESPACE_NAME(+);

十、删除临时表空间多余的数据文件

alter database tempfile '/u01/app/oracle/oradata/orcl/TSBX_DATA/TSBX_TEMP02.DBF' offline;
alter database tempfile '/u01/app/oracle/oradata/orcl/TSBX_DATA/TSBX_TEMP02.DBF' drop;




二〇二〇年六月二十三日 16:25:49

0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区