Skip to content

Commit a534126

Browse files
authored
Merge pull request oracle-samples#86 from nigelbayliss/master
RWPG subdirectory - AWR example
2 parents 692ebe6 + 7ef601a commit a534126

File tree

3 files changed

+578
-0
lines changed

3 files changed

+578
-0
lines changed

optimizer/RWPG/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This is an area for Oracle's Real World Performance Group!
2+
3+
* Generating AWR or ASH reports using Oracle Client
4+
5+
DISCLAIMER:
6+
<br/>-- These scripts are provided for educational purposes only.
7+
<br/>-- They are NOT supported by Oracle World Wide Technical Support.
8+
<br/>-- The scripts have been tested and they appear to work as intended.

optimizer/RWPG/awr/README.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
## Generating AWR or ASH reports using Oracle Client
2+
3+
When you are using a database client environment that only has an Oracle Client installation such as Instant Client, there is no immediate way to create awr or ash reports as the usual scripts in rdbms/admin under ORACLE_HOME in a full database installation aren't available. Often, however, you do have the possibility to connect using sqlplus to a database using a login that provides access to one or more awr repositories. If that is the case, you can create awr and ash reports using the dbms_workload_repository package. Doing so, however, requires you to first query the repository for existing databases, instances and snapshots. This is effectively what the scripts like awrrpt.sql in rdbms/admin do.
4+
5+
We have packed up this whole process in a single shell script that is using sqlplus to do the actual work.
6+
7+
## Download and install of the "awr.sh" shell script
8+
9+
The script is a single, self-contained shell script. You simply download it and put it somewhere in your PATH. If you e.g. are using Instant Client, put it the same place where you have sqlplus.
10+
11+
## Requirements
12+
13+
Your environment variables need to be configured to allow database connections using sqlplus. Also, you will need to be able to connect to a database that holds an awr repository; if you connect using sqlplus, verify by running a query against dba_hist_snapshot.
14+
15+
For the rest of this readme, it assumed that this is possible using system/manager@//awrhost/awr; you need to replace this with credentials to your database. An example usage of the script is to generate awr and ash reports from an ATP or ADW database, where you do not have access to the server. These cloud databases will be created with a user called "admin" and a password specified when you created the database using the cloud console. From the cloud console you can also get connect strings and download sqlnet wallets. Once the wallet is installed in your client environment, you will have access to the admin account using a connection like admin/MyChosenPassword@database_tp which is what you must provide using the -a option of the awr.sh script.
16+
17+
## Usage
18+
19+
Simply call the script without any arguments to get a brief usage:
20+
21+
```
22+
qry usage: awr.sh [-h] -a awrrep [-d dbid] [-i inst#] [-f tstm] [-u/t tstm]
23+
awr usage: awr.sh -a awrrep -d dbid -i inst# bsnap esnap file/dir
24+
ash usage: awr.sh -a awrrep -d dbid -i inst# btime etime swidth file/dir
25+
```
26+
27+
28+
As the output shows, the script really has three modes - a query mode used to provide information about available databases, instances and snapshots in the repository, and two generation modes to actually create an awr or an ash. The query mode is used when the last three or four arguments (bsnap esnap file, btime etime swidth file) are not provided.
29+
30+
Typing only the -h option, gives you a more detailed help:
31+
32+
```
33+
-a awrrep : specify username/password@cstring for awr repository
34+
-d dbid : list snapshots for only this database
35+
-i inst# : list snapshots for only this instance
36+
-f tstm : limit listing from this timestamp
37+
-u tstm : limit listing until this timestamp
38+
-t tstm : limit listing to this timestamp
39+
40+
-a is compulsory
41+
42+
If -d is not specified, list all available databases
43+
If only -d is specified, list first/last snapshots for that database
44+
45+
Format for timestamps are YYYY.MM.DDTHH24:MI, i.e. with "T" to
46+
separate date from time, and with time in minute resolution
47+
48+
If -d and one or more of -i -f, -u/t are specified,
49+
list all snapshots matching -i, -f, -u/t
50+
The -u and -t options have identical purpose
51+
52+
If -d, -i and exactly three arguments are specified
53+
generate awr for the chosen database and instance
54+
covering the snapshot interval from bsnap to esnap
55+
and write to the named file.
56+
57+
If -d, -i and exactly four arguments are specified
58+
generate ash for the chosen database and instance
59+
covering the time interval from btime to etime
60+
with ash slots every swidth seconds and write to the
61+
named file.
62+
63+
If the name of a directory is provided, an html formatted
64+
file will be created named dbid_inst_bsnap_esnap.html
65+
for awr or dbid_inst_btime_etime.html for ash
66+
```
67+
68+
The options and their arguments must be put in the order shown and the -a option with its argument being the full connect string to your repository database must always be provided. The various useful combinations of -d, -i, -f and -u are mentioned below.
69+
70+
## Query mode
71+
72+
To get a brief listing of all available databases in the repository, only give the -a option:
73+
74+
```
75+
awr.sh -a system/manager@//awrhost/awr
76+
77+
DBID C SCOUNT INST_LIST
78+
---------- - ---------- --------------------------------------------------
79+
8521111 353 1
80+
20190404 280 1,2
81+
40763195 18 1,2
82+
169739606 67 1
83+
186457481 25 1
84+
222390028 12 1
85+
283265821 208 1
86+
313070952 1701 1,2,3,4,5,6,7
87+
```
88+
89+
This shows a list of all databases, the total number of snapshots for each, and the list of instances. The second column (C) will have a value if the database is your own database and it is either not a pdb (N), is a pdb (P) or is the root of a PDB (/). A sample output is this:
90+
91+
```
92+
DBID C SCOUNT INST_LIST
93+
---------- - ---------- --------------------------------------------------
94+
3370815010 P 1558 2,3,6,7,8
95+
3951758934 / 1597 1,2,3,4,5,6,7,8
96+
```
97+
98+
which shows that the first database is a PDB that has snapshots generated for instances 2,3,6,7,8 and the the second database is the root and that it has snapshots generated on all instances 1 until 8.
99+
100+
Next, you many want details about a specific database, which is done by providing the DBID of that database using the -d option:
101+
102+
```
103+
awr.sh -a system/manager@//awrhost/awr -d 40763195
104+
105+
INST MIN_SNAP MAX_SNAP SCOUNT MIN_TIME MAX_TIME
106+
----- ---------- ---------- ---------- ------------------ ------------------
107+
1 11167 11175 9 2018.10.19T06:00 2018.10.19T10:00
108+
2 11167 11175 9 2018.10.19T06:00 2018.10.19T10:00
109+
```
110+
111+
For each instance, the first and last snapshot ID, the number of snapshots and the snapshot time of those first/last snapshots are shown. Note that the time is with minute resolution and the there is a letter "T" to separate date part and time part. If you want to see all snapshots available for some instance of your chosen database, specify both -d and -i:
112+
113+
```
114+
awr.sh -a system/manager@//awrhost/awr -d 40763195 -i 2
115+
116+
INST SNAP_ID SNAP_TIME
117+
----- ---------- --------------------
118+
2 11167 2018.10.19T06:00
119+
2 11168 2018.10.19T06:30
120+
2 11169 2018.10.19T07:00
121+
2 11170 2018.10.19T07:30
122+
2 11171 2018.10.19T08:00
123+
2 11172 2018.10.19T08:30
124+
2 11173 2018.10.19T09:00
125+
2 11174 2018.10.19T09:30
126+
2 11175 2018.10.19T10:00
127+
```
128+
129+
In this case, there are only 7 snapshots, if the list is longer, you can chose a part of it by specifying either or both of the -f and -u option. They both take timestamps in the format shown in the list and specify respectively the first (-f means "from") and/or the last (-u mean "until") timestamp wanted. Here is just one example:
130+
131+
```
132+
awr.sh -a system/manager@//awrhost/awr -d 40763195 -i 2 -f 2018.10.19T07 -u 2018.10.19T09
133+
134+
INST SNAP_ID SNAP_TIME
135+
----- ---------- --------------------
136+
2 11169 2018.10.19T07:00
137+
2 11170 2018.10.19T07:30
138+
2 11171 2018.10.19T08:00
139+
2 11172 2018.10.19T08:30
140+
2 11173 2018.10.19T09:00
141+
```
142+
143+
You can also use either of -f and/or -u without -i in which case snapshot id's for all instances within the limits of -f and/or -u are listed. Note that you don't actually need to include the minute part in the timestamps, you can also exclude T and the hour/minute. Using only -f and a date a few days before current date is somewhat similar to what the usual scripts in rdbms/admin can do.
144+
145+
If you want to list all snapshots for all instances of some database, use an until date in the future or a very early from date such as -f 1314:03:18 which means to show everything after the day Jacque de Molay was burned to death. If you find out why that particular date is interesting for me, I'll buy you a beer next time we meet.
146+
147+
## Awr creation mode
148+
149+
Once you know the dbid, instance number and the snapshot id's you are interested in for your awr, the script must be called with both -d and -i options and then with exactly three arguments being respectively the begin snapshot id, end snapshot id, and the file name where the awr report will be put.; the latter can include a directory part.
150+
151+
From the above, you can e.g. do:
152+
153+
```
154+
awr.sh -a system/manager@//awrhost/awr -d 40763195 -i 2 11170 11172 myawr.txt
155+
```
156+
157+
which will create a file named myawr.txt that contains a text format awr for the given database and instance over the snapshot interval 11170 until 11172. If the name of the file has suffix .htm or .html, an html formated awr will be created; if the file name has no suffix, .html will be added. If there are errors during creation of the awr, these will be shown as shown here:
158+
159+
```
160+
awr.sh -a system/manager@//awrhost/awr -d 40763195 -i 2 11170 21172 myawr.html
161+
select * from table(dbms_workload_repository.awr_report_text(40763195,2,11170,21172))
162+
*
163+
ERROR at line 1:
164+
ORA-20019: 21172 is not a valid snapshot ID.
165+
ORA-06512: at "SYS.DBMS_SWRF_REPORT_INTERNAL", line 17518
166+
ORA-06512: at "SYS.DBMS_SWRF_REPORT_INTERNAL", line 3129
167+
ORA-06512: at "SYS.DBMS_WORKLOAD_REPOSITORY", line 1204
168+
ORA-06512: at line 1
169+
```
170+
171+
## Ash creation mode
172+
173+
Once you know the dbid and the instance number for which you are interested in an ash, call the script with those provided as -d and -i arguments and then subsequently exactly four arguments being respectively begin and end time, the slot width in seconds and the name of a file or directory, where the ash will be put. As an example, if you execute
174+
175+
```
176+
awr.sh -a system/manager@//awrhost/awr -d 2376680015 -i 3 2019.12.03T11:00 2019.12.03T12:00 60 ash11to12.html
177+
```
178+
179+
an ash report covering the interval from 11:00 until 12:00 on 3-Dec-2019 with activity over time slots every 60 seconds will be put in the file specified as the last argument.

0 commit comments

Comments
 (0)