Oracle12c 儲存線上遷移

邱東陽發表於2016-02-26

首先是做了data磁碟組所有資料遷移到data01磁碟組中,因為data盤是第一個資料盤組所以 controlfilespfile和密碼檔案都在data磁碟組中,所以這些也是要遷移的。

 

 

 

資料遷移

 

例子: PDB_JN

pdb_jn  自己建的表空間資料檔案 需要登陸到 pdb_jn 中線上 move包含pdb_jn中的systemsysauxusers

 

alter database move datafile '+DATA1/QIUDB/2A4C7A7D54789BADE053653AA8C0C85F/DATAFILE/tbs_qiu.279.902188479' to '+DATA2';

alter database move datafile '+DATA1/QIUDB/2A4C7A7D54789BADE053653AA8C0C85F/DATAFILE/system.262.902178279' to '+DATA2';

alter database move datafile '+DATA1/QIUDB/2A4C7A7D54789BADE053653AA8C0C85F/DATAFILE/sysaux.264.902178289' to '+DATA2';

 

 

 

sys登陸資料庫中move會報錯

SQL> alter database move datafile '+DATA1/QIUDB/2A4C7A7D54789BADE053653AA8C0C85F/DATAFILE/tbs_qiu.256.902189879' to '+DATA2';

alter database move datafile '+DATA1/QIUDB/2A4C7A7D54789BADE053653AA8C0C85F/DATAFILE/tbs_qiu.256.902189879' to '+DATA2'

*

ERROR at line 1:

ORA-01516: nonexistent log file, data file, or temporary file "11"

 

 

 

系統的表空間資料檔案 需要在用sqlplus / as sysdba 線上move

+DATA1/QIUDB/DATAFILE/system.261.902178271

+DATA1/QIUDB/DATAFILE/sysaux.263.902178285

+DATA1/QIUDB/DATAFILE/undotbs1.257.902190169

+DATA1/QIUDB/DATAFILE/users.268.902178329

+DATA1/QIUDB/DATAFILE/undotbs2.277.902187017

 

SQL> show pdbs

 

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED

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

         2 PDB$SEED                       READ ONLY  NO

         3 PDB_JN                         READ WRITE NO

alter database move datafile '+DATA1/QIUDB/DATAFILE/undotbs2.277.902187017' to '+DATA2';

 

SQL> select name from v$datafile;

 

NAME

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

+DATA1/QIUDB/DATAFILE/system.261.902178271

+DATA1/QIUDB/2A4ABBD9CE485E58E053643AA8C0B0DA/DATAFILE/system.262.902178279

+DATA1/QIUDB/DATAFILE/sysaux.263.902178285

+DATA1/QIUDB/2A4ABBD9CE485E58E053643AA8C0B0DA/DATAFILE/sysaux.264.902178289

+DATA2/QIUDB/DATAFILE/undotbs1.257.902190169

+DATA1/QIUDB/DATAFILE/users.268.902178329

+DATA1/QIUDB/2A4C7A7D54789BADE053653AA8C0C85F/DATAFILE/system.270.902185753

+DATA1/QIUDB/2A4C7A7D54789BADE053653AA8C0C85F/DATAFILE/sysaux.271.902185759

+DATA1/QIUDB/2A4C7A7D54789BADE053653AA8C0C85F/DATAFILE/users.273.902185785

+DATA1/QIUDB/DATAFILE/undotbs2.277.902187017

+DATA2/QIUDB/2A4C7A7D54789BADE053653AA8C0C85F/DATAFILE/tbs_qiu.256.902189879

 

PDB$SEED 也有2個資料檔案需要登陸到PDB$SEEDmove

+DATA1/QIUDB/2A4ABBD9CE485E58E053643AA8C0B0DA/DATAFILE/system.262.902178279

+DATA1/QIUDB/2A4ABBD9CE485E58E053643AA8C0B0DA/DATAFILE/sysaux.264.902178289

 

 

 

臨時表空間遷移

 

