Sunday, July 4, 2021

How I Create SQL Baseline to fix my EBS query with an Execution Plan | Performance

 I am sharing on creating SQL baseline and force query to use better execution plan (plan hash value). 

I was doing today so thought to share this scenario where the query which was running fine till yesterday now suddenly running long in my EBS instance. So very important  I check the plan for a particular sqlid. 

Note my DB version in 11.2.0.4

Query to check the multiple hash plans for sql id.

select
SQL_ID
, PLAN_HASH_VALUE
, sum(EXECUTIONS_DELTA) EXECUTIONS
, sum(ROWS_PROCESSED_DELTA) CROWS
, trunc(sum(CPU_TIME_DELTA)/1000000/60) CPU_MINS
, trunc(sum(ELAPSED_TIME_DELTA)/1000000/60)  ELA_MINS
from DBA_HIST_SQLSTAT
where SQL_ID in (
'6hxw283cyw0ub') --repalce sqlid with your sqlid
group by SQL_ID , PLAN_HASH_VALUE
order by SQL_ID, CPU_MINS

I find out the best execution plan (Plan_hash_value) and force the query to use that plan. Below are the steps I did to create and fix bad queries by creating SQL baseline.



STEP 1: GENERATE ALL PREVIOUS HISTORY RUN DETAILS OF SQL_ID FROM AWR 

break off sdate
set lines 2000
set linesize 2000
col SDATE format a10
col STIME format a10
select to_char(begin_interval_time,'YYYY/MM/DD') SDATE,to_char(begin_interval_time,'HH24:MI')  STIME,s.snap_id,
        sql_id, plan_hash_value PLAN,
        ROUND(elapsed_time_delta/1000000,2) ET_SECS,
        nvl(executions_delta,0) execs,
        ROUND((elapsed_time_delta/decode(executions_delta,null,1,0,1,executions_delta))/1000000,2) ET_PER_EXEC,
        ROUND((buffer_gets_delta/decode(executions_delta,null,1,0,1,executions_delta)), 2) avg_lio,
        ROUND((CPU_TIME_DELTA/decode(executions_delta,null,1,0,1,executions_delta))/1000, 2) avg_cpu_ms,
        ROUND((IOWAIT_DELTA/decode(executions_delta,null,1,0,1,executions_delta))/1000, 2) avg_iow_ms,
        ROUND((DISK_READS_DELTA/decode(executions_delta,null,1,0,1,executions_delta)), 2) avg_pio,
        ROWS_PROCESSED_DELTA num_rows
from DBA_HIST_SQLSTAT S,  DBA_HIST_SNAPSHOT SS
where s.sql_id = '&sql_id'
and ss.snap_id  =S.snap_id
and ss.instance_number = S.instance_number
order by sdate,stime;

Enter value for sql_id: 6hxw283cyw0ub



SDATE      STIME    SNAP_ID SQL_ID              PLAN    ET_SECS      EXECS ET_PER_EXEC    AVG_LIO AVG_CPU_MS AVG_IOW_MS    AVG_PIO   NUM_ROWS
---------- ----- ---------- ------------- ---------- ---------- ---------- ----------- ---------- ---------- ---------- ---------- ----------
2021/06/30 19:00      89668 6hxw283cyw0ub 1368916072          0          0           0          0          0          0          0          0
2021/06/30 19:00      89668 6hxw283cyw0ub   40732332     509.74          1      509.74  167517768  284054.61    4066.39     979242          0
2021/06/30 20:00      89669 6hxw283cyw0ub 1368916072          0          0           0          0          0          0          0          0
2021/06/30 20:00      89669 6hxw283cyw0ub   40732332     488.65          1      488.65  167171014  266845.92    7141.55     789809          0
2021/07/01 07:00      89680 6hxw283cyw0ub   40732332     508.51          1      508.51  165308543  265980.54    3566.88     726343          0
2021/07/01 07:00      89680 6hxw283cyw0ub 1368916072          0          0           0          0          0          0          0          0
2021/07/01 08:00      89681 6hxw283cyw0ub   40732332     936.17          2      468.09  165328375  257197.28    3183.58   726323.5          0
2021/07/01 08:00      89681 6hxw283cyw0ub 1368916072          0          0           0          0          0          0          0          0
2021/07/01 09:00      89682 6hxw283cyw0ub   40732332     558.38          1      558.38  165739035  269044.73    5430.59     733766          0
2021/07/01 09:00      89682 6hxw283cyw0ub 1368916072          0          0           0          0          0          0          0          0
2021/07/01 11:00      89684 6hxw283cyw0ub   40732332    1553.27          3      517.76  167407756  266781.05    4228.16  823571.33          0
2021/07/01 15:00      89688 6hxw283cyw0ub   95728747     120.19          1      120.19    3052872   31220.28   10460.06     969074       8738
2021/07/01 15:00      89688 6hxw283cyw0ub  587292616     1372.1          3      457.37 97773871.7  199067.35    1862.32 1019655.67          0


