oracle表空间维护常用命令

---查看表空间的名字及文件所在位置:

select tablespace_name, file_id, file_name,round(bytes/(1024*1024),0) total_space

  from dba_data_files

  order by tablespace_name

 

---如何查看oracle表空间是否自动扩展 (increment_by是块数【8192byte/块】)

select file_name,tablespace_name,bytes/1024/1024 "bytes MB",autoextensible,increment_by,maxbytes/1024/1024 "maxbytes MB"

  from dba_data_files

  where tablespace_name='HSML;

select file_name,autoextensible,increment_by from dba_data_files ;

 

--- 查看Oracle数据库表空间大小(空闲、已使用),是否要增加表空间的数据文件

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) "percent_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 b.file_name 物理文件名,b.tablespace_name 表空间,b.bytes/1024/1024 大小M,(b.bytes-sum(nvl(a.bytes,0)))/1024/1024 已使用M,substr((b.bytes-sum(nvl(a.bytes,0)))/(b.bytes)

*100,1,5) 利用率  

  from dba_free_space a,dba_data_files b   where a.file_id=b.file_id  

  group by b.tablespace_name,b.file_name,b.bytes  

  order by b.tablespace_name;

 

---创建时加双引号,删除也加入双引号即可

SQL> DROP TABLESPACE "Liang" INCLUDING CONTENTS AND  DATAFILES;

 

---修改表空间为只读

alter tablespace test read only; 

 

---恢复表空间为正常状态 

alter tablespace test read wirite ;

 

怎么察看Oracle 数据库表空间的使用情况

select dbf.tablespace_name,dbf.totalspace "总量(M)",dbf.totalblocks as 总块数,dfs.freespace "剩余总量(M)",dfs.freeblocks "剩余块数",(dfs.freespace / dbf.totalspace) * 100 "空闲

比例"   

  from (select t.tablespace_name,sum(t.bytes) / 1024 / 1024 totalspace,sum(t.blocks) totalblocks

  from dba_data_files t group by t.tablespace_name) dbf,(select tt.tablespace_name,sum(tt.bytes) / 1024 / 1024 freespace,sum(tt.blocks) freeblocks

  from dba_free_space tt group by tt.tablespace_name) dfs   

  where trim(dbf.tablespace_name) = trim(dfs.tablespace_name)

 

--查询表空间数量 select * from v$tablespace

 

posted on   xihong  阅读(295)  评论(0编辑  收藏  举报

编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示