码迷,mamicode.com
首页 > 数据库 > 详细

Oracle12c 存储在线迁移

时间:2020-04-30 17:29:43      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:位置   新建   在线   led   structure   exec   介绍   get   fixed   

Oracle12c 存储在线迁移

首先是做了data磁盘组所有数据迁移到data01磁盘组中,因为data盘是第一个数据盘组所以 controlfile、spfile和密码文件都在data磁盘组中,所以这些也是要迁移的。

 

 

 

数据迁移

 

例子: PDB_JN

在pdb_jn中  自己建的表空间数据文件 需要登陆到 pdb_jn 中在线 move包含pdb_jn中的system、sysaux和users

 

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$SEED中move

+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中的数据确认,发现没有问题。

Oracle12c 存储在线迁移

标签:位置   新建   在线   led   structure   exec   介绍   get   fixed   

原文地址:https://www.cnblogs.com/yaoyangding/p/12809805.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!