Chinaunix首页 | 论坛 | 博客
  • 博客访问: 99790
  • 博文数量: 41
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 0
  • 用 户 组: 普通用户
  • 注册时间: 2018-05-23 12:43
文章分类

全部博文(41)

文章存档

2016年(2)

2015年(3)

2014年(16)

2013年(20)

分类: Oracle

2013-12-01 13:08:06

第6章 表空间和数据文件的管理


本地管理的表空间--数据字典管理的表空间


6.5数据字典表空间


--创建数据字典表空间
CREATE TABLESPACE JINLINA
DATAFILE 'C:\Disk2\MOON\JINLIAN01.DBF' SIZE 50M,
         'C:\Disk4\MOON\JINLIAN02.DBF' SIZE 50M
MINIMUM EXTENT 50K --EXTENT MANAGEMENT DICTIONARY
DEFAULT STORAGE (INITIAL 50K NEXT 50K MAXEXTENTS 100 PCTINCREASE 0);
--表空间是否为数据字典管理
SET LINE 120
COL TABLESPACE_NAME FOR A15
SELECT TABLESPACE_NAME,BLOCK_SIZE,EXTENT_MANAGEMENT,SEGMENT_SPACE_MANAGEMENT
FROM dba_tablespaces;
--查询其他磁盘存储参数
SET LINE 120
COL TABLESPACE_NAME FOR A15
select tablespace_name,initial_extent,next_extent,max_extents,pct_increase,min_extlen
from dba_tablespaces;
--查看与文件有关信息
col file_name for a50
select file_id,file_name,tablespace_name,bytes
from dba_data_files
order by file_id;




6.6本地管理的表空间
--创建本地管理的表空间
create tablespace jinlian_index
datafile 'c:\Disk6\MOON\jinlian_index.dbf' size 50M
extent management local
uniform size 1m;
--表空间是否为数据字典管理
SET LINE 120
COL TABLESPACE_NAME FOR A15
SELECT TABLESPACE_NAME,BLOCK_SIZE,EXTENT_MANAGEMENT,SEGMENT_SPACE_MANAGEMENT
FROM dba_tablespaces
where tablespace_name like 'JIN%';
--查询其他磁盘存储参数
SET LINE 120
COL TABLESPACE_NAME FOR A15
select tablespace_name,initial_extent,next_extent,max_extents,pct_increase,min_extlen
from dba_tablespaces
WHERE tablespace_name like 'JIN%';
--查看与文件有关信息
col file_name for a50
select file_id,file_name,tablespace_name,bytes,autoextensible
from dba_data_files
where file_id > 5
order by file_id;




6.7还原表空间
--创建还原表空间
create undo tablespace jinlian_undo
datafile 'C:\Disk7\MOON\JINLINA_UNDO.DBF' size 20m;
...............
--查询相关信息
select tablespace_name,block_size,extent_management,segment_space_management
from dba_tablespaces
where tablespace_name like 'JIN%';
--查询是否为还原表空间
select tablespace_name,status,contents
from dba_tablespaces
where tablespace_name like 'JIN%';


(2013/11/21)
6.8临时表空间
--查看临时表空间和对应的文件
col file for a30
col tablespace for a10
select f.file#,t.ts#,f.name "File",t.name "Tablespace"
from v$tempfile f,v$tablespace t
where f.ts#=t.ts#;
--创建临时表空间
create temporary tablespace jinlian_temp
tempfile 'C:\Disk8\MOON\jinlian_temp.dbf' size 10M
extent management local
uniform size 2 M;--每个extent大小为2M
--查看创建的表空间是否为临时
SELECT TABLESPACE_NAME,status,contents
from dba_tablespaces
where tablespace_name like 'JIN%';
--查看表空间文件
col file for a30
col tablespace for a10
select f.file#,t.ts#,f.name "File",t.name "Tablespace"
from v$tempfile f,v$tablespace t
where f.ts#=t.ts#;
--查询磁盘相关信息
select tablespace_name,block_size,extent_management,segment_space_management,min_extents
from dba_tablespaces
where tablespace_name like 'JIN%';


6.9默认临时表空间
col property_name for a25
col property_value for a9
col description for a32
select * from database_properties
where property_name like 'DEFAULT%';


--修改当前默认临时表空间
 alter database
 default temporary tablespace jinlian_temp;
--验证
select * from database_properties
where property_name like 'DEFAULT%';


6.10设置表空间为脱机
col name for a10
select file#, name,status
from v$datafile
where file# >= 8;


alter tablespace jinlina rename to jinlian;
alter tablespace jinlian offline;
--查看表空间文件是否为脱机状态
col name for a20
select file#, name,status
from v$datafile
where file# >= 3;


alter tablespace jinlian online;
--设置只读表空间
alter tablespace jinliAN read only;
select tablespace_name,status,contents
from dba_tablespaces
where tablespace_name like 'JINLIAN%';


