标签:trail snr domain alter 数据文件 大小 shutdown 内容 update
本文将介绍如何给rac搭建单节点的dg,以及如何对其进行角色转换。预先具备的知识(rac搭建,单实例-单实例dg搭建)
主库rac(已安装rac,并已有数据库orcl)
rac1:192.168.56.11,sid1:orcl1,version:11.2.0.4
rac2:192.168.56.12,sid2:orcl2,version:11.2.0.4
从库(已安装单实例数据库软件,无数据库实例)
oradg:192.168.56.102,sid:orcldg,version:11.2.0.4
** 以下所有主库操作都在节点1上做,如果需要在节点2上做的,我会标明
先查看数据库的归档状态以及是否开启强制写日志,从下图可以看到目前数据库并没有打开归档,也没有开启强制写日志
SQL> select log_mode, force_logging from v$database;
数据库在mount状态下打开归档
SQL> alter system set log_archive_dest_1=‘location=+data‘ sid=‘*‘ scope=spfile;
SQL> shutdown immediate; # 两节点都关闭
SQL> startup mount; # 只开启节点1
SQL> alter database archivelog;
SQL> alter database open;
强制日志写,数据库在open状态就能修改
SQL> alter database force logging;
SQL> startup; # 当节点1open完毕后,在节点2上打开数据库
再来查看数据库的归档状态以及是否开启强制写日志
SQL> select log_mode, force_logging from v$database;
SQL> alter system set log_archive_config=‘dg_config=(orcl,orcldg)‘ sid=‘*‘; # orcl是主库的db_unique_name,orcldg是从库的db_unique_name
SQL> alter system set log_archive_dest_3=‘service=orcldg valid_for=(online_logfiles,primary_role) db_unique_name=orcldg‘ sid=‘*‘;
[oracle@rac1 ~]$ scp $ORACLE_HOME/dbs/orapw$ORACLE_SID 192.168.56.102:$ORACLE_HOME/dbs/orapworcldg
这里参数文件跟给单实例搭建单实例dg没什么区别,所以不做具体介绍
[root@oradg ~]# vi $ORACLE_HOME/dbs/initorcldg.ora
*.audit_file_dest=‘/u01/app/oracle/admin/orcldg/adump‘ *.audit_trail=‘db‘ *.compatible=‘11.2.0.4.0‘ *.control_files=‘/u01/app/oracle/oradata/orcldg/controlfile/control01.ctl‘ *.db_block_size=8192 *.db_domain=‘‘ *.db_name=‘orcl‘ *.diagnostic_dest=‘/u01/app/oracle‘ *.log_archive_config=‘dg_config=(orcl,orcldg)‘ *.log_archive_dest_2=‘location=/u01/app/oracle/oradata/orcldg/archstdlog/ valid_for=(standby_logfiles,standby_role) db_unique_name=orcldg‘ *.memory_target=838860800 *.open_cursors=300 *.processes=150 *.remote_login_passwordfile=‘exclusive‘ *.undo_tablespace=‘UNDOTBS1‘ standby_file_management=auto # 该参数默认值是manual,需要将其改为auto,表示主库的数据文件发生修改(如新建,重命名等),相应地从库也做相应修改 db_unique_name=‘orcldg‘ db_file_name_convert=‘+DATA/orcl/datafile/‘,‘/u01/app/oracle/oradata/orcldg/datafile/‘,‘+DATA/orcl/tempfile/‘,‘/u01/app/oracle/oradata/orcldg/tempfile/‘ log_file_name_convert=‘+DATA/orcl/onlinelog/‘,‘/u01/app/oracle/oradata/orcldg/onlinelog/‘
[oracle@oradg ~]$ mkdir -p /u01/app/oracle/admin/orcldg/adump
[oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/controlfile
[oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/archstdlog
[oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/datafile
[oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/tempfile
[oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/onlinelog
[oracle@oradg ~]$ export ORACLE_SID=orcldg
[oracle@oradg ~]$ sqlplus / as sysdba
SQL> create spfile from pfile;
SQL> startup nomount
因为采用duplicate方式复制主库数据,所以需要将从库配置为静态注册的形式
[oracle@oradg ~]$ vi $ORACLE_HOME/network/admin/listener.ora
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = orcldg) (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) (SID_NAME = orcldg) ) ) LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.102)(PORT = 1521)) )
[oracle@oradg ~]$ lsnrctl start
# 两个节点都要设置
[oracle@rac1 ~]$ vi $ORACLE_HOME/network/admin/tnsnames.ora
orcldg = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.102)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcldg) ) )
[oracle@rac2 ~]$ vi $ORACLE_HOME/network/admin/tnsnames.ora
内容跟rac1一致,略
# 这里我的主库的sys密码是123456,从库与主库一致
[oracle@rac1 ~]$ sqlplus sys/123456@orcldg as sysdba
rman连接主库和从库
[oracle@rac1 ~]$ rman target / auxiliary sys/123456@orcldg
RMAN> duplicate target database for standby from active database;
添加的日志大小跟主库的onlinelog保持一致,数量多两组(主库的onlinelog信息查看v$log)
group的编号不与当前的onlinelog重复即可
[oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/standbylog/
SQL> alter database add standby logfile group 21 ‘/u01/app/oracle/oradata/orcldg/standbylog/std01.log‘ size 50M;
SQL> alter database add standby logfile group 22 ‘/u01/app/oracle/oradata/orcldg/standbylog/std02.log‘ size 50M;
SQL> alter database add standby logfile group 23 ‘/u01/app/oracle/oradata/orcldg/standbylog/std03.log‘ size 50M;
SQL> alter database add standby logfile group 24 ‘/u01/app/oracle/oradata/orcldg/standbylog/std04.log‘ size 50M;
SQL> alter database add standby logfile group 25 ‘/u01/app/oracle/oradata/orcldg/standbylog/std05.log‘ size 50M;
SQL> alter database add standby logfile group 26 ‘/u01/app/oracle/oradata/orcldg/standbylog/std06.log‘ size 50M;
SQL> alter database recover managed standby database disconnect from session;
SQL> alter system switch logfile;
当从库应用归档一段时间后,就关闭应用归档日志,打开从库。
SQL> alter database recover managed standby database cancel;
SQL> alter database open;
SQL> alter database recover managed standby database using current logfile disconnect from session;
主库做修改
SQL> update scott.emp set sal=2000;
SQL> commit;
从库查询
SQL> select * from scott.emp;
至此,给rac搭建一个单实例的dg就已经做完了,跟单实例搭建单实例的dg没什么区别。接下来介绍如何切换。
使用grid账号,创建归档路径
[grid@rac1 ~]$ asmcmd
ASMCMD> lsdg # 查看磁盘组名字
ASMCMD> cd data
ASMCMD> cd orcl
ASMCMD> mkdir ARCHSTDLOG
使用sys数据库账号,修改数据库参数
SQL> alter system set log_archive_dest_2=‘location=+DATA/ORCL/ARCHSTDLOG/ valid_for=(standby_logfiles,standby_role) db_unique_name=orcl‘ sid=‘*‘;
添加的日志的大小跟主库的onlinelog保持一致,数量多两组(主库的onlinelog信息查看v$log)
SQL> alter database add standby logfile thread 1 group 21 (‘+data‘) size 50M;
SQL> alter database add standby logfile thread 1 group 22 (‘+data‘) size 50M;
SQL> alter database add standby logfile thread 1 group 23 (‘+data‘) size 50M;
SQL> alter database add standby logfile thread 2 group 24 (‘+data‘) size 50M;
SQL> alter database add standby logfile thread 2 group 25 (‘+data‘) size 50M;
SQL> alter database add standby logfile thread 2 group 26 (‘+data‘) size 50M;
SQL> alter system set standby_file_management=auto sid=‘*‘;
SQL> alter system set db_file_name_convert=‘/u01/app/oracle/oradata/orcldg/datafile/‘,‘+DATA/orcl/datafile/‘,‘/u01/app/oracle/oradata/orcldg/tempfile/‘,‘+DATA/orcl/tempfile/‘ sid=‘*‘ scope=spfile;
SQL> alter system set log_file_name_convert=‘/u01/app/oracle/oradata/orcldg/onlinelog/‘,‘+DATA/orcl/onlinelog/‘ sid=‘*‘ scope=spfile;
到这里,主库转换为备库的准备工作已完成!
这里的配置tnsnams.ora的目的是,当从库转变为主库之后,原主库变为从库,需要给原主库发送归档日志,所以这里的tnsnames要指向原主库,又由于dg库应用归档只能在一个节点上, 所以toorcl只指向节点1。
[oracle@oradg ~]$ vi $ORACLE_HOME/network/admin/tnsnames.ora
toorcl = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.11)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) )
[oracle@oradg ~]$ mkdir -p /u01/app/oracle/oradata/orcldg/archivelog
SQL> alter system set log_archive_dest_1=‘location=/u01/app/oracle/oradata/orcldg/archivelog/ valid_for=(online_logfiles,primary_role) db_unique_name=orcldg‘;
SQL> alter system set log_archive_dest_3=‘service=toorcl valid_for=(online_logfiles,primary_role) db_unique_name=orcl‘;
到这里,从库转为主库的准备工作已完成!
SQL> select database_role,switchover_status from v$database;
集群在做角色转换时,只能有一个实例是打开状态,其余都要关闭,所以将节点2的实例关闭。
SQL> shutdown immediate; # 只在节点2上做
在节点1上执行以下命令,将主库转为从库,并且关闭实例
SQL> alter database commit to switchover to physical standby with session shutdown;
SQL> select database_role,switchover_status from v$database;
如果是"NOT ALLOWED"表示归档还没有应用完成,可以等待一段时间
如果日志全部应用了再查看角色转换状态
SQL> select database_role,switchover_status from v$database;
如果角色转换状态是TO PRIMARY,那么表示可以进行角色转换
执行从转主的命令,命令执行成功后,数据库的状态会变为mount
SQL> alter database commit to switchover to primary;
SQL> alter database open;
在节点1和节点2上
SQL> startup
节点1上应用归档
SQL> alter database recover managed standby database using current logfile disconnect from session;
节点3上切换归档
SQL> alter system switch logfile;
主库做修改
SQL> update scott.emp set sal=3000;
SQL> commit;
从库查询
SQL> select * from scott.emp;
如果发现日志传不到备库的话可以在主库通过以下命令查看错误原因
SQL> select dest_id,dest_name,log_sequence,status,error from v$archive_dest;
如果报上面的错误的话,可以把归档开关重启一下即可
SQL> alter system set log_archive_dest_state_3=‘defer‘ sid=‘*‘;
SQL> alter system set log_archive_dest_state_3=‘enable‘ sid=‘*‘;
1. dg的切换需要停掉所有的应用,并把数据库的所有连接全部kill掉,账号全锁,切换完成后再解锁
2. rac在切换时,只留一个活的实例,其它全部关闭
3. 命令每执行一条,就留意返回的结果,并实时查看alert.log
标签:trail snr domain alter 数据文件 大小 shutdown 内容 update
原文地址:https://www.cnblogs.com/ddzj01/p/12044310.html