Tuesday, November 3, 2015

Execution Plan and Statistics


http://nimishgarg.blogspot.ae/2015/09/how-to-get-execution-plan-and.html



How do you check EXECUTION PLAN of a QUERY? I got this question on my facebook chat many times. "EXPLAIN PLANE" The answer was quite simple, Right? Actually it depends on what I am looking for. "AUTOT TRACE" is my personal favourite but I use one of the following depending on various situations.
1) EXPLAIN PLAN
2) AUTOT TRACE
3) DBMS_XPLAN.DISPLAY_CURSOR
4) SQL TRACE (10046)and TKPROF

Lets execute them to have an idea on how these methods are different and what information one provides and other doesn't.

1) EXPLAIN PLAN (basic and simple)
SQL> explain plan for select * from dual;
Explained.

SQL> SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY());

PLAN_TABLE_OUTPUT
----------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost  |
----------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     1 |     2 |     2 |
|   1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     2 |
----------------------------------------------------------
Note
-----
   - 'PLAN_TABLE' is old version

11 rows selected.


2) AUTOT TRACE (PLAN + STATS)
SQL> set autot trace
SQL> select * from dual;

Execution Plan
----------------------------------------------------------

----------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost  |
----------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     1 |     2 |     2 |
|   1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     2 |
----------------------------------------------------------
Note
-----
   - 'PLAN_TABLE' is old version

Statistics
----------------------------------------------------------
         25  recursive calls
         13  db block gets
         34  consistent gets
          1  physical reads
       3060  redo size
        208  bytes sent via SQL*Net to client
        362  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed


3) DBMS_XPLAN.DISPLAY_CURSOR (PLAN + OTHER DETAILS)
SQL> SELECT * FROM DUAL;
D
-
X

SQL> SELECT SQL_ID FROM V$SQL WHERE SQL_TEXT LIKE 'SELECT * FROM DUAL%';
SQL_ID
-------------
9g6pyx7qz035v

SQL> select * from table(dbms_xplan.display_cursor('9g6pyx7qz035v',NULL,'ADVANCED'));
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------
SQL_ID  9g6pyx7qz035v, child number 0
-------------------------------------
SELECT * FROM DUAL

Plan hash value: 3543395131
--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |       |       |     2 (100)|          |
|   1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     2   (0)| 00:00:01 |

PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------

Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1 / DUAL@SEL$1

Outline Data
-------------
  /*+
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------
      BEGIN_OUTLINE_DATA
      IGNORE_OPTIM_EMBEDDED_HINTS
      OPTIMIZER_FEATURES_ENABLE('11.2.0.3')
      DB_VERSION('11.2.0.3')
      ALL_ROWS
      OUTLINE_LEAF(@"SEL$1")
      FULL(@"SEL$1" "DUAL"@"SEL$1")
      END_OUTLINE_DATA
  */

Column Projection Information (identified by operation id):

PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------
   1 - "DUAL"."DUMMY"[VARCHAR2,1]

Note
-----
   - SQL plan baseline SQL_PLAN_c7fbanxudy9yvef6f73b0 used for this statement

41 rows selected.


4) SQL TRACE (10046)and TKPROF
Click here to know how to generate trace files and execute TKPROF in simple steps.
http://nimishgarg.blogspot.com/2010/10/oracle-tkprof-simple-steps.html

Tuesday, March 31, 2015

How To Install and manage Java JDK on Oracle Linux



taken from :
http://lorenzkeller.blogspot.ae/2015/01/how-to-install-and-manage-java-jdk-on.html


Every Time I set up an Oracle Linux server, I ask myself, how have I done it last time ...

1. Check which Java Version (JDK7, JDK8, ...) is certified with your software.
e.g. Oracle Fusion Middleware supported system configurations:
http://www.oracle.com/technology/software/products/ias/files/fusion_certification.html 

2. Check support policy, esp. end of life for your desired Java Version
http://www.oracle.com/technetwork/java/javase/downloads/eol-135779.html

3. Download JDK
http://www.oracle.com/technetwork/java/javase/downloads/index.html

4. Install JDK 

# ls -l jdk*
-rw-r--r--. 1 oracle oinstall 126679286 Jan  9 13:01 jdk-7u71-linux-x64.rpm
-rw-r--r--. 1 oracle oinstall 142191827 Jan  9 13:06 jdk-8u25-linux-x64.rpm


