0% found this document useful (0 votes)
19 views

Practice 6 Monitoring Data Guard Configuration

Uploaded by

Pavan Raghu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Practice 6 Monitoring Data Guard Configuration

Uploaded by

Pavan Raghu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Practice 6: Monitoring Data Guard Configuration | page: 1

Practice Monitoring Data Guard Configuration


Title

Purpose In this practice we will demonstrate how to use the tools to monitor a Data
Guard configuration.

Software Oracle database version 12.1.0.2 on Oracle Linux 6.7 64-bit.


version

Document 1.1, Aug-2016


version

Required Script Files


Software
Script files can be downloaded from the lecture resources.
/ Files

SQL Developer
SQL Developer will be used to run the SQL commands in this practice. It can
be downloaded from the following link:
http://www.oracle.com/technetwork/developer-tools/sql-
developer/overview/index.html

VirtualBox Appliance
The practice has been implemented on an Oracle virtual appliances that have
been in practice number 3. We named that practice “Practice 3 Configure the
Broker”.

Hardware No major changes will be performed on the appliance. Therefore, it is not


necessary to make a copy of the appliance files used in this practice.

The Environment Architecture


It is the same as the practice number 3. It was a Data Guard configuration with a primary
database and a physical standby database managed by the Broker.

Oracle 12c Data Guard Administration Course by Ahmed Baraka


Practice 6: Monitoring Data Guard Configuration | page: 2

Data Guard Configuration Specifications

Protection Mode Maximum Performance

fast-start failover Disabled

The management interface Broker

Standby Database Type Physical Standby

Standby Database Unique Name ORADB_S2

Standby Database Hostname srv2

Oracle 12c Data Guard Administration Course by Ahmed Baraka


Practice 6: Monitoring Data Guard Configuration | page: 3

The Practice Overview


Prepare the Practice Environment
 We will work on the appliances that we created in the practice number 3. No
need to take a copy of them.

Study the Monitoring Tools


You will do the following in this practice:

 Simulate sample work load on the primary database. You will create the scripts
that will be used to apply simple DML load operations on the Data Guard
configuration.
 Use the monitoring tools that you learnt about in the lecture.
 Simulate an outage of the apply process in the standby database and study how
the output of our tools will be different.

Oracle 12c Data Guard Administration Course by Ahmed Baraka


Practice 6: Monitoring Data Guard Configuration | page: 4

Practice Procedure

Get the Environment Ready

1. In VirtualBox open the two appliances in the folder “Practice 3 Configure the Broker”

2. Start the appliances then start the databases and make sure they are available.

3. Verify the Broker configuration is enabled


dgmgrl sys/oracle@oradb
show configuration
show database oradb
show database oradb_s2
edit database oradb_s2 set state=apply-on;

Oracle 12c Data Guard Administration Course by Ahmed Baraka


Practice 6: Monitoring Data Guard Configuration | page: 5

Create Loading Scripts

4. Create a table that will be used for our testing case.


sqlplus sys/oracle@oradb as sysdba
alter user hr identified by oracle ;
alter user hr account unlock ;

connect hr/oracle@oradb

CREATE TABLE hr.NAMES


( ID NUMBER , NAME VARCHAR2(50), HDATE DATE, SAL NUMBER, REGION VARCHAR2(1));

CREATE SEQUENCE S cache 1000;

5. We will create a package that has two procedures. One will insert some random testing data into
the NAMES table and one will apply random DML (INSERT, UPDATE, or DELETE) operations
against the NAMES table.
Note: You can download the script files from the lecture resources.
/* Create Random Load Package */
CREATE OR REPLACE PACKAGE LOAD_GENERATOR
IS
-- insert random rows in NAMES table
PROCEDURE INSERT_NAMES ( P_ROWS IN NUMBER);
-- random DML on NAMES
PROCEDURE RandomDML(P_ITERATION IN NUMBER, P_MAX IN NUMBER);
END load_generator;
/

CREATE OR REPLACE PACKAGE Body LOAD_GENERATOR


IS
-- generate random text: its lengnth between 4 and the passed value
FUNCTION G_TEXT(P_SIZE IN NUMBER) RETURN VARCHAR2
IS
V VARCHAR2(2000);
BEGIN
FOR I IN 1..DBMS_RANDOM.VALUE(4,P_SIZE) LOOP
V := V || CHR(ROUND(DBMS_RANDOM.VALUE(65,90))); -- 122
END LOOP;
RETURN V;
END;

PROCEDURE INSERT_NAMES ( P_ROWS IN NUMBER)


