Oracle distributes a pair of scripts in $ORACLE_HOME/rdbms/admin.
- awrextr.sql exports the AWR repository (including the ASH data), optionally for a range of AWR snapshot IDs.
- awrload.sql the export into a staging table and then moves it into the AWR repository in the current database from where you can reference it via the usual DBA_HIST% views and work with it in the usual way.
Getting Started
1. Build Oracle VirtualBox Linux VM
I use Frits Hoogland's vagrant builder to create a standard Oracle database on a Linux VM in VirtualBox. I always build the latest version of Oracle because I can import an AWR export into a higher version of the database, but not a lower one.- Frits' blog describes the basic process: A total unattended install of Linux and the Oracle database (https://fritshoogland.wordpress.com/2016/08/02/a-total-unattended-install-of-linux-and-the-oracle-database/).
- Install Vagrant on the host machine (download from https://www.vagrantup.com/).
- Download Vagrant Builder from https://gitlab.com/FritsHoogland/vagrant-builder
- Modern Oracle distributions should be downloaded Oracle Technical Resources (formerly OTN) https://www.oracle.com/technical-resources/ and put in the ansible\files directory,
- It can take less than an hour to build a new virtual box with a freshly built Oracle database at the version of your choice.
2. Make Life Easier For Yourself
I sometimes install other utilities into the virtual machine, such as git, using yum.yum install gitexport ORACLE_SID=oracle
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES3. Share a Folder on the Host Machine
I usually leave the AWR export file on my host machine rather than copy it into the virtual machine. I create a VirtualBox shared folder so that the VirtualBox VM can reference a folder on the host machine. In this case, I have shared c:\temp on my host Windows laptop and called the filesystem temp. Note that it is auto-mounted and permanent.In the VirtualBox, the shared folder has been mounted as /media/sf_temp.
[oracle@oracle-database sql]$ df /media/sf_temp
Filesystem     1K-blocks      Used Available Use% Mounted on
temp           974661916 340278844 634383072  35% /media/sf_tempusermod -G vboxsf -a oraclegrep oracle /etc/group
vboxsf:x:994:oracle[oracle@oracle-database ~]$ id
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),100(users),994(vboxsf),54322(dba)CREATE OR REPLACE DIRECTORY TEMP as '/media/sf_temp';4. Oracle FILESYSTEMIO_OPTIONS Parameter
Initially, I got the following error when trying to run a data pump import from the shared folder:ORA-39000: bad dump file specification
ORA-31640: unable to open dump file "/media/sf_temp/awrdat_xxxx_xxxx.dmp" for read
ORA-27041: unable to open file
Linux-x86_64 Error: 22: Invalid argument
Additional information: 2ALTER SYSTEM SET FILESYSTEMIO_OPTIONS=none SCOPE=SPFILE;
SHUTDOWN IMMEDIATE
STARTUP5. Data Pump Import
Now you can import an AWR export (previously exported with awrextr.sql) with the script awrload.sql.cd $ORACLE_HOME/rdbms/admin
sqlplus / as sysdba
@awrloadWorking with Imported Data
The AWR data exported from another database will be visible through all the usual database views. It can be distinguished by having the database ID of the original database. If, like me, you are used to mining ASH data with SQL scripts, then they will work if you specify the DBID. However, I have a couple of tips for working with imported AWR data.SQLDB360 (EDB360 and SQLD360)
Sometimes I run an eDB360 report on the imported data. The reports and graphs of ASH data and the system time model are particularly useful.I can generate AWR reports for any pair of snapshots in the imported repository, not just the ones generated by the client and provided to me. eDB360 generates AWR reports for peak periods by various criteria.
Having installed git, I can use it to download the latest version of SQLDB360.
cd ~/
git clone https://github.com/sqldb360/sqldb360.git
cd ~/sqldb360cd ~/
curl -LO https://github.com/sqldb360/sqldb360/archive/unstable.zip
unzip unstable.zipcol max(startup_time) format a26
col min(begin_interval_time) format a26
col max(end_interval_time) format a26
SELECT dbid, db_name, count(*), max(startup_time)
FROM   dba_hist_database_instance
GROUP BY dbid, db_name
/
SELECT dbid, min(begin_interval_time), max(end_interval_time)
FROM   dba_hist_snapshot
GROUP BY dbid
/      DBID DB_NAME     COUNT(*) MAX(STARTUP_TIME)
---------- --------- ---------- --------------------------
1884370030 ORACLE             9 20-JUN-19 10.51.50.000 AM
3743596248 XXXXXXX            4 05-MAY-19 01.03.57.000 AM
      DBID MIN(BEGIN_INTERVAL_TIME)   MAX(END_INTERVAL_TIME)
---------- -------------------------- --------------------------
1884370030 18-JUN-19 07.03.44.000 PM  20-JUN-19 11.02.49.684 AM
3743596248 18-JUN-19 05.00.13.342 PM  19-JUN-19 11.00.20.020 AM- Set the database ID with the DBID from the export.
- Specify edb360_conf_date_from/to parameters to match the range of dates in the import.
- this is a sample custom configuration requesting to produce just one section
-- for all possible DEF values please review edb360_00_config.sql
-- section to report. null means all (default)
-- report column, or section, or range of columns or range of sections i.e. 3, 3-4, 3a, 3a-4c, 3-4c, 3c-4
DEF edb360_sections = '';
-- range of dates below superceed history days when values are other than YYYY-MM-DD
-- default values YYYY-MM-DD mean: use edb360_conf_days
-- actual values sample: 2016-04-26
DEF edb360_conf_date_from = '2019-06-18';
DEF edb360_conf_date_to = '2019-06-19';
-- use if you need tool to act on a dbid stored on AWR, but that is not the current v$database.dbid
DEF edb360_config_dbid = '3743596248';@edb360 T custom_config_01.sql
@sqld360 5dcbnw1d9yfna T custom_config_01.sql- Some reports are based on v$ and x$ views or data dictionary views (DBA_TABLES etc.). These will report on the database in the virtual machine.
- Only the reports based on DBA_HIST% views will report on the database from which the AWR data was exported.
Nearly every section of the EDB360 report contains reports based on the AWR data, so it is not worth trying to exclude any sections when running EDB360 imported data.
Extracting Execution Plans from AWR
We would normally extract the execution plan of a particular statement from the AWR for the local database using the DISPLAY_AWR function in DBMS_XPLAN package as follows.SELECT * FROM table(dbms_xplan.display_awr('burz0q5qjtgmv'));SELECT * FROM table(dbms_xplan.display_awr('5dcbnw1d9yfna',db_id=>3743596248));In this case, instead of DISPLAY_AWR(), we can use the DISPLAY() function directly on the DBA_HIST_SQLPLAN view, thus:
set long 5000 lines 150 pages 999
column sql_text format a150
SELECT sql_text from dba_hist_sqltext
where dbid=3743596248 AND sql_id = '5dcbnw1d9yfna'
/
SELECT * FROM table(dbms_xplan.display(
  table_name=>'DBA_HIST_SQL_PLAN'
, format=>'ADVANCED +ADAPTIVE'
, filter_preds=>'dbid=3743596248 AND sql_id = ''5dcbnw1d9yfna'''))
/- The DBID and SQL_ID are passed as quoted literals to the function.
- DBMS_XPLAN.DISPLAY() does not report the SQL statement, so that must be queried separately.

 
 
 
 @go-faster.co.uk on BlueSky
@go-faster.co.uk on BlueSky 
 Posts
Posts
 
 
4 comments :
As it appeared, Oracle XE 18c can be used to load AWR dumps, moreover, two dumps with overlapping snapshot ranges can be load into different pluggable databases of the same container and being analyzed by some custom tools.
Yes, and you could import them into a single container with different DBIDs using Kyle Hailey's https://sites.google.com/site/oraclemonitor/change-awr-dbid script.
See: http://dboptimizer.com/2011/04/16/importing-multiple-databases-awr-repositories/.
Hi David, there is a better way to import a dump for the same DBID with overlaping snapshot ranges, just modify awrload.sql and add the parameter NEW_DBID when calling "move_to_awr": dbms_swrf_internal.move_to_awr(schname => :schname, NEW_DBID=>'12345678'). The new versions of awrload.sql (12c+) include this additional parameter.
TIP: Now we can use DBMS_XPLAN.DISPLAY_WORKLOAD_REPOSITORY instead of DBMS_XPLAN.DISPLAY_AWR. This function works with imported AWR snapshots.
Example:
set pages 4000
select *
from table (DBMS_XPLAN.DISPLAY_WORKLOAD_REPOSITORY
(sql_id => '&1'
,plan_hash_value => '&2'
,dbid => XXXXXXXXXX
,con_dbid => YYYYYYYYY
,format =>'ALL ALLSTATS LAST +OUTLINE +NOTE +PEEKED_BINDS +PROJECTION +ALIAS +COST +BYTES +PARALLEL +PARTITION +REMOTE'
,awr_location => DECODE(SYS_CONTEXT('USERENV','CON_ID'),1,'AWR_ROOT','AWR_PDB') /* AWR_ROOT or AWR_PDB */
)
);
Reference:
https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/DBMS_XPLAN.html#GUID-D416125C-FED5-4704-A371-B5EECFCE1429
Post a Comment