Friday, February 23, 2024

shelll scrips

 cat TEST_DB

https://www.funoracleapps.com/2021/06/shell-script-to-change-sys-and-system.html

TEST1
TEST2
TEST3
TEST4


Script:

#!/bin/bash
#################################################################################
#PURPOSE: TEST DB SYS and SYSTEM password change script
# Usage : sys_system_pass_change.sh [PROD]/[TEST]
#Author Version Date
#Himanshu Singh 1.0 15-AUG-2020
#
##################################################################################

#######################Before change system password prefix#######################
prefx=dundb
##############Change the below value before canging system password##################

newprefx=ebs123
. $HOME/testdb.env
checkfile=TNS_DB_CHECK.log
passch=PASS_CHANGE.log
RECEIPENTS=support@funoracleapps.com
RUN_USER=`who am i |awk '{print $1}'`
if [ $# -ne 1 ]
then
echo "No Parameter passed!! ==\>Either Pass TEST or PROD\<== Exiting"
exit 1;
fi

if [ "$1" == "TEST" ]
then
inst_file=TEST_DB
elif [ "$1" == "PROD" ]
then
inst_file=PROD_DB
else
echo "Wrong Parameter passed!! Exiting"
exit 1;
fi

pass_checker ()
{
for db_name in `cat ${inst_file}|grep -v '^#'`
do
tnsping ${db_name} > /tmp/tnsping_check
count=`grep -i "ok" /tmp/tnsping_check|wc -l`
if [ $count -ne 1 ]
then
echo "Tnsping to ${db_name} failed..Please check"
#else
#echo "TNSPING working on ${db_name}"
fi
dataname=`echo ${db_name}|tr [:upper:] [:lower:]`
echo "======================================================================="
echo " Checking the database ${db_name}" 
echo "======================================================================="
#echo "connect system/${prefx}${dataname}@${db_name}"
sqlplus -s "/as  sysdba" <<EOF
connect system/${prefx}${dataname}@${db_name}
select name from v\$database;
exit;
EOF

done
}

change_pass ()
{
for db_name in `cat ${inst_file}|grep -v '^#'`
do
dataname=`echo ${db_name}|tr [:upper:] [:lower:]`
echo "======================================================================="
echo " Working on the database ${db_name}"
echo "======================================================================="
sqlplus -s "/as  sysdba" <<EOF
connect system/${prefx}${dataname}@${db_name}
select name from v\$database;
alter user sys identified by ${newprefx}${dataname};
alter user system identified by ${newprefx}${dataname};
exit;
EOF

done
}


#################################################################
##### MAIN PROG################################################
################################################################
echo " FUNORACLEAPPS -- SYS and SYSTEM PASSWORD CHANGE UTILITY "
export PS3="Please make a selection [1-3][Press 3 for Exit]  => " 
select fun in Pass_Check Change_Pass Exit
do
case $fun in 

"Pass_Check") pass_checker > ${checkfile}
echo "Completed"
mailx -s "SYS and SYSTEM Password Connection Check in  $1 Instances on `date` executed by ${RUN_USER}" ${RECEIPENTS} < ${checkfile}
;;
"Change_Pass") change_pass > ${passch}
echo "Completed"
mailx -s "SYS and SYSTEM Password Changed Completed in $1 Instances  on `date` executed by ${RUN_USER}" ${RECEIPENTS} <  ${passch}
;;
"Exit") echo "Exiting" 
exit 0;
;;
 *)echo "Invalid option. Program will exit now."
            break
            ;;
esac
done

Thursday, February 15, 2024

tablespace move

 set feedback off

set echo off

set serverout off

set pages 0

set lines 200 

col name new_val dbname noprint

select name from v$database;

spool mvlobs_&&dbname\.sql

prompt spool mvlobs_&&dbname

select 'alter table ' || owner || '.' || table_name ||

' move lob(' || column_name || ') store as (tablespace '||tablespace_name||'_NEW);'

