場景,重新啟動資料庫,不重新啟動linux系統,所以不用考慮監聽程式,
#linux輸入lsnrctl start
1 資料庫關閉
1.1 關閉主庫
SHUTDOWN IMMEDIATE;
SQL> SHUTDOWN IMMEDIATE;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
1.2 關閉備庫
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SHUTDOWN IMMEDIATE;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
Database altered.
SQL> SHUTDOWN IMMEDIATE;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
2 資料庫啟動,
開啟的時候先開備庫啟動備庫監聽,再開主庫
2.1 啟動備庫
#STARTUP MOUNT;
#ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;
# ALTER DATABASE OPEN;
# 這裡不用設定歸檔,歸檔設定一次是永久生效的,直接startup啟動即可
STARTUP ;
SQL> STARTUP ;
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.
SQL>
2.2 啟動主庫
STARTUP ;
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.
SQL>
/*代替以下的過程,資料庫本來就是歸檔的,所以關閉之後再重新啟動,資料庫也是歸檔的
STARTUP MOUNT;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;*/
2.3 啟動備庫應用
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;
這個命令是死命令,會一直卡在這,可是後臺事實上歸檔日誌已經在同步了,除非人為的關閉 否則 一直是這種。
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.
SQL>
假設發現所有都是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
SQL>
在備庫執行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
SQL>
看到主庫備庫當前的Current log sequence都是20871,備庫上面最新的歸檔日誌applied都是YES,就表明主庫備庫資料同步一致了。
dataguard重新啟動算是徹底完畢了。到這裡強行關閉執行2.3的那個sql命令窗體。
下次再執行到2.3這一步驟,就能夠在後面加上disconnect from session,就是執行完這個命令後斷開這個回話,就是我們所能接受的,能夠接著用這個連線執行其它命令了。
#linux輸入lsnrctl start
1 資料庫關閉
1.1 關閉主庫
SHUTDOWN IMMEDIATE;
SQL> SHUTDOWN IMMEDIATE;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
1.2 關閉備庫
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
SHUTDOWN IMMEDIATE;
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
Database altered.
SQL> SHUTDOWN IMMEDIATE;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
2 資料庫啟動,
開啟的時候先開備庫啟動備庫監聽,再開主庫
2.1 啟動備庫
#STARTUP MOUNT;
#ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;
# ALTER DATABASE OPEN;
# 這裡不用設定歸檔,歸檔設定一次是永久生效的,直接startup啟動即可
STARTUP ;
SQL> STARTUP ;
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.
SQL>
2.2 啟動主庫
STARTUP ;
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.
SQL>
/*代替以下的過程,資料庫本來就是歸檔的,所以關閉之後再重新啟動,資料庫也是歸檔的
STARTUP MOUNT;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;*/
2.3 啟動備庫應用
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;
這個命令是死命令,會一直卡在這,可是後臺事實上歸檔日誌已經在同步了,除非人為的關閉 否則 一直是這種。
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.
SQL>
假設發現所有都是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
SQL>
在備庫執行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
SQL>
看到主庫備庫當前的Current log sequence都是20871,備庫上面最新的歸檔日誌applied都是YES,就表明主庫備庫資料同步一致了。
dataguard重新啟動算是徹底完畢了。到這裡強行關閉執行2.3的那個sql命令窗體。
下次再執行到2.3這一步驟,就能夠在後面加上disconnect from session,就是執行完這個命令後斷開這個回話,就是我們所能接受的,能夠接著用這個連線執行其它命令了。