# rpm -Uhv jdk-7u71-linux-x64.rpm
Preparing...                ########################################### [100%]
   1:jdk                    ########################################### [100%]
Unpacking JAR files...
    rt.jar...
    jsse.jar...
    charsets.jar...
    tools.jar...
    localedata.jar...
    jfxrt.jar...


5. Check Java Version

# java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)


If this is your expected Java Version - fine! Your are done!
If you still have a pointer to an older version, move on ...

...

6. A non expected Java Version is present?     lets say, JDK8 is still present, but you need to move back to JDK7

# java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)


7. Check Java install locations

# ls -l /usr/java/
total 8
lrwxrwxrwx. 1 root root   16 Jan  9 13:24 default -> /usr/java/latest
drwxr-xr-x. 8 root root 4096 Jan  9 13:49 jdk1.7.0_71
drwxr-xr-x. 9 root root 4096 Jan  9 13:40 jdk1.8.0_25
lrwxrwxrwx. 1 root root   21 Jan  9 13:40 latest -> /usr/java/jdk1.8.0_25


8. Make use of alternatives system to switch between versions

8.1 Syntax of alternatives

# /usr/sbin/alternatives
alternatives version 1.3.49.3 - Copyright (C) 2001 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage: alternatives --install 
                    [--initscript ]
                    [--slave ]*
       alternatives --remove 
       alternatives --auto 
       alternatives --config 
       alternatives --display 
       alternatives --set 

common options: --verbose --test --help --usage --version
                --altdir --admindir 


8.2 Register your JDKs for alternatives

usage: alternatives --install 

# /usr/sbin/alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_71/bin/java 17071

(where priority represents 17071 for jdk1.7.0_71)

# /usr/sbin/alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_25/bin/java 18025

(where priority represents 18025 for jdk1.8.0_25)

8.3 Now to switch between the versions

8.3.1 Check current java version, again

# java -version
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)


8.3.2 Change the current java version

 # /usr/sbin/alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           /usr/java/jdk1.7.0_71/bin/java
*+ 2           /usr/java/jdk1.8.0_25/bin/java

Enter to keep the current selection[+], or type selection number: 1


8.3.3 Check your current java version has changed 

# java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)


9. Keep your path JDK dynamic

The idea is, when you install for example WebLogic Server, to use a dynamic location to your JDK.
I do this with a symbolic link.
I have a folder /opt/oracle/java where I create a symbolic link, that points to the jdk.
As normal user I create the symbolic link:

$ ln -s /usr/java/jdk1.8.0_25 /opt/oracle/java/java

When an updated jdk version in available, after install I only change the symbolic link:

$ rm /opt/oracle/java/java
$ ln -s /usr/java/jdk1.8.0_31 /opt/oracle/java/java

For the WebLogic Server, the path to java will remain. No reconfiguration is needed.
So I only have to restart the WebLogic Server to use the latest JDK.

Tuesday, March 24, 2015

Setting up Linux with public-yum for all updates

  • Log in as user root
  • Download the yum repo file from http://public-yum.oracle.com
  • # cd /etc/yum.repos.d
  • # wget http://public-yum.oracle.com/public-yum-ol6.repo
  • Run yum repolist 
Depending of you internet speed it could take several minutes to build the repository.

Wednesday, September 24, 2014

How to change the screen resolution in Oracle Enterprise Linux on Vmware


I found a lot of trouble related to screen resolution which was struck to 800x600 or 600x480 resolutions  after installation of oracle enterprise linux as guest OS on vmware de. Then i went through many blogs and forums to change this problem and at last i was able to fix it. I am summarizing the steps to fix this issue.

Install Oracle Enterprise Linux
Login as "root" user and install vmware tools
After installation of vmware tools, restart it and login as a root user
go to System -> Administration -> Screen. In Hardware tab, click Configure for Monitor Type and select a suitable monitor type of high resolution e.g. LCD Panel 1280x800 etc.
Now go to etc/X11 and open XORG.CONF file
There will be a section "Screen" in that file which will contain a subsection "Display". Inside that section there is a line  'Modes "800x600" "640x480"'. Add a suitable screen resolution which you want to add e.g. i added "1280x800" and "1024x768" for my LCD. Now new line will be "Modes "1280x800" "1024x768" "800x600" "640x480".
Save it and restart the OEL. Now go to System->Preferences->Screen Resolution and select a suitable screen resolution now and enjoy.