from dba_lobs where tablespace_name not in ('SYSTEM', 'SYSAUX', 'UNDOTBS1','USERS','TEMP')

order by tablespace_name;

prompt spool off

spool off

set feedback off
set echo off
set serverout off
set pages 0
set lines 200 
col name new_val dbname noprint
select name from v$database;
spool mvtabs_&&dbname\.sql
prompt spool mvtabs_&&dbname
select 'alter table '||owner||'.'||table_name||' move tablespace '||tablespace_name||'_NEW;' 
from dba_tables 
where tablespace_name not in ('SYSTEM', 'SYSAUX', 'UNDOTBS1','USERS','TEMP') 
and tablespace_name in (select tablespace_name from dba_tablespaces where bigfile = 'NO') 
order by tablespace_name,blocks;    
prompt spool off
spool off

set feedback off
set echo off
set serverout off
set pages 0
set lines 200 
col name new_val dbname noprint
select name from v$database;
spool rebuild_idx_&&dbname\.sql
prompt spool rebuild_idx_&&dbname
select 'alter index '||owner||'.'||table_name||' rebuild tablespace '||tablespace_name||'_NEW;' 
from dba_indexes 
where tablespace_name not in ('SYSTEM', 'SYSAUX', 'UNDOTBS1','USERS','TEMP')
and index_type != 'LOB'
and tablespace_name in (select tablespace_name from dba_tablespaces where bigfile='NO')
order by tablespace_name, table_name; 
prompt spool off
spool off

Friday, March 3, 2023

 

https://github.com/nkarag/oracle_ready2run_scripts/

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

-- Find the available execution plans for a specific SQL_ID

--

--              Note that the AVG_ET_SECS (average elpased time) will not be accurate for parallel queries. 

-- The ELAPSED_TIME column contains the sum of all parallel slaves. So the 

--              script divides the value by the number of PX slaves used which gives an 

--              approximation. 

--

--              Note also that if parallel slaves are spread across multiple nodes on

--              a RAC database the PX_SERVERS_EXECUTIONS column will not be set.

--

-- author: Nikos Karagiannidis (C) 2013 - http://oradwstories.blogspot.com

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


prompt

prompt ********************************************************

prompt Find the available execution plans for a specific SQL_ID

prompt ********************************************************

prompt


set linesize 999

col avg_et_secs justify right format 9999999.99 

col cost justify right format 9999999999 

col timestamp justify center format a25 

col parsing_schema_name justify center format a30

col inst_id format 999999999 

col executions_total format 99999999999999999

col executions format 99999999999999


alter session set nls_date_format='dd-mm-yyyy hh24:mi:ss';


select 'gv$sqlarea_plan_hash' source, INST_ID, 

SQL_ID, PLAN_HASH_VALUE, 

executions, 

round(elapsed_time/decode(nvl(executions,0),0,1,executions)/1e6/

decode(px_servers_executions,0,1,px_servers_executions)/decode(nvl(executions,0),0,1,executions),2) avg_et_secs, 

px_servers_executions/decode(nvl(executions,0),0,1,executions) avg_px,

optimizer_cost cost, 

LAST_LOAD_TIME timestamp, 

parsing_schema_name --FIRST_LOAD_TIME, LAST_LOAD_TIME, LAST_ACTIVE_TIME, SQL_PROFILE

from gv$sqlarea_plan_hash

where sql_id = nvl(trim('&&sql_id'),sql_id)

UNION

SELECT 'dba_hist_sql_plan' source, null INST_ID, 

t1.sql_id sql_id, t1.plan_hash_value plan_hash_value, 

t2.executions_total, 

t2.avg_et_secs avg_et_secs, 

t2.avg_px, 

t1.cost cost, 

t1.timestamp timestamp, 

NULL parsing_schema_name 

FROM dba_hist_sql_plan t1,

