This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Tuesday, 27 July 2021

Query to find GL Flexfield security rule assignments to responsibilities

  ERP Archives - Page 82 of 87 - Oracle ERP Apps Guide

-------------------------------------------------------------------------------
-- Query to find GL Flexfield security rule assignments to responsibilities
-------------------------------------------------------------------------------
SELECT
    a.application_name          "Application Name",
    fvr.flex_value_rule_name    "Flex Value Rule",
    r.responsibility_key        "Responsibility"
FROM
    fnd_flex_value_rules        fvr,
    fnd_flex_value_rule_usages  ru,
    fnd_responsibility          r,
    fnd_application_tl          a
WHERE fvr.flex_value_rule_id = ru.flex_value_rule_id
    AND ru.responsibility_id   = r.responsibility_id
    AND ru.application_id      = a.application_id
    AND fvr.flex_value_rule_name LIKE '%XXXXXX%'
ORDER BY flex_value_rule_name;

Sunday, 18 July 2021

SQL Script Repository

 Please  download scripts from this SQL Script Repository


The scripts get used in various blog posts to monitor or diagnose things in Oracle databases. Click on the script’s name below to download the script. And please report any issues to me as well.

DB VersionScriptPurpose
19ccheck_patches_19.sqlCheck applied RUs and RURs with CDB_REGISTRY_SQLPATCH
18ccheck_patches_18.sqlCheck applied RUs and RURs with CDB_REGISTRY_SQLPATCH
12.1, 12.2
check_patches.sqlMonitor applied PSUs, BPs, RUs, RURs with DBA_REGISTRY_SQLPATCH
12.1, 12.2, 18c, 19c
check_components.sqlChecks all installed components CDB-wide with DBA_REGISTRY
12.1, 12.2, 18c, 19c
check_inv_objs.sqlChecks all invalid objects CDB-wide
11.2, 12.1, 12.2, 18c, 19c
capture_awr.sqlCapture statements from AWR – uses the oldest and newest available snapshot by default and limits to 5000 statements by elapsed time.
11.2, 12.1, 12.2, 18c, 19c
capture_cc.sqlCapture statements from Cursor Cache – uses a conservative test setting for 30 seconds only polling the CC every 5 seconds – needs to be adjusted for live systems.
19c and belowspa_cpu.sqlRun a full SQL Performance Analyzer task on captured SQL Statements – compare on CPU
19c and belowspa_buffer.sqlRun a full SQL Performance Analyzer task on capture SQL Statements – compare on buffer gets
19c and belowspa_elapsed.sqlRun a full SQL Performance Analyzer task on capture SQL Statements – compare on elapsed time
19c and below
spa_report_cpu.sql
Generate a regressed report comparing two workloads based on CPU
19c and belowspa_report_buffer.sql
Generate a regressed report comparing two workloads based on buffer gets
19c and belowspa_report_elapsed.sql
Generate a regressed report comparing two workloads based on elapsed time

 

Saturday, 17 July 2021

Oracle Long Running Queries

 You can list the long running queries in the Oracle using the following scripts.

SELECT INST_ID,SID, SERIAL#, SQL_ID,CONTEXT,TIME_REMAINING, SOFAR, TOTALWORK,
ROUND(SOFAR/TOTALWORK*100,2) "%_COMPLETE"
FROM GV$SESSION_LONGOPS
WHERE OPNAME NOT LIKE '%aggregate%'
AND TOTALWORK != 0 AND TIME_REMAINING>0
AND SOFAR <> TOTALWORK order by 9 desc;

 

 

 

You can also use the following script to see TOP Elapsed Time SQL Statements using the following script.

 SELECT st.sql_text,
sub.sql_id,
sub.ELAPSED_TIME PER_EXEC_ELAPSED_TIME_MINUTES
FROM DBA_HIST_SQLTEXT st,
( SELECT t.sql_id,
ROUND (
SUM (t.elapsed_time_delta / 60000000)
/ SUM (t.executions_delta))
ELAPSED_TIME
FROM dba_hist_sqlstat t, dba_hist_snapshot s, DBA_HIST_SQLTEXT st
WHERE t.snap_id = s.snap_id
AND t.dbid = s.dbid
AND t.instance_number = s.instance_number
AND t.executions_delta > 0
AND s.BEGIN_INTERVAL_TIME >
TO_DATE ('06/08/2021 13:00:00',
'mm/dd/yyyy hh24:mi:ss')
AND END_INTERVAL_TIME <
TO_DATE ('06/08/2021 16:01:00',
'mm/dd/yyyy hh24:mi:ss')
GROUP BY t.sql_id
ORDER BY 2 DESC) sub
WHERE sub.sql_id = st.sql_id
ORDER BY 3 DESC;

 

 

 

 

 

