场景,重启数据库,不重启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 bytesFixed Size 2213136 bytesVariable Size 3489663728 bytesDatabase Buffers 1811939328 bytesRedo Buffers 40914944 bytesDatabase mounted. Database opened. SQL> 2.2 启动主库STARTUP ;SQL> STARTUP ; ORACLE instance started. Total System Global Area 1.1358E+10 bytesFixed Size 2216744 bytesVariable Size 8589937880 bytesDatabase Buffers 2751463424 bytesRedo Buffers 13946880 bytesDatabase mounted. Database opened. SQL> /*取代下面的过程,数据库本来就是归档的,所以关闭之后再重启,数据库也是归档的STARTUP MOUNT;ALTER DATABASE ARCHIVELOG;ALTER DATABASE OPEN;*/2.3 启动备库应用ALTER DATABASE RECOVER MANAGED STANDBY DATABASE;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.dbfYES/data/oracle/oradgdata/standby_archive/1_20867_821708334.dbfYES/data/oracle/oradgdata/standby_archive/1_20868_821708334.dbfYESNAME--------------------------------------------------------------------------------APPLIED---------/data/oracle/oradgdata/standby_archive/1_20869_821708334.dbfYES2800 rows selected.SQL> 如果发现全部都是YES,证明归档日志已经在同步。在主库执行check:SQL> archive log list; Database log mode Archive ModeAutomatic archival EnabledArchive destination /oracle/app/oracle/flash_recovery_area/archivelogOldest online log sequence 20869Next log sequence to archive 20871Current log sequence 20871SQL>在备库执行checkSQL> archive log list; Database log mode Archive ModeAutomatic archival EnabledArchive destination /data/oracle/oradgdata/standby_archiveOldest online log sequence 20869Next log sequence to archive 0Current log sequence 20871SQL> 看到主库备库当前的Current log sequence都是20871,备库上面最新的归档日志applied都是YES,就表明主库备库数据同步一致了。dataguard重启算是彻底完成了。到这里强行关闭执行2.3的那个sql命令窗口。下次再执行到2.3这一步骤,就可以在后面加上disconnect from session,就是执行完这个命令后断开这个回话,就是我们所能接受的,可以接着用这个连接执行其他命令了。