(

SELECT sql_id, plan_hash_value, 

max(executions_total) executions_total, --round(SUM(elapsed_time_total)/decode(SUM(executions_total),0,1,SUM(executions_total))/1e6,2) avg_et_secs 

round(SUM(elapsed_time_total)/decode(SUM(executions_total),0,1,SUM(executions_total))/1e6/

decode(SUM(px_servers_execs_total),0,1,SUM(px_servers_execs_total))/decode(SUM(executions_total),0,1,SUM(executions_total)),2) avg_et_secs, 

SUM(px_servers_execs_total)/decode(SUM(executions_total),0,1,SUM(executions_total)) avg_px

FROM dba_hist_sqlstat

WHERE 

executions_total > 0

GROUP BY sql_id, plan_hash_value

) t2

WHERE 

t1.sql_id = nvl(TRIM('&sql_id.'), t1.sql_id)

AND t1.depth = 0

AND t1.sql_id = t2.sql_id(+)

AND t1.plan_hash_value = t2.plan_hash_value(+)

order by avg_et_secs, cost --timestamp desc 

/

undef sql_id


Sunday, November 7, 2021

top sessions

 http://db.geeksinsight.com/tools-scripts/

REF:

set pagesize 100
set linesize 250
col INSTANCE_NUMBER format 99
col SESSION_ID format 99999
col BLOCKING_INST_ID format 99
col event format a20
col WAIT_CLASS format a15
col PROGRAM format a20
col MODULE format a16
col p3 format 99999999999999999999
select sql_id,to_char(SAMPLE_TIME,'YYYYMMDD-HH24:MI:SS'),
       INSTANCE_NUMBER,SESSION_ID,PROGRAM,MODULE,EVENT,
       CURRENT_OBJ#,WAIT_CLASS,BLOCKING_INST_ID,
       BLOCKING_SESSION, p3
from dba_hist_active_sess_history
where INSTANCE_NUMBER= 3 
and SESSION_ID = 2437 
and sample_time between to_date('16-06-18 11:00:00','DD-MM-YY HH24:MI:SS')
and to_date('16-06-18 11:04:00','DD-MM-YY HH24:MI:SS')
and event ='library cache lock'
order by sample_id;

col USERNAME for a10
col machine for a30
col Text for a50 wrap on
select 
se.SID, ss.serial#,
 ss.username, 
 ss.machine,
 ss.sql_id,
 to_char(s.last_active_time,'DD-MON-YY HH:MI:SS'),
 s.last_load_time, 
 VALUE/100 cpu_secs ,
 substr(s.sql_text,1,50) Text
from 
 v$session ss, 
 v$sesstat se, 
 v$statname sn,
 v$sql s
where 
 se.STATISTIC# = sn.STATISTIC# 
and 
 NAME like '%CPU used by this session%' 
and 
 se.SID = ss.SID 
--and 
 --ss.status='ACTIVE' 
--and 
-- ss.username is not null  and ss.username!='DBMANAGER'
and 
 ss.sql_id=s.sql_id
order by VALUE desc;


SH TOP Queries
 