Sometimes you need killing some long running sessions that coming from specific machines and specific Queries.

 

 

If you want to kill some long running sessions that coming from specific machines and specific Queries, then you can create dbms Oracle job for this.

 

Before creating Oracle dbms job, firstly we need to create procedure which will perform this job, then create dbms_scheduler job and use this procedure to kill related sessions.

 

 

 

 

 

I will keep session informations in the kill_sessions_info table, so I have create it like following.

create table sys.kill_sessions_info(killId number,username varchar2(100),stext varchar2(100),stime date,duration date)

 

Then create Procedure like following. This procedure will kill sessions that coming from ‘MEHMETSALIH\DEVECI’ machine and running more than 1200 second and sql_text not like ‘%SALES%’. You can change these conditions according to your needs.

 

CREATE OR REPLACE procedure SYS.kill_long_sessions as
BEGIN

FOR i IN (select s.sid||','||s.serial# killId,s.username username,ss.sql_fulltext stext,s.logon_time stime,s.last_call_et durat from 
v$session s, v$sql ss where s.machine='MEHMETSALIH\DEVECI' and s.last_call_et>1200 and
s.sql_id=ss.sql_id and ss.sql_fulltext not like '%SALES%' )

LOOP
declare
l_error VARCHAR2(2000):='';
begin
insert into sys.kill_sessions_info values(i.killId,i.username,i.stext,i.stime,i.durat);
commit;
EXECUTE IMMEDIATE 'ALTER SYSTEM KILL SESSION '''||i.killId||''' IMMEDIATE';
EXCEPTION
WHEN OTHERS THEN
l_error:=SQLERRM;

end;
END LOOP;

COMMIT;

END;
/

 

After creating procedure, you can create DBMS_SCHEDULER job like following.

 

 

 

BEGIN
SYS.DBMS_SCHEDULER.CREATE_JOB
(
job_name => 'SYS.KILL_LONG_SESSION'
,start_date => TO_TIMESTAMP_TZ('2018/12/06 16:00:00.000000 +03:00','yyyy/mm/dd hh24:mi:ss.ff tzr')
,repeat_interval => 'FREQ=MINUTELY;INTERVAL=1'
,end_date => TO_TIMESTAMP_TZ('2090/08/18 00:00:00.000000 +03:00','yyyy/mm/dd hh24:mi:ss.ff tzr')
,job_class => 'DEFAULT_JOB_CLASS'
,job_type => 'STORED_PROCEDURE'
,job_action => 'SYS.KILL_LONG_SESSIONS'
,comments => NULL
);
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE
( name => 'SYS.KILL_LONG_SESSION'
,attribute => 'RESTARTABLE'
,value => FALSE);
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE
( name => 'SYS.KILL_LONG_SESSION'
,attribute => 'LOGGING_LEVEL'
,value => SYS.DBMS_SCHEDULER.LOGGING_OFF);
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE_NULL
( name => 'SYS.KILL_LONG_SESSION'
,attribute => 'MAX_FAILURES');
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE_NULL
( name => 'SYS.KILL_LONG_SESSION'
,attribute => 'MAX_RUNS');
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE
( name => 'SYS.KILL_LONG_SESSION'
,attribute => 'STOP_ON_WINDOW_CLOSE'
,value => FALSE);
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE
( name => 'SYS.KILL_LONG_SESSION'
,attribute => 'JOB_PRIORITY'
,value => 3);
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE_NULL
( name => 'SYS.KILL_LONG_SESSION'
,attribute => 'SCHEDULE_LIMIT');
SYS.DBMS_SCHEDULER.SET_ATTRIBUTE
( name => 'SYS.KILL_LONG_SESSION'
,attribute => 'AUTO_DROP'
,value => FALSE);

SYS.DBMS_SCHEDULER.ENABLE
(name => 'SYS.KILL_LONG_SESSION');
END;
/

 

 

you can change interval and start time according to your needs.

Find Oracle Locked Objects | Remove Table Lock in Oracle

 

Oracle Locked Objects

You can find the all locked objects and users for any Schema User with the following script. This scripts generate the kill session scripts also. You can use it to kill these sessions after review the sessions.

 

SELECT c.owner,
c.object_name,
c.object_type,
b.sid,
b.serial#,
b.inst_id,
b.status,
b.osuser,
b.machine,'alter system kill session ''' || b.sid || ',' || b.serial# || ',@'|| b.inst_id ||''';'
FROM gv$locked_object a, gv$session b, dba_objects c
WHERE b.sid = a.session_id AND a.object_id = c.object_id and c.owner= 'SCHEMA_NAME' and a.inst_id = b.inst_id;

 

 

