oracle不一致性关闭下次,Oracle DataGuard
```1、文檔介紹
本實(shí)施方案主要對(duì)Oracle DataGuard實(shí)施部署作相應(yīng)的說(shuō)明。以便實(shí)施人員能根據(jù)當(dāng)前業(yè)務(wù)特點(diǎn),規(guī)劃、建設(shè)符合高可用、高可靠的數(shù)據(jù)庫(kù)集群系統(tǒng)。具體由Oracle DG環(huán)境拓?fù)洹racle單機(jī)數(shù)據(jù)庫(kù)規(guī)劃部分構(gòu)成!
2 、Oracle Data Guard 介紹
2.1 Data Guard環(huán)境拓展
2.2 Data Guard特點(diǎn)
數(shù)據(jù)庫(kù)服務(wù)器采用DATAGUARD災(zāi)備模式,可以滿足對(duì)可用性有特殊需求的應(yīng)
用,具備以下特點(diǎn):
1、 需要冗余的服務(wù)器設(shè)備。該模式需要有冗余的服務(wù)器硬件。硬件成本較高。
2、 需要冗余的存儲(chǔ)設(shè)備。主機(jī)和備機(jī)都需要同樣的存儲(chǔ)空間,成本較高。
3、 安裝配置比較復(fù)雜。該模式比單節(jié)點(diǎn)、單實(shí)例的模式配置復(fù)雜一些,需要
更多的配置步驟。
4、 管理維護(hù)成本高。該模式對(duì)維護(hù)人員的要求較高,維護(hù)成本高。
5、 具備一定的容災(zāi)特性。當(dāng)主機(jī)整個(gè)數(shù)據(jù)庫(kù)系統(tǒng)不可用并短期內(nèi)無(wú)法恢復(fù)
時(shí),可以把數(shù)據(jù)庫(kù)系統(tǒng)切換到備機(jī)上,具備容災(zāi)的功能。
6、 備機(jī)可以用作只讀查詢。備機(jī)可以切換到只讀狀態(tài)供報(bào)表之類的查詢操
作,減輕主機(jī)的壓力。
3、Oracle DataGurad單實(shí)例部署
3.1安裝環(huán)境
在主機(jī)1上安裝數(shù)據(jù)庫(kù)軟件,并建監(jiān)聽(tīng)和實(shí)例,
在主機(jī)2上安裝數(shù)據(jù)庫(kù)軟件,并建監(jiān)聽(tīng),但不建實(shí)例。
主機(jī)1(主庫(kù)) 主機(jī)2(備庫(kù))
操作系統(tǒng) Centos6.5 64位 Centos6.5 64位
主機(jī)名 orcl orclstd
IP 192.168.168.186 192.168.168.187
數(shù)據(jù)庫(kù)軟件版本 11.2.0.4 11.2.0.4
ORACLE_BASE /u01/app/oracle /u01/app/oracle
ORACLE_HOME /u01/app/oracle/product/11.2/db_1 /u01/app/oracle/product/11.2/db_1
ORACLE_SID orcl
閃回區(qū) 開(kāi)啟
歸檔 開(kāi)啟
3.2主數(shù)據(jù)庫(kù)配置
3.2.1 設(shè)置數(shù)據(jù)庫(kù)歸檔
查看數(shù)據(jù)庫(kù)是否運(yùn)行在歸檔模式:
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled #未開(kāi)啟歸檔
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 117
Current log sequence 119
SQL>
備注:如果數(shù)據(jù)庫(kù)已經(jīng)開(kāi)啟歸檔,下面的操縱可以忽略。
如上所示未開(kāi)啟歸檔,可按下面方法開(kāi)啟數(shù)據(jù)庫(kù)歸檔
SQL> shutdown immediate #關(guān)閉數(shù)據(jù)庫(kù)
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount; #啟動(dòng)到mount狀態(tài)
ORACLE instance started.
Total System Global Area 688959488 bytes
Fixed Size 2256432 bytes
Variable Size 566231504 bytes
Database Buffers 117440512 bytes
Redo Buffers 3031040 bytes
Database mounted.
SQL> alter database archivelog; #開(kāi)啟歸檔
Database altered.
SQL> alter database open; #open數(shù)據(jù)庫(kù)
Database altered.
SQL> alter system set log_archive_dest_1='location=/data/ORCL/archivelog VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl'; #設(shè)置歸檔路徑,此處DB_UNIQUE_NAME要與此實(shí)例中指定的DB_UNIQUE_NAME保持一致
System altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /data/ORCL/archivelog
Oldest online log sequence 119
Next log sequence to archive 121
Current log sequence 121
SQL>
3.2.2 設(shè)置數(shù)據(jù)庫(kù)閃回
驗(yàn)證是否開(kāi)啟閃回
SQL> select flashback_on from v$database;
FLASHBACK_ON
NO
SQL>
備注:如果數(shù)據(jù)庫(kù)已經(jīng)開(kāi)啟flashback,那么下面步驟可忽略。
如上顯示,該數(shù)據(jù)庫(kù)未開(kāi)啟flashback,可按下面方法開(kāi)啟。
SQL> alter system set db_recovery_file_dest='/home/oracle/flashdata'; #設(shè)置閃回去路徑 (忽略)
-----------此處就是歸檔路徑
System altered.
SQL> altersystem set db_recovery_file_dest_size='15G'; #設(shè)置閃回區(qū)大小 (忽略)
System altered.
SQL> shutdown immediate; #關(guān)閉數(shù)據(jù)庫(kù)
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 688959488 bytes
Fixed Size 2256432 bytes
Variable Size 566231504 bytes
Database Buffers 117440512 bytes
Redo Buffers 3031040 bytes
Database mounted.
SQL> alter database flashback on; #開(kāi)啟閃回
Database altered.
SQL> alter database open; #open數(shù)據(jù)庫(kù)
Database altered.
SQL> select flashback_on from v$database; #驗(yàn)證是否開(kāi)啟
FLASHBACK_ON
YES
SQL>
3.2.3 設(shè)置數(shù)據(jù)庫(kù)強(qiáng)制歸檔
驗(yàn)證是否開(kāi)啟focelogging
SQL>select force_logging from v$database;
FOR
NO
如果數(shù)據(jù)庫(kù)已經(jīng)開(kāi)啟force logging,那么下面步驟可忽略。
如上可以看出數(shù)據(jù)庫(kù)未開(kāi)啟,則按下面步驟執(zhí)行:
SQL>alter database force logging; #開(kāi)啟force logging
Database altered.
SQL>select force_logging from v$database; #驗(yàn)證
FOR
YES
SQL>
3.2.4 添加STANDBY 日志文件
在備庫(kù),當(dāng)RFS進(jìn)程接受到日志后,就將其寫(xiě)入Standby日志文件里,備庫(kù)的Standby日志文件可以看做是主庫(kù)在線日志文件的一個(gè)鏡像,當(dāng)主庫(kù)做日志切換時(shí),備庫(kù)的Standby日志也做相應(yīng)的切換,切換后的Standby日志由備庫(kù)的ARCH進(jìn)程歸檔。
Oracle規(guī)定備庫(kù)的Standby日志文件大小不能小于主庫(kù)在線日志文件最大的一個(gè),一般情況下,為了管理方便,最好把所有的在線日志和Standby日志大小設(shè)為一樣。
通過(guò)下面語(yǔ)句可以查詢主庫(kù)在線日志的大小和組數(shù):
SQL> select group#,bytes/1024/1024 from v$log;
GROUP# BYTES/1024/1024
1 50
2 50
3 50
SQL>
通過(guò)下面的語(yǔ)句可以查詢備庫(kù)Standby日志的大小和組數(shù):
SQL> select group#,bytes/1024/1024 from v$standby_log;
no rows selected
創(chuàng)建standby logfile
創(chuàng)建原則
1、 確保standby redo log 的大小與主庫(kù)online redo log 的大小保持一致
2、 如主庫(kù)為單實(shí)例數(shù)據(jù)庫(kù):standby redo log組數(shù)=主庫(kù)日志組總數(shù)
3、 如果主庫(kù)是RAC數(shù)據(jù)庫(kù):standby redo log組數(shù)=(每線程的日志組數(shù) 1)*最大線程數(shù)
4、 不建議復(fù)用standby redo log,避免增加額外的I/O以及延緩重做傳輸
SQL> alter database add standby logfile group 11 ' /u01/app/oracle/flash_recovery_area/redo11_stb01.log' size 50M;
Database altered.
SQL> alter database add standby logfile group 12 '/u01/app/oracle/flash_recovery_area/redo12_stb01.log'size 50M;
Database altered.
SQL> alter database add standby logfile group 13 ' /u01/app/oracle/flash_recovery_area/redo13_stb01.log'size 50M;
Database altered.
SQL> alter database add standby logfile group 14 '/u01/app/oracle/flash_recovery_area/redo14_stb01.log' size 50M;
Database altered.
SQL> select group#,bytes/1024/1024 from v$standby_log;
GROUP# BYTES/1024/1024
11 50
12 50
13 50
14 50
SQL>
3.2.5 修改參數(shù)文件
SQL> alter system set log_archive_config='DG_CONFIG=(orcl,orclstd)'; ---主備庫(kù)唯一名,無(wú)先后順序
System altered.
SQL> alter system set log_archive_dest_2='SERVICE=orclstd LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orclstd' scope=spfile;
------此處的SERVICE是指到從庫(kù)的TNS名
--如果搭建延遲DG,加上DELAY=minutes,默認(rèn)30分鐘,啟動(dòng)方式也不同
alter database recover managed standby database delay 1440 disconnect from session;
System altered.
SQL> alter system set log_archive_dest_state_1='enable';
System altered.
SQL> alter system set log_archive_dest_state_2='enable';
System altered.
SQL> alter system set db_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl' scope=spfile;
------- db_file_name_convert是指數(shù)據(jù)文件路徑,此處設(shè)置了一樣的路徑,路徑名最后必須加上/
----------如果是集群的磁盤組就不用,例: DATA
System altered.
SQL> alter system set log_file_name_convert='/u01/app/oracle/oradata/orcl/','/u01/app/oracle/oradata/orcl/' scope=spfile;
---------日志路徑也設(shè)置成一致,路徑名最后必須加上/
----------如果是集群的磁盤組就不用,例: DATA
System altered.
SQL> alter system set fal_server='orclstd'; --備庫(kù)tns
-------與備庫(kù)設(shè)置相反
System altered.
SQL> alter system set fal_client='orcl'; --主庫(kù)tns
-------與備庫(kù)設(shè)置相反
System altered.
SQL> alter system set standby_file_management='AUTO';
System altered.
注意:上面修改的參數(shù)有的需要重啟數(shù)據(jù)庫(kù)才能生效,下面為重啟數(shù)據(jù)庫(kù)步驟
SQL> shutdown immediate
Databaseclosed.
Databasedismounted.
ORACLEinstance shut down.
SQL> startup
ORACLEinstance started.
TotalSystem Global Area 688959488 bytes
Fixed Size 2256432 bytes
VariableSize 566231504 bytes
DatabaseBuffers 117440512 bytes
RedoBuffers 3031040 bytes
Databasemounted.
Databaseopened.
SQL>
ADR_BASE_LISTENER = /u01/app/oracle
注意:如果主庫(kù)上的監(jiān)聽(tīng)之前已經(jīng)配置過(guò),這里可以忽略該步驟。
~
~
3.2.7 修改TNS配置文件
orcl:/home/oracle@orcl>vi/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
orcl =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.168.186)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
orclstd =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.168.187)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orclstd)
)
)
3.2.8 重啟監(jiān)聽(tīng)服務(wù)
orcl:/home/oracle@orcl>lsnrctl stop
orcl:/home/oracle@orcl>lsnrctl start
3.2.9 拷貝參數(shù)文件
利用spfile創(chuàng)建pfile
create pfile='/home/oracle/pfile.ora' from spfile;
將pfile拷貝到備庫(kù)
scp /home/oracle/pfile.ora 192.168.168.187:/u01/app/oracle/product/11.2.0/db_1/dbs
重命名pfile.ora為initorclstd.ora
3.2.10 拷貝密碼文件
/u01/app/oracle/product/11.2.0/db_1/dbs
scp orapworcl 192.168.168.187:/u01/app/oracle/product/11.2.0/db_1/dbs
3.3備庫(kù)配置
3.3.1 修改參數(shù)文件
以下是主庫(kù)參數(shù)文件:
orcl.db_cache_size=2113929216
orcl.java_pool_size=33554432
orcl.large_pool_size=50331648
orcl.oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orcl.pga_aggregate_target=922746880
orcl.sga_target=2768240640
orcl.shared_io_pool_size=0
orcl.shared_pool_size=536870912
orcl.streams_pool_size=0
.audit_file_dest='/u01/app/oracle/admin/orcl/adump'.audit_trail='db'
.compatible='11.2.0.4.0'.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/fast_recovery_area/orcl/control02.ctl'
.db_block_size=8192.db_domain=''
.db_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl'.db_name='orcl'
.db_recovery_file_dest='/home/oracle/flashdata'.db_recovery_file_dest_size=16106127360
.db_unique_name='ORCL'.diagnostic_dest='/u01/app/oracle'
.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'.fal_client='ORCL'
.fal_server='ORCLSTD'.log_archive_config='DG_CONFIG=(orcl,orclstd)'
.log_archive_dest_2='SERVICE=orclstd LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orclstd'.log_archive_dest_state_1='enable'
.log_archive_dest_state_2='enable'.log_archiveformat='%t%s_%r.dbf'
.log_file_name_convert='/home/oracle/flashdata/orclstd/onlinelog','/home/oracle/flashdata/orcl/onlinelog'.open_cursors=300
.pga_aggregate_target=917504000.processes=150
.remote_login_passwordfile='EXCLUSIVE'.sga_target=2752512000
.standby_file_management='AUTO'.undo_tablespace='UNDOTBS1'
以下是備庫(kù)參數(shù)文件:
orclstd.db_cache_size=3439329280
orclstd.java_pool_size=16777216
orclstd.large_pool_size=33554432
orclstd.oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
orclstd.pga_aggregate_target=922746880
orclstd.sga_target=4294967296
orclstd.shared_io_pool_size=0
orclstd.shared_pool_size=771751936
orclstd.streams_pool_size=0
.audit_file_dest='/u01/app/oracle/admin/orclstd/adump'.audit_trail='db'
.compatible='11.2.0.4.0'.control_files='/u01/app/oracle/oradata/orclstd/control01.ctl','/u01/app/oracle/fast_recovery_area/orclstd/control02.ctl'
.db_block_size=8192.db_domain=''
.db_file_name_convert='/u01/app/oracle/oradata/orcl','/u01/app/oracle/oradata/orcl'.db_name='orcl'
.db_recovery_file_dest='/home/oracle/flashdata'.db_recovery_file_dest_size=16106127360
.db_unique_name='ORCLSTD'.diagnostic_dest='/u01/app/oracle'
.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'.fal_client='ORCLSTD'
.fal_server='ORCL'.log_archive_config='DG_CONFIG=(orcl,orclstd)'
.log_archive_dest_2='SERVICE=orcl LGWR SYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'.log_archive_dest_state_1='enable'
.log_archive_dest_state_2='enable'.log_archiveformat='%t%s_%r.dbf'
.log_file_name_convert='/home/oracle/flashdata/orcl/onlinelog','/home/oracle/flashdata/orclstd/onlinelog'.open_cursors=300
.pga_aggregate_target=917504000.processes=150
.remote_login_passwordfile='EXCLUSIVE'.sga_max_size=4294967296
.sga_target=4294967296.standby_file_management='AUTO'
*.undo_tablespace='UNDOTBS1'
3.3.2 修改密碼文件
修改之前從主庫(kù)拷貝過(guò)來(lái)的密碼文件,具體如下:
orclstd:/u01/app/oracle/product/11.2.0/db_1/dbs@orclstd>mv orapworcl orapworclstd
3.3.3 創(chuàng)建相應(yīng)的文件目錄
根據(jù)上面修改的參數(shù)文件,為備庫(kù)創(chuàng)建相應(yīng)的文件目錄
orclstd:/home/oracle@orclstd>mkdir -p /u01/app/oracle/admin/orclstd/adump
orclstd:/home/oracle@orclstd>mkdir -p /u01/app/oracle/oradata/orclstd/
orclstd:/home/oracle@orclstd>mkdir -p /u01/app/oracle/oradata/orcl/
orclstd:/home/oracle@orclstd>mkdir -p /home/oracle/flashdata
3.3.4 修改監(jiān)聽(tīng)配置文件
orclstd:/u01/app/oracle/product/11.2.0/db_1/network/admin@orclstd>vi listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.168.187)(PORT = 1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orclstd)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = orclstd)
)
)
3.3.5 修改TNS配置文件
orclstd:/u01/app/oracle/product/11.2.0/db_1/network/admin@orclstd>vi tnsnames.ora
具體如下:
orcl =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.168.186)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
orclstd =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.168.187)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orclstd)
)
)
3.3.6 重啟監(jiān)聽(tīng)服務(wù)
orclstd:/data/ORCLSTD@orclstd>lsnrctl stop
orclstd:/data/ORCLSTD@orclstd>lsnrctl start
3.3.7 啟動(dòng)數(shù)據(jù)庫(kù)到nomount狀態(tài)
SQL> startup nomount pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initorclstd.ora';
ORACLE instance started.
Total System Global Area 688959488 bytes
Fixed Size 2256432 bytes
Variable Size 566231504 bytes
Database Buffers 117440512 bytes
Redo Buffers 3031040 bytes
SQL> create spfile from pfile; #創(chuàng)建spfile
File created.
再次重啟數(shù)據(jù)庫(kù)
3.3.8 驗(yàn)證監(jiān)聽(tīng)和TNS配置
主庫(kù)上驗(yàn)證:
orcl:/home/oracle@orcl>sqlplus sys/oracle@orcl as sysdba
SQLPlus: Release 11.2.0.4.0 Production onTue Jun 6 10:34:42 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise EditionRelease 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Miningand Real Application Testing options
SQL> exit
Disconnected from Oracle Database 11gEnterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Miningand Real Application Testing options
orcl:/home/oracle@orcl>sqlplus sys/oracle@orclstd as sysdba
SQLPlus: Release 11.2.0.4.0 Production onTue Jun 6 10:34:50 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise EditionRelease 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Miningand Real Application Testing options
SQL>
備庫(kù)上驗(yàn)證:
orclstd:/home/oracle@orclstd>sqlplus sys/oracle@orcl as sysdba
SQLPlus: Release 11.2.0.4.0 Production onTue Jun 6 11:05:01 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise EditionRelease 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Miningand Real Application Testing options
SQL> exit
Disconnected from Oracle Database 11gEnterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Miningand Real Application Testing options
orclstd:/home/oracle@orclstd>sqlplus sys/oracle@orclstd as sysdba
SQLPlus: Release 11.2.0.4.0 Production onTue Jun 6 11:05:05 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise EditionRelease 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Miningand Real Application Testing options
SQL>
注意:該步驟一定要在主備庫(kù)上都能通過(guò)才能執(zhí)行下面步驟
3.3.9 恢復(fù)數(shù)據(jù)庫(kù)
在備庫(kù)執(zhí)行
rman target sys/oracle@主庫(kù)tns auxiliary sys/oracle@備庫(kù)tns
orclstd:/home/oracle@orclstd>rman target sys/oracle@orcl auxiliary sys/oracle@orclstd
Recovery Manager: Release 11.2.0.4.0 -Production on Tue Jun 6 11:13:43 2017
Copyright (c) 1982, 2011, Oracle and/or itsaffiliates. All rights reserved.
connected to target database: ORCL(DBID=3677012495)
connected to auxiliary database: ORCL (not mounted)
RMAN> duplicate target database for standby from active database nofilenamecheck;
具體執(zhí)行過(guò)程顯示如下:
Starting Duplicate Db at 2017/06/06 11:14:26
using target database control file insteadof recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=19 devicetype=DISK
contents of Memory Script:
{
backup as copy reuse
targetfile '/u01/app/oracle/product/11.2.0/db_1/dbs/orapworcl' auxiliary format
'/u01/app/oracle/product/11.2.0/db_1/dbs/orapworclstd' ;
}
executing Memory Script
Starting backup at 2017/06/06 11:14:29
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=43 device type=DISK
Finished backup at 2017/06/06 11:14:31
contents of Memory Script:
{
backup as copy current controlfile for standby auxiliary format '/data/ORCLSTD/controlfile/o1_mfdm1flhj3.ctl';
sql clone "create spfile from memory";
shutdown clone immediate;
startup clone nomount;
sql clone "alter system set control_files =
''/data/ORCLSTD/controlfile/o1_mfdm1flhj3.ctl'' comment=
''Set by RMAN'' scope=spfile";
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script
Starting backup at 2017/06/06 11:14:32
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying standby control file
output filename=/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_orcl.ftag=TAG20170606T105032 RECID=5 STAMP=945946234
channel ORA_DISK_1: datafile copy complete,elapsed time: 00:00:03
Finished backup at 2017/06/06 11:14:36
sql statement: create spfile from memory
Oracle instance shut down
connected to auxiliary database (notstarted)
Oracle instance started
Total System Global Area 688959488 bytes
Fixed Size 2256432 bytes
Variable Size 566231504 bytes
Database Buffers 117440512 bytes
Redo Buffers 3031040 bytes
sql statement: alter system set control_files = ''/data/ORCLSTD/controlfile/o1_mfdm1flhj3.ctl''comment= ''Set by RMAN'' scope=spfile
Oracle instance shut down
connected to auxiliary database (notstarted)
Oracle instance started
Total System Global Area 688959488 bytes
Fixed Size 2256432 bytes
Variable Size 566231504 bytes
Database Buffers 117440512 bytes
Redo Buffers 3031040 bytes
contents of Memory Script:
{
sql clone 'alter database mount standby database';
}
executing Memory Script
sql statement: alter database mount standbydatabase
contents of Memory Script:
{
set newname for tempfile 1 to
"/data/ORCLSTD/datafile/o1_mf_tempdm1fp4bs.tmp";
switch clone tempfile all;
set newname for datafile 1 to
"/data/ORCLSTD/datafile/o1_mf_systemdm1flxkw.dbf";
set newname for datafile 2 to
"/data/ORCLSTD/datafile/o1_mf_sysauxdm1fnw5v.dbf";
set newname for datafile 3 to
"/data/ORCLSTD/datafile/o1_mf_undotbs1dm1foow9.dbf";
set newname for datafile 4 to
"/data/ORCLSTD/datafile/o1_mf_usersdm1fqcrp.dbf";
backup as copy reuse
datafile 1 auxiliary format
"/data/ORCLSTD/datafile/o1_mf_systemdm1flxkw.dbf" datafile
2auxiliary format
"/data/ORCLSTD/datafile/o1_mf_sysauxdm1fnw5v.dbf" datafile
3auxiliary format
"/data/ORCLSTD/datafile/o1_mf_undotbs1dm1foow9.dbf" datafile
4auxiliary format
"/data/ORCLSTD/datafile/o1_mf_usersdm1fqcrp.dbf" ;
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to/data/ORCLSTD/datafile/o1_mf_tempdm1fp4bs.tmp in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting backup at 2017/06/06 11:15:06
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001name=/data/ORCL/datafile/o1_mf_systemdm1flxkw.dbf
output filename=/data/ORCLSTD/datafile/o1_mf_systemdm1flxkw.dbf tag=TAG20170606T105107
channel ORA_DISK_1: datafile copy complete,elapsed time: 00:01:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002name=/data/ORCL/datafile/o1_mf_sysauxdm1fnw5v.dbf
output filename=/data/ORCLSTD/datafile/o1_mf_sysauxdm1fnw5v.dbf tag=TAG20170606T105107
channel ORA_DISK_1: datafile copy complete,elapsed time: 00:01:05
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003name=/data/ORCL/datafile/o1_mf_undotbs1dm1foow9.dbf
output file name=/data/ORCLSTD/datafile/o1_mf_undotbs1dm1foow9.dbftag=TAG20170606T105107
channel ORA_DISK_1: datafile copy complete,elapsed time: 00:00:35
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004name=/data/ORCL/datafile/o1_mf_usersdm1fqcrp.dbf
output filename=/data/ORCLSTD/datafile/o1_mf_usersdm1fqcrp.dbf tag=TAG20170606T105107
channel ORA_DISK_1: datafile copy complete,elapsed time: 00:00:03
Finished backup at 2017/06/06 11:18:07
sql statement: alter system archive log current
contents of Memory Script:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=945947890file name=/data/ORCLSTD/datafile/o1_mf_systemdm1flxkw.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=945947890file name=/data/ORCLSTD/datafile/o1_mf_sysauxdm1fnw5v.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=7 STAMP=945947890file name=/data/ORCLSTD/datafile/o1_mf_undotbs1dm1foow9.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=945947890file name=/data/ORCLSTD/datafile/o1_mf_usersdm1fqcrp.dbf
Finished Duplicate Db at2017/06/06 11:18:25
RMAN>
3.3.10 備庫(kù)開(kāi)啟實(shí)時(shí)同步
SQL> alter database open;
Database altered.
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
如果是延遲DG,啟動(dòng)語(yǔ)句,這里是延遲1440分鐘
alter database recover managed standby database delay 1440 disconnect from session;
3.3.11 開(kāi)啟flashback
上面DataGuard搭建好之后,千萬(wàn)不要忘了把備庫(kù)的flashback打開(kāi),具體如下:
SQL> alter database recover managed standby database cancel; #取消實(shí)時(shí)同步
Database altered.
SQL> shutdownimmediate #關(guān)閉數(shù)據(jù)庫(kù)
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startupmount #打開(kāi)到mount狀態(tài)
ORA-32004: obsolete or deprecatedparameter(s) specified for RDBMS instance
ORACLE instance started.
Total System Global Area 688959488 bytes
Fixed Size 2256432 bytes
Variable Size 566231504 bytes
Database Buffers 117440512 bytes
Redo Buffers 3031040 bytes
Database mounted.
SQL> alterdatabase flashback on; #開(kāi)始flashback
Database altered.
SQL> alter database open; #open數(shù)據(jù)庫(kù)
Database altered.
SQL> alter database recover managed standby database using current logfile disconnect from session; #開(kāi)啟實(shí)時(shí)同步
Database altered.
3.4驗(yàn)證DG同步
上面已經(jīng)把DataGurad搭建完,下面介紹如何驗(yàn)證DataGuard是否能實(shí)時(shí)同步
通過(guò)查看archive_log_dest_2列是否有error報(bào)錯(cuò),如果有報(bào)錯(cuò),則需要先根據(jù)報(bào)錯(cuò)內(nèi)容解決問(wèn)題
SQL>col dest_name format a30
SQL>col error format a20
SQL>select dest_name,error from v$archive_dest;
DEST_NAME ERROR
LOG_ARCHIVE_DEST_1
LOG_ARCHIVE_DEST_2
LOG_ARCHIVE_DEST_3
LOG_ARCHIVE_DEST_4
LOG_ARCHIVE_DEST_5
LOG_ARCHIVE_DEST_6
LOG_ARCHIVE_DEST_7
LOG_ARCHIVE_DEST_8
LOG_ARCHIVE_DEST_9
LOG_ARCHIVE_DEST_10
LOG_ARCHIVE_DEST_11
DEST_NAME ERROR
LOG_ARCHIVE_DEST_12
LOG_ARCHIVE_DEST_13
LOG_ARCHIVE_DEST_14
LOG_ARCHIVE_DEST_15
LOG_ARCHIVE_DEST_16
LOG_ARCHIVE_DEST_17
LOG_ARCHIVE_DEST_18
LOG_ARCHIVE_DEST_19
LOG_ARCHIVE_DEST_20
LOG_ARCHIVE_DEST_21
LOG_ARCHIVE_DEST_22
DEST_NAME ERROR
LOG_ARCHIVE_DEST_23
LOG_ARCHIVE_DEST_24
LOG_ARCHIVE_DEST_25
LOG_ARCHIVE_DEST_26
LOG_ARCHIVE_DEST_27
LOG_ARCHIVE_DEST_28
LOG_ARCHIVE_DEST_29
LOG_ARCHIVE_DEST_30
LOG_ARCHIVE_DEST_31
31rows selected.
SQL>
注意:上面顯示沒(méi)有報(bào)錯(cuò)
查詢主庫(kù)最大歸檔序號(hào),一致即歸檔同步成功。
主庫(kù)上執(zhí)行:
SQL>select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
132
備庫(kù)上操作:
SQL>select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
132
主庫(kù)上執(zhí)行日志切換
SQL>alter system archive log current;
Systemaltered.
SQL>select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
133
SQL>
備庫(kù)上再次驗(yàn)證:
SQL>select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
133
SQL>
查看主備庫(kù)狀態(tài)
主庫(kù)上執(zhí)行:
SQL>select switchover_status,database_role from v$database;
SWITCHOVER_STATUS DATABASE_ROLE
TOSTANDBY PRIMARY
備庫(kù)上執(zhí)行:
SQL>select switchover_status,database_role from v$database;
SWITCHOVER_STATUS DATABASE_ROLE
NOTALLOWED PHYSICAL STANDBY
可以創(chuàng)建一個(gè)table進(jìn)行測(cè)試
主庫(kù)上操作:
SQL>create table dg(id number);
Tablecreated.
SQL>insert into dg values(1);
1row created.
SQL>commit;
Commit complete.
SQL>select * from dg;
ID
1
備庫(kù)上操作:
SQL>select * from dg;
ID
1
SQL>
上面說(shuō)明DG是同步的。
3.5DG切換與恢復(fù)
我們配置DG的目的就是為了在主庫(kù)出現(xiàn)故障時(shí),備庫(kù)能夠提供服務(wù),保證業(yè)務(wù)的正常運(yùn)行。DG的故障切換分為switchover和failover兩種:
3.5.1 switchover
switchover是用戶有計(jì)劃的進(jìn)行停機(jī)切換,能夠保證不丟失數(shù)據(jù),下面我們來(lái)看下switchover是怎樣操作的:
主庫(kù)上操作:
SQL> select switchover_status,database_role from v$database;
SWITCHOVER_STATUS DATABASE_ROLE
TO STANDBY PRIMARY
SQL>
注意:上面查詢結(jié)果為TO STANDBY 或 SESSIONS ACTIVE表明可以進(jìn)行切換
SQL> alter database commit to switchover to physical standby with session shutdown;-- SESSIONS ACTIVE
Database altered.
SQL> startup mount
ORACLE instance started.
Total System Global Area 688959488 bytes
Fixed Size 2256432 bytes
Variable Size 566231504 bytes
Database Buffers 117440512 bytes
Redo Buffers 3031040 bytes
Database mounted.
SQL> select database_role from v$database;
DATABASE_ROLE
PHYSICAL STANDBY
備庫(kù)上操作:
SQL> select switchover_status,database_role from v$database;
SWITCHOVER_STATUS DATABASE_ROLE
TO PRIMARY PHYSICAL STANDBY
SQL>
注意:上面查詢結(jié)果顯示為TO PRIMARY 或 SESSIONS ACTIVE表明可以切換成主庫(kù);
現(xiàn)在可以把備庫(kù)切換成主庫(kù):
SQL> alter database commit to switchover to primary with session shutdown;-------- SESSIONS ACTIVE
Database altered.
SQL> alter database open;
Database altered.
SQL> select switchover_status,database_role,open_mode from v$database;
SWITCHOVER_STATUS DATABASE_ROLE OPEN_MODE
SESSIONS ACTIVE PRIMARY READ WRITE
記住:這時(shí)候需要在現(xiàn)在的備庫(kù)(原先的主庫(kù))開(kāi)啟實(shí)時(shí)同步
SQL> alter database open;
Database altered.
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
到此DG switover切換完成,驗(yàn)證方法同上。
3.5.2 failover
failover是當(dāng)主庫(kù)真正出現(xiàn)嚴(yán)重系統(tǒng)故障,如數(shù)據(jù)庫(kù)宕機(jī),軟硬件故障導(dǎo)致主庫(kù)不能支持服務(wù),從而進(jìn)行的切換動(dòng)作。
注意:為了能夠在failover后能夠恢復(fù)DG,需要在主庫(kù)上開(kāi)啟flashback,如果不開(kāi)啟flashback的話,DG就可能需要重新搭建
由于主庫(kù)已經(jīng)不可訪問(wèn),下面所有的操作都在備庫(kù)完成:
SQL> alter database recover managed standby database cancel; #停止實(shí)時(shí)同步
Database altered.
SQL> alter database recover managed standby database finish force;
Database altered.
SQL> select database_role from v$database;
DATABASE_ROLE
PHYSICAL STANDBY
SQL> alter database commit to switchover to primary with session shutdown;
Database altered.
SQL> alter database open;
Database altered.
SQL> select switchover_status,database_role,open_mode from v$database;
SWITCHOVER_STATUS DATABASE_ROLE OPEN_MODE
RESOLVABLE GAP PRIMARY READ WRITE
至此failover操作完成,原來(lái)的備庫(kù)已經(jīng)切換為主庫(kù),可以給業(yè)務(wù)提供服務(wù)了。
3.5.2 failover恢復(fù)
備注:如果未開(kāi)啟flashback,需要使用rman備份重新搭建ADG
上面提到了failover,這種情形是當(dāng)主庫(kù)真正出現(xiàn)異常之后,才會(huì)執(zhí)行的操作,那么我們執(zhí)行過(guò)failover 之后,如何在重新構(gòu)建DG,這里我們利用flashback database來(lái)重構(gòu),具體方法如下:
在新的主庫(kù)上執(zhí)行:
SQL> select to_char(standby_became_primary_scn) from v$database;
TO_CHAR(STANDBY_BECAME_PRIMARY_SCN)
977458
在之前的主庫(kù)上,也就是現(xiàn)在的備庫(kù)上執(zhí)行下面的操作:
SQL> startup mount
ORACLE instance started.
Total System Global Area 688959488 bytes
Fixed Size 2256432 bytes
Variable Size 566231504 bytes
Database Buffers 117440512 bytes
Redo Buffers 3031040 bytes
Database mounted.
SQL> flashback database to scn 977458; #這個(gè)值為在新主庫(kù)上查詢到的SCN值
Flashback complete.
SQL> alter database convert to physical standby;
Database altered.
SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 688959488 bytes
Fixed Size 2256432 bytes
Variable Size 566231504 bytes
Database Buffers 117440512 bytes
Redo Buffers 3031040 bytes
Database mounted.
Database opened.
SQL> alterd atabase recover managed standby database using current logfile disconnect from session;
Database altered.
SQL>
到此failover 恢復(fù)已經(jīng)完成,關(guān)于如何驗(yàn)證DG方法如上,這里不在介紹。
來(lái)源:https://www.icode9.com/content-2-685501.html
與50位技術(shù)專家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的oracle不一致性关闭下次,Oracle DataGuard的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 喉咙痛头晕四肢无力怎么回事?
- 下一篇: 牙周炎会不会引起咽痛?