select
decode(nvl(to_char(s.sid),-1),-1,'DISCONNECTED','CONNECTED')
"STATUS",
topsession.session_id             "SESSION_ID",
topsession.sample_time    "SAMPLE_TIME",
u.name                                         "NAME",
topsession.program                  "PROGRAM",
max(topsession.CPU)               "CPU",
max(topsession.WAITING)       "WAITING",
max(topsession.IO)                   "IO",
max(topsession.TOTAL)            "TOTAL"
from (   select
ash.session_id,
to_char(ash.sample_time,'DD-MON-YYYY HH24:MI') ,
ash.session_serial#,
ash.user_id,
ash.program,
sum(decode(ash.session_state,'ON CPU',1,0))     "CPU",
sum(decode(ash.session_state,'WAITING',1,0))    -
sum(decode(ash.session_state,'WAITING',
decode(en.wait_class,'User I/O',1, 0 ), 0))    "WAITING" ,
sum(decode(ash.session_state,'WAITING',
decode(en.wait_class,'User I/O',1, 0 ), 0))    "IO" ,
sum(decode(session_state,'ON CPU',1,1))     "TOTAL"
from v$active_session_history ash,
v$event_name en
where en.event# = ash.event#
group by session_id,user_id,session_serial#,program
order by sum(decode(session_state,'ON CPU',1,1))   )        topsession,
v$session s,
user$ u
where
u.user# =topsession.user_id and
/* outer join to v$session because the session might be disconnected */
topsession.session_id         = s.sid         (+) and
topsession.session_serial# = s.serial#   (+) and  to_char(topsession.sample_time,'DD-MON-YYYY HH24:MI')  between '19-AUG-2016 03' and '19-AUG-2016 04'
group by  topsession.session_id, topsession.session_serial#, topsession.user_id,
topsession.program, s.username,s.sid,s.paddr,u.name,topsession.sample_time
order by max(topsession.TOTAL) desc
Top Session consuming CPU last N minutes
Select
session_id,
count(*)
from
v$active_session_history
where
session_state= 'ON CPU' and
SAMPLE_TIME > sysdate – (&minutes/(24*60))
group by
session_id
order by
count(*) desc;
 
Top Waiting Session  in last 5 minutes
Select                        session_id,
count(*)
from
v$active_session_history
where
session_state='WAITING'  and
SAMPLE_TIME >  SYSDATE - (&minutes/(24*60))
group by
session_id
order by
count(*) desc;
 
Top Session Consuming CPU, IO and Waiting last n minutes
select
ash.session_id,
ash.session_serial#,ash.sql_id,
ash.user_id,
ash.program,
sum(decode(ash.session_state,'ON CPU',1,0))     "CPU",
sum(decode(ash.session_state,'WAITING',1,0))    -
sum(decode(ash.session_state,'WAITING',
decode(en.wait_class,'User I/O',1, 0 ), 0))    "WAITING" ,
sum(decode(ash.session_state,'WAITING',
decode(en.wait_class,'User I/O',1, 0 ), 0))    "IO" ,
sum(decode(session_state,'ON CPU',1,1))     "TOTAL"
from v$active_session_history ash,
v$event_name en
where en.event# = ash.event# and  SAMPLE_TIME >  SYSDATE - (&minutes/(24*60))
group by sql_id,session_id,user_id,session_serial#,program
order by sum(decode(session_state,'ON CPU',1,1));

Saturday, November 6, 2021

Gather stats on the table

 col TABLE_NAME for a30

col PARTITION_NAME for a20
col SUBPARTITION_NAME for a20
select OWNER,TABLE_NAME,PARTITION_NAME,SUBPARTITION_NAME,NUM_ROWS,LAST_ANALYZED from DBA_TAB_STATISTICS where STALE_STATS='YES';

OR

