11G Oracle RAC新增新表空間時資料檔案誤放置到本地檔案系統的修正

yyp2009發表於2014-04-30

今天看了一篇文章說是誤將新建立的表空間的資料檔案放置在了本地系統而不是共享儲存上。

是Oracle的中文技術支援部落格題目是:RAC中誤將資料檔案建立在本地盤時的修正

 

於是我想11G 也相容這些操作的方法,但是11G的新特性有一點就是可以直接支援ASM檔案系統直接可以和本地檔案系統進行檔案的拷貝了,也就是有三種方法。

1. RMAN的 copy datafile 方式

2. dbms_file_transfer方式

3. ASMCMD中的直接cp方式了

分別演示三種方式:

RMAN

1)建立好本地開始的表空間

SQL> create tablespace andy datafile '/home/oracle/andy.dbf' size 100M;

Tablespace created.

2)檢視一下狀態

SQL> select name,status from v$datafile;

NAME

--------------------------------------------------------------------------------

STATUS

-------

+DATA/racdb/datafile/system.256.823634487

SYSTEM

+DATA/racdb/datafile/sysaux.257.823634489

ONLINE

+DATA/racdb/datafile/undotbs1.258.823634489

ONLINE

NAME

--------------------------------------------------------------------------------

STATUS

-------

+DATA/racdb/datafile/users.259.823634491

ONLINE

+DATA/racdb/datafile/example.264.823634653

ONLINE

+DATA/racdb/datafile/undotbs2.265.823634943

ONLINE

NAME

--------------------------------------------------------------------------------

STATUS

-------

+DATA/racdb/datafile/undotbs3.266.823634945

ONLINE

+DATA/racdb/datafile/andylhz.272.823709117

ONLINE

+DATA/racdb/datafile/archivedata.274.824748169

ONLINE

NAME

--------------------------------------------------------------------------------

STATUS

-------

+DATA/racdb/datafile/archivedata01.275.824749235

ONLINE

/home/oracle/andy.dbf

ONLINE

3)在本地表空間上建立表 andy01

SQL> create table andy01 tablespace andy as select * from dba_objects;

Table created.

4)在第二個例項上去建立表也放在andy這個表空間上,注意紅色字型部分,報告無法定位andy.dbf資料檔案

[oracle@racdb2 ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Wed Feb 12 17:00:30 2014

Copyright (c) 1982, 2009, Oracle. All rights reserved.

SQL> conn / as sysdba

Connected.

SQL> create table andy02 tablespace andy as select * from dba_objects;

create table andy02 tablespace andy as select * from dba_objects

*

ERROR at line 1:

ORA-01157: cannot identify/lock data file 11 - see DBWR trace file

ORA-01110: data file 11: '/home/oracle/andy.dbf'

5)然後進行修正操作,先將andy表空間進行offline

然後進行RMAN 拷貝 在將資料檔案進行移動,online即可

.

SQL> alter database rename file '/home/oracle/andy.dbf' to '+data/racdb/datafile/andy.dbf';

 

第二種方式

1)先建立兩個目錄,offline表空間andy

SQL> create directory andy01 as '/home/oracle/';

Directory created.

SQL> create directory andy02 as '+data/racdb/datafile/';

Directory created.

SQL>

2)進行檔案傳輸

 

SQL> exec dbms_file_transfer.copy_file('andy01','andy.dbf','andy02','andy.dbf');

PL/SQL procedure successfully completed.

SQL>

進入asmcmd檢視一下

 

ASMCMD> pwd

+data/racdb/datafile

ASMCMD> ls

ANDYLHZ.272.823709117

ARCHIVEDATA.274.824748169

ARCHIVEDATA01.275.824749235

COPY_FILE.279.839351419

EXAMPLE.264.823634653

SYSAUX.257.823634489

SYSTEM.256.823634487

UNDOTBS1.258.823634489

UNDOTBS2.265.823634943

UNDOTBS3.266.823634945

USERS.259.823634491

andy.dbf

ASMCMD>

已經成功拷貝過去了

移動資料檔案,online資料檔案

SQL> alter database rename file '/home/oracle/andy.dbf' to '+data/racdb/datafile/andy.dbf';

Database altered.

 

 

SQL> alter tablespace andy online;

Tablespace altered.

 

第三種:通過grid使用者進入到asmcmd環境下然後直接進入到RAC環境下的資料檔案所在路徑因為是資料檔案建立在了oracle的家目錄下,grid沒有許可權讀取,所以使用root使用者將資料檔案移動到grid家目錄下同時變更權

[root@racdb1 grid]#mv andy.dbf /home/grid/

[root@racdb1 grid]#chown grid.asmadmin andy.dbf

 

[root@racdb1 grid]# su - grid

[grid@racdb1 ~]$ asmcmd

ASMCMD> cd data/racdb/datafile/

ASMCMD> ls

ANDYLHZ.272.823709117

ARCHIVEDATA.274.824748169

ARCHIVEDATA01.275.824749235

EXAMPLE.264.823634653

SYSAUX.257.823634489

SYSTEM.256.823634487

UNDOTBS1.258.823634489

UNDOTBS2.265.823634943

UNDOTBS3.266.823634945

USERS.259.823634491

ASMCMD> cp /home/grid/andy.dbf ./

copying /home/grid/andy.dbf -> +data/racdb/datafile/andy.dbf

ASMCMD> ls

ANDYLHZ.272.823709117

ARCHIVEDATA.274.824748169

ARCHIVEDATA01.275.824749235

EXAMPLE.264.823634653

SYSAUX.257.823634489

SYSTEM.256.823634487

UNDOTBS1.258.823634489

UNDOTBS2.265.823634943

UNDOTBS3.266.823634945

USERS.259.823634491

andy.dbf

ASMCMD>

移動資料檔案到共享儲存

SQL> alter database rename file '/home/oracle/andy.dbf' to '+data/racdb/datafile/andy.dbf';

Database altered.

SQL>

將資料檔案online。

 

驗證資料檔案狀態

SQL> select name,status from v$datafile;

NAME

--------------------------------------------------------------------------------

STATUS

-------

+DATA/racdb/datafile/system.256.823634487

SYSTEM

+DATA/racdb/datafile/sysaux.257.823634489

ONLINE

+DATA/racdb/datafile/undotbs1.258.823634489

ONLINE

NAME

--------------------------------------------------------------------------------

STATUS

-------

+DATA/racdb/datafile/users.259.823634491

ONLINE

+DATA/racdb/datafile/example.264.823634653

ONLINE

+DATA/racdb/datafile/undotbs2.265.823634943

ONLINE

NAME

--------------------------------------------------------------------------------

STATUS

-------

+DATA/racdb/datafile/undotbs3.266.823634945

ONLINE

 

+DATA/racdb/datafile/andylhz.272.823709117

ONLINE

+DATA/racdb/datafile/archivedata.274.824748169

ONLINE

NAME

--------------------------------------------------------------------------------

STATUS

-------

+DATA/racdb/datafile/archivedata01.275.824749235

ONLINE

+DATA/racdb/datafile/andy.dbf

ONLINE

11 rows selected.
from:
http://www.it165.net/database/html/201402/5218.html

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/13750068/viewspace-1152030/,如需轉載,請註明出處,否則將追究法律責任。

相關文章