实战:如何将Oracle单实例数据库转换成Oracle RAC数据库

导读
本文介绍如何将Oracle单实例数据库转换成Oracle RAC数据库
环境说明:
数据库节点2上有个单实例数据库zlxdb2,现在要将zlxdb2转换成RAC数据库,RAC数据库的两个实例分别是lzydb1和lzydb2。
以下是详细的操作步骤:

1、查看zlxdb2的默认undo表空间

SYS@zlxdb2>show parameter undo

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS1

2、给zlxdb2数据库创建新的UNDO表空间

SYS@zlxdb2>CREATE UNDO TABLESPACE UNDOTBS2 DATAFILE '+DATA' SIZE 100m AUTOEXTEND ON;

SYS@zlxdb2>select tablespace_name from dba_tablespaces where contents='UNDO';

TABLESPACE_NAME
------------------------------
UNDOTBS1
UNDOTBS2

将UNDOTBS1表空间设置为数据库实例lzydb1的默认undo表空间,
将UNDOTBS2表空间设置为数据库实例lzydb2的默认undo表空间。

alter system set undo_tablespace=UNDOTBS2 SCOPE=SPFILE SID='lzydb2';
alter system set undo_tablespace=UNDOTBS1 SCOPE=SPFILE SID='lzydb1';

3、查看redo日志路径和redo大小

SYS@zlxdb2>select group#,member from v$logfile order by 1;

GROUP# MEMBER
---------- --------------------------------------------------
1 +DATA/lzydb/onlinelog/group_1.290.1120398077
2 +DATA/lzydb/onlinelog/group_2.291.1120398077
3 +DATA/lzydb/onlinelog/group_3.292.1120398077


SYS@zlxdb2>select group#,thread#,bytes/1024/1024 from v$log;

GROUP# THREAD# BYTES/1024/1024
---------- ---------- ---------------
1 1 50
2 1 50
3 1 50

查看redo日志的thread号,单实例只有一个thread1

SYS@zlxdb2>select THREAD#, STATUS, ENABLED from v$thread;
THREAD# STATUS ENABLED
---------- ------ --------
1 OPEN PUBLIC

4、添加新的redo日志组group4,group5,group6,大小分别与group1,group2,group3一样50MB

alter database add logfile thread 2 group 4 ('+DATA') size 50m,group 5 ('+DATA') size 50m,group 6 ('+DATA') size 50m;

SYS@zlxdb2>select group#,member from v$logfile order by 1;

GROUP# MEMBER
---------- --------------------------------------------------
1 +DATA/zlxdb/onlinelog/group_1.275.1120355965
2 +DATA/zlxdb/onlinelog/group_2.276.1120355967
3 +DATA/zlxdb/onlinelog/group_3.277.1120355967
4 +DATA/zlxdb/onlinelog/group_4.280.1120358085
5 +DATA/zlxdb/onlinelog/group_5.281.1120358085
6 +DATA/zlxdb/onlinelog/group_6.282.1120358087

SYS@zlxdb2>select group#,thread#,bytes/1024/1024 from v$log;

GROUP# THREAD# BYTES/1024/1024
---------- ---------- ---------------
1 1 50
2 1 50
3 1 50
4 2 50
5 2 50
6 2 50

6 rows selected.

启用thread2线程的日志组

SYS@zlxdb2>alter database enable public thread 2;

SYS@zlxdb2>select THREAD#, STATUS, ENABLED from v$thread;
THREAD# STATUS ENABLED
---------- ------ --------
1 OPEN PUBLIC
2 CLOSED DISABLED

5、开启集群

SYS@zlxdb2>alter system set cluster_database=true scope=spfile sid='*';
SYS@zlxdb2>alter system set cluster_database_instances=2 scope=spfile;

6、设置新数据库lzydb的RAC参数

SYS@zlxdb2>alter system set remote_listener='scan-ip:1521';
SYS@zlxdb2>alter system set instance_number=1 scope=spfile sid='lzydb1';
SYS@zlxdb2>alter system set instance_number=2 scope=spfile sid='lzydb2';
SYS@zlxdb2>alter system set instance_name='lzydb1' scope=spfile sid='lzydb1';
SYS@zlxdb2>alter system set instance_name='lzydb2' scope=spfile sid='lzydb2';
SYS@zlxdb2>alter system set thread=1 sid='lzydb1';
SYS@zlxdb2>alter system set thread=2 sid='lzydb2';

7、从zlxdb2的spfile创建pfile参数文件,用于设置新数据库lzydb的参数

SYS@zlxdb2>create pfile='/home/oracle/initzlxdb2.ora' from spfile;

参数文件信息如下:

*.audit_file_dest='/u01/app/oracle/admin/lzydb/adump'
*.audit_trail='db'
*.cluster_database=TRUE
*.cluster_database_instances=2
*.compatible='11.2.0.4.0'
*.control_files='+DATA/lzydb/controlfile/current.289.1120398075'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_name='lzydb'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=lzydbXDB)'
lzydb1.instance_name='lzydb1'
lzydb2.instance_name='lzydb2'
lzydb1.instance_number=1
lzydb2.instance_number=2
*.open_cursors=300
*.pga_aggregate_target=314572800
*.processes=150
*.remote_listener='scan-ip:1521'
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=943718400
lzydb1.thread=1
lzydb2.thread=2
lzydb1.undo_tablespace='UNDOTBS1'
lzydb2.undo_tablespace='UNDOTBS2'

SYS@zlxdb2>show parameter spfile
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string +DATA/lzydb/spfilelzydb.ora

8、关闭zlxdb2数据库

SYS@zlxdb2>shutdown immediate

9、创建参数文件,将initlzydb2.ora指向spfile路径:

SPFILE='+DATA/lzydb/spfilelzydb.ora'

10、执行创建RAC数据库集群的脚本

SYS@zlxdb2>@?/rdbms/admin/catclust.sql
PL/SQL procedure successfully completed.

11、将新的initlzydb2.ora参数文件拷贝到节点1

[oracle@node2 ~]$ cd $ORACLE_HOME/dbs
scp initlzydb2.ora node1:$ORACLE_HOME/dbs

12、节点1重命名参数文件为initlzydb1.ora

[oracle@node1 ~]$ cd $ORACLE_HOME/dbs
mv initlzydb2.ora initlzydb1.ora

13、启动lzydb1和lzydb2两个数据库实例

[oracle@node1 ~]$ mkdir -p /u01/app/oracle/admin/lzydb/adump
export ORACLE_SID=lzydb1
sqlplus / as sysdba
startup

[oracle@node2 ~]$ mkdir -p /u01/app/oracle/admin/lzydb/adump
export ORACLE_SID=lzydb2
sqlplus / as sysdba
startup

13、数据库实例添加到CRS中

[oracle@node1 ~]$ crsctl stat res -t
[oracle@node1 ~]$ srvctl remove database -d lzydb -f
[oracle@node1 ~]$ srvctl add database -d lzydb -o $ORACLE_HOME -p +DATA/lzydb/spfilelzydb.ora
[oracle@node1 ~]$ srvctl add instance -d lzydb -n node1 -i lzydb1
[oracle@node1 ~]$ srvctl add instance -d lzydb -n node2 -i lzydb2

14、分别关闭两个新的数据库实例lzydb1和lzydb2

shut immediate

15、使用srvctl start database命令启动数据库lzydb

srvctl start database -d lzydb

16、查看数据库状态

[root@node1 ~]# crsctl stat res -t

你可能感兴趣的:(Oracle,oracle)