select OWNER,TABLE_NAME,LAST_ANALYZED,STALE_STATS from DBA_TAB_STATISTICS where OWNER='&OWNER' AND STALE_STATS='YES';
set linesize 200 trimspool on
set pagesize 100
set pause off echo off verify off
set head on term on
col begin_interval_time format a30
col min_sess_per_day format 99,999 head 'MIN|SESS|PER|DAY'
col max_sess_per_day format 99,999 head 'MAX|SESS|PER|DAY'
col avg_sess_per_day format 99,999 head 'AVG|SESS|PER|DAY'
col min_proc_per_day format 99,999 head 'MIN|PROC|PER|DAY'
col max_proc_per_day format 99,999 head 'MAX|PROC|PER|DAY'
col avg_proc_per_day format 99,999 head 'AVG|PROC|PER|DAY'
with processes as (
select snap_id, CURRENT_UTILIZATION process_count
from dba_hist_RESOURCE_LIMIT
where resource_name = 'processes'
),
sessions as (
select snap_id, CURRENT_UTILIZATION session_count
from dba_hist_RESOURCE_LIMIT
where resource_name = 'sessions'
)
select distinct
sn.begin_interval_time
, min(s.session_count) over ( partition by trunc(sn.begin_interval_time)) min_sess_per_day
, max(s.session_count) over ( partition by trunc(sn.begin_interval_time)) max_sess_per_day
, round(avg(s.session_count) over ( partition by trunc(sn.begin_interval_time)),1) avg_sess_per_day
, min(p.process_count) over ( partition by trunc(sn.begin_interval_time)) min_proc_per_day
, max(p.process_count) over ( partition by trunc(sn.begin_interval_time)) max_proc_per_day
, round(avg(p.process_count) over ( partition by trunc(sn.begin_interval_time)),1) avg_proc_per_day
from dba_hist_snapshot sn
right outer join sessions s on s.snap_id = sn.snap_id
right outer join processes p on p.snap_id = sn.snap_id
order by sn.begin_interval_time
/
SELECT OWNER,TABLE_NAME,LAST_ANALYZED,STALE_STATS from DBA_TAB_STATISTICS WHERE TABLE_NAME='&TNAME';

-- awr-top-sqlid-events.sql
-- get top 5 events per AWR snapshot, per sql_id
-- Jared Still still@pythian.com jkstill@gmail.com
--
-- 2016-11-02 jkstill - added enqueue decode

-- requires https://github.com/jkstill/oracle-script-lib/blob/master/get_date_range.sql

-- prompt for date range
@get_date_range

-- or just specify it here
--@get_date_range '2018-07-01 00:00:00' '2018-07-12 08:00:00'

@clears 

set linesize 200 trimspool on
set pagesize 60

col event format a30
col p1text format a20
col p1 format a25
col p2text format a20

spool aws-top-sqlid-event.log

break on begin_interval skip 1

with snaps as (
select 
min(snap_id) min_snap_id
, max(snap_id) max_snap_id
from dba_hist_snapshot
where begin_interval_time >= to_date(:v_begin_date,'&d_date_format')
and end_interval_time <= to_date(:v_end_date,'&d_date_format')
),
data as (
select 
h.snap_id
, h.dbid
, h.instance_number
, case h.session_state
when 'ON CPU' then 'CPU'
else h.event
end event
, h.p1text
, CASE
WHEN event like 'enq%' THEN
'0x'||trim(to_char(h.p1, 'XXXXXXXXXXXXXXXX'))||': '||
chr(bitand(h.p1, 4278190080)/16777216)||
chr(bitand(h.p1,16711680)/65536)||
' mode '||bitand(h.p1, power(2,14)-1)
ELSE NULL 
END AS p1
, h.sql_id
from dba_hist_active_sess_history h
where h.sql_id is not null
),
agg_data as (
select  distinct
to_char(hs.begin_interval_time,'&d_date_format') begin_interval
, d.instance_number
, d.sql_id
, d.event
, d.p1text
, d.p1
, count(d.event) over (partition by d.snap_id, d.sql_id, d.event, d.instance_number) event_count
from data d
join dba_hist_snapshot hs on hs.snap_id = d.snap_id
and hs.instance_number = d.instance_number
and hs.dbid = d.dbid
and hs.snap_id between (select min_snap_id from snaps)
and (select max_snap_id from snaps)
--where rownum <= 200
order by begin_interval, event_count desc, instance_number
), 
rank_output as (
select
begin_interval
, instance_number
, sql_id
, event
, p1text
, p1
, event_count
, row_number() over (partition by begin_interval, instance_number order by event_count desc) event_rank
from agg_data
)
select 
begin_interval
, instance_number
, sql_id
, event
, p1text
, p1
, event_count
, event_rank
from rank_output
where event_rank <= 5
order by begin_interval, event_count desc
/

spool off

ed aws-top-sqlid-event.log

Thursday, December 10, 2020

Day -DBA scripts-fragmentation