/*In this scenario sql_id=>6hxw283cyw0ub and plan_hash_value for good plan that we want to force is 95728747.*/
Follow below steps to create sql baseline for sql_id

STEP 2: DROP SQL TUNING SET (STS) IF EXISTS

BEGIN
  DBMS_SQLTUNE.DROP_SQLSET(
    sqlset_name > 'SQL_FOR_6hxw283cyw0ub');
END;

STEP 3: CREATE SQL TUNING SET 

BEGIN
  DBMS_SQLTUNE.create_sqlset (
    sqlset_name  > 'SQL_FOR_6hxw283cyw0ub',
    description  > 'SQL tuning set for 6hxw283cyw0ub');
END;
/

/* Populate STS from AWR by specifying snapshot for a desired plan which we found using the above query.
In this scenario snap id's are 89684 and 89688 and change plan_hash_value accordingly.*/

DECLARE
  l_cursor  DBMS_SQLTUNE.sqlset_cursor;
BEGIN
  OPEN l_cursor FOR
    SELECT VALUE(p)
    FROM   TABLE (DBMS_SQLTUNE.select_workload_repository (
                    23483,  -- begin_snap
                    23484,  -- end_snap
                    q'<sql_id in ('6hxw283cyw0ub') and plan_hash_value in (95728747)>',  -- basic_filter 
                    NULL, -- object_filter
                    NULL, -- ranking_measure1
                    NULL, -- ranking_measure2
                    NULL, -- ranking_measure3
                    NULL, -- result_percentage
                    100)   -- result_limit
                  ) p;

  DBMS_SQLTUNE.load_sqlset (
    sqlset_name     > 'SQL_FOR_6hxw283cyw0ub',
    populate_cursor > l_cursor);
END;
/

STEP 4: CHECK SQL SET DETAILS 

column text format a20
select sqlset_name, sqlset_owner, sqlset_id, sql_id,substr(sql_text,1,20) text,elapsed_time,buffer_gets,
parsing_schema_name, plan_hash_value, bind_data from dba_sqlset_statements where sqlset_name ='SQL_FOR_6hxw283cyw0ub';

STEP 5: LOAD DESIRED PLAN FROM STS AS SQL PLAN BASELINE

DECLARE
  L_PLANS_LOADED  PLS_INTEGER;
BEGIN
  L_PLANS_LOADED : DBMS_SPM.LOAD_PLANS_FROM_SQLSET(
    SQLSET_NAME > 'SQL_FOR_6hxw283cyw0ub');
END;

STEP 6: CHECK SQL PLAN BASELINE DETAILS 

SELECT sql_handle, plan_name,enabled,accepted,fixed FROM dba_sql_plan_baselines
WHERE signature IN (SELECT exact_matching_signature FROM v$sql WHERE sql_id='&SQL_ID')
order by accepted,enabled;

STEP 7: ENABLE FIXED=YES

var pbsts varchar2(30);
exec :pbsts : dbms_spm.alter_sql_plan_baseline('SQL_64e76e773c55f1c4','SQL_PLAN_69tvffwy5bwf480a6275e','FIXED','YES');

STEP 8: PURGE OLD EXECUTION PLAN FROM SHARED POOL 

Find below two parameter which are required to purge specific sql from the shared pool.

select address||','||hash_value from gv$sqlarea where sql_id ='6hxw283cyw0ub';

ADDRESS||','||HASH_VALUE
----------------------------------------------------------------------------------------
00000001C966CDA0,3656254283

Now use below command to purge sql from shared pool.

exec sys.dbms_shared_pool.purge('00000001C966CDA0,3656254283','C',1);

Re-run query or program to test


https://www.funoracleapps.com/2021/07/how-i-create-sql-baseline-to-fix-query.html

