Если в результате сбоя, Вы выполнили переключение с основной рабочей (Primary) на резервную (Standby) базу данных Oracle, чтобы она стала новой основной, то теперь можно преобразовать старую основную базу данных в резервную. Это проще, чем заново делать трудоемкое дублирование. Старый Primary должен был работать в режиме flashback перед переключением. Исходные данные:
ORATST> show configuration;
Configuration - myconf
Protection Mode: MaxAvailability
Members:
prima - Primary database
physt - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS (status updated 36 seconds ago)
SYS@prima > host echo kaputt > /home/oracle/prima/users01.dbf
SYS@prima > select * from scott.emp;
select * from scott.emp
*
ERROR at line 1:
ORA-01115: IO error reading block from file (block # )
ORA-01110: data file 4: '/home/oracle/prima/users01.dbf'
ORA-27072: File I/O error
Additional information: 4
Additional information: 130
Я только что повредил свою основную базу данных, чтобы сэмулировать ситуацию переключения на Standby при отказе. Ранее я делал резервные копии на основном сервере и мог бы выполнить восстановление из бэкапа вместо аварийного переключения. Но аварийное переключение происходит быстрее. В конце концов, для именно этого и предназначен фэйловер со Standby 🙂
[oracle@uhesse scripts]$ oratst sys/oracle@physt
ORATST for Linux: Version 12.1.0.2.0 - 64bit Production
Copyright (c) 2000, 2013, Oracle. All rights reserved.
Welcome to ORATST, type "help" for information.
Connected as SYSDBA.
ORATST> failover to physt;
Performing failover NOW, please wait...
Failover succeeded, new primary is "physt"
Операция переключения заняла не более 10 секунд. Теперь я хочу сделать из моего старого (отключенного) Primery сервера новый Standby. Если при аварии старого Primary сервера было бы отключено только электричество, например, то Reinstate
можно было бы выполнить немедленно. Но здесь один дата файлов поврежден. Reinstate
нужно применять к неповрежденным дата файлам. Поэтому сначала выполним Restore
, а затем Reinstate
:
oracle@uhesse scripts]$ rman target sys/oracle@prima
Recovery Manager: Release 12.1.0.2.0 - Production on Thu Sep 15 16:58:24 2016
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
connected to target database (not started)
RMAN> startup mount
Oracle instance started
database mounted
Total System Global Area 838860800 bytes
Fixed Size 2929936 bytes
Variable Size 490736368 bytes
Database Buffers 339738624 bytes
Redo Buffers 5455872 bytes
RMAN> restore datafile 4;
Starting restore at 2016-09-15 16:59:04
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=176 device type=DISK
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00004 to /home/oracle/prima/users01.dbf
channel ORA_DISK_1: reading from backup piece /home/oracle/fra/PRIMA/backupset/2016_09_15/o1_mf_nnndf_TAG20160915T163533_cxomgq0q_.bkp
channel ORA_DISK_1: piece handle=/home/oracle/fra/PRIMA/backupset/2016_09_15/o1_mf_nnndf_TAG20160915T163533_cxomgq0q_.bkp tag=TAG20160915T163533
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2016-09-15 16:59:05
RMAN> select flashback_on from v$database;
FLASHBACK_ON
------------------
YES
RMAN> exit
Recovery Manager complete.
[oracle@uhesse scripts]$ oratst sys/oracle@physt
ORATST for Linux: Version 12.1.0.2.0 - 64bit Production
Copyright (c) 2000, 2013, Oracle. All rights reserved.
Welcome to ORATST, type "help" for information.
Connected as SYSDBA.
ORATST> show configuration;
Configuration - myconf
Protection Mode: MaxAvailability
Members:
physt - Primary database
Warning: ORA-16629: database reports a different protection level from the protection mode
prima - Physical standby database (disabled)
ORA-16661: the standby database needs to be reinstated
Fast-Start Failover: DISABLED
Configuration Status:
WARNING (status updated 17 seconds ago)
ORATST> reinstate database prima;
Reinstating database "prima", please wait...
Reinstatement of database "prima" succeeded
ORATST> show database prima;
Database - prima
Role: PHYSICAL STANDBY
Intended State: APPLY-ON
Transport Lag: 0 seconds (computed 1 second ago)
Apply Lag: 0 seconds (computed 1 second ago)
Average Apply Rate: 44.00 KByte/s
Real Time Query: OFF
Instance(s):
prima
Database Status:
SUCCESS
При желании я могу легко переключиться обратно:
ORATST> switchover to prima;
Performing switchover NOW, please wait...
Operation requires a connection to instance "prima" on database "prima"
Connecting to instance "prima"...
Connected as SYSDBA.
New primary database "prima" is opening...
Operation requires start up of instance "physt" on database "physt"
Starting instance "physt"...
ORACLE instance started.
Database mounted.
Switchover succeeded, new primary is "prima"
ORATST> show configuration;
Configuration - myconf
Protection Mode: MaxAvailability
Members:
prima - Primary database
physt - Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS (status updated 32 seconds ago)
Вот и вся наука. Лайкните, если понравилось!