IS
V1 VARCHAR2(15);
V2 VARCHAR2(15);
BEGIN
FOR I IN 1..P_ROWS LOOP
V1 := G_TEXT(15);
V2 := G_TEXT(15);
INSERT INTO NAMES VALUES ( S.NEXTVAL, -- ID
V1 || ' ' || V2, -- NAME

Oracle 12c Data Guard Administration Course by Ahmed Baraka


Practice 6: Monitoring Data Guard Configuration | page: 6

TRUNC(SYSDATE-DBMS_RANDOM.VALUE(60,1800)), -- HDATE
ROUND(DBMS_RANDOM.VALUE(1000,55000)), -- SAL
DECODE( TO_CHAR(ROUND(DBMS_RANDOM.VALUE(1,4))), '1','N','2','W','3','E','4','S') );
-- REGION
IF MOD(I,100) = 0 THEN
COMMIT;
END IF;
END LOOP;
COMMIT;
END INSERT_NAMES;

PROCEDURE RandomDML(P_ITERATION IN NUMBER, P_MAX IN NUMBER)


IS
N NUMBER;
M NUMBER;
V_NEW_SAL NUMBER;
V1 VARCHAR2(15);
V2 VARCHAR2(15);
BEGIN
FOR I IN 1.. P_ITERATION LOOP
N := ROUND(DBMS_RANDOM.VALUE(1,3));
IF N=1 THEN
V1 := G_TEXT(15);
V2 := G_TEXT(15);
INSERT INTO NAMES VALUES ( S.NEXTVAL, -- ID
V1 || ' ' || V2, -- NAME
TRUNC(SYSDATE)-DBMS_RANDOM.VALUE(60,1800), -- HDATE
ROUND(DBMS_RANDOM.VALUE(1000,55000)), -- SAL
DECODE( TO_CHAR(ROUND(DBMS_RANDOM.VALUE(1,4))), '1','N','2','W','3','E','4','S') );
-- REGION
ELSIF N=2 THEN
M := ROUND(DBMS_RANDOM.VALUE(1,P_MAX));
V_NEW_SAL := ROUND(DBMS_RANDOM.VALUE(1000,55000));
UPDATE NAMES SET SAL = V_NEW_SAL
WHERE ID = M;
ELSIF N=3 THEN
M := ROUND(DBMS_RANDOM.VALUE(1,P_MAX));
DELETE NAMES WHERE ID = M;
END IF;
-- DBMS_LOCK.SLEEP(ROUND(DBMS_RANDOM.VALUE(0.1,2),2));
COMMIT;
END LOOP;
END RandomDML;
END load_generator;
/

6. Use the INSERT_NAMES procedure to insert some sample data into the NAMES table.
-- load 10000 rows in names table
execute load_generator.insert_names(10000);

7. Create loaddml.sql script:

mkdir scripts
cd scripts

Oracle 12c Data Guard Administration Course by Ahmed Baraka


Practice 6: Monitoring Data Guard Configuration | page: 7

vi loaddml.sql
begin
hr.LOAD_GENERATOR.RANDOMDML (&1, &2);
end;
/

8. Create loaddml.sh shell script as follows. This script accepts three arguments, number of
connections, number of iterations, and number for rows.
vi loaddml.sh
chmod +x loaddml.sh

#!/bin/bash
# apply random DML load on Oracle DB
# parameters: 1 connections, 2 Iterations, 3 rows in names
users=$1
SRVC="oradb"
UNPW="hr/oracle"
SQLCMD="/home/oracle/scripts/loaddml.sql"
x=1
y=$users
ITER=$2
MAX=$3

while [ $x -le $y ]
do
sqlplus -s $UNPW@$SRVC @$SQLCMD $ITER $MAX &
x=`expr $x + 1`
done

9. Test the script. Press [ENTER] after you run it.


# 5 connections 2000 iterations 100000 number of rows in NAMES table
./loaddml.sh 5 2000 100000

# to list the number of sqlplus that are running in the system:


ps -C "sqlplus -s" | wc -l

Oracle 12c Data Guard Administration Course by Ahmed Baraka


Practice 6: Monitoring Data Guard Configuration | page: 8

Use the Monitoring Tools

We will use SQL Developer to run the SQL commands that will be used to monitor our Data Guard
configuration.

10. Launch SQL Developer and make two connections. One to the primary database and one to the
standby database.

Note: if you want to make the editor font bigger, go to Tools menu -> User Preferances

11. Display the Data Guard related messages in the alert log file. Run the following script and
observe the output.
Tip: you can [Ctl]+[Enter] to run the statement on which the cursor is on.
ALTER SESSION SET NLS_DATE_FORMAT='DD-Mon-RR HH12:MI AM';
ALTER SESSION SET NLS_DATE_LANGUAGE=AMERICAN;