臨時表空間就不能使用move 來遷移了,需要新增與原臨時檔案相同大小的臨時檔案到新的儲存上

 

alter tablespace temp add tempfile '+DATA1/QIUDB/2A4C7A7D54789BADE053653AA8C0C85F/TEMPFILE/temp.272.902185771 size 20971520;

alter database tempfile +DATA/QIUDB/2A4C7A7D54789BADE053653AA8C0C85F/TEMPFILE/temp.272.902185771 drop;

當然還可以建一個新的臨時表空間然後切換資料庫預設臨時表空間,最後刪除之前的

alter database default temporary tablespace temp2;

drop tablespace temp including contents and datafile;

 

 

控制檔案以及引數檔案遷移

 

遷移控制檔案需要停庫

 

1、  首先確認資料庫當前使用的是哪個控制檔案

SQL> show parameter control_files

 

NAME                                 TYPE                   VALUE

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

control_files                        string                 +DATA/SDCLDDB/CONTROLFILE/curr

                                                            ent.304.879778695

2、  停掉所有例項資料庫(略)

3、  複製控制檔案

[grid@sddxcna02 ~]$ asmcmd

ASMCMD> ls

CRS/

DATA/

DATA01/

ASMCMD> cd data

ASMCMD> cd sdclddb

ASMCMD> ls

1616F923B3A9E061E053650A040AFA55/

1617E477401923DDE053650A040A5F38/

161A5F780EEA10CCE053660A040A6D27/

166CAA44368FAAA5E053650A040A6C07/

CONTROLFILE/

DATAFILE/

FD9AC20F64D244D7E043B6A9E80A2F2F/

ONLINELOG/

PARAMETERFILE/

PASSWORD/

TEMPFILE/

ASMCMD> cd CONTROLFILE/

ASMCMD> ls

Current.270.879764093

Current.290.879768065

Current.304.879778695

ASMCMD> cp Current.304.879778695 +data01/sdclddb/CONTROLFILE/

copying +data/sdclddb/CONTROLFILE/Current.304.879778695 -> +data01/sdclddb/CONTROLFILE/Current.304.879778695

ASMCMD-8016: copy source '+data/sdclddb/CONTROLFILE/Current.304.879778695' and target '+data01/sdclddb/CONTROLFILE/Current.304.879778695' failed

ORA-15056: additional error message

ORA-15046: ASM file name '+data01/sdclddb/CONTROLFILE/Current.304.879778695' is not in single-file creation form

ORA-06512: at "SYS.X$DBMS_DISKGROUP", line 486

ORA-06512: at line 3 (DBD ERROR: OCIStmtExecute)

 

ASMCMD> cp Current.304.879778695 Current.ora          

copying +data/sdclddb/CONTROLFILE/Current.304.879778695 -> +data/sdclddb/CONTROLFILE/Current.ora

ASMCMD> ls

Current.270.879764093

Current.290.879768065

Current.304.879778695

Current.ora

ASMCMD> cp Current.ora +data01/sdclddb/CONTROLFILE/

copying +data/sdclddb/CONTROLFILE/Current.ora -> +data01/sdclddb/CONTROLFILE/Current.ora

4、  修改控制檔案引數並確認是否啟庫成功

SQL> startup nomount

ORACLE instance started.

 

Total System Global Area 1.3341E+11 bytes

Fixed Size                  7662768 bytes

Variable Size            2.1475E+10 bytes

Database Buffers         1.1167E+11 bytes

Redo Buffers              260771840 bytes

SQL> alter system set control_files='+DATA01/SDCLDDB/CONTROLFILE/current.ora' scope=spfile  sid='*';

 

System altered.

SQL> shutdown immediate;

ORA-01507: database not mounted

 

 

ORACLE instance shut down.

SQL> exit

[oracle@sddxcna02 app]$ sqlplus "/as sysdba"

SQL*Plus: Release 12.1.0.2.0 Production on Tue Feb 23 22:25:30 2016

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

Connected to an idle instance.

SQL> startup nomount;

ORACLE instance started.

