时间:2021-07-01 10:21:17 帮助过:54人阅读
oracle dataguard搭建请看如下链接 http://www.itopers.com/?p=679 switchover主要是在数据库升级,硬件升级等进行。如下将如何进行switchover: 在prmary将数据库设置为standby SQL alter database commit to switchover to physical standby;Database alte
oracle dataguard搭建请看如下链接
http://www.itopers.com/?p=679
switchover主要是在数据库升级,硬件升级等进行。如下将如何进行switchover:
在prmary将数据库设置为standby
SQL> alter database commit to switchover to physical standby; Database altered.
11g时,执行这个命令后,数据库已经关闭了,不需要手动进行关闭了
SQL> select db_unique_name,database_role,open_mode,switchover_status from v$database; select db_unique_name,database_role,open_mode,switchover_status from v$database * ERROR at line 1: ORA-01034: ORACLE not available Process ID: 2650 Session ID: 458 Serial number: 211
然后启动启动到mount状态查看:
SQL> startup mount ORACLE instance started. Total System Global Area 1.3462E+10 bytes Fixed Size 2265984 bytes Variable Size 3321891968 bytes Database Buffers 1.0133E+10 bytes Redo Buffers 4460544 bytes Database mounted. SQL> select db_unique_name,database_role,open_mode,switchover_status from v$database; DB_UNIQUE_NAME DATABASE_ROLE OPEN_MODE ------------------------------ ---------------- -------------------- SWITCHOVER_STATUS -------------------- actvdb01 PHYSICAL STANDBY MOUNTED RECOVERY NEEDED
查看已经是PHYSICAL STANDBY状态了。
打开数据库,这个时候应该是read only状态:
SQL> alter database open; Database altered. SQL> select db_unique_name,database_role,open_mode,switchover_status from v$database; DB_UNIQUE_NAME DATABASE_ROLE OPEN_MODE ------------------------------ ---------------- -------------------- SWITCHOVER_STATUS -------------------- actvdb01 PHYSICAL STANDBY READ ONLY RECOVERY NEEDED
这个时候primary已经变成了standby了。
然后连接到之前的standby服务器上:
先查看状态,确定日志应用是否完整
SQL> select db_unique_name,database_role,open_mode from v$database; DB_UNIQUE_NAME DATABASE_ROLE OPEN_MODE ------------------------------ ---------------- -------------------- actvdb02 PHYSICAL STANDBY READ ONLY WITH APPLY SQL> archive log list Database log mode Archive Mode Automatic archival Enabled Archive destination USE_DB_RECOVERY_FILE_DEST Oldest online log sequence 348 Next log sequence to archive 0 Current log sequence 353 SQL> alter database recover managed standby database cancel; Database altered. SQL> select db_unique_name,database_role,open_mode from v$database; DB_UNIQUE_NAME DATABASE_ROLE OPEN_MODE ------------------------------ ---------------- -------------------- actvdb02 PHYSICAL STANDBY READ ONLY
然后将standby切换成primary
SQL> alter database commit to switchover to primary; Database altered. SQL> select db_unique_name,database_role,open_mode from v$database; DB_UNIQUE_NAME DATABASE_ROLE OPEN_MODE ------------------------------ ---------------- -------------------- actvdb02 PRIMARY MOUNTED
完成后,状态已经变成的primary了,注意,在执行切换过程中,不能有任何session连接,如果有会有如下报错:
SQL> alter database commit to switchover to primary; alter database commit to switchover to primary * ERROR at line 1: ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected
把session关闭掉,重新执行即可。
然后打开数据库,在新primary中(也就是老的standby)
SQL> alter database open; Database altered. SQL> select db_unique_name,database_role,open_mode from v$database; DB_UNIQUE_NAME DATABASE_ROLE OPEN_MODE ------------------------------ ---------------- -------------------- actvdb02 PRIMARY READ WRITE SQL> select db_unique_name,database_role,open_mode,switchover_status from v$database; DB_UNIQUE_NAME DATABASE_ROLE OPEN_MODE ------------------------------ ---------------- -------------------- SWITCHOVER_STATUS -------------------- actvdb02 PRIMARY READ WRITE TO STANDBY
查看状态已经变成了primary,且为read write了。表示已经成功从standby转成primary了
然后再登录到standby中(之前的primary中)启用mrp进程
SQL> alter database recover managed standby database using current logfile disconnect from session; Database altered. SQL> select db_unique_name,database_role,open_mode,switchover_status from v$database; DB_UNIQUE_NAME DATABASE_ROLE OPEN_MODE ------------------------------ ---------------- -------------------- SWITCHOVER_STATUS -------------------- actvdb01 PHYSICAL STANDBY READ ONLY WITH APPLY NOT ALLOWED
再查看进程已经是应用日志状态了。
到新的primary中将创建表测试是否能正常应用日志:
SQL> create table test.t11 (id number)tablespace test; Table created.
到standby中查看已经能正常传输、应用日志了:
SQL> select owner,table_name from dba_tables where owner='TEST'; OWNER TABLE_NAME ------------------------------ ------------------------------ TEST T2 TEST TEST_TABLE TEST TEST01 TEST TEST02 TEST TEST03 TEST T4 TEST T5 TEST T7 TEST T6 TEST T8 TEST T11 OWNER TABLE_NAME ------------------------------ ------------------------------ TEST T9 12 rows selected.
只要前面 的配置没有问题,switchover是很简单的,特别注意以下几点:
*.local_listener 这个配置是的自己的tnsname名字
*.fal_client=’actvdb’??? 这个配置的是自己的tnsname,不管是primary,还是standby
*.fal_server=’actvdbbak’?? 这个配置的是对方的tnsname,不管是primary,还是standby
原文地址:oracle 11g switchover, 感谢原作者分享。