Wednesday, 2 October 2013

Sql Tuning and Performance

As salamo alaikum wa rahmatullah

SQL Performance Analyzer in Oracle Database 11g Release - 1

The concept of SQL tuning sets, along with the DBMS_SQLTUNE package to manupulate them, was introduced in Oracle 10g as port of the Automatic Sql Tunning functionality. Oracle 11g makes futher user of SQL tunning set with the SQL performance anlyzer, which compares the performance of the statements in tunning set before and after a database change. The database change can be as major as you like, such as:
Database, operating system, or hardware upgrades.
Database,  operating system, or hardware configuration changes.
Database initialization parameter changes.
Schema changes, such as adding indexes or materialized views.
Refreshing optimizer statistics.
Creating or changing SQL profiles.

Unlike Database Replay, the SQL Performance Analyzer does not try and replicate the workload on the system. It just plugs through each statement gathering performance statistics.

The SQL Performance Analyzer can be run manually using the DBMS_SQLPA package or using Enterprise Manager. This article gives an overview of both methods.

Setting Up the Test
Creating SQL Tuning Sets using the DBMS_SQLTUNE Package
Running the SQL Performance Analyzer using the DBMS_SQLPA Package
Creating SQL Tuning Sets using Enterprise Manager
Running the SQL Performance Analyzer using Enterprise Manager
Optimizer Upgrade Simulation
Parameter Change
Transferring SQL Tuning Sets

Setting Up the Test

The Sql Performance analyzer requires SQL tunning sets, and SQL tuning sets are pointless unless they contain SQL, so the first task should be to issue some SQL statements. We are only trying to demonstrate the technology, so the examples can be really simple. The following code creates a test user called SPA_TEST_USER.

CONNECT AS SYSDBA
Create user spa_test_user IDENTIFIED BY spa_test_user QUOTA UNLIMITED ON users;

GRANT CONNECT,CREATE TABLE TO spa_test_user;

Next, connect to the test user and create a test table called 'MY_OBJECTS' using a query from the ALL_OBJECTS view.

CONNECT spa_test_user/spa_test_user
CREATE TABLE MY_OBJECTS AS SELECT * FROM ALL_OBJECTS;
Exec DBMS_STATS.gather_table_Stats(USER,'MY_OBJECTS',cascade=>TRUE);
or EXEC DBMS_STATS.gather_table_stats('spa_test_user','MY_OBJECTS',cascade=>TRUE);

This schema represents our "before" state. Still logged in as the test user, issue the following statemtns.

SELECT COUNT(*) FROM MY_OBJECT WHERE OBJECT_ID <=100;
SELECT COUNT(*) FROM MY_OBJECT WHERE OBJECT_ID =100;
SELECT COUNT(*) FROM MY_OBJECT WHERE OBJECT_ID <=1000;
SELECT COUNT(*) FROM MY_OBJECT WHERE OBJECT_ID =1000;
SELECT COUNT(*) FROM MY_OBJECT WHERE OBJECT_ID BETWEEN 100 AND 1OOO;

Notice all statements make reference to the currently unidexed OBJECT_ID column. Later we will be indexing this column to create our changed "after" state.

The select statements are now in the shared pool, so we can start creating an SQL Tunning set.

Creating SQL Tunning Sets using DNMS_SQLTUNE Package

The DBMS_SQLTUNE package contains procedure and functions that allow us to create, manipulate and drop the SQL tunning sets. The first step is to create an SQL tunning set called spa_test_sqlset using the CREATE_SQLSET procedure.

Sql> Conn / as sysdba
Sql> EXEC DBMS_SQLTUNE.create_sqlset(sqlset_name=>'spa_test_sqlset');

Next, the SELECT_CURSOR_CACHE table function is used to retrieve a cursor containing all SQL statements that were parsed by the SPA_TEST_USER schema and contain the word "MY_OBJECTS". The resulting cursor is loaded into the the tuning test using the LOAD_SQLSET procedure.

