Friday, January 5, 2018

creating baselines from AWR for consistant performance and how to move them to another environments

1)
Here we are creating a BASELINE profiles from previous runs using AWR reports... if we think the execution plan in one database is working fine and want to have the same consistant execution plan for sql.

login as system user

1)

BEGIN
  DBMS_SQLTUNE.CREATE_SQLSET(
    sqlset_name => 'BASIC_PROC_NAME',
    description => 'SQL Tuning Set for loading plan into SQL Plan Baseline');
END;
/

2)

DECLARE
  cur sys_refcursor;
BEGIN
  OPEN cur FOR
    SELECT VALUE(P)
    FROM TABLE(
       dbms_sqltune.select_workload_repository(begin_snap=>4176, end_snap=>4179,basic_filter=>'sql_id = ''0cadrfdx9t0z1e''',attribute_list=>'ALL')
              ) p;
     DBMS_SQLTUNE.LOAD_SQLSET( sqlset_name=> 'BASIC_PROC_NAME', populate_cursor=>cur);
  CLOSE cur;
END;
/



 SELECT
  first_load_time          ,
  executions as execs              ,
  parsing_schema_name      ,
  elapsed_time  / 1000000 as elapsed_time_secs  ,
  cpu_time / 1000000 as cpu_time_secs           ,
  buffer_gets              ,
  disk_reads               ,
  direct_writes            ,
  rows_processed           ,
  fetches                  ,
  optimizer_cost           ,
  sql_plan                ,
  plan_hash_value          ,
  sql_id                   ,
  sql_text
   FROM TABLE(DBMS_SQLTUNE.SELECT_SQLSET(sqlset_name => 'BASIC_PROC_NAME')
             );
           


3)

DECLARE
my_plans pls_integer;
BEGIN
  my_plans := DBMS_SPM.LOAD_PLANS_FROM_SQLSET(
    sqlset_name => 'BASIC_PROC_NAME',
    basic_filter=>'plan_hash_value = ''4972313474'''
    );
END;
/

Make sure you see the row….

SELECT * FROM dba_sql_plan_baselines ;

select sql_handle, sql_text, plan_name,PARSING_SCHEMA_NAME,enabled,accepted,fixed,to_char(last_executed,'dd-mon-yy HH24:MI') last_executed from dba_sql_plan_baselines;

4) To backup the sql baseline to other environment... then continue.

exec DBMS_SPM.CREATE_STGTAB_BASELINE('SQL_PROF_BASELINE','SCHEMA_NAME');

select table_name,owner from dba_tables where table_name='SQL_PROF_BASELINE';

SELECT * FROM dba_sql_plan_baselines;
no rows initially

5)

var x number;
begin
:x := DBMS_SPM.PACK_STGTAB_BASELINE('SQL_PROF_BASELINE', 'SCHEMA_NAME', sql_handle => 'SQL_300901f0272d8837', plan_name => 'SQL_PLAN_30281y0mkv21r64b2d935' );
end;
/


6)

export ....

7)

Purge the existing which is not good....

exec DBMS_SHARED_POOL.PURGE ('0000000410E16308, 3635099784', 'C');

8)
import.... as system user

unpack...

7)

 var x number;
begin
:x := DBMS_SPM.UNPACK_STGTAB_BASELINE('SQL_PROF_BASELINE', 'SCHEMA_NAME');
end;
 /

SELECT * FROM dba_sql_plan_baselines;

***************************** END **********************************



 DECLARE
  v_dropped_plans number;
BEGIN
  v_dropped_plans := DBMS_SPM.DROP_SQL_PLAN_BASELINE (
     sql_handle => 'SQL_300901f0272d8837'
);
  DBMS_OUTPUT.PUT_LINE('dropped ' || v_dropped_plans || ' plans');
END;
/


Hope this Helps....

Performance: database slowness/blocking when Oracle Auto Task scheduled window jobs are running.


Disable below Oracle scheduled Auto jobs when you see slowness in the Application in one of the environments. 
If you have your own Gather Statistics Job  running in your environment and you do not want these advisor jobs..
These jobs usually runs in the night in weekdays and has a bigger window in the weekend.

exec DBMS_AUTO_TASK_ADMIN.DISABLE(client_name => 'auto optimizer stats collection',operation => NULL,window_name => NULL);
exec DBMS_AUTO_TASK_ADMIN.DISABLE(client_name => 'auto space advisor',operation => NULL,window_name => NULL);
exec DBMS_AUTO_TASK_ADMIN.DISABLE(client_name => 'sql tuning advisor',operation => NULL,window_name => NULL);



Hope this Helps...

Wednesday, January 3, 2018

How to check whether table is getting used or not in oracle

To find whether object that is getting used or not please do these little steps to judge...

1) using dba_dependiencies..

select
   owner,
   type,
   name,
   referenced_owner,
   referenced_type,
   referenced_name
from
   dba_dependencies