Remove Table Lock in Oracle

You can find the all locked objects and users for any Schema User with the following script. This scripts generate the kill session scripts also. You can use it to kill these sessions after review the sessions.

SELECT c.owner,
c.object_name,
c.object_type,
b.sid,
b.serial#,
b.inst_id,
b.status,
b.osuser,
b.machine,'alter system kill session ''' || b.sid || ',' || b.serial# || ',@'|| b.inst_id ||''';'
FROM gv$locked_object a, gv$session b, dba_objects c
WHERE b.sid = a.session_id AND a.object_id = c.object_id and c.object_name='TABLE_NAME' and a.inst_id = b.inst_id;;

 

 

Oracle DBA ( Database Administrator ) needs useful scripts to monitor, analyze and check Oracle database for routine database operations and monitoring.

 

Find Blocking Sessions in Oracle

You can find historical blocking session and lock with below scripts. Change date time column which is specified with bold character.

select v.sql_text,v.sql_fulltext,sub.* from v$sql v,
(select sample_time,s.sql_id sql_id, session_state, blocking_session,
owner||'.'||object_name||':'||nvl(subobject_name,'-') obj_name,s.program,s.module,s.machine
from dba_hist_active_sess_history s, dba_objects o
where sample_time between
to_date('27/02/2019 07:30:02','DD/MM/YYYY HH24:MI:SS')
and
to_date('28/02/2019 15:10:02','DD/MM/YYYY HH24:MI:SS')
and event = 'enq: TX - row lock contention'
and o.data_object_id = s.current_obj#
order by 1 desc) sub where sub.sql_id=v.sql_id;




You can find momentarily blocking session and lock with below scripts.

select s1.username || '@' || s1.machine
|| ' ( THIS SID=' || s1.sid || ' )  is blocking '
|| s2.username || '@' || s2.machine || ' ( SID=' || s2.sid || ' ) ' AS blocking_status
from gv$lock l1, gv$session s1, gv$lock l2, gv$session s2
where s1.sid=l1.sid and s2.sid=l2.sid
and l1.BLOCK=1 and l2.request > 0
and l1.id1 = l2.id1
and l2.id2 = l2.id2 ;

 

You can generate Kill script of Blocking sessions like below.

SELECT 
'alter system kill session ''' || SID || ',' || s.serial# || ',@'||inst_id||''';',sid,username,serial#,process,NVL (sql_id, 0),
sql_address,blocking_session,wait_class,event,p1,p2,p3,seconds_in_wait
FROM gv$session s WHERE blocking_session_status = 'VALID'
OR sid IN (SELECT blocking_session
FROM gv$session WHERE blocking_session_status = 'VALID');

 

 

Alter system kill session

query result will be like below if you have blocking session in your database.

alter system kill session '1,39390,@1';
alter system kill session '2,2536,@1';
alter system kill session '3,26324,@1';


Kill Locked Session

Sometimes application developers or client offers you to kill any session or sessions group like SQL Net Client, or JDBC Client sessions or RMAN sessions.

You need to find session SID and SERIAL# with below script.

select s.SID,s.SERIAL#,S.USERNAME from v$session s where s.sid=63;

 

You can kill any session with its SID and SERIAL# number like below.

alter system kill session '63,1963';

 

Customer offers you to kill sessions group like SQL Net Client, or JDBC Client sessions or RMAN sessions. You can generate kill session script like below. You can change event to kill any other event group sessions.

SELECT 'kill -9 ' || p.spid, s.username,
'alter system kill session ''' || SID || ',' || s.serial# || ''';'
FROM v$session s, v$process p
WHERE s.paddr = p.addr(+)
AND s.SID IN (SELECT SID
FROM v$session_wait
WHERE event LIKE 'SQL*Net message from client%')
and s.username ='DEVECI'
and s.saddr not in ( select SES_ADDR from v$transaction );


Sometimes you have just SQL_ID and you need to find sessions related with this SQL_ID, then you can find like below and you can generate kill script like below.

SELECT 'kill -9 ' || p.spid, s.username,
'alter system kill session ''' || SID || ',' || s.serial# ||',@'||p.inst_id|| ''';'
FROM gv$session s, gv$process p
where s.SQL_ID like '4p5w3j8b3yhcw'
and s.PADDR = p.ADDR (+)
and s.STATUS='ACTIVE'
order by 1;


You can kill RMAN sessions which gives extra efor to the database like below.

SELECT 'kill -9 ' || p.spid, s.username,
       'alter system kill session ''' || SID || ',' || s.serial# ||',@'||p.inst_id|| ''';'
  FROM gv$session s, gv$process p
 WHERE s.paddr = p.addr(+)
