ORA-16456錯誤,由於備庫未mount而在主庫執行切換,解決辦法詳解
如果對資料庫進行主備庫的切換需要的前提條件是:
(1)備庫必須mount狀態下,主庫open狀態
(2)必須不能在最大保護模式下
我們有時做主備庫的切換,結果忘記了把備庫處於mount狀態而是open狀態下;
當在primary執行過切換操作之後:
SQL>alterdatabase commit to switchover to physical standby;
Databasealtered.
現在對primary庫進行檢視:
00:26:[email protected] SQL>select switchover_status from v$database;
SWITCHOVER_STATUS
----------------------------------------
RECOVERY NEEDED
狀態我們發現時recovery needed
這個時刻,我感覺出事了,該怎麼辦??
我就在主庫執行了如下操作:(以為這樣會可以的,但是不行)
00:26:26 [email protected] SQL>alter database commit to switchoverto primary;
alter database commit to switchover to primary
*
ERROR at line 1:
ORA-16456: switchover to standby in progress or completed
0:26:54 [email protected] SQL>shutdown immediate;
ORA-01092: ORACLE instance terminated.Disconnection forced
00:27:17 [email protected] SQL>startup mount;
ORA-24324: service handle not initialized
ORA-01041: internal error. hostdefextension doesn't exist
00:27:25 [email protected] SQL>exit
然後mount主庫:
00:27:30 SQL>startup mount;
ORACLE instance started.
Total System Global Area 417546240 bytes
Fixed Size 2228944 bytes
Variable Size 289410352 bytes
Database Buffers 121634816 bytes
Redo Buffers 4272128 bytes
Database mounted.
在standby庫執行:
mount備庫:
03:21:36 SQL>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
03:21:48 SQL>startup mount;
ORACLE instance started.
Total System Global Area 417546240 bytes
Fixed Size 2228944 bytes
Variable Size 289410352 bytes
Database Buffers 121634816 bytes
Redo Buffers 4272128 bytes
Database mounted.
03:22:02 SQL>
開啟主庫:
00:27:41 SQL>alter database open;
Database altered.
把主庫的切換狀態進行切換過來,再試一下:
00:31:30 SQL>alter database commit to switchover to primary;
Database altered.
Ok,成功了,看來往下面走是有希望了
繼續,go!!!!
00:32:08 [email protected] SQL>select statusfrom v$instance;
STATUS
------------------------
MOUNTED
00:32:22 [email protected] SQL>alter database open;
Database altered.
00:32:32 [email protected] SQL>selectswitchover_status from v$database;
SWITCHOVER_STATUS
----------------------------------------
TO STANDBY
終於看到to standby了,心裡算是鬆了一口氣!!
ok,開始真正的主備庫的切換:
一定要注意:主庫一定要處於open狀態,備庫一定要處於mount狀態
0:41:57 [email protected] SQL> alter database commit to switchoverto physical standby
Database altered.
主庫執行成功:
在備庫要進行操作:
03:46:06 SQL>select switchover_status from v$database;
SWITCHOVER_STATUS
----------------------------------------
RECOVERY NEEDED
03:46:46 SQL>alter database recover managed standbydatabase disconnect session;
alter database recovermanaged standby database disconnect session
*
ERROR at line 1:
ORA-00274: illegalrecovery option SESSION
為什麼錯??? 少了一個關鍵字,from
03:52:23 SQL>alter database recover managed standby database disconnect FROM session;
Database altered.
ORACLE instance shut down.
03:56:01 SQL>startup
ORACLE instance started.
Total System Global Area 417546240 bytes
Fixed Size 2228944 bytes
Variable Size 301993264 bytes
Database Buffers 109051904 bytes
Redo Buffers 4272128 bytes
Database mounted.
Database opened.
03:56:43 SQL>select switchover_status from v$database;
SWITCHOVER_STATUS
----------------------------------------
TO PRIMARY
03:57:13 SQL>alter database commit to switchover to primary;
Database altered.
03:57:42 SQL>shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
03:58:20 SQL>
Ok,開啟主備庫:
Ok,到此主備庫已經完整切換了