11G Oracle RAC添加新表空間時數據文件誤放置到本地文件系統的修正

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

是Oracle的中文技術支持博客題目是:RAC中誤將數據文件建立在本地盤時的修正oracle


  因而我想11G 也兼容這些操做的方法,可是11G的新特性有一點就是能夠直接支持ASM文件系統直接能夠和本地文件系統進行文件的拷貝了,也就是有三種方法。ide

1. RMAN的 copy datafile 方式字體

2. dbms_file_transfer方式spa

3. ASMCMD中的直接cp方式了blog

分別演示三種方式:get

RMANcmd

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

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

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便可

wKioL1L7ObbzZwMlAAI7uS-UAhQ842.jpg

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.

相關文章
相關標籤/搜索