Oracle_052_lesson_p7

Managing Database Storage Structures 管理DB存儲架構

you should be able to:
1、Describe the storage of table row data in blocks
2、Create and manage tablespaces
3、Obtain tablespace information

desc dba_segments;
desc dba_extents;

例 循環插入:
declare
begin
for i in 1..100 loop
insert into hr.emp select * from hr.employess
end loop
end
/

alter system checkpoint; 提交內存數據寫入磁盤;

Oracle_052_lesson_p7

創建表空間
redo :執行的操作語句
undo :原始數據,回滾用
conn hr/hr;
select * from session_privs;
show parameter undo;
Oracle_052_lesson_p7

Oracle_052_lesson_p7

Oracle_052_lesson_p7

Oracle_052_lesson_p7

Oracle_052_lesson_p7
注:離線offline mode 有三種: normal 、temporary、immediate
oracle表空間offline的三種方式區別

一 offline 表空間注意事項
1 不能離線如下表空間
system
undo tablespace
temporary tablespace
2 考慮下離線表空間對某些用戶是否有影響,比如某個用戶的默認表空間爲你要離線的表空間。
二 alter tablespace ....offline 後面可跟參數 normal/temporary/immediate
normal:
A tablespace can be taken offline normally if no error conditions exist
for any of the datafiles of the tablespace. No datafile in the tablespace
can be currently offline as the result of a write error. When you specify
OFFLINE NORMAL, the database takes a checkpoint for all datafiles of the
tablespace as it takes them offline. NORMAL is the default
以上說明:
1 normal 是offline的默認方式
2 normal 對錶空間的所有數據文件執行檢查點操作,online表空間時不需要介質恢復。
3 normal 方式離線表空間時,不應該有寫錯誤,表空間所有文件應該online狀態。

temporary:
A tablespace can be taken offline temporarily, even if there are
error conditions for one or more files of the tablespace. When
you specify OFFLINE TEMPORARY, the database takes offline the
datafiles that are not already offline, checkpointing them as it
does so.
If no files are offline, but you use the temporary clause, media
recovery is not required to bring the tablespace back online.
However, if one or more files of the tablespace are offline
because of write errors, and you take the tablespace offline
temporarily, the tablespace requires recovery before you can
bring it back online.

以上說明:
1 offline temporary 表空間時,如果表空間中沒有offline的數據文件,則online該表空間時不需要介質恢復。
2 offline temporary 表空間時,不會對已經offline的數據文件執行檢查點操作,僅僅對online的數據文件執行檢查點操作
3 offline temporary 表空間時,對於離線表空間之前已經offline的數據文件,則online該表空間時,offline數據文件需要介質恢復。

immediate:
A tablespace can be taken offline immediately, without the
database taking a checkpoint on any of the datafiles. When you
specify OFFLINE IMMEDIATE, media recovery for the tablespace is
required before the tablespace can be brought online. You
cannot take a tablespace offline immediately if the database is
running in NOARCHIVELOG mode.
以上說明三點:
1 offline immediate 不會對錶空間的任何文件執行檢查點操作。
2 online 表空間時需要對所有數據文件進行 media recovery
3 offline immediate 需要數據庫日誌模式爲歸檔

注意事項
如果必須離線表空間,推薦使用offline normal 方式離線該表空間,因爲該表空間online時不需要執行介質恢復。

三 實驗

1 測試offline temporary

查詢系統當前表空間以及相應的數據文件
SQL> select a.name as tablespace,b.file#,b.status,b.name as datafile from v$tablespace a,v$datafile b where a.ts#=b.ts#;

TABLESPACE FILE# STATUS DATAFILE


SYSTEM 1 SYSTEM /oracle/CRM2/CRM/system01.dbf
SYSAUX 3 ONLINE /oracle/CRM2/CRM/sysaux01.dbf
USERS 4 ONLINE /oracle/CRM2/CRM/users01.dbf
UNDOTBS2 6 ONLINE /oracle/CRM2/CRM/undotbs2.dbf
ZX 5 ONLINE /oracle/CRM2/CRM/zx1.dbf
ZX 2 ONLINE /oracle/CRM2/CRM/zx2.dbf

SQL> alter database datafile 2 offline;

Database altered.
不能用offline normal正常offline 因爲表空間zx數據文件2已經offline狀態
SQL> alter tablespace zx offline;
alter tablespace zx offline
*
ERROR at line 1:
ORA-01191: file 2 is already offline - cannot do a normal offline
ORA-01110: data file 2: '/oracle/CRM2/CRM/zx2.dbf'
用offline temporary 離線
SQL> alter tablespace zx offline temporary;

Tablespace altered.

SQL> alter tablespace zx online;
alter tablespace zx online
*
ERROR at line 1:
ORA-01113: file 2 needs media recovery
ORA-01110: data file 2: '/oracle/CRM2/CRM/zx2.dbf'

SQL> recover datafile 2;
Media recovery complete.

使zx表空間online
SQL> alter tablespace zx online;

Tablespace altered.

2 測試offline immediate

查詢當前表空間及其數據文件。
SQL> select a.name as tablespace,b.file#,b.status,b.name as datafile from v$tablespace a,v$datafile b where a.ts#=b.ts#;

TABLESPACE FILE# STATUS DATAFILE


SYSTEM 1 SYSTEM /oracle/CRM2/CRM/system01.dbf
SYSAUX 3 ONLINE /oracle/CRM2/CRM/sysaux01.dbf
USERS 4 ONLINE /oracle/CRM2/CRM/users01.dbf
UNDOTBS2 6 ONLINE /oracle/CRM2/CRM/undotbs2.dbf
ZX 5 ONLINE /oracle/CRM2/CRM/zx1.dbf
ZX 2 ONLINE /oracle/CRM2/CRM/zx2.dbf

SQL> alter tablespace zx offline immediate;

Tablespace altered.

SQL> alter tablespace zx online;
alter tablespace zx online
*
ERROR at line 1:
ORA-01113: file 2 needs media recovery
ORA-01110: data file 2: '/oracle/CRM2/CRM/zx2.dbf'

SQL> recover datafile 2;
Media recovery complete.
SQL> alter tablespace zx online;
alter tablespace zx online
*
ERROR at line 1:
ORA-01113: file 5 needs media recovery
ORA-01110: data file 5: '/oracle/CRM2/CRM/zx1.dbf'

SQL> recover datafile 5;
Media recovery complete.
SQL> alter tablespace zx online;

Tablespace altered.

Oracle_052_lesson_p7

Oracle_052_lesson_p7

Oracle_052_lesson_p7

例:
drop tablespace test;
create table tt1 tablespace test as select * from hr.regions;
刪表空間: drop tablespace test1 include contents and datafiles;
select tablespace_name, status from dba_tablespaces;

Oracle_052_lesson_p7
OMF->指定文件路徑

SQL>select member from v$logfile;
SQL>show parameter db_create;

Oracle_052_lesson_p7

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章