MAA_example01

MAA
1)comparison
@@@preview 2-nodes => 1-node rac to dataguard
@@@reference http://www.oracledba.org
primary node:
    Operation System: rhel5.4
    Oracle Version: oracle 10g => 10.2.0.1
    Shared Storage: ASM
    Oracle Home: /u01/app/oracle/product/10.2.0/db_1
              /u01/app/oracle/product/10.2.0/asm_1
        Node: station3(RDBB1) , station4(RDBB2)
    Db_name: RDBB
        Db_unique_name: RDBB
    Service Name: RDBB_SRV, RDBB
 
standby node:
    Operation System: rhel5.4
    Oracle Version: oracle 10g => 10.2.0.1
    Shared Storage: ASM
    Oracle Home: /u01/app/oracle/product/10.2.0/db_1
              /u01/app/oracle/product/10.2.0/asm_1
        Node: station5
    Db_name: RDBB
        Db_unique_name: RDBC 
    Service Name: RDBC_SRV, RDBC

1@@@@step by step
#!/bin/bash
set -x
case $1 in
1)
#primary db
#run as oracle
#care about hostname, global_dbname, ip address.
cat > $TNS_ADMIN/listener.ora <<EOF
LISTENER_STATION3 =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
      (ADDRESS = (PROTOCOL = TCP)(HOST = station3-vip.example.com)(PORT = 1521)(IP = FIRST))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.3)(PORT = 1521)(IP = FIRST))
    )
  )
#JUST FOR DATA GUARD BROKER
SID_LIST_LISTENER_STATION3 =
   ( SID_LIST =
     ( SID_DESC =
       (GLOBAL_DBNAME = RDBB )  # <== dbname.<db_domain>
       (ORACLE_HOME = /u01/app/oracle/produce/10.2.0/db_1 )
       (SID_NAME = RDBB )   
     )
   )
EOF


cat > $TNS_ADMIN/tnsnames.ora <<!
RDBB1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = station3-vip.example.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = RDBB)
      (INSTANCE_NAME = RDBB1)
    )
  )

RDBC =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = station5-vip.example.com)(PORT = 1521))
    (LOAD_BALANCE = yes)
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = RDBC)
      (FAILOVER_MODE =
        (TYPE = SELECT)
        (METHOD = BASIC)
        (RETRIES = 180)
        (DELAY = 5)
      )
    )
  )

RDBB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = station3-vip.example.com)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = station4-vip.example.com)(PORT = 1521))
    (LOAD_BALANCE = yes)
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = RDBB)
      (FAILOVER_MODE =
        (TYPE = SELECT)
        (METHOD = BASIC)
        (RETRIES = 180)
        (DELAY = 5)
      )
    )
  )

#LOCAL_LISTENER Aliases for EACH NODE.
#REMOTE_LISTENER ALIAS
#SERVICE NAME of the primary db == ORACLE_SID

LISTENER_RDBC1 =
  (ADDRESS = (PROTOCOL = TCP)(HOST = station5-vip)(PORT = 1521))


LISTENER_RDBB2 =
  (ADDRESS = (PROTOCOL = TCP)(HOST = station4-vip)(PORT = 1521))


LISTENER_RDBB1 =
  (ADDRESS = (PROTOCOL = TCP)(HOST = station3-vip)(PORT = 1521))


RDBC1 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = station5-vip.example.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = RDBC)
      (INSTANCE_NAME = RDBC1)
    )
  )

LISTENERS_RDBC =
  (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = station5-vip.example.com)(PORT = 1521))
  )

LISTENERS_RDBB =
  (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = station3-vip.example.com)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = station4-vip.example.com)(PORT = 1521))
  )

RDBC_SRV =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = station5-vip.example.com)(PORT = 1521))
    (LOAD_BALANCE = yes)
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = RDBC_SRV)
      (FAILOVER_MODE =
        (TYPE = SELECT)
        (METHOD = BASIC)
        (RETRIES = 180)
        (DELAY = 5)
      )
    )
  )

RDBB_SRV =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = station3-vip.example.com)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = station4-vip.example.com)(PORT = 1521))
    (LOAD_BALANCE = yes)
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = RDBB_SRV)
      (FAILOVER_MODE =
        (TYPE = SELECT)
        (METHOD = BASIC)
        (RETRIES = 180)
        (DELAY = 5)
      )
    )
  )

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