set head off
set feedback off
spool kill_&a_sess_i1.sql
select 'spool kill_&a_sess.log' from dual;
select 'set feedback on' from dual;
select 'alter system kill session '||chr(39)||sid||','||serial#||chr(39)||';'
from v$session
where username='&a';
select 'spool off' from dual;
spool off
@kill_&a_sess_i1.sql
spool chk_Rajtest_sess_i1.log
select 'set feedback on' from dual;
select sid, serial# from v$session where username='Rajtest';
spool off

Rebuild index

set feedback off
set echo off
set serverout off
set pages 0
set lines 200 
col name new_val dbname noprint
select name from v$database;
spool rebuild_idx_&&dbname\.sql
prompt spool rebuild_idx_&&dbname
select 'alter index '||owner||'.'||table_name||' rebuild tablespace '||tablespace_name||'_NEW;' 
from dba_indexes 
where tablespace_name not in ('SYSTEM', 'SYSAUX', 'UNDOTBS1','USERS','TEMP')
and index_type != 'LOB'
and tablespace_name in (select tablespace_name from dba_tablespaces where bigfile='NO')
order by tablespace_name, table_name; 
prompt spool off
spool off

Tablespace usage

set pages 1000
set lines 133

set pagesize 80
set wrap off

ttitle center 'Weekly Tablespace Monitoring' skip 2 -
center 'List of Tablespaces where "Space Used" > 80%' skip 2

col tablespace_name format a30
col TABLESPACE_NAME heading "Tablespace|Name"
col Allocated_size heading "Allocated|Size(GB)" form 99999999.99
col Current_size heading "Current|Size(GB)" form 99999999.99
col Used_size heading "Used|Size(GB)" form 99999999.99
col Available_size heading "Available|Size(GB)" form 99999999.99
col Pct_used heading "%Used (vs)|(Allocated)" form 99999999.99
select a.tablespace_name
        ,a.alloc_size/1024/1024/1024 Allocated_size
        ,a.cur_size/1024/1024/1024 Current_Size
        ,(u.used+a.file_count*65536)/1024/1024/1024 Used_size
        ,(a.alloc_size-(u.used+a.file_count*65536))/1024/1024/1024 Available_size
        ,((u.used+a.file_count*65536)*100)/a.alloc_size Pct_used
from     dba_tablespaces t
        ,(select t1.tablespace_name
        ,nvl(sum(s.bytes),0) used
        from  dba_segments s
        ,dba_tablespaces t1
         where t1.tablespace_name=s.tablespace_name(+)
         group by t1.tablespace_name) u
        ,(select d.tablespace_name
        ,sum(greatest(d.bytes,nvl(d.maxbytes,0))) alloc_size
        ,sum(d.bytes) cur_size
        ,count(*) file_count
        from dba_data_files d
        group by d.tablespace_name) a
where t.tablespace_name=u.tablespace_name
and ((u.used+a.file_count*65536)*100)/a.alloc_size>50
and t.tablespace_name=a.tablespace_name
order by t.tablespace_name;


user login


set pages 0
 set lines 150
 set linesize 150
 set term on
 set feedback off
select 'sample_time,username,program,machine' from sys.dual;
SELECT
   sample_time||','||
   u.username||','||
   h.program ||','||
   h.MACHINE
FROM
   DBA_HIST_ACTIVE_SESS_HISTORY h,
   DBA_USERS u,
   DBA_HIST_SQLTEXT s
WHERE  sample_time > sysdate -30
AND
   INSTANCE_NUMBER in ( '1','2')
   AND  u.USERNAME not in ('SYS','SYSTEM','DBSNMP','SYSMAN','PRD')
   AND h.user_id=u.user_id
   AND h.sql_id = s.sql_iD
ORDER BY  sample_time ASC;