taken from : https://sites.google.com/site/technicalinfosite/tips---techniques/howtochangethescreenresolutioninoracleenterpriselinuxonvmware


Sunday, April 6, 2014

Oracle Error with Explain Plan | ORA-00904: "OTHER_TAG": invalid identifier

when we try to explan plan, we get the below error, this is becauae the plan table is corrupted
drop and recreate the plan table.


SQL> explain plan for   select * from id_meta_ticket_query;
Explained.


SQL> SELECT * FROM TABLE(dbms_xplan.display);

PLAN_TABLE_OUTPUT
------------------------------------------------------
ERROR: an uncaught error in function display has happe  Please provide also a DMP file of the used plan
       ORA-00904: "OTHER_TAG": invalid identifier


SQL> drop table  plan_table;
Table dropped.

SQL> @$ORACLE_HOME/rdbms/admin/utlxplan.sql
Table created.

SQL> explain plan for  select * from id_meta_ticket_query;
Explained.

SQL>  select * from table(dbms_xplan.display());

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------
Plan hash value: 683485703

------------------------------------------------------------------------------------------
| Id  | Operation         | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |                      |     1 |   867 |     2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS FULL| ID_META_TICKET_QUERY |     1 |   867 |     2   (0)| 00:00:01 |
------------------------------------------------------------------------------------------

8 rows selected.

Wednesday, December 25, 2013

ORA-00600: internal error code, arguments: [723], [248344], [248344], [memory leak]



Solution:

1. For few leaks size: Ignore this ORA-600 [723] as it is more of a housekeeping message and is not really a cause for concern.

OR

2. In order to avoid the ORA-00600[723] , you can set the 10262 event;
SEE: (Doc ID 39308.1) ORA-600 [723] "PGA memory leak"

As a workaround, use event 10262 to suppress the error check. Set event 10262 at a level greater than the size of the leaked memory, e.g.:

-- > your error message: ORA-00600: internal error code, arguments: [723], [248344], [248344], [memory leak], [], [], [], [] <<<<<< LEAK 248344 ... 250Ko.

SQL> connect / as sysdba
SQL> alter system set events '10262 trace name context forever, level 300000';

This prevents the leak being reported which is not serious and is only signalled on logging out the session before freeing the memory, and so no memory is wasted.

OR

3. Apply the latest Patchset 10G Release2 database version (102050) which is fixing this issue. 

Patch Link: https://updates.oracle.com/Orion/PatchDetails/process_form?patch_num=8202632

Tuesday, December 24, 2013

Troubleshooting ORA-600 [723] "PGA memory leak


PURPOSE: This article discusses the internal error "ORA-600 [723]", what it means and possible actions. The information here is only applicable to the versions listed and is provided only for guidance.

ERROR: ORA-600 [723] [a] [b]

VERSIONS: versions 6.0 to 11.1

DESCRIPTION: This is a memory leak in the Program Global Area (PGA) PGA is checked for Space leaks at logoff time and a leak was found. There is no data corruption with this error.

ARGUMENTS: Arg [a] Logoff PGA size in bytes Arg [b] "memory leak"

FUNCTIONALITY: MEMORY COMPONENT

IMPACT:
PROCESS FAILURE - but only during session delete so impact is minimal
NON CORRUPTIVE - No underlying data corruption.

SUGGESTIONS: Event 10262 can be set to safely ignore small memory leaks.

Set the following in init.ora for example to disable space leaks less than 4000 bytes

event = "10262 trace name context forever, level 4000"
and stop and restart the database. Repeated errors can be diagnosed further by sending the alert.log and trace files to Oracle Support Services.

Known Issues:

Bug# 6749617
See Note 6749617.8 OERI[723] of "Global Blockers" memory on disconnect
Fixed: 10.2.0.5

Bug# 5891737
See Note 5891737.8Dump (kcblsod) / OERI:723 / Memory leak in ASM/RAC
Fixed: 10.2.0.4, 11.1.0.6, 10.2.0.3.P17


Saturday, December 21, 2013

Table Fragmentation