RDBB2 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = station4-vip.example.com)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = RDBB)
      (INSTANCE_NAME = RDBB2)
    )
  )
!

lsnrctl reload LISTENER_STATION3
scp  $TNS_ADMIN/tnsnames.ora station4:$TNS_ADMIN/tnsnames.ora
;;

2)
#primary db
#run as oracle
sqlplus /nolog<<EOF
conn / as sysdba
alter database force logging;
alter system set log_file_name_convert='+FRA/rdbc','+FRA/rdbb','+DATA/rdbc','+DATA/rdbb' scope=spfile sid='*';
alter system set db_file_name_convert='+DATA/rdbc','+DATA/rdbb' scope=spfile sid='*';

alter system set dg_broker_config_file1='+DATA/RDBB/dgbroker/dg_config_file1.dat' sid='*';
alter system set dg_broker_config_file2='+FRA/RDBB/dgbroker/dg_config_file2.dat' sid='*';
alter system set dg_broker_start=FALSE sid='*';

alter system set fal_client='RDBB1' sid='rdbb1';
alter system set fal_client='RDBB2' sid='rdbb2';
alter system set fal_server='RDBC' sid='*';

alter system set local_listener='LISTENER_RDBB1' sid='rdbb1';
alter system set local_listener='LISTENER_RDBB2' sid='rdbb2';
alter system set remote_os_authent=true scope=spfile;
alter system set remote_listener='LISTENERS_RDBB' sid='*';

alter system set log_archive_config='dg_config=(rdbb,rdbc)' sid='*';
alter system set log_archive_dest_1='location=use_db_recovery_file_dest valid_for=(online_logfiles,all_roles)     db_unique_name=rdbb' sid='*';
alter system set log_archive_dest_2='service=rdbc lgwr async valid_for=(online_logfiles,primary_role)  db_unique_name=rdbc' sid='*';
alter system set log_archive_dest_3='location=+fra/rdbb/standbylog valid_for=(standby_logfiles,standby_role) db_unique_name=rdbb' sid='*';
alter system set log_archive_dest_state_1='enable' sid='*';
alter system set log_archive_dest_state_2='defer'  sid='*';
alter system set log_archive_dest_state_3='enable' sid='*';

alter system set log_archive_max_processes=7 sid='*';
alter system set log_archive_min_succeed_dest=2 sid='*';
alter system set remote_login_passwordfile='exclusive' sid='*';
alter system set service_names='rdbb','rdbb_srv' sid='*';

alter system set standby_archive_dest='+fra/rdbb/standbylog' sid='*';
alter system set standby_file_management='auto' sid='*';
create pfile='$ORACLE_HOME/dbs/initrdbb.ora' from spfile;
EOF

export ORACLE_HOME=/u01/app/oracle/product/10.2.0/asm_1
export ORACLE_SID=+ASM1
asmcmd -p<<EOF
cd +data/rdbb
mkdir dgbroker
cd +fra/rdbb
mkdir standbylog
EOF
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export ORACLE_SID=RDBB1
scp $ORACLE_HOME/dbs/initrdbb.ora station4:$ORACLE_HOME/dbs/initrdbb.ora

;;

3)
#primary db
#run as oracle
sqlplus /nolog<<EOF
conn /as sysdba
alter system set standby_file_management=manual sid='*';
alter database  add standby logfile thread 1
group 5 size 52M,
group 6 size 52M,
group 7 size 52M;
alter database add standby logfile thread 2
group 8 size 52M,
group 9 size 52M,
group 10 size 52M;
alter system set standby_file_management=auto sid='*';
EOF
;;