where
referenced_owner like 'ABC_%'
and referenced_type ='TABLE'
and referenced_name in (
'ABC_123');

2) check any DDL Operations where done.

SELECT TABLE_NAME,PARTITION_NAME,SUBPARTITION_NAME,INSERTS,UPDATES,DELETES,TRUNCATED,TIMESTAMP FROM dba_TAB_MODIFICATIONS
WHERE TABLE_NAME='TMP_UCL_USER';


3) find any sql's were run from awr snapshots... add columns / make changes as you need.

select
   p.object_name  ,p.sql_id,
   to_char(sn.end_interval_time,'DD-MM')   ,
   count(1)                           
from
  dba_hist_sql_plan   p,
  dba_hist_sqlstat    s,
  dba_hist_snapshot  sn
where
  p.object_owner <> 'SYS' 
and
  p.sql_id = s.sql_id
and
  s.snap_id = sn.snap_id
  and
  sn.end_interval_time between to_date ('20-12-2017 10:00','DD-MM-YYYY HH24:MI')  and to_date ('01-01-2018 19:30','DD-MM-YYYY HH24:MI') and
 --s.executions_delta > 1000
p.object_name in (
 and
s.module not in ('emagent_SQL_oracle_database','emagent_AQMetrics','Oracle Enterprise Manager.Metric Engine')
group by p.object_name, to_char(sn.end_interval_time,'DD-MM'),p.sql_id
order by   2,1;


hope this helps......

how to get pluggable databases info from container database in oracle 12C using a common user.

This post helps you to query all pluggable databases info using common user in container database.. To do that we need to create a common user in the container database and provide neccesary grants.
As you all know we can create a common user with out "C##" in the container database by using "_" parameter..

alter session set "_ORACLE_SCRIPT"=true;

provide neccessary grants... connect/select_catalog_role/select any dictionary/ alter session/create session ... if neccesary tablespace limits too...

once the user is created you still need to run below command to read the pluggable databases information...

alter user COMMON_USER_CHECK set container_data=all;

Using this user and CDB* views now you can get all the info from container.  in one place..



Hope this helps..

Script to get Lun ids for Linux in VM for ASM disks.



Below information will be handy when you want to know the lun id'd for the raw devices you are using in the ASM environment ..this will eliminate the need for you to wait for Unix admins to give you the lun info. ....

> there are 2 scripts... one is .sql and another one is .sh(main shell)..

1)
 make a script to ger ASM info of the raw devices...

set heading off
set feedback off
set echo off
set pagesize 0
col NAME for a30
col PATH for a30
spool asm_info.log
select NAME,PATH,OS_MB from V$ASM_DISK order by NAME asc;

2)
then make a main shell.... and give execute permissions...

--------------------------------------------------------------------
ORACLE_SID=+ASM
ORACLE_HOME=/usr/app/oracle/db_1
PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID
export ORACLE_HOME
export PATH
echo $ORACLE_SID
echo $ORACLE_HOME
cd /usr/job/scripts/lun_info

rm -f /usr/job/scripts/lun_info/asm_info.log
rm -f /usr/job/scripts/lun_info/asm_info_cut.log
rm -f /usr/job/scripts/lun_info/asm_info_final.log
rm -f /usr/job/scripts/lun_info/asm_disk_lun_info.log
rm -f /usr/job/scripts/lun_info/asm_raw-physical.log

sqlplus / as sysdba << EOF
set heading off
set feedback off
set echo off
set pagesize 0
@disk_info.sql
exit
EOF
#cat asm_info.log|cut -c7- > asm_info_cut.log
cat asm_info.log| awk '{print $2}' > asm_info_cut.log
cat asm_info_cut.log|while read disk
do
echo "`cat /etc/udev/rules.d/60-raw.rules | grep -v '^#' | grep $disk | awk '{print $2}' | grep -Po '".*?"' | grep -oP '"\K[^"]+' `" >> asm_disk_lun_info.log
done

cat asm_disk_lun_info.log |while read rawd
do
echo "$rawd  `lsscsi | grep $rawd'' | awk '{print $1}'` " >> asm_raw-physical.log
done

paste asm_info.log asm_disk_lun_info.log asm_raw-physical.log| awk  '
BEGIN {
format = "%-20s %-18s %-19s %-18s  %-19s %s\n"
printf format,  "ASM_groups", "ASM_RAW_DISK",  "OS_DISK_SIZE", "UNIX_MAP_Disk", "LINUX_id",  "LINUX_SCSI_id"
printf format,  "----------", "-------------", "------------", "-------------", "--------", "-------------"}
{for(i=1;i<=NF;i++)
printf("%-20s%c", $i, (i==NF) ? ORS : "")}' >> asm_info_final.log;
exit;

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


look for asm_info_final.log...... for this column....

LINUX_SCSI_id  --- validate with your storage admins...

Hope this helps......................................


PostgreSql: Useful Commands-

 1)   ************************* Users ***************************  -- List of users with roles assigned: SELECT usename AS role_name,   CASE...