http://www.orafaq.com/node/1936


"dbms_redefinition"

SQL> create table TABLE1 (
2 no number,
3 name varchar2(20) default 'NONE',
4 ddate date default SYSDATE);

Table created.

SQL> alter table table1 add constraint pk_no primary key(no);

Table altered.

SQL> begin
2 for x in 1..100000 loop
3 insert into table1 ( no , name, ddate)
4 values ( x , default, default);
5 end loop;
6 end;
7 /

PL/SQL procedure successfully completed.

SQL> create or replace trigger tri_table1
2 after insert on table1
3 begin
4 null;
5 end;
6 /

Trigger created.

SQL> select count(*) from table1;

COUNT(*)
----------
100000

SQL> delete table1 where rownum <= 50000;

50000 rows deleted.

SQL> commit;

Commit complete.

SQL> exec dbms_stats.gather_table_stats('SCOTT','TABLE1');

PL/SQL procedure successfully completed.

SQL> select table_name, round((blocks*8),2)||'kb' "size"
2 from user_tables
3 where table_name = 'TABLE1';

TABLE_NAME size
------------------------------ ------------------------------------------
TABLE1 2960kb

SQL> select table_name, round((num_rows*avg_row_len/1024),2)||'kb' "size"
2 from user_tables
3 where table_name = 'TABLE1';

TABLE_NAME size
------------------------------ ------------------------------------------
TABLE1 822.69kb


SQL> --Minimum Privs required "DBA" role or "SELECT" on dbms_redefinition pkg
SQL> --First check table is condidate for redefinition.
SQL>
SQL> exec sys.dbms_redefinition.can_redef_table('SCOTT',-
> 'TABLE1',-
> sys.dbms_redefinition.cons_use_pk);

PL/SQL procedure successfully completed.

SQL> --After verifying that the table can be redefined online, you manually crea
te an empty interim table (in the same schema as the table to be redefined)
SQL>
SQL> create table TABLE2 as select * from table1 WHERE 1 = 2;

Table created.

SQL> exec sys.dbms_redefinition.start_redef_table ( 'SCOTT',-
> 'TABLE1',-
> 'TABLE2');

PL/SQL procedure successfully completed.

SQL> --This procedure keeps the interim table synchronized with the original tab
le.
SQL>
SQL> exec sys.dbms_redefinition.sync_interim_table ('SCOTT',-
> 'TABLE1',-
> 'TABLE2');

PL/SQL procedure successfully completed.

SQL> --Create PRIMARY KEY on interim table(TABLE2)
SQL> alter table TABLE2
2 add constraint pk_no1 primary key (no);

Table altered.

SQL> create trigger tri_table2
2 after insert on table2
3 begin
4 null;
5 end;
6 /

Trigger created.

SQL> --Disable foreign key on original table if exists before finish this proces
s.
SQL>
SQL> exec sys.dbms_redefinition.finish_redef_table ( 'SCOTT',-
> 'TABLE1',-
> 'TABLE2');

PL/SQL procedure successfully completed.

SQL> exec dbms_stats.gather_table_stats('SCOTT','TABLE1');

PL/SQL procedure successfully completed.

SQL> select table_name, round((blocks*8),2)||'kb' "size"
2 from user_tables
3 where table_name = 'TABLE1';

TABLE_NAME size
------------------------------ ------------------------------------------
TABLE1 1376kb

SQL> select table_name, round((num_rows*avg_row_len/1024),2)||'kb' "size"
2 from user_tables
3 where table_name = 'TABLE1';

TABLE_NAME size
------------------------------ ------------------------------------------
TABLE1 841.4kb

SQL> select status,constraint_name
2 from user_constraints
3 where table_name = 'TABLE1';

STATUS CONSTRAINT_NAME
-------- ------------------------------
ENABLED PK_NO1

SQL> select status ,trigger_name
2 from user_triggers
3 where table_name = 'TABLE1';

STATUS TRIGGER_NAME
-------- ------------------------------
ENABLED TRI_TABLE2

SQL> drop table TABLE2 PURGE;

Table dropped.

Monday, July 8, 2013

Empty Oracle Listener.log files

The listener.log file grows and it’s not possible to just move the file whilst the listener is up.  The tnslsnr process always holds this log file.


