创建表空间:
create tablespace middledb_data datafile '/u01/app/oracle/oradata/middledb/middledb_data01.dbf' size 1024M autoextend on next 32M maxsize unlimited logging extent management local autoallocate blocksize 8k segment space management auto flashback on;
语句相关作用:
1. 创建表空间,名称为 middledb_data;
2. 表空间有一个数据文件*.dbf,大小为1024MB;
3. 允许表空间自动扩展(autoextends),每次增长32MB(next 32M),并且不限制最大大小;
4. 说明表空间本地(local)管理,并自动分配范围(autoallocate),用户不能指定范围的大小;
5. 段空间(segment)的空间管理上使用bitmaps(auto)来管理数据块。使用AUTO会比使用MANUAL有更好的空间利用率,与效能上的提升。
查询当前用户的表空间
select tablespace_name from dba_tablespaces;
查询当前用户的表空间 和大小
select t.TABLESPACE_NAME,d.FILE_NAME,d.AUTOEXTENSIBLE,d.USER_BYTES,d.USER_BLOCKS,d.MAXBYTES,d.MAXBLOCKS,d.ONLINE_STATUS,d.STATUS
from dba_tablespaces t ,dba_data_files d
where t.TABLESPACE_NAME=d.TABLESPACE_NAME
order by t.TABLESPACE_NAME,d.FILE_NAME;
select
tb1.Tablespace_name "Tablespace_name",
decode(sign(tb2.Sizes-0.99),1,round(tb2.Sizes,2) || 'GB',round(tb2.Sizes*1024,2) || 'MB') "Size",
decode(sign((tb2.Sizes-tb1.Free)-0.99),1,round((tb2.Sizes-tb1.Free),2) || 'GB',round((tb2.Sizes-tb1.Free)*1024,2) || 'MB') "Used",
decode(sign(tb1.Free-0.99),1,round(tb1.Free,2) || 'GB',round(tb1.Free*1024,2) || 'MB') "Free",
decode(sign(tb2.Max-0.99),1,round(tb2.Max,2) || 'GB',round(tb2.Max*1024,2) || 'MB') "Max",
to_number(round(((tb2.Sizes-tb1.Free)/tb2.Sizes)*100,2)) "Usage%",
to_number(round(((tb2.Sizes-tb1.Free)/tb2.Max)*100,2)) "Usageofmax%"
from
(select
tablespace_name,
round(sum(bytes)/power(2, 30),2) as Free
from dba_free_space
group by tablespace_name) tb1,
(select
tablespace_name,
round(sum(user_bytes)/power(2, 30),2) as Sizes,
round(sum(decode(autoextensible,'YES',maxbytes,'NO',bytes)/power(2, 30))) as Max
from dba
增加表空间文件04
alter tablespace TBS_LS_HTR add datafile '/u01/app/oracle/oradata/orcl/TBS_LS_HTR04.dbf' SIZE 1024M AUTOEXTEND ON NEXT 32M MAXSIZE UNLIMITED
修改表空间自增张
alter database datafile '/u01/app/oracle/oradata/orcl/TBS_LS_HTR03.dbf' AUTOEXTEND ON NEXT 32M MAXSIZE UNLIMITED
2.创建表空间和数据文件以后需要创建相应的用户和密码并给与授权:
CREATE USER GWM_PBOC_UAT IDENTIFIED BY oracle456
DEFAULT TABLESPACE "USERS"
TEMPORARY TABLESPACE "TEMP"
PROFILE "DEFAULT"
QUOTA UNLIMITED ON "USERS";
grant "dba" to middledb;
alter user middledb default role none;
(将该user已被授权的角色都设置为默认角色,非默认角色要激活才能拥有该角色的权限)
之后就可以执行二命令