(1)
主库安装数据库,备库只安装软件,我们可以采用在主库装完软件的时候对虚拟机进行复制。
主库在用dbca建库的时候,全局数据库选择szscpdb,sid选择szsc。
(2)
配置主库和备库信息
主库:
操作系统:oracle liunx 5.6
主机名:SZSCPDB
ip地址:192.168.1.21
oracle_sid:szsc
db_unqiue_name:szscpdb
service_name:szscpdb
global_name:szscpdb
监听名、端口:listener、1521
备库:
操作系统:oracle liunx 5.6
主机名:SZSCSTB
ip地址:192.168.1.22
oracle_sid:szsc
db_unqiue_name:szscstb
service_name:szscstb
global_name:szscstb
监听名、端口:listener、1521
(3)
查看主库和备库的hosts文件,确定ip和主机名的解析:
主库:
[oracle@SZSCPDB szscpdb]$ cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.1.21 SZSCPDB
192.168.1.22 SZSCSTB
备库:
[oracle@SZSCSTB szscstb]$ cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.1.21 SZSCPDB
192.168.1.22 SZSCSTB
(4)
确定主库的监听是开启的
[oracle@SZSCPDB szscpdb]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 15-DEC-2013 15:30:42
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=SZSCPDB)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 15-DEC-2013 14:24:29
Uptime 0 days 1 hr. 6 min. 12 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/SZSCPDB/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=SZSCPDB)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "szscXDB" has 1 instance(s).
Instance "szsc", status READY, has 1 handler(s) for this service...
Service "szscpdb" has 2 instance(s).
Instance "szsc", status UNKNOWN, has 1 handler(s) for this service...
Instance "szsc", status READY, has 1 handler(s) for this service...
The command completed successfully
(5)
配置主库为归档模式:
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /arch/szscpdb
Oldest online log sequence 3
Next log sequence to archive 5
Current log sequence 5
(6)
更改主库为force logging
SQL> alter database force logging;
Database altered.
(7)
创建主库的密码文件
[root@SZSCPDB dbs]# cd /u01/app/oracle/product/11.2.0/db_1/dbs/
[root@SZSCPDB dbs]# orapwd file=$ORACLE_HOME/dbs/orapwszsc password=oracle entries=30;
(8)
修改主库的监听文件,请确保有SID_LIST_LISTENER:
[root@SZSCPDB dbs]# cd /u01/app/oracle/product/11.2.0/db_1/network/admin/
[root@SZSCPDB admin]# vi listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = szscpdb)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = szsc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = SZSCPDB)(PORT = 1521))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
(9)
修改主库的tnsname文件:
[root@SZSCPDB admin]# vi tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
SZSCPDB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.21)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = szscpdb)
)
)
SZSCSTB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.22)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = szscstb)
)
)
(10)
修改主库的参数文件:
[root@SZSCPDB admin]# cd /u01/app/oracle/product/11.2.0/db_1/dbs/
szsc.__db_cache_size=192937984
szsc.__java_pool_size=4194304
szsc.__large_pool_size=4194304
szsc.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
szsc.__pga_aggregate_target=209715200
szsc.__sga_target=306184192
szsc.__shared_io_pool_size=0
szsc.__shared_pool_size=96468992
szsc.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/szscpdb/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/szscpdb/control01.ctl','/u01/app/oracle/oradata/szscpdb/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='szscpdb'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=szscXDB)'
*.log_archive_config='dg_config=(szscpdb,szscstb)'
*.log_archive_dest_1='LOCATION=/arch/szscpdb LGWR VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=szscpdb'
*.log_archive_dest_2='SERVICE=SZSCSTB ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=szscstb'
*.DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/szscstb/','/u01/app/oracle/oradata/szscpdb/'
*.LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/szscstb/','/u01/app/oracle/oradata/szscpdb/'
*.log_archive_format='%t_%s_%r.arc'
*.memory_target=512753664
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
*.standby_file_management='AUTO'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.fal_server=szscstb
*.fal_client=szscpdb
*.db_unique_name=szscpdb
注意:
1、
log_archive_dest_2='SERVICE=SZSCSTB
这个参数就是tnsnames的别名,就是这个文件开头的那个大写的名字。
2、
*.fal_server=szscstb
*.fal_client=szscpdb
这两个参数是各自的service_name。
(11)
传输主库的参数文件、密码文件以及tnsname文件到备库上:
[oracle@SZSCPDB dbs]$ cd /u01/app/oracle/product/11.2.0/db_1/dbs
scp initszsc.ora orapwszsc SZSCSTB:$ORACLE_HOME/dbs
[oracle@SZSCPDB ~]$ cd /u01/app/oracle/product/11.2.0/db_1/network/admin/
scp tnsnames.ora SZSCSTB:$ORACLE_HOME/network/admin
(12)
修改备库的参数文件:
[root@SZSCSTB admin]# cd /u01/app/oracle/product/11.2.0/db_1/dbs/
[root@SZSCSTB dbs]# vi initszsc.ora
szsc.__db_cache_size=192937984
szsc.__java_pool_size=4194304
szsc.__large_pool_size=4194304
szsc.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
szsc.__pga_aggregate_target=209715200
szsc.__sga_target=306184192
szsc.__shared_io_pool_size=0
szsc.__shared_pool_size=96468992
szsc.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/szscstb/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/szscstb/control01.ctl','/u01/app/oracle/oradata/szscstb/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='szscpdb'
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=szscXDB)'
*.log_archive_config='dg_config=(szscpdb,szscstb)'
*.log_archive_dest_1='LOCATION=/arch/szscstb LGWR VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=szscstb'
*.log_archive_dest_2='SERVICE=SZSCPDB ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=szscpdb'
*.DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/szscpdb/','/u01/app/oracle/oradata/szscstb/'
*.LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/szscpdb/','/u01/app/oracle/oradata/szscstb/'
*.log_archive_format='%t_%s_%r.arc'
*.memory_target=512753664
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.undo_tablespace='UNDOTBS1'
*.standby_file_management='AUTO'
*.log_archive_dest_state_1=enable
*.log_archive_dest_state_2=enable
*.fal_server=szscpdb
*.fal_client=szscstb
*.db_unique_name=szscstb
(13)
在备库上创建相应的目录,因为备库开始没有创建数据库,有些目录是参数文件中没有的。
1、
audit_file_dest:
[oracle@SZSCSTB ~]$ mkdir -p /u01/app/oracle/admin/szscstb/adump/
2、
control_files:
[oracle@SZSCSTB ~]$ mkdir -p /u01/app/oracle/oradata/szscstb
3、
创建一个备份文件的位置,等会主库会将备份传递过来:
[root@SZSCSTB ~]# mkdir /backup
[root@SZSCSTB ~]# chown -R oracle:oinstall /backup
4、
创建一个归档目录,接收主库传递的归档日志:
[root@SZSCSTB ~]# mkdir -p /arch/szscstb
[root@SZSCSTB ~]# chown -R oracle:oinstall /arch/szscstb
(15)
在主库上用rman做一个全备,也需要创建备份的目录:
[root@SZSCPDB ~]# mkdir /backup
[root@SZSCPDB ~]# chown -R oracle:oinstall /backup
RMAN>backup device type disk format '/backup/%U' database plus archivelog;
(16)
将主库的备份文件传递到备库上:
[oracle@SZSCPDB admin]$ cd /backup/
[oracle@SZSCPDB backup]$ scp * SZSCSTB:/backup
(17)
将备库启动到nomount状态:
[root@SZSCSTB ~]# su - oracle
[oracle@SZSCSTB ~]$ sqlplus / as sysdba
SQL> startup nomount;
(18)
修改备库的监听文件。
[oracle@SZSCSTB admin]$ vi listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = szscstb)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
(SID_NAME = szsc)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = SZSCSTB)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
(19)
启动监听,确保服务名注册无误)
[oracle@SZSCSTB ~]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 15-DEC-2013 07:42:41
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=SZSCSTB)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 15-DEC-2013 06:13:05
Uptime 0 days 1 hr. 29 min. 36 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/SZSCSTB/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=SZSCSTB)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "szscXDB" has 1 instance(s).
Instance "szsc", status READY, has 1 handler(s) for this service...
Service "szscstb" has 2 instance(s).
Instance "szsc", status UNKNOWN, has 1 handler(s) for this service...
Instance "szsc", status READY, has 1 handler(s) for this service...
The command completed successfully
(20)
主库应用备份文件到备库上,使用duplicate方式(在主库上执行)
RMAN> connect auxiliary sys/oracle@SZSCSTB
connected to auxiliary database: SZSCPDB (not mounted)
RMAN> duplicate target database for standby;
Starting Duplicate Db at 08-MAR-13
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=10 device type=DISK
contents of Memory Script.:
{
restore clone standby controlfile;
}
executing Memory Script
Starting restore at 08-MAR-13
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /BACKUP/0lo3vm4i_1_1
channel ORA_AUX_DISK_1: piece handle=/backup/0lo3vm4i_1_1 tag=TAG20130308T022752
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:02
output file name=/u01/app/oracle/oradata/szscstb/control01.ctl
output file name=/u01/app/oracle/oradata/szscstb/control02.ctl
Finished restore at 08-MAR-13
contents of Memory Script.:
{
sql clone 'alter database mount standby database';
}
executing Memory Script
sql statement: alter database mount standby database
contents of Memory Script.:
{
set newname for tempfile 1 to
"/u01/app/oracle/oradata/szscstb/temp01.dbf";
switch clone tempfile all;
set newname for datafile 1 to
"/u01/app/oracle/oradata/szscstb/system01.dbf";
set newname for datafile 2 to
"/u01/app/oracle/oradata/szscstb/sysaux01.dbf";
set newname for datafile 3 to
"/u01/app/oracle/oradata/szscstb/undotbs01.dbf";
set newname for datafile 4 to
"/u01/app/oracle/oradata/szscstb/users01.dbf";
restore
clone database
;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/szscstb/temp01.dbf in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 08-MAR-13
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to //u01/app/oracle/oradata/szscstb/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/szscstb/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/szscstb/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/szscstb/users01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /backup/0ko3vm18_1_1
channel ORA_AUX_DISK_1: piece handle=/backup/0ko3vm18_1_1 tag=TAG20130308T022752
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:02:05
Finished restore at 08-MAR-13
contents of Memory Script.:
{
switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=2 STAMP=809491977 file name=/u01/app/oracle/oradata/szscstb/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=3 STAMP=809491977 file name=/u01/app/oracle/oradata/szscstb/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=809491977 file name=/u01/app/oracle/oradata/szscstb/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=809491977 file name=/u01/app/oracle/oradata/szscstb/users01.dbf
Finished Duplicate Db at 08-MAR-13
(21)
执行备库恢复模式。(在备库上执行)
SQL> select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
szsc MOUNTED
SQL> alter database recover managed standby database disconnect from session;
Database altered.
(22)
查看日志同步情况,确保日志都应用了。
SQL> SELECT SEQUENCE#, REGISTRAR, FIRST_TIME, NEXT_TIME, APPLIED
2 FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
SEQUENCE# REGISTR FIRST_TIM NEXT_TIME APPLIED
---------- ------- --------- --------- ---------
13 RFS 15-DEC-13 15-DEC-13 YES
14 RFS 15-DEC-13 15-DEC-13 YES
15 RFS 15-DEC-13 15-DEC-13 YES
16 RFS 15-DEC-13 15-DEC-13 YES
17 RFS 15-DEC-13 15-DEC-13 YES
18 RFS 15-DEC-13 15-DEC-13 YES
19 RFS 15-DEC-13 15-DEC-13 YES
20 RFS 15-DEC-13 15-DEC-13 YES
21 RFS 15-DEC-13 15-DEC-13 YES
22 RFS 15-DEC-13 15-DEC-13 YES
(23)
创建standby logfile。主库和备库都要添加。
主库:
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/szscpdb/sredo01.log' size 512M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/szscpdb/sredo02.log' size 512M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/szscpdb/sredo03.log' size 512M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/szscpdb/sredo04.log' size 512M;
备库:
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/szscstb/sredo01.log' size 512M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/szscstb/sredo02.log' size 512M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/szscstb/sredo03.log' size 512M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE '/u01/app/oracle/oradata/szscstb/sredo04.log' size 512M;
(24)
实现日志同步。(备库上执行)
SQL> alter database recover managed standby database disconnect from session;
完成之后,结束这个恢复进程:
SQL> alter database recover managed standby database cancel;
将备库启动到open read only的状态。
SQL> alter database open read only;
(25)
查看主库和备库的日志同步情况,确保已经同步。(如果没有同步,继续第24步)
主库:
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /arch/szscpdb
Oldest online log sequence 21
Next log sequence to archive 23
Current log sequence 23
备库:
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /arch/szscstb
Oldest online log sequence 21
Next log sequence to archive 0
Current log sequence 23
在备库上执行:
SQL> SELECT SEQUENCE#, REGISTRAR, FIRST_TIME, NEXT_TIME, APPLIED
2 FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;
SEQUENCE# REGISTR FIRST_TIM NEXT_TIME APPLIED
---------- ------- --------- --------- ---------
13 RFS 15-DEC-13 15-DEC-13 YES
14 RFS 15-DEC-13 15-DEC-13 YES
15 RFS 15-DEC-13 15-DEC-13 YES
16 RFS 15-DEC-13 15-DEC-13 YES
17 RFS 15-DEC-13 15-DEC-13 YES
18 RFS 15-DEC-13 15-DEC-13 YES
19 RFS 15-DEC-13 15-DEC-13 YES
20 RFS 15-DEC-13 15-DEC-13 YES
21 RFS 15-DEC-13 15-DEC-13 YES
22 RFS 15-DEC-13 15-DEC-13 YES
(26)
确认数据可以同步,在主库上创建一张表,看备库上是否可以查看到。
主库:
SQL> create table zsx (id number);
Table created.
备库:
SQL> desc zsx
ERROR:
ORA-04043: object zsx does not exist
注意:
发现数据没有同步,请执行下面27,接收数据。
(27)
备库上接收数据,并自动同步:
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
SQL> desc zsx
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER
(28)
再次验证数据是否同步。
主库:
SQL> insert into zsx values(1);
1 row created.
SQL> commit;
Commit complete.
备库:
SQL> select * from zsx;
ID
----------
1
(29)
如果28步没有问题,那么就代表你的DG配置成功了。下一阶段就是实现switchover了。
网页题目:手把手教你安装DataGuard
URL标题:
http://cdxtjz.com/article/gdghos.html