Procedure 1:
LSNRCTL>  set Log_status off
$ mv listener.log  listener_old.log
$  touch listener.log
LSNRCTL>  set Log_status on

Procedure 2: Create batch script like below and schedule to run once a week
$ more truncate_listener.sh
cd /u00/app/oracle/product/10.2.0/network/log/
cp listener.log /u00/app/oracle/product/10.2.0/network/log/backup/listener_`date '+%Y%m%d'`.log
echo > listener.log

Procedure 3: Stop Listener logs
set LOGGING_LISTENER=OFF in the listener.ora file to stop the listener logging.

Tuesday, May 28, 2013

Auditing FGA:


create user adlfga identified by adlfga;
grant resource,connect to adlfga;

BEGIN DBMS_FGA.ADD_POLICY(      object_schema => 'AE001T3',
object_name => 'ID_TICKET_DETAILS',
policy_name => 'TICKET_LPO_POLICY',
audit_condition => NULL,
audit_column => 'TICKET_LPO',
enable => true,
statement_types => ‘SELECT,INSERT,UPDATE,DELETE’
);
end;

conn adl_fga_handler/adl_fga_handler;
create table audit_event 2 (audit_event_no number);

create or replace procedure sp_audit(object_schema in varchar2,object_name in varchar2,policy_name in varchar2)ascount number;

begin
select nvl(max(audit_event_no),0) into count from audit_event;
insert into audit_event values (count+1); commit;

end;

select DB_USER,OS_USER,POLICY_NAME,SQL_TEXT, TIMESTAMP from dba_fga_audit_trail where POLICY_NAME='TICKET_LPO_POLICY';

How to Check the version of and Update opatch utility



Checking the opatch utility version:
$ cd $ORACLE_HOME/OPatch
$ opatch lsinventory

Invoking OPatch 10.2.0.4.3
Oracle Interim Patch Installer version 10.2.0.4.3
Copyright (c) 2007, Oracle Corporation.  All rights reserved.
Oracle Home       : /u01/app/oracle/product/10.2.0
Central Inventory : /u00/app/oracle/oraInventory
   from           : /var/opt/oracle/oraInst.loc
OPatch version    : 10.2.0.4.3
OUI version       : 10.2.0.4.0
OUI location      : /u01/app/oracle/product/10.2.0/oui
Log file location : /u01/app/oracle/product/10.2.0/cfgtoollogs/opatch/opatch2013-05-27_16-24-15PM.log
Lsinventory Output file location : /u01/app/oracle/product/10.2.0/cfgtoollogs/opatch/lsinv/lsinventory2013-05-27_16-24-15PM.txt
--------------------------------------------------------------------------------
Installed Top-level Products (2):
Oracle Database 10g                                                  10.2.0.1.0
Oracle Database 10g Release 2 Patch Set 3                            10.2.0.4.0
There are 2 products installed in this Oracle Home.
Interim patches (1) :
Patch  8350262      : applied on Thu Nov 22 14:55:53 GMT-04:00 2012
   Created on 14 Sep 2010, 04:59:44 hrs PST8PDT
   Bugs fixed:
     8350262
--------------------------------------------------------------------------------
OPatch succeeded.



How to update the opatch utility?
Go to :
https://updates.oracle.com/Orion/PatchDetails/handle_plat_lang_change?release=80102000&plat_lang=46P&patch_file=&file_id=&password_required=&password_required_readme=&merged_trans=&aru=13116067&patch_num=6880880&patch_num_id=979663&default_release=80102000&default_plat_lang=23P&default_compatible_with=&patch_password=&orderby=&direction=&no_header=0&sortcolpressed=&tab_number=

Description OPatch 10.2
Product Universal Installer
Select a Release : ORACLE 10.2.0.0.0
Platform or Language   : ORACLE SOLARIS  ON SPARC(64-BIT)
Last Updated 07-NOV-2010
Size 27M (28674793 bytes)
Entitlement Class   Software
Classification   General

Download the patch
Transfer the patch p6880880_102000_SOLARIS64.zip to remote server and unzip it

Backup the existing OPatch directory
$ mv OPatch/ opatch_backup

$ mv p6880880_102000_SOLARIS64.zip $ORACLE_HOME
$ unzip_sparc p6880880_102000_SOLARIS64.zip
bash-3.00$ cd OPatch/
bash-3.00$ opatch lsinventory
Invoking OPatch 10.2.0.5.1