DECLARE 
L_CURSOR DBMPS_SQLTUNE.SQLSET_CURSOR;
BEGIN
OPEN L_CURSOR FOR
SELECT VALUE(a)
FROM  TABLE (
DBMS_SQLTUNE.SELECT_CURSOR_CACHE(
BASIC_FILTER => 'SQL_TEXT LIKE ''%MY_OBJECTS'' AND PARSING_SCHEMA_NAME=''SPA_TEST_USER'', ATTRIBUTE_LIST => 'ALL')
) a;
DBMS_SQLTUNE.LOAD_SQLSET(SQLSET_NAME => 'SPA_TEST_SQLSET', POPULATE_CURSOR => L_CURSOR);
END;


The DBA_SQLSET_STATEMENTS view allows us to see which statements have been associated with the tuning set.

Select sql_text From dba_select_statements where sqlset_name ='spa_test_sqlset'

out put 
------------------


-----------------

Now we have an SQL tuning set, we can start using the SQL performance analyzer.

Running the SQL Performance Analyzer using the DBMS_SQLPA Package

The DBMS_SQLPA package is the PL/SQL API used to manage the SQL performance analyzer. The first is to create an analysis task using the CREATE_ANALYSIS_TASK function, passing in the SQL tunning set name and making a not of the resulting task name.

Conn / AS SYSDBA

VARIABLE V_TASK VARCHAR(64);
EXEC :V_TASK := DBMS_SQLPA.CREATE_ANALYSIS_TASK(SQLSET_NAEM=>'SPA_TEST_SQLSET');

PL/SQL PROCEDURE SUCCESSFULLY COMPLETED.

SQL> PRINT :V_TASK


Next, user the EXECUTE_ANALYSIS_TASK procedure to execute the contents of the SQL tunning set against the current state of the database to gather information about the performance before any modifications are made. This analysis run is named before_change.

BEGIN
DBMS_SQLPA.execute_analysis_task(
task_name => :v_task,
execution_type =>'test execute',
execution_name => 'before_change');
END;
/

Now we have the "Before" performance information, we need to make a change so we can test the "after" performance. For this example we will simply add an index to the test table on the OBJECT_ID column.
In a new SQL*PLUS session create the index using the following statements.

Conn spa_test_user/spa_test_user

CREATE INDEX my_objects_index_01 ON my_objects(object_id);

EXEC DBMS_STATS.gather_table_stats(USER,'MY_OBJECTS',cascade => TRUE);

Now, we can return to our original session and test the performance after the database change. Once again use the EXECUTE_ANALYSIS_TASK procedure, naming the analysis task "after_change".

BEGIN
DBMS_SQLPA.execute_analysis_task (
task_name => :v_task,
execution_type => 'test execute',
execution_name => 'after_change');
END;
/

Once the before and after analysis task completed, we must run a comparison analysis task. The following code explicitly names the analysis tasks to compare using name-value pairs in the EXECUTION_PARAMS parameter. If this is ommited, the latest two analysis runs are compared.

BEGIN
DBMS_SQLPA.execute_analysis_task(
task_name => :v_task,
execution_type =>'compare performance',
execution_params => dbms_advisor.arglist(
'execution_name1',
'before_change',
'execution_name2',
'after_change')
);
END;
/

With this final analysis run complete, we can check out the comparison report using REPORT_ANALYSIS_TASK function. The function returns a CLOB containing the report in TEXT, XML or HTML format.
Its usage is shown below

Note :- Oracle 11gR2 also includes an 'ACTIVE' format that looks more like the Enterprise Manager output.

SET PAGESIZE 0
SET LINESIZE 1000
SET LONG 1000000
SET LONGCHUNKSIZE 1000000
SET TRIMSPOOL ON
SET TRIM ON

SPOOL /tmp/execute_comparison_report.htm

SELECT DBMS_SQLPA.report_analysis_task(:v_task,'HTML','ALL') From dual;

SPOOL OFF

---

Mohammad Shahnawaz
Oracle's Passion

Privileges on Tablespace

As salamo alaikum wa rahmatullah,

Provide the Privileges on Tablespace.

Situation :- I have created a user by name test_user and try to create a table with big data an error is thrown by the oracle like "no privileges on tablespace system", here is step by step solution of this.

[Windows Operating System]
C:\windows\system>Sqlplus "/ as sysdba"
Sql> show user
"SYS"

sql> create user test_user identified by test_user Quota unlimited on users tablespace system;

sql> grant connect, create table to test_user;

sql>connect test_user/test_user
sql> Create table My_Table As select * from all_objects;

Oracle error -> no privileges on tablespace system.

sql> connect sys as sysdba
password : *******
sql> Alter user test_user Quota 100M On system;
sql>Grant unlimited tablespace to test_user;
sql> connect test_user/test_user
sql>Create table My_Tables AS Select * from all_objects;
Table created

--
Mohammad Shahnawaz
Oracle's Passion

Monday, 19 August 2013

Database Object for Database space usage

As salamo alaikum wa rahmatullah

DBA_TABLESPACES
DBA_SEGMENTS
DBA_EXTENTS
DBA_FREE_SPACE
DBA_LMT_FREE_SPACE
DBA_THRESHOLDS
DBA_OUTSTANDING_ALERTS
DBA_ALERT_HISTORY
V$ALERT_TYPES

-> select reason_id, object_type, scope, internal_metric_category,
internal_metric_name from v$alert_types
where group_name = 'Space';


Sample select queries.

-> select tablespace_name, block_size, contents, extent_management from dba_tablespaces;

-> select tablespace_name, count(*) NUM_OBJECTS,sum(bytes), sum(blocks), sum(extents) from dba_segments group by rollup (tablespace_name);

-> select owner, segment_name, tablespace_name,extent_id, file_id, block_id, bytes from dba_extents where segment_name = 'XXX$';

-> select tablespace_name, sum(bytes) from dba_free_space group by tablespace_name;


--
Thanks and Regards
Mohammad Shahanwaz
oracle's passion

Tuesday, 13 August 2013

Definition of AD utility

As salamo alaikum wa rahmatullah

This top containin Utilities & program code which is very frequently used by DBA’s . So where are these utilities or program in file system ? (I think you all know but for begineers its in AD_TOP/bin )

Lets see one line definition of each

AD Utility ?
AD Utilities are a group of tools designed to install, upgrade, maintain, and patch applications.

ADPATCH ?
is a utility that is used to apply individual patches, mini-packs, or maintenance packs to an Oracle Applications instance.

ADADMIN ?
AD Administration (adadmin) is used performs maintenance/administration tasks on an Oracle Appls Instance. Task associated with adadmin are divided into two broad categories database and file system task.

ADCTRL ?
Utility to determine status of worker (started by adpatch , adadmin or other ad utility) and to control ( restart/drop/skip) workers.

ADRELINK ?
Used to relink apps executables with product libraries , if some library defination is changed or executable is corrupted.

ADMRGPCH ?
To merge different patches & create single patch . This is helpful when you have too many patches , you can merge them & apply in one shot.

ADCLONE ?
Utility to clone Insatnce from Test to Prod , Vice Versa

ADCONFIG ?
To configure different components in Aplications like changing port number or domainname or incresing number of JVM’s

ADIDENT ?
utility to find version of a file in oracle applications (Identification )

ADLICMGR ?
To license a product in applications , you might have license to use only 10 products initially then later decided to use 5 more so license them first by this utility

ADSPLICE ?
You add a product in application, by default you might have 90-105 ( may be more ) products like AP, GL, AR and now oracle released one more product so add this product using this utility .

This is overview & usages of each application DBA Utility , now in next topic I will start with patching & how these utilities are used & options available with them . If you are amazed/confused whats this patching donot worry I will explain in deatil but if you are a DBA you might already be knowing patching & might have applied coupel of database patches using opatch now lets use ADPATCH to apply application or apps patches.


--
Thanking you
Mohammad Shahnawaz
oracle's passion

Monday, 12 August 2013

What are re-start file?

As salamo alaikum wa rahmatullah,


The restart files are files used by the managers or workers to restart a failed job. When a job complete the restart files are deleted, but backup files still are saved on the system with the extensions .bak, .bk2 or bk3.

The restart files are located in the $APPL_TOP/admin/<SID>/restart directory.

--
Thanks and Best Regards
Mohammad Shahnawaz
oracle's passion

Command to check the Trigger at Logon time

As salamo alaikum wa rahmatullah,
conenct / as sysdba

select owner, trigger_name from DBA_TRIGGERS

where trigerring_event like 'LOGON%'

--
Thank's and Best Regards
Mohammad Shahnawaz
Oracle's Passion

Schema registered with E-Business Suite

As salamo alaikum wa rahmatullah

You can run the following statement to see which schemas are currently registered with the Ebusiness Suite:

select distinct(upper(oracle_username)) sname
from fnd_oracle_userid a, fnd_product_installations b
where a.oracle_id = b.oracle_id
order by sname;


--
Thanks and Best Regards
Mohammad Shahnawaz
Oralce's Passion