oracle 表空间创建
程序员文章站
2022-05-07 16:42:23
...
SYS用户在CMD下以DBA身份登陆:
在CMD中打sqlplus /nolog
然后再conn / as sysdba
//创建临时表空间
create temporary tablespace user_temp
tempfile 'D:\oracle\oradata\Oracle9i\user_temp.dbf'
size 50m
autoextend on
next 50m maxsize 20480m
extent management local;
//创建数据表空间
create tablespace test_data
logging
datafile 'D:\oracle\oradata\Oracle9i\user_data.dbf'
size 50m
autoextend on
next 50m maxsize 20480m
extent management local;
//创建用户并指定表空间
create user username identified by password
default tablespace user_data
temporary tablespace user_temp;
//给用户授予权限
grant connect,resource to username;
撤权:
revoke 权限... from 用户名;
删除用户命令
drop user user_name cascade;
删除表空间
DROP TABLESPACE data01 INCLUDING CONTENTS AND DATAFILES;
改变表空间状态
1.使表空间脱机
ALTER TABLESPACE game OFFLINE;
如果是意外删除了数据文件,则必须带有RECOVER选项
ALTER TABLESPACE game OFFLINE FOR RECOVER;
2.使表空间联机
ALTER TABLESPACE game ONLINE;
3.使数据文件脱机
ALTER DATABASE DATAFILE 3 OFFLINE;
4.使数据文件联机
ALTER DATABASE DATAFILE 3 ONLINE;
5.使表空间只读
ALTER TABLESPACE game READ ONLY;
6.使表空间可读写
ALTER TABLESPACE game READ WRITE;
扩展表空间
首先查看表空间的名字和所属文件
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space
from dba_data_files
order by tablespace_name;
1.增加数据文件
ALTER TABLESPACE game
ADD DATAFILE '/oracle/oradata/db/GAME02.dbf' SIZE 1000M;
2.手动增加数据文件尺寸
ALTER DATABASE DATAFILE '/oracle/oradata/db/GAME.dbf'
RESIZE 4000M;
3.设定数据文件自动扩展
ALTER DATABASE DATAFILE '/oracle/oradata/db/GAME.dbf
AUTOEXTEND ON NEXT 100M
MAXSIZE 10000M;
设定后查看表空间信息
SELECT A.TABLESPACE_NAME,A.BYTES TOTAL,B.BYTES USED, C.BYTES FREE,
(B.BYTES*100)/A.BYTES "% USED",(C.BYTES*100)/A.BYTES "% 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
在CMD中打sqlplus /nolog
然后再conn / as sysdba
//创建临时表空间
create temporary tablespace user_temp
tempfile 'D:\oracle\oradata\Oracle9i\user_temp.dbf'
size 50m
autoextend on
next 50m maxsize 20480m
extent management local;
//创建数据表空间
create tablespace test_data
logging
datafile 'D:\oracle\oradata\Oracle9i\user_data.dbf'
size 50m
autoextend on
next 50m maxsize 20480m
extent management local;
//创建用户并指定表空间
create user username identified by password
default tablespace user_data
temporary tablespace user_temp;
//给用户授予权限
grant connect,resource to username;
撤权:
revoke 权限... from 用户名;
删除用户命令
drop user user_name cascade;
删除表空间
DROP TABLESPACE data01 INCLUDING CONTENTS AND DATAFILES;
改变表空间状态
1.使表空间脱机
ALTER TABLESPACE game OFFLINE;
如果是意外删除了数据文件,则必须带有RECOVER选项
ALTER TABLESPACE game OFFLINE FOR RECOVER;
2.使表空间联机
ALTER TABLESPACE game ONLINE;
3.使数据文件脱机
ALTER DATABASE DATAFILE 3 OFFLINE;
4.使数据文件联机
ALTER DATABASE DATAFILE 3 ONLINE;
5.使表空间只读
ALTER TABLESPACE game READ ONLY;
6.使表空间可读写
ALTER TABLESPACE game READ WRITE;
扩展表空间
首先查看表空间的名字和所属文件
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space
from dba_data_files
order by tablespace_name;
1.增加数据文件
ALTER TABLESPACE game
ADD DATAFILE '/oracle/oradata/db/GAME02.dbf' SIZE 1000M;
2.手动增加数据文件尺寸
ALTER DATABASE DATAFILE '/oracle/oradata/db/GAME.dbf'
RESIZE 4000M;
3.设定数据文件自动扩展
ALTER DATABASE DATAFILE '/oracle/oradata/db/GAME.dbf
AUTOEXTEND ON NEXT 100M
MAXSIZE 10000M;
设定后查看表空间信息
SELECT A.TABLESPACE_NAME,A.BYTES TOTAL,B.BYTES USED, C.BYTES FREE,
(B.BYTES*100)/A.BYTES "% USED",(C.BYTES*100)/A.BYTES "% 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