ALTER DATABASE 與 ALTER TABLESPACE OFFLINE的區別
一.DataFile離線或聯機的兩種方法:
① ALTER DATABASE 語句修改單獨的DataFile
② ALTER TABLESPACE 語句修改所有的DataFile
1、在ARCHIVRLOG模式下的更改DataFile狀態
ALTER DATABASE DATAFILE '/u02/oracle/rbdb1/stuff01.dbf' ONLINE;
ALTER DATABASE DATAFILE '/u02/oracle/rbdb1/stuff01.dbf' OFFLINE;
或者用檔案號來表示 :
SQL>select file#,name,checkpoint_change# from v$datafile;
FILE# | NAME | CHECKPOINT_CHANGE# |
1 | D:/ORACLE/ORADATA/DBA/SYSTEM01.DBF | 1194854 |
2 | D:/ORACLE/ORADATA/DBA/UNDOTBS01.DBF | 1194854 |
3 | D:/ORACLE/ORADATA/DBA/SYSAUX01.DBF | 1194854 |
4 | D:/ORACLE/ORADATA/DBA/USERS01.DBF | 1194854 |
5 | D:/ORACLE/ORADATA/DBA/TEST01.DBF | 1203262 |
ALTER DATABASE DATAFILE 5 ONLINE;
ALTER DATABASE DATAFILE 5 OFFLINE;
注:只有在ARCHIVELOG模式下才可使用ALTER DATABASE來更改DataFile
2、在NOARCHIVELOG模式下使DataFile離線
由於在NOARCHIVELOG模式下,資料檔案離線後會造成資料的遺失,所以只能使用ALTER DATABASE語句下帶有DATAFILE和OFFLINE DROP子句的選項將該DataFile直接取消,例如該DataFile只包含臨時段資料,並沒有備份時
ALTER DATABASE DATAFILE '/u02/oracle/rbdb1/users3.dbf' OFFLINE DROP;
3、修改TableSpace中所有DataFile或TempFile的可用性
ALTER TABLESPACE ... DATAFILE {ONLINE|OFFLINE}
ALTER TABLESPACE ... TEMPFILE {ONLINE|OFFLINE}
注:修改某TableSpace中的所有資料檔案,但是TableSpace本身的狀態不改變。
我們不能使用'alter database datafile ... offline' 在歸檔模式下,但是 'alter tablespace ... offline' 可以。
我們不是使用'alter tablespace ... offline'在資料庫的read-only模式下,但是'alter database datafile ... offline' 可以。
總結:
① ALTER TABLESPACE可以在資料庫裝載狀態時釋出,無需開啟
② 涉及到系統表空間、撤銷表空間、預設臨時表空間時,必須是未開啟的資料庫
③ ALTER DATABASE DATAFILE 語句中必須填入檔案全名
二. 表空間 與 資料檔案 離線的區別
1. ALTER TABLESPACE ... OFFLINE
Does a checkpoint on the datafiles
Takes the datafiles offline
表空間Offline時,資料檔案的SCN會被凍結,而且表空間的資料檔案offline/online時又會發生檔案檢查點,使單個資料檔案SCN和資料庫其他問題不一致。
表空間online時,Oracle會取得當前SCN,解凍offline檔案SCN,和當前SCN同步。
tablespace offline有幾種選項可供選擇normal, temporary,immediate, for recovery,而在datafile中則沒有這些選項。
SQL>select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1203246
SQL>alter tablespace test offline;
Tablespace altered.
SQL>select file#,name,checkpoint_change# from v$datafile;
FILE# | NAME | CHECKPOINT_CHANGE# |
1 | D:/ORACLE/ORADATA/DBA/SYSTEM01.DBF | 1194854 |
2 | D:/ORACLE/ORADATA/DBA/UNDOTBS01.DBF | 1194854 |
3 | D:/ORACLE/ORADATA/DBA/SYSAUX01.DBF | 1194854 |
4 | D:/ORACLE/ORADATA/DBA/USERS01.DBF | 1194854 |
5 | D:/ORACLE/ORADATA/DBA/TEST01.DBF | 1203262 |
SQL>select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1203328
SQL>alter tablespace test online;
Tablespace altered.
SQL>select file#,name,checkpoint_change# from v$datafile;
FILE# | NAME | CHECKPOINT_CHANGE# |
1 | D:/ORACLE/ORADATA/DBA/SYSTEM01.DBF | 1,194,854 |
2 | D:/ORACLE/ORADATA/DBA/UNDOTBS01.DBF | 1,194,854 |
3 | D:/ORACLE/ORADATA/DBA/SYSAUX01.DBF | 1,194,854 |
4 | D:/ORACLE/ORADATA/DBA/USERS01.DBF | 1,194,854 |
5 | D:/ORACLE/ORADATA/DBA/TEST01.DBF | 1,203,343 |
SQL>select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1203440
2. ALTER DATABASE DATAFILE ... OFFLINE
單純的offline datafile,將不會觸發檔案檢查點,只有針對offline tablespace的時候才會觸發檔案檢查點,這也是為什麼online datafile需要media recovery而online tablespace不需要。
注:只有在ARCHIVELOG模式下才可使用ALTER DATABASE來更改DataFile
SQL>select file#,name,checkpoint_change# from v$datafile;
FILE# | NAME | CHECKPOINT_CHANGE# |
1 | D:/ORACLE/ORADATA/DBA/SYSTEM01.DBF | 1,194,854 |
2 | D:/ORACLE/ORADATA/DBA/UNDOTBS01.DBF | 1,194,854 |
3 | D:/ORACLE/ORADATA/DBA/SYSAUX01.DBF | 1,194,854 |
4 | D:/ORACLE/ORADATA/DBA/USERS01.DBF | 1,194,854 |
5 | D:/ORACLE/ORADATA/DBA/TEST01.DBF | 1,203,343 |
SQL>select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1219831
SQL>alter database datafile 5 offline;
Database altered.
SQL>select file#,name,checkpoint_change# from v$datafile;
FILE# | NAME | CHECKPOINT_CHANGE# |
1 | D:/ORACLE/ORADATA/DBA/SYSTEM01.DBF | 1,194,854 |
2 | D:/ORACLE/ORADATA/DBA/UNDOTBS01.DBF | 1,194,854 |
3 | D:/ORACLE/ORADATA/DBA/SYSAUX01.DBF | 1,194,854 |
4 | D:/ORACLE/ORADATA/DBA/USERS01.DBF | 1,194,854 |
5 | D:/ORACLE/ORADATA/DBA/TEST01.DBF | 1,203,343 |
SQL>select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1219882
SQL>alter database datafile 5 online;
Error at line 1
ORA-01113: 檔案 5 需要介質恢復
ORA-01110: 資料檔案 5: 'D:/ORACLE/ORADATA/DBA/TEST01.DBF'
SQL>recover datafile 5;
完成介質恢復
SQL>alter database datafile 5 online;
Database altered.
SQL>select file#,name,checkpoint_change# from v$datafile;
FILE# | NAME | CHECKPOINT_CHANGE# |
1 | D:/ORACLE/ORADATA/DBA/SYSTEM01.DBF | 1,194,854 |
2 | D:/ORACLE/ORADATA/DBA/UNDOTBS01.DBF | 1,194,854 |
3 | D:/ORACLE/ORADATA/DBA/SYSAUX01.DBF | 1,194,854 |
4 | D:/ORACLE/ORADATA/DBA/USERS01.DBF | 1,194,854 |
5 | D:/ORACLE/ORADATA/DBA/TEST01.DBF | 1,219,929 |
SQL>select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1220043
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15880878/viewspace-720072/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- alter database datafile offline drop 與 alter tablespace drop datafile 區別Database
- alter database datafile offline and alter database tablespace ...offlineDatabase
- datafile offline 與alter tablespace offline 的區別
- alter database drop datafile 與 drop tablespace file 的區別Database
- alter database offline 與 alter database offline drop效果比對Database
- alter database和alter system和alter session的區別DatabaseSession
- ALTER DATABASE DATAFILE OFFLINEDatabase
- 忍不住問下alter system 和alter database的區別Database
- alter system events與alter system event的區別
- alter database datafile 4 offline drop;Database
- alter database datafile .... offline drop的問題Database
- VMS: ALTER TABLESPACE/DATABASE TO RENAME FILES on VMS [ID 9560.1]Database
- alter database datafile offline drop相關問題Database
- alter table move 和 alter table shrink space的區別
- tablespace offline與datafile offline 區別
- zt:alter system switch logfile與ALTER SYSTEM ARCHIVE LOG CURRENT的區別Hive
- alter database in OracleDatabaseOracle
- alter table move 與shrink space的區別
- alter database create datafileDatabase
- alter database create datafile '' as ''Database
- ALTER SYSTEM SWITCH LOGFILE ALTER SYSTEM ARCHIVELOG CURRENT 區別Hive
- alter system switch logfile和alter system archive log current的區別Hive
- alter system switch logfile 和 alter system archive log current 的區別Hive
- ALTER DATABASE RESETLOGS 的作用Database
- v$lock之alter table drop column與alter table set unused column區別系列五
- tablespace offline 和datafile offline的區別
- alter database open resetlogs;Database
- [轉]alter system switch logfile和alter system archive log current的區別Hive
- ALTER TABLE MOVE | SHRINK SPACE區別
- alter table move跟shrink space的區別
- alter database disable thread 2Databasethread
- DATA GUARD 中alter database 命令Database
- ALTER TABLE MOVE和SHRINK SPACE區別
- oracle裡tablespace offline和datafile offline的區別Oracle
- ALTER DATABASE CLEAR UNARCHIVED LOGFILE的使用DatabaseHive
- alter database ... create datafile的原理及用途Database
- alter system switch log file 與 archive log current/all 區別Hive
- 在alter tablespace_datafile begin backup_offline_oracle block之fileq和ckptq變化OracleBloC