本系列是一个一般初学者学习过程的记录,如有错误请指正。
一定要先切換主庫為備庫,在切換備庫為主庫。
1. 在主庫上
SQL> alter database commit to switchover to physical standby;
Database altered.
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
2. 以備用模式啟用主數據庫
SQL> startup nomount
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
SQL> alter database mount standby database ;
Database altered.
SQL> alter database recover managed standby database disconnect from session;
Database altered.
3. 在從庫上
SQL> alter database commit to switchover to primary ;
Database altered.
注: 因為是備庫沒有standby RED日志 在用此命令是會自動生成RED
如:
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY
RESETLOGS after incomplete recovery UNTIL CHANGE 418582
Resetting resetlogs activation ID 0 (0x0)
Wed Aug 17 00:57:30 2011
Errors in file /u01/admin/misdb/udump/misdb_ora_4433.trc:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/u01/oradata/misdb/redo01.log'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
Wed Aug 17 00:57:32 2011
Errors in file /u01/admin/misdb/udump/misdb_ora_4433.trc:
ORA-00313: open failed for members of log group 2 of thread 1
ORA-00312: online log 2 thread 1: '/u01/oradata/misdb/redo02.log'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
Wed Aug 17 00:57:35 2011
Errors in file /u01/admin/misdb/udump/misdb_ora_4433.trc:
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: '/u01/oradata/misdb/redo03.log'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
Switchover: Complete - Database shutdown required
Completed: alter database commit to switchover to primary
SQL> startup
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
SQL> alter system switch logfile;
System altered.
SQL> archive log list ;
Database log mode Archive Mode
Automatic archival Disabled
Archive destination /u01/oradata/arch
Oldest online log sequence 88
Next log sequence to archive 88
Current log sequence 89
SQL> alter system archive log current;
System altered.
SQL> archive log list ;
Database log mode Archive Mode
Automatic archival Disabled
Archive destination /u01/oradata/arch
Oldest online log sequence 88
Next log sequence to archive 90
Current log sequence 90
SQL> archive log list ;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/oradata/arch
Oldest online log sequence 85
Next log sequence to archive 0
Current log sequence 90
4. 主庫切換到備庫后,切換回來來
4.1在主節點(原備庫)
SQL> alter database commit to switchover to physical standby ;
Database altered.
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup nomount ;
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
SQL> alter database mount standby database ;
Database altered.
SQL> alter database recover managed standby database disconnect from session;
Database altered.
4.2 在從庫(原主庫)
SQL> alter database commit to switchover to primary;
Database altered.
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
SQL> archive log list ;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/oradata/arch
Oldest online log sequence 0
Next log sequence to archive 91
Current log sequence 91
SQL> alter system archive log current;
System altered.
SQL> archive log list ;
Database log mode Archive Mode
Automatic archival Disabled
Archive destination /u01/oradata/arch
Oldest online log sequence 88
Next log sequence to archive 0
Current log sequence 90
SQL> archive log list ;
Database log mode Archive Mode
Automatic archival Disabled
Archive destination /u01/oradata/arch
Oldest online log sequence 88
Next log sequence to archive 0
Current log sequence 92
SQL>
設置歸檔頻率
如果要強制主庫按一定時間歸檔 ,那需要在主庫中設置
Archive_lag_target
Alter syste set Archive_lag_target=1800 scopth=both;
建議在1800-7200之間 ,如果設置低於30分鐘 會導致性能問題
5. 物理standby 切換failover
注意: 在執行切換failover時 ,可能是主庫over了,用所有的備份都無法恢復,只能啟用備庫,如果啟用成功此備庫就不能改回standby庫。
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database activate standby database ;
Database altered.
SQL> alter database mount ;
Database altered.
SQL> alter database open;
Database altered.
成功切換以後,可以對主庫進行重建,備份,恢復
一定要先切換主庫為備庫,在切換備庫為主庫。
1. 在主庫上
SQL> alter database commit to switchover to physical standby;
Database altered.
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
2. 以備用模式啟用主數據庫
SQL> startup nomount
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
SQL> alter database mount standby database ;
Database altered.
SQL> alter database recover managed standby database disconnect from session;
Database altered.
3. 在從庫上
SQL> alter database commit to switchover to primary ;
Database altered.
注: 因為是備庫沒有standby RED日志 在用此命令是會自動生成RED
如:
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY
RESETLOGS after incomplete recovery UNTIL CHANGE 418582
Resetting resetlogs activation ID 0 (0x0)
Wed Aug 17 00:57:30 2011
Errors in file /u01/admin/misdb/udump/misdb_ora_4433.trc:
ORA-00313: open failed for members of log group 1 of thread 1
ORA-00312: online log 1 thread 1: '/u01/oradata/misdb/redo01.log'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
Wed Aug 17 00:57:32 2011
Errors in file /u01/admin/misdb/udump/misdb_ora_4433.trc:
ORA-00313: open failed for members of log group 2 of thread 1
ORA-00312: online log 2 thread 1: '/u01/oradata/misdb/redo02.log'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
Wed Aug 17 00:57:35 2011
Errors in file /u01/admin/misdb/udump/misdb_ora_4433.trc:
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: '/u01/oradata/misdb/redo03.log'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
Switchover: Complete - Database shutdown required
Completed: alter database commit to switchover to primary
SQL> startup
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
SQL> alter system switch logfile;
System altered.
SQL> archive log list ;
Database log mode Archive Mode
Automatic archival Disabled
Archive destination /u01/oradata/arch
Oldest online log sequence 88
Next log sequence to archive 88
Current log sequence 89
SQL> alter system archive log current;
System altered.
SQL> archive log list ;
Database log mode Archive Mode
Automatic archival Disabled
Archive destination /u01/oradata/arch
Oldest online log sequence 88
Next log sequence to archive 90
Current log sequence 90
SQL> archive log list ;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/oradata/arch
Oldest online log sequence 85
Next log sequence to archive 0
Current log sequence 90
4. 主庫切換到備庫后,切換回來來
4.1在主節點(原備庫)
SQL> alter database commit to switchover to physical standby ;
Database altered.
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup nomount ;
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
SQL> alter database mount standby database ;
Database altered.
SQL> alter database recover managed standby database disconnect from session;
Database altered.
4.2 在從庫(原主庫)
SQL> alter database commit to switchover to primary;
Database altered.
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 236000356 bytes
Fixed Size 451684 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
Database mounted.
Database opened.
SQL> archive log list ;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/oradata/arch
Oldest online log sequence 0
Next log sequence to archive 91
Current log sequence 91
SQL> alter system archive log current;
System altered.
SQL> archive log list ;
Database log mode Archive Mode
Automatic archival Disabled
Archive destination /u01/oradata/arch
Oldest online log sequence 88
Next log sequence to archive 0
Current log sequence 90
SQL> archive log list ;
Database log mode Archive Mode
Automatic archival Disabled
Archive destination /u01/oradata/arch
Oldest online log sequence 88
Next log sequence to archive 0
Current log sequence 92
SQL>
設置歸檔頻率
如果要強制主庫按一定時間歸檔 ,那需要在主庫中設置
Archive_lag_target
Alter syste set Archive_lag_target=1800 scopth=both;
建議在1800-7200之間 ,如果設置低於30分鐘 會導致性能問題
5. 物理standby 切換failover
注意: 在執行切換failover時 ,可能是主庫over了,用所有的備份都無法恢復,只能啟用備庫,如果啟用成功此備庫就不能改回standby庫。
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database activate standby database ;
Database altered.
SQL> alter database mount ;
Database altered.
SQL> alter database open;
Database altered.
成功切換以後,可以對主庫進行重建,備份,恢復
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10201716/viewspace-705123/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10201716/viewspace-705123/