具體步驟如下
一
SQL> alter database force logging;
Database altered
##查看狀態
SQL> select FORCE_LOGGING from v$database;
FOR
YES
System altered
SQL> shutdown immediate;
Database closed
Database dismounted
ORACLE instance shut down
SQL> startup mount;
ORACLE instance started
Total System Global Area
Fixed Size
Variable Size
Database Buffers
Redo Buffers
Database mounted
SQL> alter database archivelog;
Database altered
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /arch
Oldest online log sequence
Next log sequence to archive
Current log sequence
SQL> alter database open;
Database altered
為主數據庫添加
添加備用日志文件是規則
(每線程日志文件最大數目 +
SQL> select GROUP#
GROUP# MEMBERS BYTES/
SQL> select GROUP#
GROUP# MEMBER
SQL> alter database add standby logfile
Database altered
SQL> create pfile=
File created
orcl
orcl
orcl
orcl
orcl
*
*
patible=
ntrol_files=
re_dump_dest=
*
*
*
*
*
*
*
*
*
*
*
*
)
*
*
*
*
*
*
*
*
a_target=
*
*
*
*
SQL> shutdown immediate;
Database closed
Database dismounted
ORACLE instance shut down
SQL> startup pfile=
ORACLE instance started
Total System Global Area
Fixed Size
Variable Size
Database Buffers
Redo Buffers
Database mounted
Database opened
SQL>
SQL> create spfile from pfile=
File created
[oracle@node
SQL> ALTER DATABASE CREATE STANDBY CONTROLFILE AS
Database altered
主庫
ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
orclpri =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
orclstandby =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
監聽信息如下
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SERVICE_NAME=orclpri)
(ORACLE_HOME = /oracle/product/
(SID_NAME=ORCL)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC
)
)
二備機操作
orcl
orcl
orcl
orcl
orcl
*
*
patible=
ntrol_files=
re_dump_dest=
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
a_target=
*
*
*
*
ntrol_files=
為
ntrol_files=
備庫
ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
orclpri =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
orclstandby =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
監聽信息如下
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SERVICE_NAME=orclstandby)
(ORACLE_HOME = /oracle/product/
(SID_NAME=ORCL)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC
)
)
SQL> startup pfile=
ORACLE instance started
Total System Global Area
Fixed Size
Variable Size
Database Buffers
Redo Buffers
SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
Database altered
SQL> alter database recover managed standby database disconnect from session;
Database altered
如果主庫從不過來歸檔
ALTER SYSTEM SET log_archive_dest_state_
ALTER SYSTEM SET log_archive_dest_state_
通過在主庫執行alter system switch logfile
三
select switchover_stats from v$database;
如果是to standby 表可以正常切換
直接執行
ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;
否則執行
ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;
shutdown immediate;
startup nomount;
alter database mount standby database;
如果是to_primary 表可以正常切換
在備庫
SELECT SWITCHOVER_STATUS FROM V$DATABASE;
執行
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
否則執行
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;
shutdown immediate;
startup;
然後觀察主備庫日志
From:http://tw.wingwit.com/Article/program/Oracle/201311/16864.html