SELECT FACILITY, ERROR_CODE, TIMESTAMP, MESSAGE


FROM V$DATAGUARD_STATUS
WHERE TRUNC(TIMESTAMP)= TRUNC(SYSTIMESTAMP)
ORDER BY TIMESTAMP;

12. Check if there is any redo log gap. This should be run from the standby database.
SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE#
FROM V$ARCHIVE_GAP;

13. The following script is another way to check if there is any redo log gap, from the primary
database:
SELECT MAX(SEQUENCE#), THREAD#
FROM V$ARCHIVED_LOG
WHERE RESETLOGS_CHANGE# = (SELECT MAX(RESETLOGS_CHANGE#) FROM V$ARCHIVED_LOG)
GROUP BY THREAD#;

SELECT DESTINATION, STATUS, ARCHIVED_THREAD#, ARCHIVED_SEQ#


FROM V$ARCHIVE_DEST_STATUS WHERE STATUS <> 'DEFERRED' AND STATUS <> 'INACTIVE';

Oracle 12c Data Guard Administration Course by Ahmed Baraka


Practice 6: Monitoring Data Guard Configuration | page: 9

14. In the standby database, examine the transport and apply lag statistics. Run the following
script:
ALTER SESSION SET NLS_DATE_FORMAT='DD-Mon-RR HH12:MI AM';
ALTER SESSION SET NLS_DATE_LANGUAGE=AMERICAN;

SELECT NAME, VALUE, UNIT, TIME_COMPUTED


FROM V$DATAGUARD_STATS
WHERE NAME IN ('transport lag','apply lag','apply finish time');

15. Simulate an outage in the apply process. Do that by simply stopping the process in the dgmgrl.
You can do that in the standby putty session window.
dgmgrl sys/oracle@oradb
edit database oradb_s2 set state=apply-off;

16. Apply some load on the primary database.


./loaddml.sh 5 2000 100000

17. In the standby database, examine again the apply lag statistics.

18. In the dgmgrl command prompt, issue the following command and observe the statistics:
SHOW DATABASE oradb_s2

19. Start the apply process


edit database oradb_s2 set state=apply-on;

20. In the standby database, examine again the apply lag statistics.

21. Obtain the active apply rate. Run the following command in the standby database:
SELECT START_TIME , ITEM, SOFAR || ' ' || UNITS Sofar
FROM V$RECOVERY_PROGRESS
WHERE ITEM IN ('Active Apply Rate', 'Average Apply Rate', 'Redo Applied');

22. In the dgmgrl command prompt, issue the following command and observe the statistics:
SHOW DATABASE oradb_s2

23. Using the Broker check if any archived redo log has not been sent to the standby database.

Note: I had to increase the width of the Putty window to maximum to properly observe the output.

If the STATUS column is ARCHIVED, this means the archived redo log file has not been sent to the
standby database. If it is CURRENT, it means the current online redo log file is being read and therefore
all the archived redo log files have been sent.
SHOW DATABASE oradb SendQEntries

24. Check if there is any archive log file received by the standby database but not applied:
SHOW DATABASE oradb_s2 RECVQENTRIES

Oracle 12c Data Guard Administration Course by Ahmed Baraka


Practice 6: Monitoring Data Guard Configuration | page: 10

25. In the standby database, list the processes that are running as part of the Data Guard
configuration and check out their operations:
SELECT PID, PROCESS, STATUS, CLIENT_PROCESS, CLIENT_PID, THREAD#, SEQUENCE# SEQ#, BLOCK#,
BLOCKS
FROM V$MANAGED_STANDBY
ORDER BY PROCESS;

Oracle 12c Data Guard Administration Course by Ahmed Baraka


Practice 6: Monitoring Data Guard Configuration | page: 11

Notes

Deleting Arched Redo Log Files in the Primary database


 Many archived redo log files must have been generated as part of the actions that we have
performed in this practice. To utilize the disk space, I would delete them using rman in the primary
database. The delete archivelog command will not delete an archived redo log file, if the file
has not been transported to all mandatory standby databases.
rman target /
delete archivelog all;

Note: if there is a file that has not been transported yet to the standby database, the file will not be
deleted and you will receive a warning message.

Shutting Down the Broker Configuration Members


 Stop the Broker configuration members:
EDIT DATABASE oradb_s2 SET STATE=APPLY-OFF;

 Close the SQL Developer

 Shutdown the databases and then the appliances

Oracle 12c Data Guard Administration Course by Ahmed Baraka

You might also like