and s.TYPE ='USER'
and s.program like 'rman%';


Sometimes you want to kill all users sessions except Application user. You can use following query to do this task.

SELECT 'kill -9 ' || p.spid, s.username,
       'alter system kill session ''' || SID || ',' || s.serial# ||',@'||p.inst_id|| ''';'
  FROM gv$session s, gv$process p
 WHERE s.paddr = p.addr(+)
and s.TYPE ='USER'
AND s.USERNAME <>'MSDEVECI';



 

 

Kill Session Script

You may want to kill some users sessions which is still executing more than 300 seconds, then you can use following useful Oracle DBA script.

 

SELECT 'kill -9 ' || p.spid, s.username,
       'alter system kill session ''' || SID || ',' || s.serial# || ''';'
  FROM v$session s, v$process p
 WHERE s.paddr = p.addr(+)
       AND s.SID IN (
   select sid
  from v$sql_monitor where status ='EXECUTING'  and elapsed_time/1000000> 300 
  and username in ('MEHMET','SALIH'))



You may want to kill some users sessions which are still executing more than 720 seconds and without SYS user and User type ( not background sessions ), then you can use following useful Oracle DBA script.

 

SELECT 
'alter system kill session ''' || SID || ',' || s.serial# ||',@'||p.inst_id|| ''';'
FROM gv$session s, gv$process p
WHERE s.paddr = p.addr(+)
and s.TYPE ='USER' and s.username!='SYS' and status='ACTIVE' and last_call_et > 720;


DBMS_OUTPUT.PUT_LINE in PL/SQL

 I will explain dbms_output.put_line in PL/SQL in this post.

DBMS_OUTPUT.PUT_LINE

 

PL/SQL has DBMS_OUTPUT package that is used to send messages from procedures, packages, and triggers. This package is used to display output to a screen.

 

PUT_LINE

DBMS_OUTPUT.PUT_LINE procedure is used to place a line in the buffer or display output to a screen.

Syntax

DBMS_OUTPUT.PUT_LINE (item IN VARCHAR2);

 

Example:

SQL> SET SERVEROUTPUT ON 
SQL> BEGIN DBMS_OUTPUT.PUT_LINE ('Hello IT Tutorial'); 
2 DBMS_LOCK.SLEEP (10); 
3 END;
4 /

Hello IT Tutorial

PL/SQL procedure successfully completed.

SQL>

dbms_output.put_line procedure trims off white space from output as follows.

SQL> 
SQL> SET SERVEROUTPUT ON
SQL> BEGIN DBMS_OUTPUT.PUT_LINE ('   Hello IT Tutorial    ');
2 END;
3 /
Hello IT Tutorial

PL/SQL procedure successfully completed.

SQL>


When your lines exceeds the line limit, you receive an error message after execution.

Alert Log file location in Oracle

I will explain Alert Log file locations in Oracle in this post.

 Alert log file is most important log file for Oracle DBAs, because this file includes chronological log of messages and errors of Oracle database like startup, shutdown, log switches, partition add , session kill and etc.

 

You can learn the Alert log file location of Oracle instance using the following query.

SQL> select value from GV$DIAG_INFO WHERE name='Diag Trace';

VALUE
------------------------------------------------------------------

/u01/app/oracle/diag/rdbms/msdb/msdb2/trace
/u01/app/oracle/diag/rdbms/msdb/msdb1/trace

SQL>

 

My database is cluster and it has 2 nodes, so you saw two location for 2 instances.

MSSQL SERVER CHECK_POLICY = ON / OFF

While creating a user on the sql server, the chech policy parameter tests the conformity of the user password and the db password structure.

CREATE LOGIN EKARA WITH PASSWORD = ‘a’, CHECK_EXPIRATION = OFF, CHECK_POLICY = off, DEFAULT_DATABASE = xyz;
I get the error you would expect:

CREATE LOGIN EKARA WITH PASSWORD = ‘Abcd_2021?’, CHECK_EXPIRATION = OFF, CHECK_POLICY = on, DEFAULT_DATABASE = xyz;

Commands completed successfully.

Friday, 25 June 2021

Temp tablespace space check.

set pages 1000;

set lines 120;

set feedback off;

SELECT   A.tablespace_name tablespace, D.mb_total,

        SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_used,

        D.mb_total - SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_free

FROM     v$sort_segment A,

        (

        SELECT   B.name, C.block_size, SUM (C.bytes) / 1024 / 1024 mb_total

        FROM     v$tablespace B, v$tempfile C

        WHERE    B.ts#= C.ts#

        GROUP BY B.name, C.block_size

        ) D

WHERE    A.tablespace_name = D.name

GROUP by A.tablespace_name, D.mb_total

/