4)
#primary db
srvctl stop database -d rdbb
srvctl start database -d rdbb
mkdir -p /u01/backup
rm -rf /u01/backup/*
rman target / <<EOF
run{
sql "alter system switch logfile";
allocate channel c1 type disk format '/u01/backup/Primary_bkp_for_Standby_%U';
backup database;
backup current controlfile for standby;
sql "alter system archive log current";
}

EOF
;;

5)
#primary db
cd $ORACLE_HOME/dbs
rm -rf orapwRDBB1
orapwd file=orapwRDBB1 password=oracle1 entries=5
echo $?
scp orapwRDBB1 station4:$ORACLE_HOME/dbs/orapwRDBB2
;;

6)
#standby db, run as oracle
mkdir -p /u01/backup
scp station3:/u01/backup/*   /u01/backup
scp station3:$ORACLE_HOME/dbs/initrdbb.ora  $ORACLE_HOME/dbs/initrdbc.ora
scp station3:$ORACLE_HOME/dbs/orapwRDBB1  $ORACLE_HOME/dbs/orapwRDBC1
scp station3:$TNS_ADMIN/tnsnames.ora  $TNS_ADMIN/tnsnames.ora

export ORACLE_HOME=/u01/app/oracle/product/10.2.0/asm_1
export ORACLE_SID=+ASM1
asmcmd -p<<EOF
cd +data
mkdir rdbc
cd rdbc
mkdir PARAMETERFILE
mkdir DATAFILE
mkdir TEMPFILE
mkdir ARCHIVELOG
mkdir CONTROLFILE
mkdir ONLINELOG
mkdir STANDBYLOG
mkdir DGBROKER
cd +fra/rdbc
mkdir standbylog
exit
EOF

mkdir -p /u01/app/oracle/admin/RDBC/adump
mkdir -p /u01/app/oracle/admin/RDBC/bdump
mkdir -p /u01/app/oracle/admin/RDBC/cdump
mkdir -p /u01/app/oracle/admin/RDBC/udump
mkdir -p /u01/app/oracle/admin/RDBC/script
;;

7)
#run as oracle user
#modify the initrdbc.ora manual!!!
sqlplus /nolog<<EOF
conn /as sysdba
create spfile='+DATA/rdbc/parameterfile/spfilerdbc.ora' from pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/initrdbc.ora';
startup nomount
exit
EOF
echo ""
;;

8)
#assure you could tnsping rdbb1 to node1 of primary db.
rman target sys/oracle1@rdbb1 auxiliary / <<EOF
run{
allocate channel c1 device type disk;
allocate auxiliary channel aux_1 device type disk;
duplicate target database for standby dorecover;
release channel ch1;
release channel aux_1;
}
exit
EOF

sqlplus /nolog<<EOF
conn / as sysdba;
select name from v\$controlfile;
select open_mode from v\$database;
exit
EOF
;;


9)
#standby db as oracle user
sqlplus /nolog<<EOF
conn / as sysdba
alter system set standby_file_management=manual sid='*';
alter database add standby logfile thread 1
group 11 size 52M,
group 12 size 52M,
group 13 size 52M;
alter database add standby logfile thread 2
group 14 size 52M,
group 15 size 52M,
group 16 size 52M;
alter system set standby_file_management=auto sid='*';
alter database recover managed standby database using current logfile disconnect from session;
EOF
;;

10)
set -x
#standby db as oracle or root user.
srvctl add database -d RDBC -o /u01/app/oracle/product/10.2.0/db_1 -s mount -r physical_standby
srvctl add instance -d RDBC -i rdbc1 -n station5
srvctl modify instance -d RDBC -i rdbc1 -s +ASM1
;;

11)
#standby db as oracle
sqlplus /nolog<<!
conn /as sysdba;
alter system set log_archive_dest_state_2='enable' sid='*';
!
sqlplus sys/oracle1@rdbb1 as sysdba <<EOF
alter system set log_archive_dest_state_2='enable' sid='*';
EOF
;;

12)
#run on both db.
sqlplus /nolog<<! >/home/oracle/checkmaa.txt
conn /  as sysdba
select * from v\$archive_gap;
select process, client_process, sequence#, status from v\$managed_standby;
select name, sequence#, applied from v\$archived_log order by sequence#;
select archived_thread#, archived_seq#, applied_thread#, applied_seq#
from v\$archive_dest_status;
select thread#, max (sequence#) from v\$log_history group by thread#;
select thread#, max (sequence#) from v\$archived_log where APPLIED='YES' group by thread#;
!
;;


*)
echo "Maa, dg: 2-node-rac => 1-node-rac guide"
echo "From the beginning, do 1-4 on the primary db."
echo "1) config the listener.ora and tnsnames.ora for dataguard broker as oracle user;"
echo "2) config the parameter file in primary db as oracle user;"
echo "3) add the online logfile group as oracle user;"
echo "4) backup all the file to a directory using rman as oracle user;"
echo "5) sync orapwxxx to both nodes"
echo ""
echo "From the point, do 6-11 on the standby db."
echo "6) receive all files, and create dir for duplicating db"
echo "7) create spfile from pfile in standby db.!!!!"
echo "8) startup nomount, duplicate primary db to standby db"
echo "9) create standby logfile thread 1,2 and recover db."
echo "10) add and modify the database and instance"
echo "11) enable the log_archive_dest_state_2 for both rac"
echo ""
echo "At last, run the check script"
echo "12) run the check script on standby and primary db, respectively"
;;
esac



2@@@@check
SQL> alter system switch logfile;
@@@
[oracle@station3 bdump]$ tail -f alert_RDBB1.log
.......................
Thread 1 advanced to log sequence 18
  Current log# 1 seq# 18 mem# 0: +DATA/rdbb/onlinelog/group_1.297.785370037
  Current log# 1 seq# 18 mem# 1: +FRA/rdbb/onlinelog/group_1.322.785370045
Fri Jun  8 10:24:55 2012
LNS: Standby redo logfile selected for thread 1 sequence 18 for destination LOG_ARCHIVE_DEST_2

@@@
[oracle@station5 bdump]$ tail -f alert_RDBC1.log
..................
ri Jun  8 10:25:45 2012
Redo Shipping Client Connected as PUBLIC
-- Connected User is Valid
RFS[13]: Assigned to RFS process 28089
RFS[13]: Identified database type as 'physical standby'
Fri Jun  8 10:25:46 2012
Redo Shipping Client Connected as PUBLIC
-- Connected User is Valid
RFS[14]: Assigned to RFS process 28091
RFS[14]: Identified database type as 'physical standby'
RFS[14]: Archived Log: '+FRA/rdbc/standbylog/2_6_785370037.arc'
Fri Jun  8 10:25:54 2012
Redo Shipping Client Connected as PUBLIC
-- Connected User is Valid
RFS[15]: Assigned to RFS process 28320
RFS[15]: Identified database type as 'physical standby'
RFS[15]: Archived Log: '+FRA/rdbc/standbylog/1_16_785370037.arc'
Fri Jun  8 10:25:54 2012
RFS[6]: Archived Log: '+FRA/rdbc/standbylog/1_17_785370037.arc'
Fri Jun  8 10:25:56 2012
Media Recovery Log +FRA/rdbc/standbylog/2_6_785370037.arc
Media Recovery Log +FRA/rdbc/standbylog/1_15_785370037.arc
Media Recovery Log +FRA/rdbc/standbylog/1_16_785370037.arc
Media Recovery Log +FRA/rdbc/standbylog/1_17_785370037.arc
Media Recovery Waiting for thread 2 sequence 7 (in transit)






@@@
@@@standby
[oracle@station5 ~]$ cat standby_init.ora
RDBC1.__db_cache_size=180355072
RDBC1.__java_pool_size=4194304
RDBC1.__large_pool_size=4194304
RDBC1.__shared_pool_size=88080384
RDBC1.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/RDBC/adump'
*.background_dump_dest='/u01/app/oracle/admin/RDBC/bdump'
*.cluster_database_instances=2
*.cluster_database=true
*.compatible='10.2.0.1.0'
*.control_files='+DATA/rdbc/controlfile/current.285.785392139','+FRA/rdbc/controlfile/backup.267.785392139'#Restore Controlfile
*.core_dump_dest='/u01/app/oracle/admin/RDBC/cdump'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_file_name_convert='+DATA/rdbb','+DATA/rdbc'
*.db_name='RDBB'
*.db_recovery_file_dest='+fra'
*.db_recovery_file_dest_size=2147483648
*.db_unique_name='RDBC'
*.dg_broker_config_file1='+DATA/RDBC/dgbroker/dg_config_file1.dat'
*.dg_broker_config_file2='+FRA/RDBC/dgbroker/dg_config_file2.dat'
*.dg_broker_start=FALSE
*.dispatchers='(PROTOCOL=TCP) (SERVICE=RDBCXDB)'
rdbc1.fal_client='RDBC1'
*.fal_server='RDBB'
*.global_names=TRUE
RDBC1.instance_number=1
*.job_queue_processes=10
rdbc1.local_listener='LISTENER_RDBC1'
*.log_archive_config='dg_config=(rdbb,rdbc)'
*.log_archive_dest_1='location=use_db_recovery_file_dest valid_for=(online_logfiles,all_roles)  db_unique_name=rdbc'
*.log_archive_dest_2='service=rdbc_srv lgwr async valid_for=(online_logfiles,primary_role)  db_unique_name=rdbb'
*.log_archive_dest_3='location=+fra/rdbb/standbylog valid_for=(standby_logfiles,standby_role) db_unique_name=rdbc'
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
*.log_archive_dest_state_3='enable'
*.log_archive_format='%t_%s_%r.arc'
*.log_archive_max_processes=7
*.log_archive_min_succeed_dest=2
*.log_file_name_convert='+FRA/rdbb','+FRA/rdbc','+DATA/rdbb','+DATA/rdbc'
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_listener='LISTENERS_RDBC'
*.remote_login_passwordfile='exclusive'
*.remote_os_authent=TRUE
*.service_names='rdbc','rdbc_srv'
*.sga_target=285212672
*.standby_archive_dest='+fra/rdbc/standbylog'
*.standby_file_management='AUTO'
RDBC1.thread=1
*.undo_management='AUTO'
RDBC1.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/RDBC/udump'


@@@
@@@primary db
[oracle@station3 ~]$ cat primary_init.ora
RDBB1.__db_cache_size=159383552
RDBB2.__db_cache_size=176160768
RDBB2.__java_pool_size=4194304
RDBB1.__java_pool_size=4194304
RDBB2.__large_pool_size=4194304
RDBB1.__large_pool_size=4194304
RDBB1.__shared_pool_size=109051904
RDBB2.__shared_pool_size=92274688
RDBB2.__streams_pool_size=0
RDBB1.__streams_pool_size=0
*.audit_file_dest='/u01/app/oracle/admin/RDBB/adump'
*.background_dump_dest='/u01/app/oracle/admin/RDBB/bdump'
*.cluster_database_instances=2
*.cluster_database=true
*.compatible='10.2.0.1.0'
*.control_files='+DATA/rdbb/controlfile/current.298.785370029','+FRA/rdbb/controlfile/current.323.785370031'
*.core_dump_dest='/u01/app/oracle/admin/RDBB/cdump'
*.db_block_size=8192
*.db_create_file_dest='+DATA'
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_file_name_convert='+DATA/rdbc','+DATA/rdbb'
*.db_name='RDBB'
*.db_recovery_file_dest='+fra'
*.db_recovery_file_dest_size=2147483648
*.dg_broker_config_file1='+DATA/RDBB/dgbroker/dg_config_file1.dat'
*.dg_broker_config_file2='+FRA/RDBB/dgbroker/dg_config_file2.dat'
*.dg_broker_start=FALSE
*.dispatchers='(PROTOCOL=TCP) (SERVICE=RDBBXDB)'
rdbb1.fal_client='RDBB1'
rdbb2.fal_client='RDBB2'
*.fal_server='RDBC'
*.global_names=FALSE
RDBB2.instance_number=2
RDBB1.instance_number=1
*.job_queue_processes=10
rdbb1.local_listener='LISTENER_RDBB1'
rdbb2.local_listener='LISTENER_RDBB2'
*.log_archive_config='dg_config=(rdbb,rdbc)'
*.log_archive_dest_1='location=use_db_recovery_file_dest
        valid_for=(online_logfiles,all_roles)     db_unique_name=rdbb'
*.log_archive_dest_2='service=rdbc lgwr async
    valid_for=(online_logfiles,primary_role)  db_unique_name=rdbc'
*.log_archive_dest_3='location=+fra/rdbb/standbylog
    valid_for=(standby_logfiles,standby_role) db_unique_name=rdbb'
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
*.log_archive_dest_state_3='enable'
*.log_archive_format='%t_%s_%r.dbf'
*.log_archive_max_processes=7
*.log_archive_min_succeed_dest=2
*.log_file_name_convert='+FRA/rdbc','+FRA/rdbb','+DATA/rdbc','+DATA/rdbb'
*.open_cursors=300
*.pga_aggregate_target=94371840
*.processes=150
*.remote_listener='LISTENERS_RDBB'
*.remote_login_passwordfile='exclusive'
*.remote_os_authent=TRUE
*.service_names='rdbb','rdbb_srv'
*.sga_target=285212672
*.standby_archive_dest='+fra/rdbb/standbylog'
*.standby_file_management='AUTO'
RDBB2.thread=2
RDBB1.thread=1
*.undo_management='AUTO'
RDBB2.undo_tablespace='UNDOTBS2'
RDBB1.undo_tablespace='UNDOTBS1'
*.user_dump_dest='/u01/app/oracle/admin/RDBB/udump'




你可能感兴趣的:(MAA,MAA)