Total System Global Area 1.3341E+11 bytes

Fixed Size                  7662768 bytes

Variable Size            2.1475E+10 bytes

Database Buffers         1.1167E+11 bytes

Redo Buffers              260771840 bytes

SQL>

SQL> alter database mount;

Database altered.

SQL> alter database open;

 

Database altered.

SQL>

SQL> show parameter control_files

NAME                                 TYPE        VALUE

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

control_files                        string      +DATA01/SDCLDDB/CONTROLFILE/cu

                                                 rrent.ora

 

引數檔案的遷移

 

1、  首先確認當前spfile

SQL> show parameter spfile

 

NAME                                 TYPE        VALUE

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

spfile                               string      +DATA/SDCLDDB/PARAMETERFILE/

                                                 spfile .276.879779171

2、  建立 pfile  (因為有些引數需要調整,建個pfile方便點)

SQL> create pfile=’/oracle/app/spfile.ora’ from spfile;

File created.

3、  停庫並指定pfile啟動資料庫同時建立新的spfile

SQL> shutdown immediate;

ORACLE instance shut down.

SQL>startup pfile=’/oracle/app/spfile.ora’  nomount;

ORACLE instance started.

Total System Global Area 1.3341E+11 bytes

Fixed Size                  7662768 bytes

Variable Size            2.1475E+10 bytes

Database Buffers         1.1167E+11 bytes

Redo Buffers              260771840 bytes

SQL>

SQL> create spfile=’+data01/SDCLDDB/PARAMETERFILE/ spfile1.ora’ from pfile=’/oracle/app/spfile.ora’

File created.

注: 這裡一定要新建spfile不要像控制檔案一樣拷貝,因為在OCR 中記錄著spfile位置。當你使用srvctl start database –db sdclddb

     Oracle還是會找原data磁碟組中的引數檔案啟動資料庫。這裡建立spfile也就是告訴oracle我用新的spfile OCR的記錄也會變更。

4、  修改所有 節點$ORACLE_HOME/dbs 下的 init配置檔案內容如下

SPFILE='+DATA01/SDCLDDB/PARAMETERFILE/spfile1.ora'

5、  停庫然後使用srvctl 啟動所有節點

SQL> shutdown immediate;

ORACLE instance shut down.

[oracle@sddxcna02 app]$ srvctl start database –db sdclddb

 

6、  檢查所有節點引數

SQL> show parameter spfile

 

NAME                                 TYPE        VALUE

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

spfile                               string      +DATA01/SDCLDDB/PARAMETERFILE/

                                                 spfile1.ora

SQL> show parameter control_files

NAME                                 TYPE        VALUE

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

control_files                        string      +DATA01/SDCLDDB/CONTROLFILE/cu

                                                 rrent.ora

 

密碼檔案遷移

 

現在口令檔案也可以被儲存在ASM中,這樣做的好處是,即可以通過ASM保護和加強口令檔案的管理,在RAC模式下,更可以使得多例項共享同一個口令檔案,保證口令檔案的一致性。

 

方法 

1、通過類似如下的命令可以將口令檔案建立到ASM磁碟組中:

orapwd file='+DATA01/SDCLDDB/PASSWORD/pwdsdclddb' dbuniquename='sdclddb' password='123456'

2、通過如下命令可以檢查配置,預設直接生效

srvctl config database -d  sdclddb

在輸出中包含了關於口令檔案配置的資訊:

Password file: +DATA01/SDCLDDB/PASSWORD/pwdsdclddb

3、如果沒有變更,可以通過配置指定資料庫在啟動時呼叫該口令檔案

srvctl modify database -db sdclddb -pwfile  +DATA01/SDCLDDB/PASSWORD/pwdsdclddb

 

 

 

遇到的問題:

[oracle@sddxcna02 dbs]$ orapwd file='+DATA01/SDCLDDB/PASSWORD/pwdsdclddb' dbuniquename='sdclddb' password='123456'

 

OPW-00010: Could not create the password file.

ORA-15056: additional error message

