Archive for March, 2010
Using DBMS_SQLDIAG
As a DBA, have you ever had an issue you suspected may be a bug and have been asked to generate “test data” for Oracle development? We ran into this at a client recently and found a cool 11g utility (at least I *think* it’s new :)) to get Oracle Support the data they need to reproduce the issue in-house.
The situation had to do with optimizer_features_enable being set to 11.1.0.7 in a database recently upgraded form 9.2.0.5 in an Oracle eBusiness Suite environment (11.5.10.2) that utilized Oracle Reports heavily. Our problem was specific to a custom Report that had optimizer hints embedded in the main query. With optimizer_features_enable set to 11.1.0.7, the report retrieved no rows. With it set to 9.2.0.x or 10.2.0.x, it returned the proper number of rows. Based on this data discrepancy, we felt it safe to set optimizer_features_enable < 11.1.0.7 across the board, as we didn’t know the scope of the issue.
During our work on an SR with Oracle, they asked for us to send the query, all the versions and optimizer settings, as well as an export of all the tables involved in the query with exported optimizer statistics. Our problem was several-fold; first, the query was complex and had many embedded views, so we didn’t really want to spend time deconstructing it to get a comprehensive list of tables to export. Second, the underlying tables were very large (hundreds of millions of rows for a few of them) and we didn’t have disk space or quite frankly, time, to export all the tables in their entirety.
Enter DBMS_SQLDIAG …
Using DBMS_SQLDIAG and 11g Data Pump features, we were able to quickly generate a complete test case to export a subset of the rows from all the impacted tables, very quickly and with minimal disk space requirements. Here’s what we did:
- Grabbed the offending query from a TKPROF’d trace file
- Used this syntax to generate a test case:
declare
tc_out clob;
begin
dbms_sqldiag.export_sql_testcase(directory=>’<directory>’,
sql_text=>’<SQL Text>’,
testcase => tc_out,
exportdata=>TRUE,
samplingpercent=>1);
end;
/
In the above example, note the following:
- <directory> is a valid directory - check DBA_DIRECTORIES
- <SQL Text> is the SQL statement from the TKPROF output
- exportdata=>TRUE tells DBMS_SQLDIAG to export the data from the base tables
- samplingpercent=>1 tells Data Pump to use a 1% sampling size. This was important to limit the number of rows
After executing, a number of XML, log, and Data Pump export dumps are generated to <directory> and available to upload to the SR!
One additional step we took was to export table statistics for all the tables involved in the query. For this, we looked in the log file for all tables export and used DBMS_STATS.EXPORT_TABLE_STATS to export segment statistics.
The obvious benefit here is that it enabled us to continue working on the SR, but some other possible applications of DBMS_SQLDIAG could be for internal testing purposes, testing functionality/performance across versions of Oracle without a complicated upgrade, regression testing, and so forth.











