oracle用户、表空间操作常用命令-CSDN博客

176 阅读1分钟

创建表空间:

 

create tablespace tablespace_name datafile '/dbf/data.dbf' size 1000M autoextend on next 100M;

创建用户并指定默认表空间:

create user cxf identified by 111111 default tablespace tablespace_name ;

赋予用户权限:

grant connect,resource,dba to cxf;

扩展表空间:

ALTER TABLESPACE tablespace_name ADD DATAFILE '/dbf/data2.DBF' SIZE 32767M;

查看用户和默认表空间的关系:

select username,default_tablespace from dba_users;

修改用户密码:

alter user 用户名 identified by 新密码;

查看剩余表空间大小:

select tablespace_name,sum(bytes)/1024/1024/1024 free_space from dba_free_space group by tablespace_name;

查看表空间使用情况:

SELECT a.tablespace_name "表空间名称",

total / (1024 * 1024) "表空间大小(M)",

free / (1024 * 1024) "表空间剩余大小(M)",

(total - free) / (1024 * 1024 ) "表空间使用大小(M)",

total / (1024 * 1024 * 1024) "表空间大小(G)",

free / (1024 * 1024 * 1024) "表空间剩余大小(G)",

(total - free) / (1024 * 1024 * 1024) "表空间使用大小(G)",

round((total - free) / total, 4) * 100 "使用率 %"

FROM (SELECT tablespace_name, SUM(bytes) free

FROM dba_free_space

GROUP BY tablespace_name) a,

(SELECT tablespace_name, SUM(bytes) total

FROM dba_data_files

GROUP BY tablespace_name) b

WHERE a.tablespace_name = b.tablespace_name

查看表空间物理文件的名称及大小

SELECT tablespace_name,

file_id,

file_name,

round(bytes / (1024 * 1024), 0) total_space

FROM dba_data_files

ORDER BY tablespace_name;

写在最后

写文章目的就是交流分享,如有问题还请指正,本人邮箱784482906@qq.com