Oracle Interim Patch Installer version 10.2.0.5.1
Copyright (c) 2010, Oracle Corporation.  All rights reserved.


Oracle Home       : /u01/app/oracle/product/10.2.0
Central Inventory : /u00/app/oracle/oraInventory
   from           : /var/opt/oracle/oraInst.loc
OPatch version    : 10.2.0.5.1
OUI version       : 10.2.0.4.0
OUI location      : /u01/app/oracle/product/10.2.0/oui
Log file location : /u01/app/oracle/product/10.2.0/cfgtoollogs/opatch/opatch2013-05-27_16-33-16PM.log
Patch history file: /u01/app/oracle/product/10.2.0/cfgtoollogs/opatch/opatch_history.txt
Lsinventory Output file location : /u01/app/oracle/product/10.2.0/cfgtoollogs/opatch/lsinv/lsinventory2013-05-27_16-33-16PM.txt
--------------------------------------------------------------------------------
Installed Top-level Products (2):
Oracle Database 10g                                                  10.2.0.1.0
Oracle Database 10g Release 2 Patch Set 3                            10.2.0.4.0
There are 2 products installed in this Oracle Home.
Interim patches (1) :
Patch  8350262      : applied on Thu Nov 22 14:55:53 GMT-04:00 2012
Unique Patch ID:  13011839
   Created on 14 Sep 2010, 04:59:44 hrs PST8PDT
   Bugs fixed:
     8350262
--------------------------------------------------------------------------------
OPatch succeeded.
bash-3.00$

Thursday, May 2, 2013

Oracle terms and Ideas you need to know before beginning


Oracle Parser
It performs syntax analysis as well as semantic analysis of SQL statements for execution, expands views referenced in the query into separate query blocks, optimizing it and building (or locating) an executable form of that statement.

Hard Parse
A hard parse occurs when a SQL statement is executed, and the SQL statement is either not in theshared pool, or it is in the shared pool but it cannot be shared. A SQL statement is not shared if the metadata for the two SQL statements is different i.e. a SQL statement textually identical to a preexisting SQL statement, but the tables referenced in the two statements are different, or if the optimizer environment is different.

Soft Parse
A soft parse occurs when a session attempts to execute a SQL statement, and the statement is already in the shared pool, and it can be used (that is, shared). For a statement to be shared, all data, (including metadata, such as the optimizer execution plan) of the existing SQL statement must be equal to the current statement being issued.

Cost Based Optimizer
It generates a set of potential execution plans for SQL statements, estimates the cost of each plan, calls the plan generator to generate the plan, compares the costs, and then chooses the plan with the lowest cost. This approach is used when the data dictionary has statistics for at least one of the tables accessed by the SQL statements. The CBO is made up of the query transformer, the estimator and the plan generator.

EXPLAIN PLAN
A SQL statement that enables examination of the execution plan chosen by the optimizer for DML statements. EXPLAIN PLAN makes the optimizer to choose an execution plan and then to put data describing the plan into a database table. The combination of the steps Oracle uses to execute a DML statement is called an execution plan. An execution plan includes an access path for each table that the statement accesses and an ordering of the tables i.e. the join order with the appropriate join method.

Oracle Trace
Oracle utility used by Oracle Server to collect performance and resource utilization data, such as SQL parse, execute, fetch statistics, and wait statistics. Oracle Trace provides several SQL scripts that can be used to access server event tables, collects server event data and stores it in memory, and allows data to be formatted while a collection is occurring.

SQL Trace
It is a basic performance diagnostic tool to monitor and tune applications running against the Oracle server. SQL Trace helps to understand the efficiency of the SQL statements an application runs and generates statistics for each statement. The trace files produced by this tool are used as input for TKPROF.

TKPROF
It is also a diagnostic tool to monitor and tune applications running against the Oracle Server. TKPROF primarily processes SQL trace output files and translates them into readable output files, providing a summary of user-level statements and recursive SQL calls for the trace files. It also shows the efficiency of SQL statements, generate execution plans, and create SQL scripts to store statistics in the database.

Wednesday, May 1, 2013

Object Statistics Are Locked



ORA-38029 "Object Statistics Are Locked" - Possible Causes [ID 433240.1]

