tablespace online問題解決

來源:互聯網
上載者:User

tablespace online問題解決

今天在做一些示範的時候,在虛擬機器上裝了兩套資料庫軟體,Oracle 10g和11g的。還是在示範普通資料檔案遷移的時候還是碰到了一些意料之外的問題,從當時的情況來看感覺還是比較詭異的,所以馬上切換到另外一套環境去實驗就沒有任何問題了。對於這個問題事後進行了分析,發現還是一些簡單常規的錯誤,自己還是對一些細節沒有掌握好, 本來對於普通資料檔案的遷移流程是很簡單的,在資料庫open狀態就可以遷移,

 基本步驟如下:
alter tablespace xxxx offline;
 cp datafiles
 alter tablespace xxx rename sourcexxxxx  to targetxxxxx;
 alter tablespace xxxxx online;
結果在11g的環境示範的時候,自己為了圖省事,想offline更快些,就直接用了offline immediate的選項。

SQL> alter tablespace data offline immediate;

Tablespace altered.
然後敲了下面的命令嘗試拷貝資料檔案,但是拋出的錯誤看起來滿高深的,其實就是最後的單引號導致的。
SQL>  !cp /u02/ora11g/oradata/TEST/disk4/data01.dbf /u02/ora11g/oradata/TEST/disk3/data01.dbf'
 /bin/bash: -c: line 0: unexpected EOF while looking for matching `''
 /bin/bash: -c: line 1: syntax error: unexpected end of file

[ora11g@oel1 ~]$ cp /u02/ora11g/oradata/TEST/disk4/data01.dbf /u02/ora11g/oradata/TEST/disk3/data01.dbf
 [ora11g@oel1 ~]$ orasql
然後直接拷貝資料檔案

SQL> alter tablespace data rename datafile '/u02/ora11g/oradata/TEST/disk4/data01.dbf' to '/u02/ora11g/oradata/TEST/disk3/data01.dbf';

Tablespace altered.
然後開始做online操作,這也是一個常規操作,但是拋出了下面的錯誤。

SQL> alter tablespace data online;
 alter tablespace data online
 *
 ERROR at line 1:
 ORA-01113: file 4 needs media recovery
 ORA-01110: data file 4: '/u02/ora11g/oradata/TEST/disk3/data01.dbf'

這個時候從日誌來看是資料檔案需要介質恢複。
 結果想馬上把問題修好,就直接用了recover database,結果從錯誤來看就更有些玄妙了。
SQL> recover database;
 ORA-00283: recovery session canceled due to errors
 ORA-01124: cannot recover data file 1 - file is in use or recovery
 ORA-01110: data file 1: '/u02/ora11g/oradata/TEST/disk5/system01.dbf'
似乎這個時候恢複還是一個看似不能完成的任務,果斷放棄這個環境,切換到10g的環境,老老實實的做了一遍檔案的遷移,這次就沒有任何問題了。
 步驟如下:

SQL> select tablespace_name from user_tablespaces;

TABLESPACE_NAME
 ------------------------------
 SYSTEM
 SYSAUX
 UNDOTBS
 TEMP

SQL> create tablespace data datafile '/u02/ora11g/oradata/TEST/disk3/data01.dbf' size 10M;

Tablespace created.

SQL> alter tablespace data offline;

Tablespace altered.

SQL> !cp /u02/ora11g/oradata/TEST/disk3/data01.dbf /u02/ora11g/oradata/TEST/disk4/data02.dbf

SQL> alter tablespace data rename datafile '/u02/ora11g/oradata/TEST/disk3/data01.dbf' to '/u02/ora11g/oradata/TEST/disk4/data02.dbf';

Tablespace altered.

SQL> alter tablespace data online;

Tablespace altered.
從整個過程來看,唯一的不同之處就在於出問題的那個環境我使用了offline immediate選項
 從官方查看offline的這幾個選項,可以看到還是有很大的不同,預設使用的是normal選項。

OFFLINE NORMAL Specify NORMAL to flush all blocks in all data files in the tablespace out of the system global area (SGA). You need not perform media recovery on this tablespace before bringing it back online. This is the default.

OFFLINE TEMPORARY If you specify TEMPORARY, then Oracle Database performs a checkpoint for all online data files in the tablespace but does not ensure that all files can be written. Files that are offline when you issue this statement may require media recovery before you bring the tablespace back online.

OFFLINE IMMEDIATE If you specify IMMEDIATE, then Oracle Database does not ensure that tablespace files are available and does not perform a checkpoint. You must perform media recovery on the tablespace before bringing it back online.
所以在自己使用offline immediate的時候,這個時候還沒有做checkpoint,如果要使用online選項的時候,還是需要做recover操作。
 大體明白了這麼多,那麼怎麼修複呢,

SQL>  alter tablespace data online;
  alter tablespace data online
 *
 ERROR at line 1:
 ORA-01113: file 4 needs media recovery
 ORA-01110: data file 4: '/u02/ora11g/oradata/TEST/disk4/data02.dbf'

SQL> recover datafile 4;
 Media recovery complete.
SQL> alter tablespace data online;

Tablespace altered.
或者說在一些關鍵的操作的時候還是最好能夠做checkpoint,也就是使用預設的offline normal選項。
 這是一個很簡單很基礎的問題,但是在特定時間裡可能就沒有意識到,看來還是需要不斷鞏固,多做練習:)

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.