Fragmentation
set linesize 200 trimspool on
col owner for a22
col table_name for a30
col tablespace_name for a20
select t.owner,t.table_name, s.tablespace_name,
round(s.bytes/1024/1024) actual_MB,
round((t.num_rows+1) * t.avg_row_len/1024/1024) optimal_MB,
round(s.bytes/1024/1024) -
round((t.num_rows+1) * t.avg_row_len/1024/1024) CLAIMABLE_MB
from dba_tables t, dba_segments s
where t.owner = s.owner and s.owner='&owner_name'
and  t.table_name = s.segment_name
and round(s.bytes/1024/1024) - round((t.num_rows+1) * t.avg_row_len/1024/1024) > 200
order by CLAIMABLE_MB desc
/

long running sql
col os_username for a12
col os_pid for 99999
col session_machine for a15
col session_program for a15
col current_sql for a120
SELECT
s.sid sid
, s.serial# serial_id
, s.status session_status
, s.username oracle_username
, s.osuser os_username
, p.spid os_pid
, s.machine session_machine
, s.program session_program
, s.client_info 
, SUBSTR(sa.sql_text, 1, 1024) current_sql
FROM
v$process p
, v$session s
, v$sqlarea sa
WHERE
p.addr (+) = s.paddr
AND s.sql_address = sa.address(+)
AND s.sql_hash_value = sa.hash_value(+)
AND s.audsid <> userenv('SESSIONID')
AND s.username IS NOT NULL
AND s.status = 'ACTIVE'
ORDER BY sid;
CPU usage 

set linesize 200
set pagesize 120
col module for a60
SELECT   mymodule "Module", SUM (cpu_time) "CPU Time", SUM (wait_time) "Wait 
Time",
         SUM (cpu_time) + SUM (wait_time) "Total Time"
    FROM (SELECT a.module mymodule,
                 (CASE (session_state)
                     WHEN 'ON CPU'
                        THEN wait_time / 100
                  END
                 ) cpu_time,
                 (CASE (session_state)
                     WHEN 'WAITING'
                        THEN time_waited / 100
                  END
                 ) wait_time
            FROM dba_hist_active_sess_history a, dba_hist_snapshot b
           WHERE b.end_interval_time > sysdate-1
             AND a.snap_id = b.snap_id
             AND a.user_id NOT IN (0, 5)
             AND a.instance_number = b.instance_number)
GROUP BY mymodule
  HAVING SUM (cpu_time) + SUM (wait_time) > 0
ORDER BY 2 DESC;


Snapshot Standby database and how to convert physical standby database to snapshot standby database (READ WRITE mode)

 Snapshot Standby database and how to convert physical standby database to snapshot standby database (READ WRITE mode)

SQL> ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';
Session altered.
SQL> SELECT   a.thread#,  b. last_seq, a.applied_seq, a. last_app_timestamp, b.last_seq-a.applied_seq   ARC_DIFF FROM (SELECT  thread#, MAX(sequence#) applied_seq, MAX(next_time) last_app_timestamp FROM gv$archived_log WHERE applied = 'YES' GROUP BY thread#) a,           (SELECT  thread#, MAX (sequence#) last_seq FROM gv$archived_log GROUP BY thread#) b WHERE a.thread# = b.thread#;
   THREAD#   LAST_SEQ APPLIED_SEQ LAST_APP_TIMESTAMP     ARC_DIFF
---------- ---------- ----------- -------------------- ----------
         1         75          75 04-DEC-2019 11:09:55          0
         2         69          69 04-DEC-2019 11:07:26          0
SQL> select status,instance_name,database_role,open_mode from v$database,v$Instance;
STATUS       INSTANCE_NAME    DATABASE_ROLE    OPEN_MODE
------------ ---------------- ---------------- --------------------
MOUNTED      RAJDBA           PHYSICAL STANDBY MOUNTED
SQL> select thread#,max(sequence#) from v$archived_log where applied='YES' group by thread#;
   THREAD# MAX(SEQUENCE#)
