Oracle数据库dg主备切换

一、数据库切换
1、业务环境:
主库:10.100.0.9
备库:10.100.0.18
空闲:10.100.0.201

目的:主库和备库切换。

1、主库操作--------------------------------------------------------------------------------------------
1.1 关闭主库监听
su - oracle
lsnrctl stop(只在主库操作)

1.2 在主库端检查数据库可切换状态
sqlplus / as sysdba
SQL> select switchover_status from v$database;

如果SWITCHOVER_STATUS 的值为TO STANDBY 表示可以正常切换.

SQL>alter database commit to switchover to physical standby;

Database altered.

如果SWITCHOVER_STATUS 的值为SESSIONS ACTIVE:

SQL> alter database commit to switchover to physical standby with session shutdown;

Database altered.

tailf ORACLE_SID/bdump/alert_$ORACLE_SID.log 查看日志

2、备库操作---------------------------------------------------------------------------------

2.1这时候到备份库 在备库验证可切换状态

sqlplu / as sysdba

SQL> select switchover_status from v$database;

SWITCHOVER_STATUS

2.22.将目标备库转换为主库
如果SWITCHOVER_STATUS 的值为TO PRIMARY 则:

SQL> alter database commit to switchover to primary;

Database altered.

如果SWITCHOVER_STATUS 的值为SESSIONS ACTIVE 则:

SQL> alter database commit to switchover to primary with session shutdown;

Database altered.

select FILE_NAME,TABLESPACE_NAME,status from dba_temp_files;

tailf ORACLE_SID/bdump/alert_$ORACLE_SID.log 查看日志

3、修改新备库ip(原主库)----------------------------------------------------------------------------

ping 10.100.0.201

sed -i 's/10.100.0.9/10.100.0.201/g' /etc/sysconfig/network-scripts/ifcfg-bond0
cat /etc/sysconfig/network-scripts/ifcfg-bond0

/etc/init.d/network restart

3.1新主库操作(原备库) 更换ip 此ip 为业务ip

sed -i 's/10.100.0.18/10.100.0.9/g' /etc/sysconfig/network-scripts/ifcfg-bond0
sed -i 's/10.100.0.18/10.100.0.9/g' $ORACLE_HOME/network/admin/listener.ora
cat /etc/sysconfig/network-scripts/ifcfg-bond0

/etc/init.d/network restart

4.重启新主库监听(原备库)-------------------------------------------------------------------------------
lsnrctl stop
lsntctl start

Sql> shutdown immediate;
Sql> startup;

lsnrctl status 如果一直未注册到监听里面,需手动注册一下
Sql>ALTER SYSTEM REGISTER;

至此可以进行业务测试,最后剩余步骤恢复dg 同步状态

二、剩余步骤恢复dg 同步状态
下面进一步恢复dg

1.修改新主备库tnsname.ora文件 (此文件主备库完全一样)
cat << EOF > $ORACLE_HOME/network/admin/tnsnames.ora.bak
DB_WENDING =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.100.0.18)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = WENDING)
)
)
DB_PHYSTDBY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.100.0.9)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = PHYSTDBY)
)
)
EOF

2.修改新备库监听文件(原主库)
cat << EOF > $ORACLE_HOME/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /home/oracle/oracle10g/product/10.2.0/db_1)
(PROGRAM = extproc)
)
)

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.100.0.9)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
)
EOF

3、 查看主备 的 /etc/hosts 配置要正确

4,启动新备库库监听 (原主库)

lsnrctl start

重启新备库
Sql>shutdown immediate;
Sql> startup;

5、 新备库执行同步语句
SQL> alter database recover managed standby database disconnect from session;

6、备库查看主备文件同步情况
select sequence#,dest_id,first_time,next_time,archived,applied from v$archived_log order by sequence#

7、主库
set linesize 160 pagesize 999
col destination for a30;
col error for a60;
select status,destination,error from v$archive_dest;

8、主备库都检查
set linesize 160 pagesize 999
col destination for a30;
col error for a60;
select dbid,database_role from varchived_log;
select max(sequence#) from v$archived_log where applied='YES';

9、备库
select process,status,sequence#from v$managed_standby;

10检查新主库脚本

10.1检查rman 备份脚本,以及磁盘挂载目录
10.2检查rman备份监控脚本
备份放在哪台服务器上,监控脚本就放在哪台服务器上。数据量比较大的备份最好放在备库上备份。监控脚本不要放在存储上。
check_rman_backup.sh
10.3检查dg 健康状态脚本
主库是oracle_wending_check.sh
备库是oracle_phystdby_check.sh
有的需要布置check_dg.sh
10.4检查清理归档脚本
主库del_appl_standy_arc_wending.sh
备库del_appl_standy_arc_phystdby.sh

三、新主库启动后如有以下错误,请参考解决方法

一,ORA-30012: undo tablespace 'UNDOTBS1' does not exist or of wrong type
Fri Apr 20 21:17:12 2018

解决方法:
SQL> show parameter undo
NAME TYPE VALUE


undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS1

SQL> select name from v$tablespace where name like '%UNDO%';
NAME


UNDOTBS3

sql > create pfile from spfile;

cd $ORACLE_HOME/dbs

vi init$ORACLE_SID.ora
修改undo_tablespace=UNDOTBS3

然后startup mount pfile=ORACLE_SID.ora (此处请写绝对路径)

sql > create spfile from pfile;

sql> shutdown immediate;

sql> startup

二,数据库启动后,如应用报如下错误 ORA-01187 ORA-01110,或避免报次错,请预先检查一下临时表空间状态

SQL> select TABLESPACE_NAME,FILE_NAME,STATUS from dba_temp_files;

TABLESPACE_NAME FILE_NAME STATUS


TEMP /oradata/ygdb/temp01.dbf AVAILABLE

如果不是AVAILABLE,请执行以下语句
alter tablespace TEMP add tempfile '/oradata/ygdb/temp02.dbf' size 100m autoextend on;
alter tablespace TEMP drop tempfile '/oradata/ygdb/temp01.dbf';

SQL> alter database tempfile '/oradata/ccod/temp01.dbf' drop;
alter tablespace TEMP add tempfile '/oradata/ccod/temp01.dbf' size 100m autoextend on;

你可能感兴趣的:(Oracle数据库dg主备切换)