ORA-15221: ASM operation requires compatible.asm of 12.1.0.0.0 or higher

ORA-06512: at line 4

解決思路:

SQL> select group_number, name,compatibility, database_compatibility from v$asm_diskgroup;

 

GROUP_NUMBER NAME     COMPATIBILITY    DATABASE_COMPATIBILITY

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

           4 DATA01   10.1.0.0.0       10.1.0.0.0

           0 DATA     12.1.0.0.0       10.0.0.0.0

           1 CRS      12.1.0.0.0       10.1.0.0.0

SQL>select group_number, name, value from v$asm_attribute where name like 'compatible%'

GROUP_NUMBER  NAME           VALUE

 

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

1      compatible.asm     12.1.0.0.0

 

1     compatible.rdbms    10.1.0.0.0

 

可以使用alter diskgroup data01 set attribute 'compatible.asm'='12.1'; 改變版本,但是不知道是否 對資料有影響。

查詢資料,根據官網介紹:

COMPATIBLE.ASM  

Determines the minimum software version for an Oracle ASM instance that can use the disk group. This setting also affects the format of the data structures for the Oracle ASM metadata on the disk.

For Oracle ASM in Oracle Database 11g, 10.1 is the default setting for the COMPATIBLE.ASM attribute when using the SQL CREATE DISKGROUP statement, the ASMCMD mkdg command, and Oracle Enterprise Manager Create Disk Group page. When creating a disk group with ASMCA, the default setting is 11.2.

自己測試環境試驗:

SQL> create diskgroup DATA01  external redundancy disk '/dev/asm-diskqa';

 

Diskgroup created.

SQL> select group_number, name, compatibility, database_compatibility from v$asm_diskgroup;

 

GROUP_NUMBER NAME                           COMPATIBILITY                                                DATABASE_COMPATIBILITY

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

           5 DATA01                         10.1.0.0.0                                                   10.1.0.0.0

           1 DATA1                          12.1.0.0.0                                                   10.1.0.0.0

           4 OCR                            12.1.0.0.0                                                   10.1.0.0.0

           2 DATA2                          12.1.0.0.0                                                   10.1.0.0.0

           3 DATA3                          12.1.0.0.0                                                   10.1.0.0.0

 

磁碟增加資料以便測試:

CREATE TABLESPACE text_tmp DATAFILE  '+DATA01' SIZE 50m AUTOEXTEND OFF;

 

create user texttmp identified by texttmp default tablespace text_tmp 

temporary tablespace TEMP   quota 20000M on text_tmp;

 

create TABLE texttmp.text as select * from DBA_SEGMENTS;

 

update texttmp.text set owner='qiudb' where owner='AUDSYS';

 

 

改變磁碟組版本

SQL> alter diskgroup data01 set attribute 'compatible.asm'='12.1';

 

Diskgroup altered.

 

SQL> select group_number, name,compatibility, database_compatibility from v$asm_diskgroup;

 

GROUP_NUMBER NAME                           COMPATIBILITY                                                DATABASE_COMPATIBILITY

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

           5 DATA01                         12.1.0.0.0                                                   10.1.0.0.0

           1 DATA1                          12.1.0.0.0                                                   10.1.0.0.0

           4 OCR                            12.1.0.0.0                                                   10.1.0.0.0

           2 DATA2                          12.1.0.0.0                                                   10.1.0.0.0

           3 DATA3                          12.1.0.0.0                                                   10.1.0.0.0

 

停掉所有節點,然後重啟

[root@12crac1 bin]# ./crsctl stop crs

[root@12crac1 bin]# ./crsctl strt crs

 

測試

update texttmp.text set owner='AUDSYS' where owner='QIUDB';

 

select * from texttmp.text

 
經過測試環境測試,修改磁碟組的 COMPATIBILITY  版本對資料是沒有什麼影響,當然我做測試的資料量很小。在生產環境中首先要做好備份,然後才做不確認的操作,通過生產環境修改。對磁碟DATA01中的資料確認,發現沒有問題。

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

相關文章