建立表空间
CREATE TABLESPACE data01
DATAFILE '/oracle/oradata/db/DATA01.dbf' SIZE 500M
UNIFORM SIZE 128k; #指定区尺寸为128k,如不指定,区尺寸默认为64k
删除表空间
DROP TABLESPACE data01 INCLUDING CONTENTS AND DATAFILES;
一、建立表空间
CREATE TABLESPACE data01
DATAFILE '/oracle/oradata/db/DATA01.dbf' SIZE 500M
UNIFORM SIZE 128k; #指定区尺寸为128k,如不指定,区尺寸默认为64k
二、建立UNDO表空间
CREATE UNDO TABLESPACE UNDOTBS02
DATAFILE '/oracle/oradata/db/UNDOTBS02.dbf' SIZE 50M
#注意:在OPEN状态下某些时刻只能用一个UNDO表空间,如果要用新建的表空间,必须切换到该表空间:
ALTER SYSTEM SET undo_tablespace=UNDOTBS02;
三、建立临时表空间
CREATE TEMPORARY TABLESPACE temp_data
TEMPFILE '/oracle/oradata/db/TEMP_DATA.dbf' SIZE 50M
四、改变表空间状态
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;
五、删除表空间
DROP TABLESPACE data01 INCLUDING CONTENTS AND DATAFILES;
六、扩展表空间
首先查看表空间的名字和所属文件
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_NAME;
///////////////////////////////////////////////////////////////////////////
一、进入oracle下
# su - oracle
as4101> lsnrctl start
as4101> svrmgrl
svrmgrl> connect internal;
svrmgrl> shutdown immediate;
svrmgrl> startup
二、查看有哪些表空间
svrmgrl> SELECT * FROM DBA_TABLESPACES;
SYSTEM RBS TEMP TOOLS USERS
三、将USERS表空间DROP
svrmgrl> ALTER TABLESPACE USERS OFFLINE;
svrmgrl> DROP TABLESPACE USERS;
四、查看表空间的空余大小
svrmgrl> SELECT TABLESPACE_NAME,SUM(BYTES)/1024/1024 MB
FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME;
TABLESPACE_NAME MB
------------------------------ ---------
DD_DATA 1136.3672
DD_IDX 787.18164
JX_DATA 827.94531
JX_IDX 503.16016
RBS 371.9668
SYSTEM 457.81445
TEMP 1499.9961
TOOLS 36.462891
五、查看数据文件放置的路径
svrmgrl> SELECT TABLESPACE_NAME,BYTES/1024/1024 MB,FILE_NAME
FROM DBA_DATA_FILES;
TABLESPACE_NAME MB FILE_NAME
------------------------------ --------- ---------------
SYSTEM 500 /dev/rdrd/drd4
RBS 500 /dev/rdrd/drd14
RBS 1000 /dev/rdrd/drd15
RBS 500 /dev/rdrd/drd32
TOOLS 50 /dev/rdrd/drd5
TEMP 1000 /dev/rdrd/drd22
TEMP 500 /dev/rdrd/drd23
JX_DATA 500 /dev/rdrd/drd33
六、对应SYSTEM表空间有一个回退段,为SYSTEM,另有一些回退段是属于RBS的,
先将RBS下的回退段都OFFLINE,并DROP,然后将RBS表空间DROP并重新创建,
最后,创建回退段。回退段4个,每个大小为RBS/4,这个值可以当作OPTIMAL值,
即等于INITIAL+NEXT*MAXEXTENTS
svrmgrl> ALTER ROLLBACK SEGMENT R01 OFFLINE;
svrmgrl> DROP ROLLBACK SEGMENT R01;
svrmgrl> alter tablespace rbs offline;
svrmgrl> drop tablespace rbs;
svrmgrl> Create TABLESPACE "RBS" DATAFILE
'/dev/rdrd/rbs01.ora' SIZE 500M,
'/dev/rdrd/rbs02.ora' SIZE 500M;
svrmgrl> CREATE ROLLBACK SEGMENT "R01" TABLESPACE "RBS"
STORAGE ( INITIAL 200M NEXT 2M OPTIMAL 250M
MINEXTENTS 2 MAXEXTENTS 25);
七、查看回退段及表空间的状态,若为ONLINE,即结束,为OFFLINE,要ONLINE
svrmgrl> select SEGMENT_NAME,TABLESPACE_NAME,status from DBA_ROLLBACK_SEGS;
svrmgrl> ALTER ROLLBACK SEGMENT R01 ONLINE;
八、临时表空间TEMP,先DROP,再重建。
svrmgrl> alter tablespace temp offline;
svrmgrl> drop tablespace temp;
svrmgrl> CREATE TABLESPACE temp DATAFILE
'/dev/rdrd/drd22' SIZE 1000M storage (initial 300m next 20m
minextens 2 maxextents 35 pctincrease 0);
九、工具表空间TOOLS大小为50M足够用,系统表空间SYSTEM为100M足够用。
十、创建数据表空间:
DD_DATA、DD_IDX、JX_DATA、JX_IDX、SF_DATA、SF_IDX、JF_DATA、JF_IDX
svrmgrl> CREATE TABLESPACE dd_data DATAFILE
'/dev/rdrd/drd9' SIZE 1000M,
'/dev/rdrd/drd10' SIZE 1000M,
'/dev/rdrd/drd26' SIZE 1000M,
'/dev/rdrd/drd35' SIZE 1000M,
'/dev/rdrd/drd42' SIZE 500M;
十一、创建用户
svrmgrl> CREATE USER ddbh IDENTIFIED BY ddbh
DEFAULT TABLESPACE dd_data
TEMPORARY TABLESPACE temp
QUOTA UNLIMITED ON dd_data
QUOTA UNLIMITED ON dd_idx
QUOTA UNLIMITED ON rbs
QUOTA UNLIMITED ON temp;
十二、用户权限
svrmgrl> grant connect,resources,imp_full_database,exp_full_database,
create public synonym,drop public synonym to ddbh;
若要查看V$SESSION,KILL SESSION, DROP USER,CREATE USER等,则
svrmgrl> grant select on v_$session to public;
svrmgrl> grant alter system,drop user,create user to "*******";