---------- --------------
         1             75
         2             69
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
NO
SQL> show parameter db_recovery_file_dest
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      /b01/fra
db_recovery_file_dest_size           big integer 820G
SQL> alter database flashback_on on;
alter database flashback_on on
                            *
ERROR at line 1:
ORA-02231: missing or invalid option to ALTER DATABASE

SQL> alter database flashback on;
alter database flashback on
*
ERROR at line 1:
ORA-01153: an incompatible media recovery is active

SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database flashback on;
Database altered.
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
YES
Once the standby database is mounted, convert the Physical standby database to snapshot standby

SQL> alter database convert to snapshot standby;
Database altered.
SQL> alter database open;
Database altered.
SQL> select status,instance_name,database_role,open_mode from v$database,v$Instance;
STATUS       INSTANCE_NAME    DATABASE_ROLE    OPEN_MODE
------------ ---------------- ---------------- --------------------
OPEN         RAJDBA           SNAPSHOT STANDBY READ WRITE
SET PAUSE ON
SET PAUSE 'Press Return to Continue'
SET PAGESIZE 60
SET LINESIZE 300
SET VERIFY OFF
 
COLUMN scn FOR 999,999,999,999,999
COLUMN Incar FOR 99
COLUMN name FOR A25
COLUMN storage_size FOR 999,999,999,999
COLUMN guarantee_flashback_database FOR A3
 
SELECT 
      database_incarnation# as Incar,
      scn,
      name,
      time,
      storage_size,
      guarantee_flashback_database
FROM 
      v$restore_point
ORDER BY 4
/
INCAR                  SCN NAME                      TIME                                                                            STORAGE_SIZE GUA
----- -------------------- ------------------------- --------------------------------------------------------------------------- ---------------- ---
    3    6,086,495,469,099 SNAPSHOT_STANDBY_REQUIRED 04-DEC-19 11.24.09.000000000 AM                                                  209,715,200 YES
                           _12/04/2019 11:24:09
SQL> select open_mode from v$database;
Press Return to Continue
OPEN_MODE
--------------------
READ WRITE
SQL> !hostname

SQL>

Steps on converting back a snapshot standby database to physical standby database.


SQL> select open_mode from v$database;
Press Return to Continue
OPEN_MODE
--------------------
READ WRITE
SQL> !hostname

SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORACLE instance started.
Press Return to Continue
Total System Global Area 1.0737E+10 bytes
Fixed Size                  3722144 bytes
Variable Size            1275069536 bytes
Database Buffers         9428795392 bytes
Redo Buffers               29831168 bytes
Database mounted.
SQL> alter database convert to physical standby;
Database altered.
SQL> select status,instance_name,database_role,open_mode from v$database,v$Instance;
Press Return to Continue
STATUS       INSTANCE_NAME    DATABASE_ROLE    OPEN_MODE
------------ ---------------- ---------------- --------------------
MOUNTED      RAJDBA           PHYSICAL STANDBY MOUNTED
SQL>
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING ARCHIVED LOGFILE DISCONNECT;
Database altered.
SQL> SELECT RECOVERY_MODE FROM V$ARCHIVE_DEST_STATUS;
Press Return to Continue
RECOVERY_MODE
-----------------------
MANAGED

About Me

My photo
Sydney, NSW, Australia
An experienced IT professional (14+ years) worked in multiple industries such as consulting, education, financial, retail sectors. Carries good work experience in relational database design, analysis, modeling, development, administration, implementation, trouble shooting, support etc. Experienced in Oracle/SQL Server/MySQL DBA involving setup, configuration, tuning, backups, disaster recovery, high availability Oracle 11g/12C/19C RAC clusters; SQL server 2008/2012/2016 clusters, Oracle Engineered Systems such as EXADATA, ODA and Oracle and Azure Cloud. Performed Software Installations, Migrations, Database Capacity Planning, Automation of backup implementation, Cloud migration Tuning Oracle in windows/Unix platforms. In addition, experienced in UNIX administration, Shell scripting. PowerShell scripting A team player with communication skills.