Pythian Blog: Technical Track

Conventions Make for Easy Automation

I talk a lot about implementing conventions, which usually results in easy automation. Here are examples of shell scripts you can run from any host to manage the Data Guard environment. You should be able to use the same framework and extrapolate from it to meet your needs. Show Data Guard status from host1: [oracle@ol7-121-dg1 ~]$ echo $ORACLE_SID hawk [oracle@ol7-121-dg1 ~]$ /sf_working/dg_show.sh DGMGRL for Linux: Version 12.1.0.2.0 - 64bit Production Copyright (c) 2000, 2013, Oracle. All rights reserved. Welcome to DGMGRL, type "help" for information. DGMGRL> connect / Connected as SYSDG. DGMGRL> show configuration Configuration - dg_hawk Protection Mode: MaxPerformance Members: hawka - Primary database hawkb - Physical standby database Fast-Start Failover: DISABLED Configuration Status: SUCCESS (status updated 54 seconds ago) DGMGRL> show database hawka Database - hawka Role: PRIMARY Intended State: TRANSPORT-ON Instance(s): hawk Database Status: SUCCESS DGMGRL> show database hawkb Database - hawkb Role: PHYSICAL STANDBY Intended State: APPLY-ON Transport Lag: 0 seconds (computed 4 seconds ago) Apply Lag: 0 seconds (computed 4 seconds ago) Average Apply Rate: 1.00 KByte/s Real Time Query: OFF Instance(s): hawk Database Status: SUCCESS DGMGRL> exit [oracle@ol7-121-dg1 ~]$ Show Data Guard status from host2: [oracle@ol7-121-dg2 ~]$ echo $ORACLE_SID hawk [oracle@ol7-121-dg2 ~]$ /sf_working/dg_show.sh DGMGRL for Linux: Version 12.1.0.2.0 - 64bit Production Copyright (c) 2000, 2013, Oracle. All rights reserved. Welcome to DGMGRL, type "help" for information. DGMGRL> connect / Connected as SYSDG. DGMGRL> show configuration Configuration - dg_hawk Protection Mode: MaxPerformance Members: hawka - Primary database hawkb - Physical standby database Fast-Start Failover: DISABLED Configuration Status: SUCCESS (status updated 18 seconds ago) DGMGRL> show database hawka Database - hawka Role: PRIMARY Intended State: TRANSPORT-ON Instance(s): hawk Database Status: SUCCESS DGMGRL> show database hawkb Database - hawkb Role: PHYSICAL STANDBY Intended State: APPLY-ON Transport Lag: 0 seconds (computed 3 seconds ago) Apply Lag: 0 seconds (computed 3 seconds ago) Average Apply Rate: 1.00 KByte/s Real Time Query: OFF Instance(s): hawk Database Status: SUCCESS DGMGRL> exit [oracle@ol7-121-dg2 ~]$ Stop Transport from host1: [oracle@ol7-121-dg1 ~]$ /sf_working/dg_transport_on_off.sh /sf_working/dg_transport_on_off.sh: line 4: 2: ---> USAGE: /sf_working/dg_transport_on_off.sh ORACLE_UNQNAME <ON|OFF> [oracle@ol7-121-dg1 ~]$ /sf_working/dg_transport_on_off.sh hawka off DGMGRL for Linux: Version 12.1.0.2.0 - 64bit Production Copyright (c) 2000, 2013, Oracle. All rights reserved. Welcome to DGMGRL, type "help" for information. DGMGRL> connect / Connected as SYSDG. DGMGRL> show configuration Configuration - dg_hawk Protection Mode: MaxPerformance Members: hawka - Primary database hawkb - Physical standby database Fast-Start Failover: DISABLED Configuration Status: SUCCESS (status updated 10 seconds ago) DGMGRL> edit database hawka set state=TRANSPORT-off; Succeeded. DGMGRL> show database hawka Database - hawka Role: PRIMARY Intended State: TRANSPORT-OFF Instance(s): hawk Database Status: SUCCESS DGMGRL> exit [oracle@ol7-121-dg1 ~]$ Start Transport from host2: [oracle@ol7-121-dg2 ~]$ /sf_working/dg_transport_on_off.sh hawka on DGMGRL for Linux: Version 12.1.0.2.0 - 64bit Production Copyright (c) 2000, 2013, Oracle. All rights reserved. Welcome to DGMGRL, type "help" for information. DGMGRL> connect / Connected as SYSDG. DGMGRL> show configuration Configuration - dg_hawk Protection Mode: MaxPerformance Members: hawka - Primary database hawkb - Physical standby database Fast-Start Failover: DISABLED Configuration Status: SUCCESS (status updated 36 seconds ago) DGMGRL> edit database hawkb set state=TRANSPORT-on; Error: ORA-16516: current state is invalid for the attempted operation Failed. DGMGRL> show database hawkb Database - hawkb Role: PHYSICAL STANDBY Intended State: APPLY-ON Transport Lag: 0 seconds (computed 15 seconds ago) Apply Lag: 0 seconds (computed 15 seconds ago) Average Apply Rate: 1.00 KByte/s Real Time Query: OFF Instance(s): hawk Database Status: SUCCESS DGMGRL> exit [oracle@ol7-121-dg2 ~]$ dg_show.sh
#!/bin/bash -e
 check_dg()
 {
  dgmgrl -echo << EOF
  connect /
  show configuration
  show database ${ORACLE_SID}a
  show database ${ORACLE_SID}b
  exit
 EOF
 }
 check_dg
 exit
dg_transport_on_off.sh
#!/bin/bash -e
 DN=`dirname $0`
 BN=`basename $0`
 ST=${2:?"---> USAGE: $DN/$BN ORACLE_UNQNAME <ON|OFF>"}
 check_dg()
 {
  dgmgrl -echo << EOF
  connect /
  show configuration
  edit database ${ORACLE_UNQNAME} set state=TRANSPORT-${ST};
  show database ${ORACLE_UNQNAME}
  exit
 EOF
 }
 check_dg
 exit
 
Conclusions? None necessary :=)

No Comments Yet

Let us know what you think

Subscribe by email