您的位置:首页 > 数据库 > Oracle

Oracle表空间管理

2015-06-03 14:51 246 查看
1.创建表空间

create tablespace yyy
datafile '/u01/oracle/oradata/orcl/yyy01.dbf'
size 50m
autoextend on
next 50m maxsize unlimited
extent management local


2.创建用户

create user yyy identified by yyy
default tablespace yyy
temporary tablespace temp
profile DEFAULT


3.授权权限

-- Grant/Revoke object privileges
grant select on SYS.V_$SESSION to yyy;
grant select on SYS.V_$SESSTAT to yyy;
grant select on SYS.V_$STATNAME to yyy;
-- Grant/Revoke role privileges
grant connect to yyy;
grant resource to yyy;
-- Grant/Revoke system privileges
grant create view to yyy;
grant debug connect session to yyy;
grant unlimited tablespace to yyy;


4.查询表空间的大小

SELECT t.tablespace_name, round(SUM(bytes / (1024 * 1024)), 0) ts_size
FROM dba_tablespaces t, dba_data_files d
WHERE t.tablespace_name = d.tablespace_name
GROUP BY t.tablespace_name;


5.查看表空间对应的数据文件id和数据文件名称

SELECT tablespace_name,
file_id,
file_name,
round(bytes / (1024 * 1024), 0) total_space
FROM dba_data_files
ORDER BY tablespace_name;


6.查看表空间的使用情况

SELECT a.tablespace_name,
a.bytes/1024/1024 "total/m",
b.bytes/1024/1024 "used/m",
c.bytes/1024/1024 "free/m",
Round((c.bytes * 100)/a.bytes,2) " FREE %"
FROM sys.sm$ts_avail a, sys.sm$ts_used b, sys.sm$ts_free c
WHERE a.tablespace_name = b.tablespace_name
AND a.tablespace_name = c.tablespace_name;


7.更改表空间大小(dbf)

alter database datafile '数据文件路径' resize 大小;


8.删除表空间及关联关系

DROP TABLESPACE tablesapce_name including contents and datafiles cascade constraint;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: