1. 程式人生 > >本地管理的表空間--資料字典管理的表空間

本地管理的表空間--資料字典管理的表空間

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;