alter tablespace jinlian read write;


6.12改变表空间的存储设置
alter tablespace jinlian minimum extent 100k;
/*
ORA-25143: 默认存储子句与分配策略不兼容
对于使用AUTOALLOCATE 或 UNIFORM分配策略的本地化管理表空间这样修改不不允许的。
alter database datafile 'C:\DISK2\MOON\JINLIAN01.DBF' autoextend on;
alter database datafile 'C:\DISK4\MOON\JINLIAN02.DBF' autoextend on;
还可以通过增加数据文件的方式
alter tablespace xxx add datafile '/oradata/data/xxxx.dbf' size 200M;
*/
alter tablespace jinlian 
default storage(initial 100k next 100k maxextents 200);


(2013/11/22)
6.13重置表空间大小
--查看那些表空间和文件可以扩展
col file_name for a50
select file_id,file_name,tablespace_name,bytes,autoextensible
from dba_data_files
where file_id > 0
order by file_id;
--
alter database datafile
'C:\DISK6\MOON\JINLIAN_INDEX.DBF' autoextend on
next 1M;


6.14手工重置数据文件的大小
select file_id,file_name,tablespace_name,bytes/(1024*1024) MB
from dba_data_files
where tablespace_name like 'JIN%';
--
ALTER DATABASE DATAFILE 'C:\DISK2\MOON\JINLIAN01.DBF' RESIZE 100M;
--怎加数据文件来增加数据库大小
alter TABLESPACE JINLIAN ADD DATAFILE 'C:\DISK6\MOON\JINLIAN013.DBF' SIZE 80M;


6.15移动数据文件的方法
==================================
6.16移动数据文件的实例
(2013/11/23)
/*移动非系统表空间*/
--查看数据库文件分布,是否有I\O冲突
set line 120
col file_name for a45
select file_id,file_name,tablespace_name
from dba_data_files
where file_name like '%ORACLE%'
order by file_id;
--了解表空间的当前状态
select tablespace_name,status,contents
from dba_tablespaces
where tablespace_name not like 'JINLIAN%';
--表空间脱机状态
alter tablespace users offline;
--检查
select tablespace_name,status,contents
from dba_tablespaces
where tablespace_name not like 'JINLIAN%';
--复制文件
host copy C:\oracle\product\10.2.0\oradata\MOON\USERS01.DBF  C:\Disk2\ORADATA;
--重新命名表空间所对应的文件(在控制文件中修改这文件的地址或指针)
alter tablespace users rename datafile
'C:\oracle\product\10.2.0\oradata\MOON\USERS01.DBF'
to
'C:\Disk2\ORADATA\USERS01.DBF';
--表空间联机
alter tablespace users online;
--检查
select tablespace_name,status,contents
from dba_tablespaces
where tablespace_name not like 'JINLIAN%';
set line 120
col file_name for a45
select file_id,file_name,tablespace_name
from dba_data_files
where file_name like '%ORADATA%'
order by file_id;


/*移动系统表空间*/
--1关闭数据库
shutdown immediate
--2启动例程将数据库启动为加载状态
startup mount
--3复制文件
host copy C:\oracle\product\10.2.0\oradata\MOON\SYSTEM01.DBF C:\Disk1\ORADATA
host dir C:\Disk1\ORADATA
--4修改system表空间所对应的文件
alter database rename 
file 'C:\oracle\product\10.2.0\oradata\MOON\SYSTEM01.DBF' 
to 'C:\Disk1\ORADATA\SYSTEM01.DBF';
--5.将数据库状态置为Open
alter database open;
--查询是否成功
set line 120
col file_name for a45
select file_id,file_name,tablespace_name
from dba_data_files
where file_name like '%ORADATA%'
order by file_id;
--6.删除垃圾文件


==================================


6.17迁移数据字典和本地管理的表空间
/*移数据字典--迁移-->本地管理的表空间*/
--查看当前用户
show user;
--查看数据字典管理的表空间
select tablespace_name,block_size,extent_management,segment_space_management,min_extents
from dba_tablespaces
where tablespace_name like 'JIN%'
--迁移
execute dbms_space_admin.tablespace_migrate_from_local('JINLIAN');


6.18删除表空间
--查看表空间和对应的文件
select file_id,file_name,tablespace_name
from dba_data_files
where file_id>0
order by file_id;
--查看临时表空间和对应的文件
col file for a30
select f.file#,f.name as "File",t.ts#,t.name as "tablespace"
from v$tempfile f,v$tablespace t
where f.ts#=t.ts#;
--删除表空间
drop tablespace jinlian_index inluding contents and datafiles;


6.19利用OMF来管理表空间
alter system set db_create_file_dest = 'C:\Disk5\ORADATA';
CREATE TABLESPACE guifei;
alter tablespace guifei add datafile size 50M;

阅读(2837) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~