oracle 10.2.0.5.0 Dataguard


[oracle@lp admin]$ uname -a
 2.6.32-300.10.1.el5uek #1 SMP Wed Feb 22 17:37:40 EST 2012 x86_64 x86_64 x86_64 GNU/Linux
oracle version;
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
CORE    10.2.0.5.0    Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
    
    2.1  dataguard规划  
      
    Host_IP            DB_NAME   DB_UNIQUE_NAME     Net Service Name  
      
    主库192.168.100.50 HNDB        HNDB                     HNDB
      
    备库192.168.100.52 HNDB        HNDB02                   HNDB02  
      
    主库归档路径  /home/oracle/archivelog
    备库归档路径  /home/oracle/archivelog
    同步模式    lgwr async
    保护模式:    最大性能模式  
   此模式下,ORACLE备库的数据差一个日志文件 就是说只有REDO日志成为ARCHIVE LOG日志的时候,能会同步 。


安装ORACLE 10 的环境变量
cat oracle10g.sh
#!/bin/bash
# by peter 2014-12-04
rm -rf /etc/yum.repos.d/*
cat>/etc/yum.repos.d/localhost.repo< [Server]
name=Server
baseurl=ftp://192.168.100.1/5u8/Server
enabled=1
gpgcheck=0
gpgkey=ftp://192.168.100.1/5u8/RPM-GPG-KEY-redhat-release

[Cluster]
name=Cluster
baseurl=ftp://192.168.100.1/5u8/Cluster
enabled=1
gpgcheck=0
gpgkey=ftp://192.168.100.1/5u8/RPM-GPG-KEY-redhat-release

[ClusterStorage]
name=ClusterStorage
baseurl=ftp://192.168.100.1/5u8/ClusterStorage
enabled=1
gpgcheck=0
gpgkey=ftp://192.168.100.1/5u8/RPM-GPG-KEY-redhat-release

[VT]
name=VT
baseurl=ftp://192.168.100.1/5u8/VT
enabled=1
gpgcheck=0
gpgkey=ftp://192.168.100.1/5u8/RPM-GPG-KEY-redhat-release
EOF

yum install -y binutils compat-db compat-gcc compat-gcc-34-c++* compat-libstdc++-33* gcc gcc-c++ glibc glibc-commond glibc-devel glibc-headers libgcc libXp libXt libXtst libaio libaio-devel libgcc libstdc++ libstdc++-devel libgomp make numactl-devel sysstat
chkconfig iptables off



echo "create group: dba oper oinstall asmadmin asmdba asmoper and user:oracle grid"
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
groupadd -g 10000 dba
groupadd -g 10001 oper
groupadd -g 10002 oinstall
useradd  -u 10006 -g oinstall -G dba,oper oracle
echo "oracle" | passwd --stdin oracle
cat >> /etc/sysctl.conf << EOF
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 262144
net.core.rmem_max = 262144
net.core.wmem_default = 262144
net.core.wmem_max = 262144
EOF
/sbin/sysctl -p  
cat>> /etc/security/limits.conf << EOF
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
EOF
echo " session    required     /lib64/security/pam_limits.so" >> /etc/pam.d/login
echo "session   required     pam_limits.so" >> /etc/pam.d/login

cat >>/etc/profile<< EOF
if [ $USER = "oracle" ]; then
     if [ $SHELL = "/bin/ksh" ]; then
     ulimit -p 16384
    ulimit -n 65536
else
    ulimit -u 16384 -n 65536

    fi
fi
EOF

mkdir -pv /u01/app/oracle
chown -R oracle:oinstall /u01/app/
chmod -R 755 /u01/

cat >>/home/oracle/.bash_profile < ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1; export ORACLE_HOME
ORACLE_SID=hndb;export ORACLE_SID
PATH=$ORACLE_HOME/bin:$PATH; export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:$ORACLE_HOME:/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/jre:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;export CLASSPATH
EOF

查看数据库的一些现有状态。

SQL> select name,LOG_MODE,FORCE_LOGGING from v$database;

NAME      LOG_MODE     FOR
--------- ------------ ---
HNDB      NOARCHIVELOG NO

SQL> select version from v$instance;

VERSION
-----------------
10.2.0.5.0

SQL> show parameter name

NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert             string
db_name                  string     hndb
db_unique_name                 string     hndb
global_names                 boolean     FALSE
instance_name                 string     hndb
lock_name_space              string
log_file_name_convert             string
service_names                 string     hnd

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  599785472 bytes
Fixed Size            2098112 bytes
Variable Size          163580992 bytes
Database Buffers      427819008 bytes
Redo Buffers            6287360 bytes
Database mounted.
SQL> alter database archivelog;

Database altered.

SQL> alter database force logging;

Database altered.

SQL> allter database open;

SQL> archive log list
Database log mode           Archive Mode
Automatic archival           Enabled
Archive destination           USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     1
Next log sequence to archive   3
Current log sequence           3

SQL> select name,LOG_MODE,FORCE_LOGGING from v$database;                         

NAME      LOG_MODE     FOR
--------- ------------ ---
HNDB      ARCHIVELOG   YES

[oracle@lp ~]$  mkdir -pv /home/oracle/archivelog
mkdir: created directory `/home/oracle/archivelog'
[oracle@lp ~]$ mkdir -pv /home/oracle/std_log
mkdir: created directory `/home/oracle/std_log'


[oracle@lp admin]$ mkdir /home/oracle/dg_config
[oracle@lp admin]$ cd $ORACLE_HOME/network/admin/
[oracle@lp admin]$ cp listener.ora tnsnames.ora /home/oracle/dg_config/
[oracle@lp admin]$ cd $ORACLE_HOME/dbs
[oracle@lp dbs]$ cp orapwHNDB /home/oracle/dg_config/

SQL> alter system set log_archive_config='dg_config=(HNDB,HNDB02)' scope =spfile;

System altered.

SQL> alter system set log_archive_dest_1='location=/home/oracle/archivelog/ valid_for=(all_logfiles,all_roles) db_unique_name=HNDB' scope =spfile;

System altered.

SQL> alter system set log_archive_dest_2='service=HNDB02 async lgwr valid_for=(online_logfiles,primary_role) db_unique_name=HNDB02' scope =spfile;

System altered.

SQL> alter system set db_unique_name=HNDB scope=spfile;

System altered.

SQL> alter system set instance_name=HNDB scope=spfile;

System altered.

SQL> alter system set service_names=HNDB scope=spfile;

System altered

SQL> alter system set log_archive_dest_state_1=enable scope=spfile;

System altered.

SQL> alter system set log_archive_dest_state_2=enable scope=spfile;

System altered.

 
SQL> alter system set FAL_SERVER=HNDB02 scope=spfile;
SQL> alter system set fal_client=HNDB scope=spfile;

SQL> alter system set DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/HNDB02',' /u01/app/oracle/oradata/HNDB' scope=spfile;  

System altered.

SQL> alter system set LOG_FILE_NAME_CONVERT=' /u01/app/oracle/oradata/HNDB02',' /u01/app/oracle/oradata/HNDB' scope=spfile;

System altered.


SQL> alter system set standby_file_management=auto scope=spfile;

alter system set STANDBY_ARCHIVE_DEST='LOCATION=/home/oracle/archivelog' scope=spfile;



[oracle@lp dg_config]$ rman target /

Recovery Manager: Release 10.2.0.5.0 - Production on Fri Dec 5 04:22:53 2014

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

connected to target database: HNDB (DBID=686290904)

RMAN> backup full database format '/home/oracle/dg_config/backup_%T_%s_%p.bak';

Starting backup at 05-DEC-14
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=138 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/u01/app/oracle/oradata/HNDB/system01.dbf
input datafile fno=00003 name=/u01/app/oracle/oradata/HNDB/sysaux01.dbf
input datafile fno=00005 name=/u01/app/oracle/oradata/HNDB/example01.dbf
input datafile fno=00002 name=/u01/app/oracle/oradata/HNDB/undotbs01.dbf
input datafile fno=00004 name=/u01/app/oracle/oradata/HNDB/users01.dbf
channel ORA_DISK_1: starting piece 1 at 05-DEC-14
channel ORA_DISK_1: finished piece 1 at 05-DEC-14
piece handle=/home/oracle/dg_config/backup_20141205_1_1.bak tag=TAG20141205T042303 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 05-DEC-14
channel ORA_DISK_1: finished piece 1 at 05-DEC-14
piece handle=/home/oracle/dg_config/backup_20141205_2_1.bak tag=TAG20141205T042303 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 05-DEC-14

RMAN> sql "alter system archive log  current";

sql statement: alter system archive log  current

RMAN>  backup archivelog all format='/home/oracle/dg_config/arch_%T_%s_%p.bak';

Starting backup at 05-DEC-14
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archive log backupset
channel ORA_DISK_1: specifying archive log(s) in backup set
input archive log thread=1 sequence=3 recid=1 stamp=865484081
input archive log thread=1 sequence=4 recid=2 stamp=865484619
input archive log thread=1 sequence=5 recid=3 stamp=865484650
channel ORA_DISK_1: starting piece 1 at 05-DEC-14
channel ORA_DISK_1: finished piece 1 at 05-DEC-14
piece handle=/home/oracle/dg_config/arch_20141205_3_1.bak tag=TAG20141205T042410 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 05-DEC-14

RMAN> exit


Recovery Manager complete.

SQL> alter database create standby controlfile as '/home/oracle/dg_config/std.ctl';

Database altered.

SQL> create pfile='/home/oracle/dg_config/p.ora' from spfile;

File created.

copy all file to standby !!!!!!!!
###################################################

standby standby

####################################################

[oracle@lp02 ~]$ mkdir -pv /home/oracle/dg_config

#########################################################
primary
#######################################################
[oracle@lp ~]$ scp  -rv /home/oracle/dg_config/* oracle@192.168.100.52:/home/oracle/dg_config/
Executing: program /usr/bin/ssh host 192.168.100.52, user oracle, command scp -v -r -d -t /home/oracle/dg_config/
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.100.52 [192.168.100.52] port 22.
debug1: Connection established.
debug1: identity file /home/oracle/.ssh/identity type -1
debug1: identity file /home/oracle/.ssh/id_rsa type -1
debug1: identity file /home/oracle/.ssh/id_dsa type -1
debug1: loaded 3 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '192.168.100.52' is known and matches the RSA host key.
debug1: Found key in /home/oracle/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure.  Minor code may provide more information
No credentials cache found

debug1: Next authentication method: publickey
debug1: Trying private key: /home/oracle/.ssh/identity
debug1: Trying private key: /home/oracle/.ssh/id_rsa
debug1: Trying private key: /home/oracle/.ssh/id_dsa
debug1: Next authentication method: password
oracle@192.168.100.52's password:
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending command: scp -v -r -d -t /home/oracle/dg_config/
Sending file modes: C0640 29521920 arch_20141205_3_1.bak
Sink: C0640 29521920 arch_20141205_3_1.bak
arch_20141205_3_1.bak                                                                                                                100%   28MB   9.4MB/s   00:03    
Sending file modes: C0640 622059520 backup_20141205_1_1.bak
backup_20141205_1_1.bak                                                                                                                0%    0     0.0KB/s   --:-- ETASink: C0640 622059520 backup_20141205_1_1.bak
backup_20141205_1_1.bak                                                                                                              100%  593MB   9.0MB/s   01:06    
Sending file modes: C0640 7143424 backup_20141205_2_1.bak
Sink: C0640 7143424 backup_20141205_2_1.bak
backup_20141205_2_1.bak                                                                                                              100% 6976KB   6.8MB/s   00:00    
Sending file modes: C0644 670 listener.ora
Sink: C0644 670 listener.ora
listener.ora                                                                                                                         100%  670     0.7KB/s   00:00    
Sending file modes: C0640 2048 orapwHNDB
Sink: C0640 2048 orapwHNDB
orapwHNDB                                                                                                                            100% 2048     2.0KB/s   00:00    
Sending file modes: C0644 1683 p.ora
Sink: C0644 1683 p.ora
p.ora                                                                                                                                100% 1683     1.6KB/s   00:00    
Sending file modes: C0644 193 sqlnet.ora
Sink: C0644 193 sqlnet.ora
sqlnet.ora                                                                                                                           100%  193     0.2KB/s   00:00    
Sending file modes: C0640 7061504 std.ctl
std.ctl                                                                                                                                0%    0     0.0KB/s   --:-- ETASink: C0640 7061504 std.ctl
std.ctl                                                                                                                              100% 6896KB   6.7MB/s   00:00    
Sending file modes: C0644 702 tnsnames.ora
tnsnames.ora                                                                                                                           0%    0     0.0KB/s   --:-- ETASink: C0644 702 tnsnames.ora
tnsnames.ora                                                                                                                         100%  702     0.7KB/s   00:01    
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 70.6 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
debug1: Exit status 0

[oracle@lp ~]$ 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.100.50  lp.peter.com lp
192.168.100.52  lp02.peter.com lp02

###################################################

standby standby

####################################################


[oracle@lp02 ~]$ cd dg_config/

[oracle@lp02 dg_config]$ ls
arch_20141205_3_1.bak  backup_20141205_1_1.bak  backup_20141205_2_1.bak  listener.ora  orapwHNDB  p.ora  sqlnet.ora  std.ctl  tnsnames.ora

[oracle@lp02 dg_config]$ cp p.ora s.ora
[oracle@lp02 dg_config]$ vim s.ora
[oracle@lp02 dg_config]$ cat s.ora
HNDB.__db_cache_size=427819008
HNDB.__java_pool_size=4194304
HNDB.__large_pool_size=4194304
HNDB.__shared_pool_size=155189248
HNDB.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/HNDB02/adump'
*.background_dump_dest='/u01/app/oracle/admin/HNDB02/bdump'
*.compatible='10.2.0.5.0'
*.control_files='/u01/app/oracle/oradata/HNDB02/control01.ctl','/u01/app/oracle/oradata/HNDB02/control02.ctl','/u01/app/oracle/oradata/HNDB02/control03.ctl'
*.core_dump_dest='/u01/app/oracle/admin/HNDB02/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_file_name_convert='
    /u01/app/oracle/oradata/HNDB',' /u01/app/oracle/oradata/HNDB02'
*.db_name='HNDB'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=HNDBXDB)'
*.fal_client='HNDB02'
*.fal_server='HNDB'
*.job_queue_processes=10
*.log_archive_config='dg_config=(HNDB,HNDB02)'
*.log_archive_dest_1='location=/home/oracle/archivelog/ valid_for=(all_logfiles,all_roles) db_unique_name=HNDB02'
*.log_archive_dest_2='service=HNDB async lgwr valid_for=(online_logfiles,primary_role) db_unique_name=HNDB'
*.log_archive_dest_state_1='ENABLE'
*.log_archive_dest_state_2='ENABLE'
*.log_archive_max_processes=5
*.log_file_name_convert=' /u01/app/oracle/oradata/HNDB',' /u01/app/oracle/oradata/HNDB02'
*.open_cursors=300
*.pga_aggregate_target=199229440
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=597688320
*.standby_archive_dest='LOCATION=/home/oracle/archivelog'
*.standby_file_management='AUTO'
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/HNDB02/udump'

[oracle@lp02 dg_config]$ diff p.ora s.ora
6,7c6,7
< *.audit_file_dest='/u01/app/oracle/admin/HNDB/adump'
< *.background_dump_dest='/u01/app/oracle/admin/HNDB/bdump'
---
> *.audit_file_dest='/u01/app/oracle/admin/HNDB02/adump'
> *.background_dump_dest='/u01/app/oracle/admin/HNDB02/bdump'
9,10c9,10
< *.control_files='/u01/app/oracle/oradata/HNDB/control01.ctl','/u01/app/oracle/oradata/HNDB/control02.ctl','/u01/app/oracle/oradata/HNDB/control03.ctl'
< *.core_dump_dest='/u01/app/oracle/admin/HNDB/cdump'
---
> *.control_files='/u01/app/oracle/oradata/HNDB02/control01.ctl','/u01/app/oracle/oradata/HNDB02/control02.ctl','/u01/app/oracle/oradata/HNDB02/control03.ctl'
> *.core_dump_dest='/u01/app/oracle/admin/HNDB02/cdump'
15c15
---
>     /u01/app/oracle/oradata/HNDB',' /u01/app/oracle/oradata/HNDB02'
20,21c20,21
< *.fal_client='HNDB'
< *.fal_server='HNDB02'
---
> *.fal_client='HNDB02'
> *.fal_server='HNDB'
24,25c24,25
< *.log_archive_dest_1='location=/home/oracle/archivelog/ valid_for=(all_logfiles,all_roles) db_unique_name=HNDB'
< *.log_archive_dest_2='service=HNDB02 async lgwr valid_for=(online_logfiles,primary_role) db_unique_name=HNDB02'
---
> *.log_archive_dest_1='location=/home/oracle/archivelog/ valid_for=(all_logfiles,all_roles) db_unique_name=HNDB02'
> *.log_archive_dest_2='service=HNDB async lgwr valid_for=(online_logfiles,primary_role) db_unique_name=HNDB'
29c29
< *.log_file_name_convert=' /u01/app/oracle/oradata/HNDB02',' /u01/app/oracle/oradata/HNDB'
---
> *.log_file_name_convert=' /u01/app/oracle/oradata/HNDB',' /u01/app/oracle/oradata/HNDB02'
39c39
< *.user_dump_dest='/u01/app/oracle/admin/HNDB/udump'
---
> *.user_dump_dest='/u01/app/oracle/admin/HNDB02/udump'

[oracle@lp02 dg_config]$ mkdir -pv /u01/app/oracle/admin/HNDB02/adump
mkdir: created directory `/u01/app/oracle/admin'
mkdir: created directory `/u01/app/oracle/admin/HNDB02'
mkdir: created directory `/u01/app/oracle/admin/HNDB02/adump'
[oracle@lp02 dg_config]$ mkdir -pv /u01/app/oracle/admin/HNDB02/bdump
mkdir: created directory `/u01/app/oracle/admin/HNDB02/bdump'
[oracle@lp02 dg_config]$ mkdir -pv /u01/app/oracle/oradata/HNDB02/
mkdir: created directory `/u01/app/oracle/oradata'
mkdir: created directory `/u01/app/oracle/oradata/HNDB02'
[oracle@lp02 dg_config]$ mkdir -pv /u01/app/oracle/admin/HNDB02/udump
mkdir: created directory `/u01/app/oracle/admin/HNDB02/udump'


[oracle@lp02 ~]$ mkdir -pv /u01/app/oracle/flash_recovery_area
mkdir: created directory `/u01/app/oracle/flash_recovery_area'
[oracle@lp ~]$  mkdir -pv /home/oracle/archivelog
mkdir: created directory `/home/oracle/archivelog'
[oracle@lp ~]$ mkdir -pv /home/oracle/std_log
mkdir: created directory `/home/oracle/std_log'


[oracle@lp02 dg_config]$ cp std.ctl /u01/app/oracle/oradata/HNDB02/control01.ctl
[oracle@lp02 dg_config]$ cp std.ctl /u01/app/oracle/oradata/HNDB02/control02.ctl
[oracle@lp02 dg_config]$ cp std.ctl /u01/app/oracle/oradata/HNDB02/control03.ctl
[oracle@lp02 dg_config]$ cp orapwHNDB $ORACLE_HOME/dbs/orapwHNDB02
[oracle@lp02 dg_config]$ cp listener.ora sqlnet.ora tnsnames.ora $ORACLE_HOME/network/admin
[oracle@lp02 admin]$ vim listener.ora
[oracle@lp02 admin]$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (PROGRAM = extproc)
    )
    (SID_DESC =   
              (GLOBAL_DBNAME = HNDB02)   
              (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)     
              (SID_NAME = HNDB02)
  )
)

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = lp02.peter.com)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
  )

[oracle@lp02 admin]$ vim tnsnames.ora
[oracle@lp02 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

HNDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = lp.peter.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = HNDB)
    )
  )


HNDB02 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = lp02.peter.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = HNDB02)
    )
  )

EXTPROC_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
    (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)


[oracle@lp02 dg_config]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Fri Dec 5 04:50:01 2014

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> create spfile from pfile='/home/oracle/dg_config/s.ora';

File created.

SQL> startup nomount;
ORACLE instance started.

Total System Global Area  599785472 bytes
Fixed Size            2098112 bytes
Variable Size          163580992 bytes
Database Buffers      427819008 bytes
Redo Buffers            6287360 bytes
SQL> alter database mount standby database;

SQL> alter system set db_unique_name=HNDB02 scope=both;


此时可以查看你的日志有没有过来
oracle@lp02 dbs]$ cd /home/oracle/archivelog/
[oracle@lp02 archivelog]$ ls
1_6_865411675.dbf  1_7_865411675.dbf  1_8_865411675.dbf  1_9_865411675.dbf

排错方式:
standby 备库上的查看
1.用ROOT在standby上查看TCP的流量

[root@lp02 ~]# tcpdump -i eth0 port 1521
06:55:09.698137 IP lp.peter.com.22687 > lp02.peter.com.ncube-lm: . 123706:125154(1448) ack 2649 win 142
06:55:09.698147 IP lp.peter.com.22687 > lp02.peter.com.ncube-lm: . 125154:126602(1448) ack 2649 win 142
06:55:09.698304 IP lp.peter.com.22687 > lp02.peter.com.ncube-lm: . 126602:128050(1448) ack 2649 win 142
06:55:09.698309 IP lp.peter.com.22687 > lp02.peter.com.ncube-lm: P 128050:129228(1178) ack 2649 win 142
2.查看网络日志:
[oracle@lp02 admin]$ tailf /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
05-DEC-2014 06:51:04 * (CONNECT_DATA=(SERVICE_NAME=HNDB02)(CID=(PROGRAM=oracle)(HOST=lp.peter.com)(USER=oracle))) * (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.100.50)(PORT=22678)) * establish * HNDB02 * 0
05-DEC-2014 06:51:05 * (CONNECT_DATA=(SERVICE_NAME=HNDB02)(CID=(PROGRAM=oracle)(HOST=lp.peter.com)

3.查看数据库日志:有没有RFS的进程在活动
tailf  /u01/app/oracle/admin/HNDB02/bdump/alert_HNDB02.log

RFS[5]: Assigned to RFS process 4001
RFS[5]: Identified database type as 'physical standby'
RFS[5]: Archived Log: '/home/oracle/archivelog/1_8_865411675.dbf'

primary  主库上的查看
on primary host
SQL> select DEST_ID,SEQUENCE#,ARCHIVED,APPLIED,DELETED,STATUS from v$archived_log;
下面是我在建的时候遇到的两个问题  
问题1  解决办法,alter system set db_unique_name='HNDB02'
SQL> select DEST_ID,STATUS,ERROR from v$archive_dest where dest_id in (1,2,3);

   DEST_ID STATUS
---------- ---------
ERROR
-----------------------------------------------------------------
     1 VALID


     2 ERROR
ORA-16047: DGID mismatch between destination setting and standby

     3 INACTIVE
问题2

SQL> select DEST_ID,STATUS,ERROR from v$archive_dest where dest_id in (1,2,3) ;

   DEST_ID STATUS
---------- ---------
ERROR
-----------------------------------------------------------------
     1 VALID


     2 ERROR
ORA-12514: TNS:listener does not currently know of service
requested in connect descriptor

     3 INACTIVE


   DEST_ID STATUS
---------- ---------
ERROR
-----------------------------------------------------------------
 解决办法是在 listener.ora 加入注册服务

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
      (PROGRAM = extproc)
    )
        (SID_DESC =
              (GLOBAL_DBNAME = HNDB)
              (ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
              (SID_NAME = HNDB)
  )
)

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = lp.peter.com)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    )
  )

————————————————————————————————————————————————————————————————————————————————————
SQL> alter system set log_archive_dest_state_2=defer;

SQL> alter system set log_archive_dest_state_2=enable;

————————————————————————————————————————————————————————————————————————————————————

开启备库的日志应用
SQL> alter database recover managed standby database disconnect from session;

Database altered.
当你看到日志里面有如下信息是时候,说明你的物理备库建成功了

Fri Dec 05 07:10:08 HKT 2014
Errors in file /u01/app/oracle/admin/HNDB02/bdump/hndb02_mrp0_4045.trc:
ORA-00313: open failed for members of log group 3 of thread 1
ORA-00312: online log 3 thread 1: '/u01/app/oracle/oradata/HNDB/redo03.log'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Clearing online redo logfile 3 complete
Media Recovery Log /u01/app/oracle/product/10.2.0/db_1/dbs/arch1_4_865411675.dbf
Media Recovery Log /u01/app/oracle/product/10.2.0/db_1/dbs/arch1_5_865411675.dbf
Media Recovery Log /home/oracle/archivelog/1_6_865411675.dbf
Media Recovery Log /home/oracle/archivelog/1_7_865411675.dbf
Media Recovery Log /home/oracle/archivelog/1_8_865411675.dbf
Media Recovery Waiting for thread 1 sequence 9 (in transit)


将DataGuard从“最大性能模式”升级成为“最高可用模式(最高可用物理standby)”

在主库和备库之间都要创建 standby logfile 如下:比主库多一组日志就可以了,主库上创建是为了将来做为备库使用的。

primary   standby

SQL> alter database add standby logfile group 4 ('/home/oracle/std_log/std_redo04.log') size 50m;

Database altered.

SQL> alter database add standby logfile group 5 ('/home/oracle/std_log/std_redo05.log') size 50m;

Database altered.

SQL> alter database add standby logfile group 6 ('/home/oracle/std_log/std_redo06.log') size 50m;

Database altered.

SQL> alter database add standby logfile group 7 ('/home/oracle/std_log/std_redo07.log') size 50m;

Database altered.

SQL> alter system set standby_file_management=auto;


更改主库上的log_archivelog_dest

SQL> alter system set log_archive_dest_1='location=/home/oracle/archivelog lgwr sync affirm  valid_for=(all_logfiles,all_roles) db_unique_name=HNDB';

System altered.

SQL> alter system set log_archive_dest_2='service=HNDB02 lgwr sync affirm  valid_for=(online_logfile,primary_role) db_unique_name=HNDB02';

System altered.
更改备库上的log_archivelog_des

SQL> alter system set log_archive_dest_1='location=/home/oracle/archivelog lgwr sync affirm  valid_for=(all_logfiles,all_roles) db_unique_name=HNDB02';

System altered.

SQL> alter system set log_archive_dest_2='service=HNDB lgwr sync affirm  valid_for=(online_logfile,primary_role) db_unique_name=HNDB';

System altered.

在备库上应用

SQL> alter database recover managed standby database  using current logfile disconnect from session;

Database altered.

也可以通在主库上修改一个数据,在备库上查询。

此时你可以在日志里看到如下的信息:

alter database recover managed standby database  using current logfile disconnect from session
Fri Dec 05 08:32:07 HKT 2014
Attempt to start background Managed Standby Recovery process (HNDB02)
MRP0 started with pid=22, OS id=3308
Fri Dec 05 08:32:07 HKT 2014
MRP0: Background Managed Standby Recovery process started (HNDB02)
Managed Standby Recovery starting Real Time Apply
 parallel recovery started with 2 processes
Fri Dec 05 08:32:13 HKT 2014
Waiting for all non-current ORLs to be archived...
Media Recovery Waiting for thread 1 sequence 9
Fri Dec 05 08:32:13 HKT 2014
Completed: alter database recover managed standby database  using current logfile disconnect from session

看到成功信息后,我们可以在进行下步,在主库和备库上都要
1。创建一个standby_archivelog
mkdir -pv /home/oracle/standby_archivelog
主库上

SQL> alter system set log_archive_dest_3='location=/home/oracle/stdby_archivelog valid_for=(standby_logfile,standby_role) db_unique_name=HNDB';  

System altered.

alter database set standby database to maximize availability;

在备库日志里可以看到

Primary database is in MAXIMUM AVAILABILITY mode
Changing standby controlfile to MAXIMUM AVAILABILITY mode
Changing standby controlfile to RESYNCHRONIZATION level
Primary database is in MAXIMUM AVAILABILITY mode
Changing standby controlfile to MAXIMUM AVAILABILITY level
RFS[3]: Successfully opened standby log 4: '/home/oracle/std_log/std_redo04.log'
Fri Dec 05 08:49:11 HKT 2014
Redo Shipping Client Connected as PUBLIC
-- Connected User is Valid

或可以在主库和备库都可以查看。

SQL> select protection_mode,database_role,protection_level from v$database;

PROTECTION_MODE      DATABASE_ROLE    PROTECTION_LEVEL
-------------------- ---------------- --------------------
MAXIMUM AVAILABILITY PRIMARY          MAXIMUM AVAILABILITY


备库上的语句;

SQL> alter system set log_archive_dest_3='location=/home/oracle/stdby_archivelog valid_for=(standby_logfile,standby_role) db_unique_name=HNDB02';  

System altered.

在主库上查看
SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
TO STANDBY

说明主库已经做好切换的准备了。

在主库上做一次切换

SQL> alter database commit to switchover to physical standby with session shutdown ;

Database altered.

在备库的日志上可以看到
Redo Shipping Client Connected as PUBLIC
-- Connected User is Valid
RFS[5]: Assigned to RFS process 3388
RFS[5]: Identified database type as 'physical standby'
Fri Dec 05 09:00:53 HKT 2014
Media Recovery Log /home/oracle/stdby_archivelog1_11_865411675.dbf
Media Recovery Waiting for thread 1 sequence 12
Fri Dec 05 09:01:30 HKT 2014
Redo Shipping Client Connected as PUBLIC
-- Connected User is Valid
RFS[6]: Assigned to RFS process 3398
RFS[6]: Identified database type as 'physical standby'
RFS[6]: Archived Log: '/home/oracle/archivelog/1_12_865411675.dbf'
Redo Shipping Client Connected as PUBLIC
-- Connected User is Valid
RFS[7]: Assigned to RFS process 3400
RFS[7]: Identified database type as 'physical standby'
Fri Dec 05 09:01:33 HKT 2014
Media Recovery Log /home/oracle/archivelog/1_12_865411675.dbf
Identified End-Of-Redo for thread 1 sequence 12
Fri Dec 05 09:01:33 HKT 2014
Media Recovery End-Of-Redo indicator encountered
Fri Dec 05 09:01:33 HKT 2014
Media Recovery Applied until change 463246
Fri Dec 05 09:01:33 HKT 2014
MRP0: Media Recovery Complete: End-Of-REDO (HNDB02)
Begin: Standby Redo Logfile archival
End: Standby Redo Logfile archival
Resetting standby activation ID 686329304 (0x28e88dd8)
Fri Dec 05 09:01:35 HKT 2014
MRP0: Background Media Recovery process shutdown (HNDB02)
最后在原来主库上

SQL>shutdown immediate
SQL>startup

SQL> select protection_mode,database_role,protection_level from v$database;

PROTECTION_MODE      DATABASE_ROLE    PROTECTION_LEVEL
-------------------- ---------------- --------------------
MAXIMUM AVAILABILITY PHYSICAL STANDBY MAXIMUM AVAILABILITY

SQL> alter database recover managed standby database using current logfile disconnect from session;

Database altered.

可以看到主库此时已经成为备库了

原来的备库上查看

SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
TO PRIMARY

SQL> alter database commit to switchover to primary;

Database altered.

SQL> alter database open;

Database altered.

SQL> select protection_mode,database_role,protection_level from v$database;

PROTECTION_MODE      DATABASE_ROLE    PROTECTION_LEVEL
-------------------- ---------------- --------------------
MAXIMUM AVAILABILITY PRIMARY          MAXIMUM AVAILABILITY


在Reference里面对这两列的解释如下(10GR2)
================================================================
PROTECTION_MODE    VARCHAR2(20)    Protection mode currently in effect for the database:

    MAXIMUM PROTECTION - Database is running in maximized protection mode
    MAXIMUM AVAILABILITY - Database is running in maximized availability mode
    RESYNCHRONIZATION - Database is running in resynchronization mode
    MAXIMUM PERFORMANCE - Database is running in maximized protection mode
    UNPROTECTED - Database is unprotected (this normally occurs when the primary database is mounted and not open)

PROTECTION_LEVEL    VARCHAR2(20)    Aggregated protection mode currently in effect for the database:

    MAXIMUM PROTECTION - Database is running in maximized protection mode
    MAXIMUM AVAILABILITY - Database is running in maximized availability mode
    RESYNCHRONIZATION - Database is running in resynchronization mode
    MAXIMUM PERFORMANCE - Database is running in maximized protection mode
    UNPROTECTED - Database is unprotected (this normally occurs when the primary database is mounted and not open)

成功切换 然后再切换回去
现在的主库上 HNDB02
SQL> alter database commit to switchover to physical standby with session shutdown ;

Database altered.

SQL> shutdown immediate
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area  599785472 bytes
Fixed Size            2098112 bytes
Variable Size          163580992 bytes
Database Buffers      427819008 bytes
Redo Buffers            6287360 bytes
Database mounted.
Database opened.
SQL>  select protection_mode,database_role,protection_level from v$database;

PROTECTION_MODE      DATABASE_ROLE    PROTECTION_LEVEL
-------------------- ---------------- --------------------
MAXIMUM AVAILABILITY PHYSICAL STANDBY MAXIMUM AVAILABILITY

SQL>  alter database recover managed standby database using current logfile disconnect from session;

Database altered.

在现在的备库上HNDB上

SQL> alter database commit to switchover to primary;
 有个问题,发现数据库需要shutdown immediate 然后再startup
再查看状态

SQL> shutdown immediate
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area  599785472 bytes
Fixed Size            2098112 bytes
Variable Size          163580992 bytes
Database Buffers      427819008 bytes
Redo Buffers            6287360 bytes
Database mounted.
Database opened.

SQL> select protection_mode,database_role,protection_level from v$database;

PROTECTION_MODE      DATABASE_ROLE    PROTECTION_LEVEL
-------------------- ---------------- --------------------
MAXIMUM AVAILABILITY PRIMARY          MAXIMUM AVAILABILITY

SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
TO STANDBY
***************************************
然后再 Oracle Data Guard fast-start failover配置
   这一步是官网上建议安装的。 在另一台观察机器observer 上安装DGMGRL。就是安装一个Oracle 的客户端。 并在observer machine上配置相关的参数。包括配置监听, 使这台机器能访问主备库的实例。 然后通过这个observer来判断主备库的状态。 如果主库出现问了, 那么observer 就会切换主备库。 放在另一台机器的原因也很明显,如果放在主库上,如果主库系统崩溃了,那么Observer也就失效了。 在这个实验中,我不在单独在其他机器上安装DGMGRL命令。 我直接在备库的系统上配置这个observer.

 
***************************************
在主库上!

SQL> show parameter broke;

NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
dg_broker_config_file1             string     /u01/app/oracle/product/10.2.0
                         /db_1/dbs/dr1HNDB.dat
dg_broker_config_file2             string     /u01/app/oracle/product/10.2.0
                         /db_1/dbs/dr2HNDB.dat
dg_broker_start              boolean     FALSE
SQL> select flashback_on from v$database;

FLASHBACK_ON
------------------
NO
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  599785472 bytes
Fixed Size            2098112 bytes
Variable Size          163580992 bytes
Database Buffers      427819008 bytes
Redo Buffers            6287360 bytes
Database mounted.
SQL> alter database flashback on;

Database altered.

SQL> alter database open;

Database altered.

SQL> alter system set dg_broker_start=true;

System altered.



SQL> !

[oracle@lp admin]$ dgmgrl
DGMGRL for Linux: Version 10.2.0.5.0 - 64bit Production

Copyright (c) 2000, 2005, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.

DGMGRL> connect sys/oracle@HNDB
Connected.

DGMGRL> CREATE CONFIGURATION testbroke as PRIMARY DATABASE IS HNDB CONNECT IDENTIFIER IS  HNDB;      
Configuration "testbroke" created with primary database "hndb"
DGMGRL> add database HNDB02 as connect identifier is HNDB02  maintained as physical;
Database "hndb02" added
DGMGRL> SHOW CONFIGURATION

Configuration
  Name:                testbroke
  Enabled:             NO
  Protection Mode:     MaxAvailability
  Fast-Start Failover: DISABLED
  Databases:
    hndb   - Primary database
    hndb02 - Physical standby database

Current status for "testbroke":
DISABLED
DGMGRL> edit database HNDB02 set property LogXptMode = 'sync';
DGMGRL> edit database HNDB set property LogXptMode = 'sync';
DGMGRL> SHOW DATABASE verbose HNDB

Database
  Name:            hndb
  Role:            PRIMARY
  Enabled:         NO
  Intended State:  OFFLINE
  Instance(s):
    HNDB

  Properties:
    InitialConnectIdentifier        = 'hndb'
    ObserverConnectIdentifier       = ''
    LogXptMode                      = 'SYNC'
    Dependency                      = ''
    DelayMins                       = '0'
    Binding                         = 'OPTIONAL'
    MaxFailure                      = '0'
    MaxConnections                  = '1'
    ReopenSecs                      = '300'
    NetTimeout                      = '180'
    LogShipping                     = 'ON'
    PreferredApplyInstance          = ''
    ApplyInstanceTimeout            = '0'
    ApplyParallel                   = 'AUTO'
    StandbyFileManagement           = 'AUTO'
    ArchiveLagTarget                = '0'
    LogArchiveMaxProcesses          = '5'
    LogArchiveMinSucceedDest        = '1'
    DbFileNameConvert               = '     /u01/app/oracle/oradata/HNDB02,  /u01/app/oracle/oradata/HNDB'
    LogFileNameConvert              = ' /u01/app/oracle/oradata/HNDB02,  /u01/app/oracle/oradata/HNDB'
    FastStartFailoverTarget         = ''
    StatusReport                    = '(monitor)'
    InconsistentProperties          = '(monitor)'
    InconsistentLogXptProps         = '(monitor)'
    SendQEntries                    = '(monitor)'
    LogXptStatus                    = '(monitor)'
    RecvQEntries                    = '(monitor)'
    HostName                        = 'lp.peter.com'
    SidName                         = 'HNDB'
    LocalListenerAddress            = '(ADDRESS=(PROTOCOL=tcp)(HOST=lp.peter.com)(PORT=1521))'
    StandbyArchiveLocation          = '/home/oracle/archivelog'
    AlternateLocation               = ''
    LogArchiveTrace                 = '0'
    LogArchiveFormat                = '%t_%s_%r.dbf'
    LatestLog                       = '(monitor)'
    TopWaitEvents                   = '(monitor)'

Current status for "hndb":
DISABLED

DGMGRL> SHOW DATABASE verbose HNDB02

Database
  Name:            hndb02
  Role:            PHYSICAL STANDBY
  Enabled:         NO
  Intended State:  OFFLINE
  Instance(s):
    HNDB02

  Properties:
    InitialConnectIdentifier        = 'hndb02'
    ObserverConnectIdentifier       = ''
    LogXptMode                      = 'SYNC'
    Dependency                      = ''
    DelayMins                       = '0'
    Binding                         = 'OPTIONAL'
    MaxFailure                      = '0'
    MaxConnections                  = '1'
    ReopenSecs                      = '300'
    NetTimeout                      = '180'
    LogShipping                     = 'ON'
    PreferredApplyInstance          = ''
    ApplyInstanceTimeout            = '0'
    ApplyParallel                   = 'AUTO'
    StandbyFileManagement           = 'AUTO'
    ArchiveLagTarget                = '0'
    LogArchiveMaxProcesses          = '5'
    LogArchiveMinSucceedDest        = '1'
    DbFileNameConvert               = '     /u01/app/oracle/oradata/HNDB,  /u01/app/oracle/oradata/HNDB02'
    LogFileNameConvert              = ' /u01/app/oracle/oradata/HNDB,  /u01/app/oracle/oradata/HNDB02'
    FastStartFailoverTarget         = ''
    StatusReport                    = '(monitor)'
    InconsistentProperties          = '(monitor)'
    InconsistentLogXptProps         = '(monitor)'
    SendQEntries                    = '(monitor)'
    LogXptStatus                    = '(monitor)'
    RecvQEntries                    = '(monitor)'
    HostName                        = 'lp02.peter.com'
    SidName                         = 'HNDB02'
    LocalListenerAddress            = '(ADDRESS=(PROTOCOL=tcp)(HOST=lp02.peter.com)(PORT=1521))'
    StandbyArchiveLocation          = '/home/oracle/archivelog'
    AlternateLocation               = ''
    LogArchiveTrace                 = '0'
    LogArchiveFormat                = '%t_%s_%r.dbf'
    LatestLog                       = '(monitor)'
    TopWaitEvents                   = '(monitor)'

Current status for "hndb02":
DISABLED

DGMGRL> ENABLE CONFIGURATION;

切到从库
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  599785472 bytes
Fixed Size            2098112 bytes
Variable Size          163580992 bytes
Database Buffers      427819008 bytes
Redo Buffers            6287360 bytes
Database mounted.
SQL> alter database flashback on;

Database altered.

SQL> alter system set dg_broker_start=true;

System altered.

SQL> !
[oracle@lp02 ~]$ dgmgrl
DGMGRL for Linux: Version 10.2.0.5.0 - 64bit Production

Copyright (c) 2000, 2005, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.
DGMGRL> connect sys/oracle@HNDB02
Connected.
DGMGRL> show configuration
Error: ORA-16532: Data Guard broker configuration does not exist

Configuration details cannot be determined by DGMGRL
DGMGRL> SHOW CONFIGURATION

Configuration
  Name:                testbroke
  Enabled:             YES
  Protection Mode:     MaxAvailability
  Fast-Start Failover: DISABLED
  Databases:
    hndb   - Primary database
    hndb02 - Physical standby database

Current status for "testbroke":
Warning: ORA-16610: command 'EDIT DATABASE hndb02 SET PROPERTY' in progress


DGMGRL> START OBSERVER
Observer started

再切回主库
[oracle@lp admin]$ dgmgrl
DGMGRL for Linux: Version 10.2.0.5.0 - 64bit Production

Copyright (c) 2000, 2005, Oracle. All rights reserved.

Welcome to DGMGRL, type "help" for information.
DGMGRL> connect sys/oracle@HNDB
Connected.
DGMGRL> show database HNDB

Database
  Name:            hndb
  Role:            PRIMARY
  Enabled:         YES
  Intended State:  ONLINE
  Instance(s):
    HNDB

Current status for "hndb":
SUCCESS

DGMGRL> show database HNDB02

Database
  Name:            hndb02
  Role:            PHYSICAL STANDBY
  Enabled:         YES
  Intended State:  ONLINE
  Instance(s):
    HNDB02

Current status for "hndb02":
SUCCESS

DGMGRL> ENABLE FAST_START FAILOVER;
Enabled.
DGMGRL> show configuration

Configuration
  Name:                testbroke
  Enabled:             YES
  Protection Mode:     MaxAvailability
  Fast-Start Failover: ENABLED
  Databases:
    hndb   - Primary database
    hndb02 - Physical standby database
           - Fast-Start Failover target

Current status for "testbroke":
SUCCESS
配置到些完成
下面把主库的网络断了,看看备库是不是会自动切换到成为主库。
在主库上
su root
ifconfig eth0 down

此时在备库的日志上可以看到。
Sun Dec 07 06:58:20 HKT 2014
Attempting fast-start failover because the threshold of 30 seconds has elapsed.
Sun Dec 07 06:58:20 HKT 2014
DMON: Beginning failover
Sun Dec 07 06:58:20 HKT 2014
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH FORCE
Sun Dec 07 06:58:20 HKT 2014
Terminal Recovery: Stopping real time apply
Sun Dec 07 06:58:20 HKT 2014
MRP0: Background Media Recovery cancelled with status 16037
Sun Dec 07 06:58:20 HKT 2014
Errors in file /u01/app/oracle/admin/HNDB02/bdump/hndb02_mrp0_5171.trc:
ORA-16037: user requested cancel of managed recovery operation
Managed Standby Recovery not using Real Time Apply

在终端上可以看到以下信息,可能是我将数据直OPEN 的原因。
DGMGRL> START OBSERVER
Observer started

06:58:20.52  Sunday, December 07, 2014
Initiating fast-start failover to database "hndb02"...
Performing failover NOW, please wait...
Operation requires shutdown of instance "HNDB02" on database "hndb02"
Shutting down instance "HNDB02"...
ORA-01109: database not open

Database dismounted.
ORACLE instance shut down.
Operation requires startup of instance "HNDB02" on database "hndb02"
Starting instance "HNDB02"...
Unable to connect to database
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor

Failed.
You are no longer connected to ORACLE
Please connect again.
Unable to start instance "HNDB02"
You must start instance "HNDB02" manually
Unable to failover
07:00:01.17  Sunday, December 07, 2014
[W000 12/07 07:00:01.17] Failover failed. Quit observer.

安提示打开数据库
[oracle@lp02 ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Sun Dec 7 07:00:54 2014

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area  599785472 bytes
Fixed Size            2098112 bytes
Variable Size          163580992 bytes
Database Buffers      427819008 bytes
Redo Buffers            6287360 bytes
Database mounted.
ORA-16649: database will open after Data Guard broker has evaluated Fast-Start
Failover status
SQL> select protection_mode,database_role,protection_level from v$database;

PROTECTION_MODE      DATABASE_ROLE    PROTECTION_LEVEL
-------------------- ---------------- --------------------
MAXIMUM AVAILABILITY PRIMARY          RESYNCHRONIZATION
此时可以在数据日志里找到

ALTER SYSTEM SET log_archive_dest_state_2='RESET' SCOPE=BOTH;
FSFP started with pid=27, OS id=5316
Sun Dec 07 07:01:29 HKT 2014
Failover succeeded. Primary database is now HNDB02.

再回到原来的主库 HNDB 可以发现原来的库已经自动,shutdown 没有查到任何的实例进程。
[root@lp admin]# ifconfig eth0 down
[root@lp admin]#
[root@lp admin]# ps -ef |grep ora_
root      8117  8059  0 07:10 pts/0    00:00:00 grep ora_


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29901741/viewspace-1359673/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29901741/viewspace-1359673/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值