數據文件的操作

-------------
(1)創建表空間
create smallfile tablespace "NEWS"
datafile 'd:\...dbf'
size 100m autoextend on next 10m maxsize 200m
logging
extent management local    [uniform size 160m|autoallocate]
segment space managment auto
default nocompress;
(2)在新的表空間創建表,並確定第一個區間的大小
select extent_id,bytes from dba_extents where owner='SYSTEM' and segment_name='TABLE24';
(3)手動添加區間,並通過重複執行以下命令來觀察每個新區間的大小
alter table table24 allocate extent;
(4)將字典管理的表空間轉換爲本地管理
execute dbms_space_admin.tablespace_migragte_to_local('tablespacename');
(5)將對象移動到新表空間
alter table emp move tablespace sales;
alter index emp_index rebulid online tablespace sales;
 1.create tablespace test datafile '/u01/app/oracle/mnt/orcl11g/test.dbf' size 1m ;
 2.alter database datafile '/u01/app/oracle/mnt/orcl11g/test.dbf' resize 1g;(小表空間)
   alter tablespace test1 resize 10g;(大表空間)
 3.alter tablespace test datafile '/u01/app/oracle/mnt/orcl11g/test.dbf'
   autoextend on
   next 10m
   maxsize 200m;
  extent management local
  segment space management auto;
(6)重新調整表空間的大小,可添加數據文件也可以調整現有數據文件的大小
alter database datafile '/u01/app/oracle/mnt/orcl11g/test.dbf' resize 1g;
alter tablespace test add  datafile '/u01/app/oracle/mnt/orcl11g/test_02.dbf'
alter tablespace  datafile '/u01/app/oracle/mnt/orcl11g/test_02.dbf' autoextent on next 50m maxsize 3g;
(7)重命名錶空間及其數據文件
alter tablespace storetabs rename to storedata;
alter tablespace storedata offline;
host rename c:\oracle\oradata\orcl11g\storetabs_01.dbf storedata_01.dba
host rename c:\oracle\oradata\orcl11g\storetabs_02.dbf storedata_02.dba
alter database rename file 'c:\oracle\oradata\orcl11g\storetabs_01.dbf' to 'c:\oracle\oradata\orcl11g\storedata_01.dbf'
alter database rename file 'c:\oracle\oradata\orcl11g\storetabs_02.dbf' to 'c:\oracle\oradata\orcl11g\storedata_02.dbf'
alter tablespace storedata online;
(8)使表空間聯機或脫機
alter tablespace tablespacename offline[normal,immediate,temporary]
normal將強制實施針對所有表空間數據文件的檢查點。默認方式
immediate將立即使表空間和數據文件脫機,不會轉儲任何髒緩存區。如果這麼做,數據文件將受到損壞(可能丟失未提交的更改)在使表空間重新聯機之前,必須通過應用來自重做日誌變更向量進行恢復
temporary脫機將針對所有可以執行檢查點操作的所有文件實施檢查點,然後按順序使表空間及文件脫機。
(9)刪除表空間
drop tablespace tablespacename
如果未指定including contents 關鍵字,但表空間中包含任何對象,那麼刪除操作將失敗。使用這些關鍵字指示oracle首先刪除對象,然後刪除表空間。即使如此,在一些環境下同樣會失敗。如果表空間包含的表與另一個表空間的表存在外鍵關係,而且此表是副表,則刪除將失敗。
如果未指定and datafile關鍵字,則將刪除表空間及其內容,但數據文件仍保存在磁盤上。oracle將不瞭解他們位於何處,必須使用操作系統命令刪除他們。
(10)移動數據文件:
1.使用database移動數據文件(所有表空間,因爲在操作時實例關閉)
確定表空間的數據文件名稱
 select d.name from v$datafile d join v$tablespace t using (ts#) where t.name='SYSTEM';
 (1)作爲sysdba連接數據庫,關閉實例
(2)使用操作系統命令移動數據文件
(3)以mount模式打開數據庫
(4)使用ALTER DATABASE改變對數據庫中數據文件的引用
(5)以open模式打開數據庫
(6)對包括控制文件的數據庫執行增量備份或完整備份 alter database backup controlfile to trace;
2.使用tablespace移動數據文件(該表空間不是system,sysaux,撤銷表空間,或臨時表空間)
(1)對錶空間進行脫機處理: alter tablespace sale offline;
 (2)使用操作系統命令移動數據文:!mv /u01/app/oracle/oradata/orcl11g/sale.dbf /u01/app/oracle/mnt/orcl11g/sale.dbf
 (3)使用alter tablespace改變對數據庫中數據文件的引用
 alter tablespace sale rename datafile '/u01/app/oracle/oradata/orcl11g/sale.dbf' to '/u01/app/oracle/mnt/orcl11g/sale.dbf';
(4)將表空間聯機
 alter tablespace sale online;
(11)移動聯機重做日誌文件
 select group#,member from v$logfile order by group#,member;
(1)關閉實例
(2)使用操作系統命令移動數據文
(3)以mount模式打開數據庫
(4)使用ALTER DATABASE改變對數據庫中數據文件的引用
alter database rename datafile '/u01/app/oracle/oradata/orcl11g/redo01.log' to '/u01/app/oracle/mnt/orcl11g/redo01.log';
(5)以open模式打開數據庫
(12)移動控制文件
 select name,value from v$spparameter where name = 'control_files';
在使用spfile時:在關閉實例前,應使用alter system ....scope=spfile改變初始文件參數control_files.(靜態參數)
(1)關閉實例
(2)使用操作系統命令移動數據文
(3)以open模式打開數據庫
(13)將數據庫遷移到ASM(Dba手冊117)

 表空間類型,盤區管理類型
 select tablespace_name,block_size ,contents ,extent_management from dba_tablespaces;
 select tablespace_name,count(*) num_objects,sum(bytes),sum(blocks),sum(extents)from dba_segments group by rollup (tablespace_name);
 select owner,segment_name,tablespace_name,extent_id,file_id,block_id bytes from dba_extents where SEGMENT_NAME='EMP';
 SELECT TABLESPACE_NAME,SUM(BYTES) FROM DBA_FREE_sPACE GROUP BY TABLESPACE_NAME;

發佈了51 篇原創文章 · 獲贊 3 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章