oracle表空间(tablespace)的增删改查(create/drop/rename,move/select)
2013-03-05oracle维护中经常会对表空间进行操作,整理了一下tablespace的增删改查操作(create/drop/rename,move/select)
1、create tablespace
#!/bin/bash
dts_src=DATA_TS
data_ts1=/data1/oracle/data_201303_ts1.dbf
data_ts2=/data1/oracle/data_201303_ts2.dbf
sqlplus user01/pw123456 << EOF
CREATE TABLESPACE $dts_src DATAFILE '$data_ts1' SIZE 512M AUTOEXTEND ON NEXT 256M MAXSIZE UNLIMITED BLOCKSIZE 16k;
alter TABLESPACE $dts_src add DATAFILE '$data_ts2' SIZE 512M AUTOEXTEND ON NEXT 256M MAXSIZE UNLIMITED;
quit;
EOF
2、drop tablespace
如果tablespace中包含table,需要先进行drop table,为了drop table ,你需要查询tablespace中包含哪些table:
col SEGMENT_NAME format a30
select distinct SEGMENT_NAME,TABLESPACE_NAME from dba_segments where TABLESPACE_NAME='DATA_TS' order by SEGMENT_NAME;
假如tablename是:tablename_201202
你也可以先truncate table,再drop table.
#!/bin/bash
. ~/.bash_profile
#create drop sql
#select 'drop table '||tname||' purge;' from tab where tname like '%20110%' order by tname;
ym=201202
sqlplus user01/pw123456 << EOF
truncate table tablename_$ym;
drop table tablename_$ym purge;
DROP TABLESPACE DATA_TS_$ym INCLUDING CONTENTS AND DATAFILES;
quit;
EOF
3、重命名表空间
#!/bin/bash
dts_src=DATA_TS
dts_dst=DATA_TS_201302
data_ts1=/data1/oracle/data_201303_ts1.dbf
data_ts2=/data1/oracle/data_201303_ts2.dbf
sqlplus user01/pw123456 << EOF
alter tablespace $dts_src rename to $dts_dst;
quit;
EOF
4、改变表空间数据文件存放位置
#!/bin/bash
. ~/.bash_profile
ts=DATA_TS_201207
src1=/data3/oracle/data_ts_201207_1.dbf
dst1=/datac3/oracle/data_ts_201207_1.dbf
src2=/data3/oracle/data_ts_201207_2.dbf
dst2=/datac3/oracle/data_ts_201207_2.dbf
sqlplus user01/pw123456 << EOF
set hea off
alter tablespace $ts read only;
alter tablespace $ts offline;
!mv $src1 $dst1
!mv $src2 $dst2
alter database rename file '$src1' to '$dst1';
alter database rename file '$src2' to '$dst2';
alter tablespace $ts online;
alter tablespace $ts read write;
quit;
EOF
5、改变数据文件存储参数
alter database datafile '/data2/oracle/view_data02.dbf' AUTOEXTEND ON NEXT 256M MAXSIZE UNLIMITED;
6、查询表空间信息
col name format a50
set linesize 200
select a.name,b.name from v$tablespace a ,v$datafile b where a.TS#=b.TS#;
col file_name format a50
select TABLESPACE_NAME,FILE_NAME from dba_data_files order by TABLESPACE_NAME;
get tablespace_name
select distinct(TABLESPACE_NAME) from dba_data_files order by tablespace_name;
tablespace use space
select segment_name, sum(bytes)/1024/1024 Mbytese from user_segments where segment_type='TABLE' group by segment_name;
select sum(bytes)/1024/1024 size_mb from dba_data_files where tablespace_name='SYSTEM';
相关日志
- rman-0level全备份及恢复
- nagios监测dbbak
- oracle限制远程访问
- 给left join关联关系字段加索引
- Oracle ASM
- Oracle Database 18c
- DG两个数据库SID不同
- DG-Dgmgrl
- Oracle中的BLOB和CLOB
- oracle 启动错误:MEMORY_TARGET not supported on this system
- create bigfile tablespace
- Oracle11G新特性:分区表分区默认segment大小64k变为8M
- oracle增加md5函数
- oracle删除重复行delete repeat
- rollback回滚 (1)
- oracle中drop一个表,让数据文件释放空间
- CentOS 5.11 x64静默安装(slient install)oracle 11.2.0.4 x64
- sqlplus USER/PWD@IP:PORT/SID
- oracle删除所有表
- oracle查询长整数实例
- oracle设置NLS_DATE_FORMAT参数实例
- ORA-00600和ORA-08103错误(oracle10g)
- oracle user passwd用户密码
- oracle导入txt数据文件实例
- conn user as sysdba
- SGA/PGA的设置与调整 (9)
- ORA-01843: not a valid month (3)
- rlwrap实现sqlplus使用上下键查历史命令