管理表空间和数据文件常用脚本

1.新建表空间(本地管理方式)
(1)普通表空间
create tablespace autotbs
datafile '/oracle/autotbs01.dbf' size 100M
extent management local autoallocate;
(2)临时表空间
create temporary tablespace lmtemp
tempfile 'I:\oracle\oradata\lmtemp01.dbf' size 50M reuse
extent management local uniform size 136K;
要创建本地管理方式的 临时表空间,必须使用create temporary tablespace,并且区的分配管理方式
只能是uniform,而不能是autoallocate,这样才能保证不会在临时段中产生过多的存储碎片。

2.设置表空间脱机联机
alter tablespace autotbs offline;
alter tablespace autotbs online;

3.设置表空间为只读/可读可写
alter tablespace autotbs read only;
alter tablespace autotbs read write;

4.添加表空间数据文件
为普通表空间添加数据文件:
alter tablespace autotbs add datafile '/oracle/autotbs02.dbf' size 100M
为临时表空间添加数据文件:
alter tablespace lmtemp add tempfile '/oracle/lmtemp02.dbf' size 10M reuse;

5.改变数据文件大小
(1)设置数据文件为自动增长方式
-----------------
alter tablespace autotbs
add datafile '/oracle/autotbs02.dbf' size 50M
autoextend on next 5M maxsize 100M;
-----------------
alter database datafile '/oracle/autotbs01.dbf'
autoextend on next 1M maxsize 200M;
(2)手工改变数据文件的大小
alter database datafile '/oracle/autotbs01.dbf' resize 500M;

6.改变数据文件可用性
alter database datafile '/oracle/autotbs01.dbf' online/offline;

7.删除表空间
drop tablespace autotbs including contents and datafiles;

8.查询
(1)查询表空间的默认存储参数
select tablespace_name,initial_extent,next_extent,min_extents,max_extents,pct_increase
from dba_tablespaces;
(2)查询表空间的数据文件信息
select file_name,blocks,tablespace_name
from dba_data_files;
(3)查询数据文件的基本信息
select name,file#,Rfile#,status,bytes,checkpoint_change# lase_scn
from v$datafile;
(4)查询数据文件的自动增长方式
select tablespace_name,file_name,autoextensible from dba_data_files;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值