場景:重啓數據庫,不重啓linux系統,因此不用考慮監聽程序
Linux系統下輸入linux
$ lsnrctl start
1 數據庫關閉
1.1 關閉主庫
SQL> SHUTDOWN IMMEDIATE; Database closed. Database dismounted. ORACLE instance shut down.
1.2 關閉備庫
一、ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
二、SHUTDOWN IMMEDIATE;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL; sql
Database altered.
SQL> SHUTDOWN IMMEDIATE; Database closed. Database dismounted. ORACLE instance shut down. 2 數據庫啓動
開啓的時候先開備庫啓動備庫監聽,再開主庫數據庫
Linux系統下輸入session
$ lsnrctl startoracle
2.1 啓動備庫
#STARTUP MOUNT;
#ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;
#ALTER DATABASE OPEN;
#這裏不用設置歸檔,歸檔設置一次是永久生效的,直接startup啓動就行
SQL> STARTUP;app
ORACLE instance started. Total System Global Area 5344731136 bytes
Fixed Size 2213136 bytes
Variable Size 3489663728 bytes
Database Buffers 1811939328 bytes
Redo Buffers 40914944 bytes
Database mounted. Database opened. ide
2.2 啓動主庫
SQL> STARTUP ; ORACLE instance started.
Total System Global Area 1.1358E+10 bytes
Fixed Size 2216744 bytes
Variable Size 8589937880 bytes
Database Buffers 2751463424 bytes
Redo Buffers 13946880 bytes
Database mounted.
Database opened.
/*取代下面的過程,數據庫原本就是歸檔的,因此關閉以後再重啓,數據庫也是歸檔的
STARTUP MOUNT;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;*/
2.3 啓動備庫應用
spa
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNETC FROM SESSION; 日誌
這個命令是死命令,會一直卡在這,可是後臺其實歸檔日誌已經在同步了,除非人爲的關閉 不然 一直是這樣的。
ALTER DATABASE OPEN; --備庫不是必須處於OPEN狀態,啓動歸檔被應用便可,這個命令能夠不用執行。
2.4 check查看歸檔是否及時應用
先檢查備庫的歸檔日誌同步狀況
SQL> SELECT NAME,applied FROM v$archived_log;
......
NAME
--------------------------------------------------------------------------------
APPLIED
---------
/data/oracle/oradgdata/standby_archive/1_20866_821708334.dbf
YES
/data/oracle/oradgdata/standby_archive/1_20867_821708334.dbf
YES
/data/oracle/oradgdata/standby_archive/1_20868_821708334.dbf
YES
NAME
--------------------------------------------------------------------------------
APPLIED
---------
/data/oracle/oradgdata/standby_archive/1_20869_821708334.dbf
YES
2800 rows selected.
若是發現所有都是YES,證實歸檔日誌已經在同步。
在主庫執行check:
SQL> archive log list; Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle/app/oracle/flash_recovery_area/archivelog
Oldest online log sequence 20869
Next log sequence to archive 20871
Current log sequence 20871
在備庫執行check
SQL> archive log list; Database log mode Archive Mode
Automatic archival Enabled
Archive destination /data/oracle/oradgdata/standby_archive
Oldest online log sequence 20869
Next log sequence to archive 0
Current log sequence 20871
看到主庫備庫當前的Current log sequence都是20871,備庫上面最新的歸檔日誌applied都是YES,就代表主庫備庫數據同步一致了。
dataguard重啓算是完全完成了。到這裏強行關閉執行2.3的那個sql命令窗口。
下次再執行到2.3這一步驟,就能夠在後面加上disconnect from session,就是執行完這個命令後斷開這個回話,就是咱們所能接受的,能夠接着用這個鏈接執行其餘命令了。orm