Saturday, July 3, 2021

What is IP=FIRST in the LISTENER.ORA file ?

 In this Document

Purpose
Scope
Details
References

APPLIES TO:

Oracle Database - Enterprise Edition - Version 11.1.0.7 to 18.3.0.0.0 [Release 11.1 to 18]
Oracle Net Services - Version 11.1.0.7 to 18.1.0.0.0 [Release 11.1 to 18.1]
Information in this document applies to any platform.

PURPOSE

Starting with Oracle10g 10.1.0.3 you will see the property IP=FIRST in the LISTENER.ORA file. What is IP=FIRST used for ?

LISTENER_VENUS =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS_LIST =
        (ADDRESS = (PROTOCOL = TCP)(HOST = <hostname>-vip)(PORT = 1521)(IP = FIRST))
        (ADDRESS = (PROTOCOL = TCP)(HOST = <hostname2>)(PORT = 1521)(IP = FIRST))
      )
    )
  )

SCOPE

This note is intended to clarify usage for the IP=FIRST statement, usually in RAC setups.

DETAILS

The (IP=FIRST) statement will make the listener create a listening endpoint on the IP address to which the given HOST resolves. By default, without (IP=FIRST), the listener will listen on all network interfaces (e.g. INADDR_ANY) — see Note 421305.1 for background information on listener binding behavior.

This new attribute is covered in the Oracle Net Services documentation since Oracle 11g Release 1.

REFERENCES


APPLIES TO:

Oracle Net Services - Version 8.1.7.2 to 11.2.0.4 [Release 8.1.7 to 11.2]
Information in this document applies to any platform.

PURPOSE

This note attempts to explain how the listener binds to network addresses when it is configured for the TCP protocol.

SCOPE

The knowledge contained in this note will help you discern and eventually predict the listener behavior based on the listener configuration and system settings.   This documentation is limited in scope to 10gR2 and older listeners.  It doesn't apply to 11gR1 and newer listener behavior.

DETAILS

Introduction

Starting with Oracle 8i, the listener behavior in how it binds to IP addresses when configured with TCP protocol endpoints has changed (see Note 69026.1 for the rationale). The general rule may appear to you as being "listen on all interfaces if a hostname is specified". While this may prove correct most of the time, in particular situations the listener may behave differently.

You may force the listener into binding only to the specific IP address (even when using hostnames) by using the (IP=FIRST) statement in the address endpoint configuration in LISTENER.ORA (see Note 300729.1).


Since the listener binding point is critical for the database instances to register themselves with the listener (see Note 359277.1), it is important to understand what is the algorithm used by the listener to decide in what way to listen on its TCP endpoints.

General algorithm

You may use the following schema in order to interpret the listener behavior when it comes to binding to a TCP protocol address:

(1) If you provide an IP address, the listener will listen on that IP address

(2) If you provide a hostname:

  (a) Oracle does a gethostbyname() on that hostname (getaddrinfo() in 11g and higer); potentially more than one IP address is returned.

The gethostbyname() / getaddrinfo() library function may query the DNS server(s), the /etc/hosts file, the NIS service and perhaps other methods, based on the system configuration. How this works exactly depends on the operating system type, but usually the /etc/host.conf/etc/nsswitch.conf and /etc/resolv.conf files are governing the functionality on the UNIX platforms.

You can find the value that is expected to be given by using the ping tool (e.g. "ping <hostname>" or "ping -s <hostname>" and see what IP address will the hostname resolve to). Do not use hostnslookup or dig to find this information, since these tools will query only the DNS service and may give wrong answers in certain situations.

Be careful that even the ping utility may not disclose you all the information, e.g. it will not show all the addresses associated with a hostname, if there are more than one. Best choice is to use the check-lsnrbind program, attached to this note (see below section "Checking tool").

   (b) Oracle does a gethostname() / getaddrinfo() which will return the system's configured hostname.

The gethostname() / getaddrinfo() library function (notice the missing by particle) will return the standard hostname set for the system (or current processor, per manual pages); this is usually done at system startup.

You can find the value that is expected to be given by using the hostname tool, without any parameters (e.g. simply run "hostname").

   (c) Oracle does a gethostbyname() / getaddrinfo() on the system's hostname found in the previous step (2b).

   (d) Oracle compares the first IP returned in (2a) to all of the IPs returned in (2c). If no match is found, then the listener will bind to the resolved IP address. The IP address is registered in the listening endpoints list.

