黑土

电力相关软件技术
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

oracle 操作表空间

Posted on 2010-07-23 14:38  blackmud  阅读(459)  评论(0)    收藏  举报

---------------------------------------------- -表空间的操作----------------------------------------------------

1.创建表空间:

create tablespace tablespace_name datafile 'filepath' size filesize autoextend on next autosize maxsize filemaxsize [unlimited]

 

create tablespace sales datafile 'c:\1.txt' size 10m autoextend on next 1m maxsize 100m

2.为表空间增加数据文件:

alter tablespace tablespace_name add datafile 'filepath' size filesize autoextend on next autosize maxsize filemaxsize[unlimited]

 

alter tablespace sales datafile 'c:\2.txt' size 10m autoextend on next 1m maxsize unlimited

3.调整表空间:

alter database datafile 'filepath' resize filesize--重置表空间的大小

 

alter database datafile 'c:\2.txt' resize 10m

4.关闭表空间的自动扩展属性:

alter database datafile 'filepath' autoextend off

 

alter database datafile 'c:\2.txt' autoextend off

5.打开表空间的自动扩展属性:

alter database datafile 'filepath' autoextend on

 

alter database datafile 'c:\2.txt' autoextend on

6.使表空间脱机:

alter tablespace tablespace_name offline

7.使表空间联机:

alter tablespace tablespace_name online

8.设置表空间为只读:

alter tablespace tablespace_name read only

9.设置表空间为读写:

alter tablespace tablespace_name read write

11.删除表空间:

drop tablespace tablespace_name

12.删除表空间的同时,删除数据文件

drop tablespace tablespace_name including contents and datefiles

13.查看每个表空间占用空间的大小:

select tablespace_name,sum(bytes)/1024/1024 from dba_segments group by tablespace_name

10.移动表空间数据文件步骤:

a.使表空间脱机:alter tablespace tablespace_name offline

b.物理移动数据文件到目的地(可以是表空间的部分数据文件或者是修改数据文件的名称)

c.逻辑移动:alter tablespace tablespace_name rename datafile '源文件地址'to '目的文件地址'--注意可以将多个源文件转移到同一个目的文件地址(多个源文件地址用逗号分隔)

d.将表空间联机:alter tablespace tablespace_name online

11.查询表空间的信息:

select tablespace_name,bytes/1024/1024  file_size_mb,file_name from DBA_DATE_FILES--注意书籍库中的实体都是以大写表示

12.当数据文件被删除的时候,如果对该数据文件操作的时候,oracle会报不能找到该数据文件的错误。如何处理。

1shutdown—关闭oracle实例

2startup  --开启oracle实例并打开数据库

3alter database datafile ‘datafile_name’ offline drop;

4alter database open

13.查看表空间信息;

 

select dbf.tablespace_name,
dbf.totalspace "总量(M)",
dbf.totalblocks as 总块数,
dfs.freespace "剩余总量(M)",
dfs.freeblocks "剩余块数",

(dfs.freespace / dbf.totalspace) * 100 "空闲比例"
from (select t.tablespace_name,
sum(t.bytes) / 1024 / 1024 totalspace,
sum(t.blocks) totalblocks
from dba_data_files t
group by t.tablespace_name) dbf,
(select tt.tablespace_name,
sum(tt.bytes) / 1024 / 1024 freespace,
sum(tt.blocks) freeblocks
from dba_free_space tt
group by tt.tablespace_name) dfs
where trim(dbf.tablespace_name) = trim(dfs.tablespace_name)
alter database datafile 'D:\SDE.DBF' autoextend on

select * from dba_data_files