达梦数据库表空间管理常用SQL

编程入门 行业动态 更新时间:2024-10-10 16:18:05

达梦数据库表空间管理<a href=https://www.elefans.com/category/jswz/34/1769776.html style=常用SQL"/>

达梦数据库表空间管理常用SQL

达梦数据库表空间管理常用SQL

  • 表空间容量分析
  • 表空间创建与扩容

查看数据库状态:

select name,instance_name,status$,mode$ from v$instance;
--mode$显示Primary为主库select name,status$,role$ from v$database;
--status$:1 启动,2 启动Redo完成,3 Mount,4 Open,5 挂起,6 关闭

表空间容量分析

查数据文件大小信息:

select client_path,total_size*32/1024 TOTAL_MB,
free_size*32/1024 FREE_MB,status$,max_size,auto_extend from v$datafile;select client_path,total_size*32/1024/1024 TOTAL_GB,
free_size*32/1024/1024 FREE_GB,status$,
max_size/1024 as MAX_GB,auto_extend from v$datafile;

查表空间大小信息:

select id,name,(total_size*page)/1024/1024/1024 total_GB,
(used_size*page)/1024/1024/1024 used_GB,
((total_size-used_size)*page)/1024/1024/1024 free_GB, 
max_size from v$tablespace;--> 真实的表空间使用率
select a.id,a.name,
round((a.total_size*page)/1024/1024/1024,2) total_GB,
round(b.max_mb/1024,2) max_GB,
round((a.used_size*page)/1024/1024/1024,2) used_GB,
round((b.max_mb - a.used_size*page/1024/1024)/1024,2) free_GB, 
round((a.used_size*page)/1024/1024/b.max_mb*100,2) || '%' used_pct
from v$tablespace a,
( select group_id, sum(max_size) max_mb from v$datafile group by group_id
) b where a.id=b.group_id;

表空间创建与扩容

创建用户表空间:

--> 需要手动指定数据文件名,建议统一命名格式为:USERNAME_TIMESTAMP.dbf
create tablespace TABLESPACE_NAME datafile 'DATAFILE_NAME_1.dbf' 
size 200 autoextend on maxsize 256*1024;

为指定用户扩容表空间,需要手动指定数据文件名。

alter tablespace TABLESPACE_NAME add datafile 'DATAFILE_NAME_2.dbf' 
size 200 autoextend on maxsize 256*1024;

修改数据文件大小:

alter tablespace "表空间名" resize datafile '数据文件名' to 1128;
--> 例如将数据文件DMHR.DBF大小指定为1128MB:alter tablespace "DMHR" resize datafile 'DMHR.DBF' to 1128;

🌻 更多内容参见:

更多推荐

达梦数据库表空间管理常用SQL

本文发布于:2023-11-16 20:14:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633707.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:常用   数据库   空间   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!