— OR —

   (e) If a match is found in (2d), the listener binds on all (working) network interfaces. The fully qualified system hostname is  registered in the listening endpoints list.

You may recognize that the listener has bound to all interfaces from the "netstat -an" output: if the listener is bound to all interfaces then the IP address 0.0.0.0 will be shown — it programmers' slang this is known as the INADDR_ANY address.

Interpreting listener status

You can easily judge what is the way the listener has bound to the TCP addresses from its status output: check whether the Listening Endpoints Summary lists an IP address or a hostname. If you see an IP address then the listener had bound only to that IP, but if instead you see a hostname then the listener has bound to all interfaces (INADDR_ANY).

Let's take the following example:

$ lsnrctl status

LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 07-MAY-2007 15:29:48

Copyright (c) 1991, 2005, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date                13-APR-2007 14:11:16
Uptime                    24 days 1 hr. 18 min. 32 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /opt/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File         /opt/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.10.10.10)(PORT=1527)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=myhost.ro.oracle.com)(PORT=1521)))

In this case, the listener has bound to specific IP address 10.10.10.10 on port 1527 as well as to all interfaces (0.0.0.0 / INADDR_ANY) on port 1521.

Side effects

Some of the operating systems (e.g. UNIX platforms) may allow multiple bindings on the same TCP port, eventually coming from different listeners, as long as the (numeric) IP addresses do not conflict. For example, you may have one listener bound on the generic INADDR_ANY address and other(s) on specific IP address(es). In this case, connections may go to different listeners based on the destination IP address, including database instance registration attempts — be sure you are able to discern the way the connections and database registrations are working in this setup.

On the contrary, other operating systems (e.g. the Microsoft Windows platform), disallow having multiple bindings on the same TCP port no matter the IP addresses used, so a second attempt to bind on the same port will fail, triggering errors when starting listener(s).

Checking tool:  Please be aware that Oracle support does not support this tool nor can we assist with issues that arise in trying to compile it.

In order to check for the listener binding behavior of the Oracle listener you can use the attached C program check-lsnrbind.c. This tool needs to be run on the target server, in order to correctly identify the system hostname and to resolve the probed hostnames through the same services as the real listener.

Before using it you will need to compile it, with a command similar to the following:

cc check-lsnrbind.c -o check-lsnrbind

 

To compile the program on the Sun Solaris platform, you will need to add "-lnsl" to the command line, like the following:
cc check-lsnrbind.c -o check-lsnrbind -lnsl


The syntax is simple: just give the hostnames you want to check on its command line; if you want to see the associated IP addresses, then insert the "-v" parameter first in the command line. Here are some examples:

./check-lsnrbind test
./check-lsnrbind test1 test2.foo.com
./check-lsnrbind -v mysite.domain.com


The program has been tested to compile and run on the following platforms:

  • Linux
  • Sun Solaris 10 (needs "-lnsl" when compiling)
  • HP-UX 11.11
  • AIX 5L
  • AIX 4.3
  • TruUNIX Alpha 5.1B
  • MS Windows with CygWin

REFERENCES

NOTE:359277.1 - Changing Default Listener Port Number
NOTE:300729.1 - What is IP=FIRST in the LISTENER.ORA file ?
NOTE:69026.1 - Oracle8i and socket LISTEN operations

NOTE:421305.1 - How The Listener Binds On TCP Protocol Addresses


What is IP=FIRST in the LISTENER.ORA file ? (Doc ID 300729.1)

Oracle E-Business Suite Performance Guides

 How to Use AWR Reports to Diagnose Database Performance Issues (Doc ID 1359094.1)

Troubleshooting Oracle Applications Performance Issues (Doc ID 169935.1)

Performance Diagnosis with Automatic Workload Repository (AWR) (Doc ID 1674086.1)

Oracle E-Business Suite Performance Guide (Doc ID 1672174.1)

Oracle E-Business Suite Performance Best Practices (Doc ID 2528000.1)


Express Diagnosis of Oracle E-Business Suite Release 12.2.n Upgrade Performance Issues (Doc ID 1583752.1)

Oracle E-Business Suite Release 12.2 System Schema Migration

In This Document Section 1: Overview of the EBS System Schema Section 2: Requirements for Using the EBS System Schema Section 3: Migrating t...