Cause: Using import (imp) or data pump import (impdp) to import a table without data results in the table's statistics being locked in 10gR2.

SQL> exec dbms_stats.gather_table_stats('AE1T3OBY','id_emp_leave_details',cascade => true);
BEGIN dbms_stats.gather_table_stats('AE1T3OBY','id_emp_leave_details',cascade => true); END;

*
ERROR at line 1:
ORA-20005: object statistics are locked (stattype = ALL)
ORA-06512: at "SYS.DBMS_STATS", line 13437
ORA-06512: at "SYS.DBMS_STATS", line 13457
ORA-06512: at line 1

This query shows that the table statistics are locked.

SQL> select owner, table_name, stattype_locked from dba_tab_statistics where stattype_locked is not null;

Unlock it

Sql> exec dbms_stats.unlock_schema_stats('AE1T3OBY');

SQL> select owner, table_name, stattype_locked from dba_tab_statistics where stattype_locked is not null;

Now gather the table statistics


SQL> exec dbms_stats.gather_table_stats('AE1T3OBY','id_emp_leave_details',cascade => TRUE);

PL/SQL procedure successfully completed.


Gathering statistics sample:
begin
dbms_stats.gather_table_stats( ownname=> 'AE1T3', tabname=> 'ID_NUMBER_GEN_SOURCE' , estimate_percent=> DBMS_STATS.AUTO_SAMPLE_SIZE, cascade=> DBMS_STATS.AUTO_CASCADE, degree=> null, no_invalidate=> DBMS_STATS.AUTO_INVALIDATE, granularity=> 'AUTO', method_opt=> 'FOR ALL COLUMNS SIZE AUTO');
end;

Thursday, April 25, 2013

Oracle Database 10g: Analyze Index Vs. Gather_Index_Stats


 One of the difference I noticed about analyze index command and gather_index_stats procedure is that when we use analyze index command it updates the index statistics with number of leaf blocks equals the number of leaf blocks below HWM.

However if we use gather_index_stats statistics shows number of leaf blocks equals number of leaf blocks that actually has the data.

Here is the illustration for the same.

SQL> select owner,index_name,table_name,BLEVEL, LEAF_BLOCKS, DISTINCT_KEYS
from dba_indexes where _name='ID_TICKET_STOCK_MASTER'

OWNER
INDEX_NAME
TABLE_NAME
BLEVEL
LEAF_BLOCKS
DISTINCT_KEYS
AE1T3
STK_UKEY
ID_TICKET_STOCK_MASTER
2
10185
2515695



SQL> analyze index STK_UKEY estimate statistics;
SQL> select owner,index_name,table_name,BLEVEL, LEAF_BLOCKS, DISTINCT_KEYS
from dba_indexes where _name='ID_TICKET_STOCK_MASTER'

OWNER
INDEX_NAME
TABLE_NAME
BLEVEL
LEAF_BLOCKS
DISTINCT_KEYS
AE1T3
STK_UKEY
ID_TICKET_STOCK_MASTER
2
10184
2515448




SQL> EXEC DBMS_STATS.gather_index_stats('AE1T3','STK_UKEY');
PL/SQL procedure successfully completed.

SQL> select owner,index_name,table_name,BLEVEL, LEAF_BLOCKS, DISTINCT_KEYS
from dba_indexes where _name='ID_TICKET_STOCK_MASTER'

OWNER
INDEX_NAME
TABLE_NAME
BLEVEL
LEAF_BLOCKS
DISTINCT_KEYS
AE1T3
STK_UKEY
ID_TICKET_STOCK_MASTER
2
9428
2320245



Conclusion:
Action
INDEX_NAME
BLEVEL
LEAF_BLOCKS
DISTINCT_KEYS
SQL Query
STK_UKEY
2
10185
2515695
analyze index STK_UKEY estimate statistics;
STK_UKEY
2
10184
2515448
DBMS_STATS.gather_index_stats('AE1T3','STK_UKEY');
STK_UKEY
2
9428
2320245


Now if we see the numbers of leaf blocks reported are 9428. This plays quiet a big role for optimizer in creating plans for queries. If we don’t have correct stats for the index, it may lead to expensive explain plans.

So it’s better to use gather_index_stats rather than analyze index.

Hope this helps!!