DBA Sheet 6.1
DBA Sheet 6.1
DBA Sheet 6.1
Hardware type
OS
OS version
OS 32 bit or 64bit
who command alternative
server reboot time
Tracing
Tracing system calls
How to Trace Unix System Calls (Doc ID 110888.1)
RAM SIZE
Disks
sort by file size
List Disks
Disk size
Disk Cloning between two servers
Create a dummy disk in solaris = 1GB
copying the disks
Disk Hardware errors
Device statistics
freespace in zpool
Os used disks
CPU
Number of CPU's
CPU Usage
TOP CPU Users
Top 10 CPU consuming process
CPU & Memory used by a PID
top CPU Usage
SAR
CPU:
Memory:
Disk:
Network:
ZIP
Zipping a folder in solaris
Compress old files
compressing the folder
Reading files under .gz without uncompress
FIND/Replace
Display above & below 2 lines on grep
Finding a file
Find
MTU value
vncserver
SCP @ background
rsync the files between servers
scp faster file transfer method (ssh pwd required)
iostat
Error log
^M Error
Tree command in solaris'
History
History command
who logged in
Screen Command
Password encryption
oslevel -r
cat /etc/release
cat /etc/redhat-release
uname -m
x86_64 ==> 64-bit kernel
i686 ==> 32-bit kernel
pinky
who -b
du -sh * | sort -h
iostat -IEn (or) echo|format
fdisk -l | egrep 'Disk.*bytes' | awk '{ sub(/,/,""); sum +=$3; print $2" "$3" "$4 } END { print "—————–"; print "total: " sum " GB
http://serverfault.com/questions/4906/using-dd-for-disk-cloning
dd if=/dev/zero of=test.img bs=1024k count=1000
dd if=test.img of=test.img.bkp bs=1024000k
root@server # iostat -IEn|grep c0t600507680181050F20000000000009F2d0
c0t600507680181050F20000000000009F2d0 Soft Errors: 0 Hard Errors: 770 Transport Errors: 698
root@server #
iostat -xnp
zpool list
zpool status
cat a | grep 5 -C 2
find /opt/tivoli/tsm/client -exec grep -l "servername" {} \;
Ping all public and private nodename or IP of all nodes with corresponding MTU:
/usr/sbin/ping -s nodename mtu 2
Example in three node environment
/usr/sbin/ping -s node1-pub 1500 2
/usr/sbin/ping -s node2-pub 1500 2
/usr/sbin/ping -s node3-pub 1500 2
/usr/sbin/ping -s node1-priv 9000 2
/usr/sbin/ping -s node2-priv 9000 2
/usr/sbin/ping -s node3-priv 9000 2
Enable
------
gconftool-2 -s -t bool /desktop/gnome/remote_access/enabled true
gconftool-2 -s -t bool /desktop/gnome/remote_access/prompt_enabled false
Diable
-------
gconftool-2 -s -t bool /desktop/gnome/remote_access/enabled false
# SOURCE:
follow same as below - dont add location directly to dumpfile
cd /location
tar -cf - expdpmyfile.dmp | gzip -1 | nc -l 9999
# TARGET:
cd /thelocation/u/need
nc Sourceserver 9999 | gzip -d | tar xf - -C .
netstat -anlp | grep 1587
/sbin/ip link show
prstat -n 5 -s cpu
iostat -x 1 3
ksh
HISTTIMEFORMAT="%d/%m/%y %T "
history
last | grep root | more
int main(void)
{
system(SHELLSCRIPT);
return 0;
}
$ cc a.c
$ ./a.out
screen -S Patching ( Starting New session with Name incase of multiple screen session going to open)
screen -ls ( To list the existing screen sessions )
screen -r -d screen_name ( For attaching a existing screen name)
screen -r ( Attaching the existing screen automatically if only one session found )
screen -x Screen_name ( Attaching Multiple display Screen )
AIX
Solaris
linux
solaris,AIX
Linux
Tru 64
http://www.c0t0d0s0.org/archives/4778-Less-known-Solaris-features-Getting-rid-of-Zombies.html
Solaris
HP/UX
AIX
Linux
DEC-UNIX
To free pagecache:
Solaris
# echo 1 > /proc/sys/vm/drop_caches
To free dentries and inodes:
svmon
# echo 2 > /proc/sys/vm/drop_caches
To free pagecache, dentries and inodes:
Linux
http://serverfault.com/questions/4906/using-dd-for-disk-cloning
solaris
psrinfo | wc -l
Linux
Solaris
AIX
HP/UX
Real CPU in Solaris
http://yong321.freeshell.org/oranotes/MoveOraInventory.txt
grep -rnw /location -e "dc7h92zrnpbnq"
solaris
works only in linux
fc -l -99
history -200
solaris
int main() {
system("/work/oracle/s/mygrid.sh");
return 0;
}
$ cc b.c
$ ./a.out
https://stackoverflow.com/questions/13341832/display-two-files-side-by-side
Just to brief the changes use below command
prstat -a
-disk-cloning
getdev
cfgadm -la
prtconf
echo Cores = $(( $(lscpu | awk '/Socket/{ print $2 }') * $(lscpu | awk '/Core/{ print $4 }') ))
http://www.dba-oracle.com/t_tuning_cpu_usage_vmstat.htm
21 -exec rm -f {} ;
play-two-files-side-by-side
prstat -Z
Host CPU utilization report from DATABASE
Issue
Tracing
Tracing Oracle process OS level
Tracing SQLPLUS at OS level
Others
Killable processes
alias
SCRIPTS
Os level scripting
Shell script to execute multiple database - 12c
Profile for OS
Server maintenance
Server maintenance
Now that you confirmed the process 16514 is consuming a lot of memory, you
can "freeze" it—but not kill it—using the skill command.
Solution
$ df -kh /u01
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VGExaDb-LVDbOra1
99G 82G 12G 88% /u01
$ df -h -i /u01
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/mapper/VGExaDb-LVDbOra1
13M 13M 0 100% /u01
free -m
use this comman an see the cache memory .. It should be less… if it is more than 5Gb ask unix admin to lear the memory
prtconf | grep Mem
id -p
prctl -n project.max-shm-memory -i project 100
SELECT
STAT_NAME,
DECODE(STAT_NAME,'PHYSICAL_MEMORY_BYTES',(ROUND(VALUE/1024/1024/1024,2))
|| ' GB','FREE_MEMORY_BYTES',(ROUND(VALUE /1024/1024/1024,2))
|| ' GB',VALUE ) VALUE
FROM
v$osstat
WHERE
stat_name IN ( 'FREE_MEMORY_BYTES', 'LOAD', 'NUM_CPUS', 'NUM_CPU_CORES',
'NUM_CPU_SOCKETS', 'PHYSICAL_MEMORY_BYTES' );
sort -u $TNS_ADMIN/tnsnames.ora | grep -v "^ " | grep -v "^#" | grep -v "^(" | grep -v "^)" | sed "s/ =//g" | grep -v "^$"
for i in `ps -ef|grep pmon | awk '{print $8}'|grep -v "grep"| grep -v "ASM"| cut -d"_" -f3`
do
export ORACLE_SID=$i
sqlplus -s /nolog <<EOF
set head off echo off
conn / as sysdba
SELECT comp_name, version, status FROM dba_registry where status='INVALID';
exit
EOF
done
#!/bin/ksh
rm -rf log.txt
for i in `cat a.txt`
do
echo ' ------'$i'----- ' >> /tmp/log.txt
sqlplus -L -S << EOF >> /tmp/log.txt
/ @$i
set feedback off
set lines 750 pages 0
col value for a20
select (select name from v\$database) dbname, (select NAME from v\$pdbs where con_id=(select con_id from v\$pdbs where
rownum < 2)) con,i.host_name,p.inst_id,p.name,p.value from gv\$parameter p, gv\$instance i where p.name='global_names' an
p.inst_id=i.inst_id order by p.inst_id;
exit;
EOF
done
echo off
cls
for /f "tokens=1-2 delims= " %%b in (1.txt) do (
echo.***********************************************
echo.Connect to %%b
rem echo. Password: %%c
echo.***********************************************
rem echo.sqlplus -L sys/pwd@%%b @C:\dbname.sql
sqlplus -L "sys/pwd@%%b as sysdba" @C:\dbname.sql
)
echo.
echo.DONE
echo.Press any key to exit.
pause >nul
for i in `ps -ef |grep pmon|grep -v MGMTDB|grep -v ASM|grep -v grep|cut -d"_" -f3`
do
export ORACLE_SID=$i
export ORACLE_HOME=`ps -ef |grep pmon|grep $i|awk {'print "pwdx " $2 '}|sh|awk {'print $2 '}|sed 's/....$//'`
#!/bin/ksh
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$PATH
# ------------------------------------------------------------------------
sqlplus
# A simple -s "/ as sysdba"
kornshell script to <<EOF
force all running instances to re-register
set lines 300
# with the remote_listener (workaround for bug 13066936)
col VALUE for a65
# ------------------------------------------------------------------------
export ORACLE_HOME=/opt/oracle/product/11.1.0/db7
select
for INST name,
in `ps -aefdb_unique_name,
| grep 'ora_pmon' open_mode,database_role
| egrep -v '(grep|sed)' | sed from v\$database;
's/^.*ora_pmon_//'`
PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME/bin:/usr/bin/X11:/sbin:.:/usr/local/bin:${ORACLE_HOME}:${ORACLE_HOME}/bin
do show parameter log_archive_config
{ORACLE_HOME}/OPatch:/oracle/dba/bin
echoEOF . Reregistering $INST with remote_listener
done
export ORAENV_ASK=NO
export PATH
. oraenv
export $INST
HISTFILE=$HOME/.histdir/$(tty|sed 's-/-_-g')
sqlplus
export -SL "/ as sysdba" <<-EOF >/dev/null
DBA_INIT_INI=/oracle/dba/funcs/dba_init.ini
col remote_val new_value remote_val
select value
# NMON remote_val
variable from v\$parameter
to stop oslevel checking where name='remote_listener';
alter system set
export NMONAIX=5.2.0.0 remote_listener='';
alter system register;
alterEDITOR=vi
export system set remote_listener='&remote_val';
alterFPATH=/oracle/dba/funcs
export system register;
EOF
export TNS_ADMIN=/var/opt/oracle
done
export ORACLE_BASE=/opt/oracle
export ORACLE_ASK=YES
export ORACLE_OWNER=oracle
export NLS_LANG=AMERICAN_AMERICA.UTF8
export NLS_DATE_FORMAT='YYYY/MM/DD HH24:MI'
nins
. .kshrc
export ORATAB="/var/opt/oracle/oratab"
export ORA_CRS_HOME=`cat /etc/oratab|grep -i asm|awk -F: '{print $2}'`
tnsping gpo_core_u |
awk '{FS="[()]+";for(i=1;i<=NF;i++) if($i ~ /(HOST|PORT|SERVICE_NAME)/) print $i}'
Presnap
fi
if [[ $(ps -ef | grep ./mgr | $GREP -vE 'grep|async' | wc -l) -ne 0 ]];
then
$ECHO ' \033[1;33m Goldengate = Running \033[0;0m '
else
echo "Goldengate = Not Running"
fi
echo ' '
echo ' '
EOF
col c1 heading
chmod 755 osprecheck.sh
'end|time' format a10
col c2 heading 'wait|class' format a20
./osprecheck.sh
col c3 heading 'time|waited'
| tee presnap.txt
format 999,999,999,999
break on c1 skip 2
select
trunc(end_interval_time) c1,
wait_class
Freeze => c2,
skill -STOP 1
sum(time_waited) c3
Continue => skill -CONT 16514
from
skill -STOP oracle
dba_hist_service_wait_class
skill
join -STOP rman
dba_hist_snapshot USING(snap_id)
where
wait_class = 'Network'
group by
trunc(end_interval_time),
wait_class
order by
trunc(end_interval_time),
c3 desc;
Comments
https://weidongzhou.wordpress.com/2014/10/26/out-of-space-error-while-still-have-space/
for linux
Solaris
do
export
ORACLE
_SID=$i
sqlplus
-s /nolog
<<EOF
>/tmp/tem
p.sql
set head
off echo
off
conn / as
sysdba
ps -eo comm| grep -v grep|grep pmon|sed s/ora_pmon_//
select
decode(o
pen_mod
e,'READ
WRITE','
OPEN','M
OUNT')
from v\
$databas
e;
exit
EOF
for x in
`cat
/tmp/temp
.sql |
egrep
"OPEN|
MOUNT|
ORA-
01507"|
grep -v
"^sel"|awk
{'print
$1}'`
do
if [ "$x" =
"ORA-
01507:" ]
then
for i in `ps -ef|grep pmon | awk '{print $8}'|grep -v "grep"| grep -v "ASM"| cut -d"_" -f3` echo
do "Databas
export ORACLE_SID=$i e $i in
sqlplus -s /nolog <<EOF NOMOUN
set head off echo off T stage"
conn / as sysdba else
spool $i.sql echo
--select example script sql "Databas
select 'alter materialized view '||owner||'.'||object_name||' compile;' e $i in $x
from dba_objects stage"
where status<>'VALID'; fi
spool off; done
@$i.sql; rm
exit /tmp/temp
EOF .sql
done done
for i in `ps -ef|grep pmon | awk '{print $8}'|grep -v "grep"| grep -v "ASM"| cut -d"_" -f3`
do
export ORACLE_SID=$i
sqlplus -s /nolog <<EOF
set head off echo off feedback off
conn / as sysdba
set lines 160
select instance_name,logins,(select database_role from v\$database) database from v\$instance;
select PROCESS,status from gv\$managed_standby where process like '%MRP%';
col STBY_BEHIND_BY for a20
select (select sysdate from dual)"TIMESTAMP",s.thread#,s.MAX_SEQ#, a.MAX_APP_SEQ#,
(s.MAX_SEQ#-a.MAX_APP_SEQ#) "Difference" from
( select thread#,max(sequence#) "MAX_SEQ#" from v\$archived_log group by thread# ) s,
(select thread#,max(sequence#) "MAX_APP_SEQ#" from v\$archived_log where applied='YES'
group by thread#) a where a.thread#=s.thread#;
set serveroutput on
exec dbms_output.put_line('------------------------------');
exit
EOF
done
#!/bin/ksh
rm -rf dbhealthoutput.txt
echo "Enter the syspassword"
stty -echo
read sys_pw
stty echo
for i in `cat dblist.txt`
do
echo '***********************************************'
echo connecting to $i
echo '***********************************************'
more dbhealthoutput.txt
postsnap
if [[ $(ps -ef | grep ./mgr | $GREP -vE 'grep|async' | wc -l) -ne 0 ]];
then
$ECHO ' \033[1;33m Goldengate = Running \033[0;0m '
else
echo "Goldengate = Not Running"
fi
echo ' '
echo ' '
EOF
https://www.oracle.com/technetwork/articles/linux/part2-085179.html
You can use a user, a PID, a command or terminal id as argument. The following stops all rman commands
As you can see, skill decides that argument you entered—a process ID, userid, or command—and acts appropriately. This may
|grep -v
ASM|grep
-v grep|
cut -d"_"
-f3`
do
export
ORACLE
_SID=$i
export
ORACLE
_HOME=`
ps -ef |
grep
pmon|
grep $i|
awk {'print
"pwdx "
$2 '}|sh|
awk {'print
$2 '}|sed
's/....$//'`
export
PATH=$O
RACLE_H
OME/bin:
$ORACL
E_HOME/
OPatch:
$PATH
sqlplus -s
"/ as
sysdba"
<<EOF
set
lines 300
col
VALUE
for a65
select
name,
db_uniqu
e_name,
open_mo
de,databa
se_role
from v\
$databas
e;
show
parameter
log_archiv
e_config
EOF
done
cts appropriately. This may cause an issue in some cases, where you may have a user and a command in the same name. The best examp
me name. The best example is the "oracle" process, which is typically run by the user "oracle". So, when you want to stop the process called
to stop the process called "oracle" and you issue:
Identify the Exadata Box type
cell versions
offloading saved
Dcli
cv_cellVersion
, CAST(extract(xmltype(confval), '/cli-output/cell/flashCacheMode/text()') AS
VARCHAR2(20)) cv_flashcachemode
, CAST(extract(xmltype(confval), '/cli-output/cell/cpuCount/text()') AS VARCHAR2(10))
cpu_count
http://www.centroid.com/blog/monitoring-exadata-smart-scan
, CAST(extract(xmltype(confval), '/cli-output/cell/upTime/text()') AS VARCHAR2(20))
uptime
, CAST(extract(xmltype(confval),
grep '/cli-output/cell/kernelVersion/text()') AS VARCHAR2(30))
-i MACHINETYPES /opt/oracle.SupportTools/onecommand/databasemachine.xml
kernel_version
, CAST(extract(xmltype(confval), '/cli-output/cell/makeModel/text()') AS VARCHAR2(50))
make_model
FROM
v$cell_config -- gv$ isn't needed, all cells should be visible in all instances
WHERE
conftype = 'CELL'
ORDER BY
cv_cellname;
Scripts and Tips for Monitoring CPU Resource Manager (Doc ID 1338988.1)
/opt/oracle.SupportTools/CheckHWnFWProfile -S
select inst_id,sql_id,
decode(IO_CELL_OFFLOAD_ELIGIBLE_BYTES,0,'No','Yes') Offloaded,
decode(IO_CELL_OFFLOAD_ELIGIBLE_BYTES,0,0,
100*(IO_CELL_OFFLOAD_ELIGIBLE_BYTES-
IO_INTERCONNECT_BYTES)/
IO_CELL_OFFLOAD_ELIGIBLE_BYTES) "IO_SAVED_%"
from gv$sql
where sql_id='&sql_id';
http://oradwstories.blogspot.com/2015/02/detecting-change-in-
run as root
2015/02/detecting-change-in-execution-plan-of.html
Nice url
Disk Details
% used
ASM backup
Adding a disk
Copy an ASM file from a local ASM instance to a remote ASM instance
Blocker in ASM
Disk Size
Troubelshooting
Resizing disks
Masternode in CRS
Checking Disks
ASM LIB
ASMLIB Device to disk mapping script
unix kernal
asm disks
discovery
config files
log
spool locking_information
cp +DATA/orcl/datafile/tbsjfv.256.123456789
select to_char(sysdate,
\sys@mydb 'DD-MON-YYYY HH24:MI:SS' ) current_time from dual
. +ASM2 : +D2/jfv/tbsjfv.dbf
/
prompt ########################
$DD if=/dev/zero skip=25 bs=4k count=2560 of=$OCRLOC
prompt # Blocking Information #
prompt ########################
select
ALTERb.inst_id||'/'||b.sid blocker,
DISKGROUP DATA_DBNAME ADD DISK
-- s.module,
'/dev/rdsk/c6t600507680180854860000000000000B2d0s0' SIZE 102400 M REBALANCE
w.inst_id||'/'||w.sid
POWER 6; waiter,
b.type,
b.id1,
b.id2,
b.lmode,
w.request
from gv$lock b,
( select inst_id, sid, type, id1, id2, lmode, request
from gv$lock where request > 0 ) w
-- gv$session s
where b.lmode > 0
and ( b.id1 = w.id1 and b.id2 = w.id2 and b.type = w.type )
--and ( b.sid = s.sid and b.inst_id = s.inst_id )
order by b.inst_id, b.sid
/
ps -eaf | grep ASM | grep beq | awk '{print "kill -9 " $2}'
export ORACLE_HOME=/tmp/OraInstall2014-01-30_01-59-24AM/ext/bin
export LD_LIBRARY_PATH=/tmp/OraInstall2014-01-30_01-59-24AM/ext/bin/../lib
cd /tmp/OraInstall2014-01-30_01-59-24AM/ext/bin
./kfod.bin verbose=true, disks=all status=true op=disks
http://oraclehandson.wordpress.com/2010/08/06/cloning-oracle-asm-databases-with-kfed/
http://externaltable.blogspot.com/2013_12_01_archive.html
https://twiki.cern.ch/twiki/bin/view/PDBService/ASM_utilities
od -c -N 128 /dev/rdsk/c6t60050768018E02799800000000000FA2d0s0
https://taliphakanozturken.wordpress.com/2013/03/31/mounting-asm-diskgroup-fails-with-ora-15063-error-and-resolving-with-k
srvctl config database -db PRODDB | grep -i pass
. oraenv +ASM1
asmcmd --privilege sysdba pwcopy +DATA1/PRODDB/orapwPRODDB /tmp/orapwPRODDB
BCP:
----
. oraenv +ASM1
asmcmd --privilege sysdba pwcopy --dbuniquename STBYDB /tmp/orapwPRODDB
+DATA1/STBYDB/PASSWORD/orapwSTBYDB
(or)
ASMCMD> pwcopy /tmp/orapwPRODDB.295.999492555 +DATA1/STBYDB
. oraenv STBYDB
srvctl modify database -db STBYDB -pwfile
+DATA1/STBYDB/PASSWORD/pwdSTBYDB.3087.999923145
srvctl config database -db STBYDB | grep -i pass
uname -r
lsmod | grep -i oracle
rpm -qa | grep oracleasm
/etc/init.d/oracleasm scandisks
/etc/init.d/oracleasm listdisks
cat /etc/sysconfig/oracleasm
/usr/sbin/oracleasm init
cat <<EOF
"ORACLE_HOME" is not set
EOF
exit 1
fi
export PATH=${ORACLE_HOME}/bin:${PATH}
col path for a35
#
colGet last applied
Diskgroup log number
for a15
$ORACLE_HOME/bin/sqlplus
col DiskName for a20 -s "/ as sysdba" <<END
col disk# for 999
set pages 0 feed
col total_mb off linesize 100 heading on
for 999,999,999
set pagesizefor
col free_mb 100999,999,999
column
computeinst sum format a10 heading
of total_mb 'Inst'
on DiskGroup
column
computefile_type format a20
sum of free_mb on heading
DiskGroup 'File type'
column
break onmg format 99,999,999
DiskGroup skip 1 on report -
break on inst skip 1
compute
set pagessum 255 of mg on inst
whenever sqlerror exit 1
select a.name DiskGroup, b.disk_number Disk#, b.name DiskName, b.total_mb,
select inst, file_type,sum(mg)
b.free_mb, mg from (
b.path, b.header_status
select substr(full_alias_path,2,instr(full_alias_path,'/',2,1)-2)
from v$asm_disk b, v$asm_diskgroup a as INST,
file_type,
where a.group_number (+) =b.group_number
round((szbytes)/1048576)
order by b.group_number, as MG from ( b.name
b.disk_number,
select
/ lower(concat('', sys_connect_by_path(aname, '/'))) full_alias_path, Good query
system_created, alias_directory, file_type, szbytes
from ( select b.name gname, a.parent_index pindex, a.name aname,
a.reference_index rindex , a.system_created, a.alias_directory,
c.type file_type, c.bytes szbytes
from v\$asm_alias a, v\$asm_diskgroup b, v\$asm_file c
where a.group_number = b.group_number
and a.group_number = c.group_number(+)
and a.file_number = c.file_number(+)
and a.file_incarnation = c.incarnation(+)
and b.name = UPPER('${DG}')
)
start with (mod(pindex, power(2, 24))) = 0
and rindex in
( select a.reference_index
from v\$asm_alias a, v\$asm_diskgroup b
where a.group_number = b.group_number
and (mod(a.parent_index, power(2, 24))) = 0
-- and a.name = 'SINGLEDBNAME'
)
connect by prior rindex = pindex)
where szbytes is not null)
group by inst, file_type
/
exit;
END
exit 0
recreating asm disk sql's are stored in mymdscript in the current directory…
ith-ora-15063-error-and-resolving-with-kfed/
https://emilianofusaglia.net/2016/04/08/troubleshooting-not-mounting-acfs-file-system/
http://surachartopun.com/2009/09/asm-dvm-acfs-by-command-lines.html
http://www.idevelopment.info/data/Oracle/DBA_tips/Automatic_Storage_Management/AS
M_50.shtml
/etc/init.d/oracleasm querydisk -d `/etc/init.d/oracleasm listdisks -d` | \
cut -f2,10,11 -d" " | \
perl -pe 's/"(.*)".*\[(.*), *(.*)\]/$1 $2 $3/g;' | \
while read v_asmdisk v_minor v_major
do
v_device=`ls -la /dev | grep " $v_minor, *$v_major " | awk '{print $10}'`
echo "ASM disk $v_asmdisk based on /dev/$v_device [$v_minor, $v_major]"
done cat /etc/sysconfig/oracleasmhttp://a
https://ronnyegner.word
/etc/init.d/oracleasm disable
/etc/init.d/oracleasm enable
D5d0s0' SIZE 102400 M DISK '/dev/rdsk/c5t600507680181050F20000000000007D6d0s0' SIZE 102400 M
info.blogspot.com/2009/02/to-remove-asm-files.html
ks Offline With "Waited 15 secs for write IO to PST" (Doc ID 1581684.1)
https://ronnyegner.wordpress.com/?s=etc%2Finit.d%2Foracleasm
RAC Enabled in ORACLE_HOME or not
Diag Collections
Tracing cluvfy
crs resource script
crs resource creation script
If root.sh fails
cd $ORACLE_HOME/rdbms/lib
make -f ins_rdbms.mk rac_off --Disabling RAC binaries
make -f ins_rdbms.mk ioracle --Linking to Oracle binaries
root@rac1 ~]# kill -STOP 3595; sleep 27; kill -CONT 3814
ps -ef | grep <keyword> | grep -v grep | awk '{print $2}' | xargs kill -9
traceroute -r -F 192.168.0.210
export SRVM_TRACE=true
export SRVM_TRACE=""
rm -rf /tmp/cvutrace
mkdir /tmp/cvutrace
export CV_TRACELOC=/tmp/cvutrace
export SRVM_TRACE=true
export SRVM_TRACE_LEVEL=1
<STAGE_AREA>/runcluvfy.sh stage -pre crsinst -n <node1>,<node2>
-verbose
for res in `/opt/crs/12.1.0/grid/bin/crs_stat -p | grep "^NAME=" | cut -d =
-f 2` ; do
/opt/crs/12.1.0/grid/bin/crs_stat -p $res >/opt/oracle/resources/$res.cap
done
http://dbaregistry.blogspot.com/search/label/How%20to%20export%20and%20import%20crs%20resources
for i in `olsnodes`
do
/usr/bin/ssh -o UserKnownHostsFile=/dev/null -o
StrictHostKeyChecking=no -q $i "chmod 777 /tmp/chek.sh" > /dev/null
/usr/bin/ssh -o UserKnownHostsFile=/dev/null -o
StrictHostKeyChecking=no -q $i "/tmp/chek.sh" > /tmp/tmp.log_$i
done
paste /tmp/tmp.log* | sed -e 's/\t/ \t/g' | column -t -s$'\t'
rm -rf /tmp/tmp.log*
crsctl status res |grep -v "^$"|awk -F "=" 'BEGIN {print " "}
{printf("%s",NR%4 ? $2"|" : $2"\n")}'|sed -e 's/ *, /,/g' -e 's/, /,/g'|\
awk -F "|" 'BEGIN { printf "%-40s%-35s%-20s%-50s\n","Resource
Name","Resource Type","Target ","State" }{ split ($3,trg,",") split
($4,st,",")}{for (i in trg) {printf "%-40s%-35s%-20s%-50s\n",
$1,$2,trg[i],st[i]}}'
for i in `olsnodes` ; do /usr/bin/ssh -q $i "ps -aef | grep pmon |awk '{print $8}' | egrep -i -v 'grep' | cut -d "_" -f3" | sort > /tmp/tmp
for i in `olsnodes`
do
echo $i > /tmp/tmp.log_$i
/usr/bin/ssh -q $i " echo "================" ; ps -aef | grep pmon |
awk '{print $8}' | egrep -i -v 'grep' | cut -d "_" -f3" | sort >>
/tmp/tmp.log_$i
done
/opt/grid/12.1.0.2/bin/acfsload start
As oracle,
WITH sys_time AS (
SELECT inst_id, SUM(CASE stat_name WHEN 'DB time'
THEN VALUE END) db_time,
SUM(CASE WHEN stat_name IN ('DB CPU', 'background cpu
time')
THEN VALUE END) cpu_time
FROM gv$sys_time_model
GROUP BY inst_id )
SELECT instance_name,
ROUND(db_time/1000000,2) db_time_secs,
ROUND(db_time*100/SUM(db_time) over(),2) db_time_pct,
ROUND(cpu_time/1000000,2) cpu_time_secs,
ROUND(cpu_time*100/SUM(cpu_time) over(),2) cpu_time_pct
FROM sys_time
JOIN gv$instance USING (inst_id);
http://www.pythian.com/blog/changing-hostnames-in-oracle-rac/
http://www.pythian.com/blog/slimming-down-oracle-rac-12cs-resource-footprint/
(Doc ID 986822.1)
http://dbaregistry.blogspot.com/search/label/How%20to%20export%20and%20import%20crs%20resources
0export%20and%20import%20crs%20resources
n |awk '{print $8}' | egrep -i -v 'grep' | cut -d "_" -f3" | sort > /tmp/tmp.log_$i ; done ; paste /tmp/tmp.log* | column -t
crsctl status resource -t|grep -v ora.mgmtdb|grep -v grep|grep ora.*.db|
cut -f2 -d.|
while read line; do echo -e "\033[0;31mDatabase Name: \
033[0;0m"$line
echo -e "\033[0;31mServices: \033[0;0m"`srvctl config database -d
$line|grep Services|awk '{print $2}'`;
echo -e "\033[0;31mServers: \033[0;0m"`srvctl status database -d
$line|awk '{printf "%s.",$7}'`;
done
https://emilianofusaglia.net/2016/04/08/troubleshooting-not-mounting-acfs-file-system/
http://mahioracledba.blogspot.com/2014/01/rootsh-failed-when-installing-11gr2.html
Gaps
Standby DB Name
Last applied archive log
dgmgrl logging
dgmgrl
Error: ORA-16664: unable to receive the result from a
database
DGMGRL all errors & troubleshoot
dgmgrl log location
dataguard switchover validation
log_archive_dest_2
Dataguard switchover :
Standby_Side
delete force noprompt ARCHIVELOG from sequence 17101 until sequence 20340 thread=1;
delete force noprompt ARCHIVELOG from sequence 16151 until sequence 19560 thread=2;
On Primary database the value of controlfile_type in V$database is “CURRENT” and standby is “STANDBY”
run
{
set archivelog destination to '/ora_backup/rman/arch/';
restore archivelog from logseq=8619 until logseq=8632 thread=2;
}
for i in `ps -ef|grep pmon | awk '{print $8}'|grep -v "grep"| grep -v "ASM"| cut -d"_" -f3`
do
export ORACLE_SID=$i
dgmgrl -silent / "show configuration verbose" ; echo '------------------------------------'
done
for i in `ps -ef|grep pmon | awk '{print $8}'|grep -v "grep"| grep -v "ASM"| cut -d"_" -f3`
do
export ORACLE_SID=$i
sqlplus -s /nolog <<EOF
set head off echo off feedback off
conn / as sysdba
set lines 160
select instance_name,logins,(select database_role from v\$database) database from v\$instance;
select PROCESS,status from gv\$managed_standby where process like '%MRP%';
col STBY_BEHIND_BY for a20
select (select sysdate from dual)"TIMESTAMP",s.thread#,s.MAX_SEQ#, a.MAX_APP_SEQ#, (s.MAX_SEQ#-
a.MAX_APP_SEQ#) "Difference" from
( select thread#,max(sequence#) "MAX_SEQ#" from v\$archived_log group by thread# ) s,
(select thread#,max(sequence#) "MAX_APP_SEQ#" from v\$archived_log where applied='YES' group by
thread#) a where a.thread#=s.thread#;
set serveroutput on
exec dbms_output.put_line('------------------------------');
exit
EOF
done
primary
-----------
dgmgrl /
connect sys/pwd
CREATE CONFIGURATION 'DR' AS PRIMARY DATABASE IS 'india' CONNECT IDENTIFIER IS 'india';
ADD DATABASE 'america' AS CONNECT IDENTIFIER IS 'america' maintained as physical;
Enable configuration
show configuration ;
show database verbose india
show database verbose america
sid +ASM
cd $ORACLE_HOME/network/admin
cp listener.ora listener.ora.11142017
(SID_DESC=
(SID_NAME= america2)
(GLOBAL_DBNAME= america_dgmgrl)
(ORACLE_HOME=/ORACLE_HOME)
(ENVS="TNS_ADMIN=/ASM_HOME/network/admin")
)
else it will throw error while swithover. it will start only one instance during switover if it is not added.
please add this entry and reload the listener
dgmgrl /
connect sys/pwd
switchover to america;
connect sys/pwd
switchover to india;
RMAN>
echo set on
run {
allocate channel c1 device type disk;
allocate auxiliary channel a1 device type disk;
allocate auxiliary channel a2 device type disk;
duplicate database for standby from active database using backupset nofilenamecheck;
}
run {
set archivelog destination to '/data/archivelog';
restore clone archivelog from sequence 55 until sequence 56;
}
run{
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog all completed before 'sysdate - 1/24';
}
http://www.ritzyblogs.com/OraTalk/PostID/105/How-to-setup-DGMGRL-broker-with-example
if you want to increase the transport speed, increase the value in primary
database also .
https://www.toadworld.com/platforms/oracle/w/wiki/11334.let-s-optimize-data-
guard-configuration-I
http://emrebaransel.blogspot.com/2008/11/dataguard-performance.html
for i in `ps -ef|grep pmon | awk '{print $9}'|grep -v "grep"| grep -v "ASM"| cut -d"_"
-f3`
do
export ORACLE_SID=$i
dgmgrl -silent / "show configuration verbose" ; echo '------------------------------------'
done
run {
allocate channel prmy1 type disk;
allocate channel prmy2 type disk;
allocate channel prmy3 type disk;
allocate channel prmy4 type disk;
allocate auxiliary channel stby1 type disk;
allocate auxiliary channel stby2 type disk;
allocate auxiliary channel stby3 type disk;
allocate auxiliary channel stby4 type disk;
duplicate target database for standby
from active database section size 10G dorecover;
}
onprimary
us-physical.html
--------------
select a.thread#, (select max (sequence#) from v$archived_log
where archived='YES' and thread#=a.thread#) archived,
max(a.sequence#) applied, (select max(sequence#) from
v$archived_log where archived='YES' and thread#=a.thread#)-
max(a.sequence#) gap
from v$archived_log a where a.applied='YES' group by a.thread#
order by thread#;
v$sql_monitor
Sql details
SQL History
Identify
Identify
Explain Plan
explain plan for manual session
Process
Killing Sessions
Extra
parallelism Hints
sql patch
Sql Profiles
Sql Baselines
Sql_doctor script
AAS - Average active session from history/AWR
aas-per-min.sql
aas-per-hour.sql (AWR)
SELECT * FROM
TABLE(DBMS_XPLAN.DISPLAY_CURSOR('&sql_id',&childnumber,'A
LLSTATS LAST +PEEKED_BINDS +PROJECTION +ALIAS
+OUTLINE +PREDICATE +COST +BYTES'));
(OR)
select * from
table(dbms_xplan.display_cursor('&sql_id',&childnumber,'ADVANCED')
);
(OR)
set pagesize 0 echo off timing off linesize 1000 trimspool on trim on
long 2000000 longchunksize 2000000
select
DBMS_SQLTUNE.REPORT_SQL_MONITOR(
sql_id=>'&sql_id',
report_level=>'ALL',
type=>'TEXT')
from dual;
SELECT o.inst_id,o.sid,
o.sql_text,
o.address,
o.hash_value,
o.user_name,
s.schemaname,
o.sql_id
FROM gv$open_cursor o, gv$session s
WHERE o.saddr = s.saddr AND o.sid = s.sid AND (O.SID = &sid)
and o.inst_id=s.inst_id;
ELSE 'WAITING'
CE_NAME,
END AS state,
CURRENT_UTILIZATION
CASE WHEN state != "CURRENT",MAX_UTILIZATION "MAX"
'WAITING' THEN 'On CPU / runqueue'
FROM WRH$_RESOURCE_LIMIT
ELSE event A, WRM$_SNAPSHOT B
WHERE ENDA.RESOURCE_NAME
AS sw_event LIKE '%session%'
AND A.SNAP_ID=B.SNAP_ID
FROM
ANDv$session
A.INSTANCE_NUMBER= B.INSTANCE_NUMBER
AND
WHERE((A.INSTANCE_NUMBER=1
ANDtypeB.BEGIN_INTERVAL_TIME
= 'USER' > (SELECT STARTUP_TIME FROM
GV$INSTANCE WHERE
AND status = 'ACTIVE' INSTANCE_NUMBER=1)) OR
(A.INSTANCE_NUMBER=2
GROUP BY AND B.BEGIN_INTERVAL_TIME >
(SELECT STARTUP_TIME FROM GV$INSTANCE
CASE WHEN state != 'WAITING' THEN 'WORKING' WHERE
INSTANCE_NUMBER=2)))
ELSE 'WAITING'
order by A.INSTANCE_NUMBER,A.SNAP_ID;
END,
SELECT
CASESQL_ID, SQL_FULLTEXT,
WHEN state != 'WAITING'PLAN_HASH_VALUE, PARSING_SCHEMA_NAME, ELAPSED_TIME FROM V$SQL WH
THEN 'On CPU / runqueue'
ELSE event
END
ORDER BY
1 DESC, 2 DESC
/
-- Purge explain plan from shared pool, must be done on each RAC
node
select inst_id, sql_id, address, hash_value, plan_hash_value, sql_text
from gv$sqlarea where sql_text like 'SELECT COUNT(*) FROM
V$SESSION A WHERE A.AUDSID IN%';
select * from gv$sqlarea where sql_text like '%XLA_AE_LINES_GT%';
select inst_id, sql_id, address, hash_value, plan_hash_value, sql_text
from gv$sqlarea where sql_id = 'amd3xmgb8cnuz';
-- On each INST_ID, do these:
alter session set events '5614566 trace name context forever';
exec sys.dbms_shared_pool.purge('00000006999BD648,
1622326877','c');
alter session force parallel query;
select sql_text
from v$sqlarea
where address = (select sql_address from v$session where sid in
(select SID
from v$transaction,dba_rollback_segs,v$session
where SADDR=SES_ADDR and
XIDUSN=SEGMENT_ID and
flag=7811));
spool sql_profile_baseline_11g
declare
select
v_sql CLOB;
prf.plan_name,
beginprf.signature,
select sql_text into v_sql from dba_hist_sqltext where
decode(
sql_id='5273fz2cqkk80';
obj_type,
sys.dbms_sqldiag_internal.i_create_patch(
1,'Profile',
sql_text => v_sql,
2,'Baseline',
hint_text => 'DYNAMIC_SAMPLING(4)',
3,'Patch',
name 'Other'
=> '5273fz2cqkk80_patch');
end; ) opt_type,
/ prf.category,
prf.plan_id,
checkextractvalue(value(hnt),'.') hint
from
(
select
/*+ no_eliminate_oby */
so.name plan_name,
so.signature,
so.category,
so.obj_type,
select NAME,SIGNATURE ,STATUS,FORCE_MATCHING from dba_sql_
check so.plan_id,
sod.comp_data
from
sqlobj$ so,
sqlobj$data sod
select SQL_HANDLE,
where PLAN_NAME, ENABLED, ACCEPTED,
FIXED ,sql_textso.name from dba_sql_plan_baselines;
= '&m_plan_name'
and sod.signature = so.signature
and sod.category = so.category
select * fromand sod.obj_type = so.obj_type
table(dbms_xplan.display_sql_plan_baseline(plan_name=>'SQL_PLA
and sod.plan_id = so.plan_id
N_b7pnq6yp8da6a29d0d9b7'));
order by
All in one script signature, obj_type, plan_id
) prf,
table (
select
xmlsequence(
extract(xmltype(prf.comp_data),'/outline_data/hint')
)
Resolutionfrom normally, is to fix the execution plan in 11g by running
dual
variable
) x hnt
number
begin
;
:x :=
dbms_spm.load_plans_from_cursor_cache(
sql_id=>'&sql_id',
plan_hash_value=>&plan_hash,
fixed=>'YES');
end;
/
script.
PROMPT Explain Plan from AWR
and other_xml
REM
PROMPT is not null script is automatically executed after
The PRVTPOOL.PLB
================================
)
DBMSPOOL.SQL runs.
)
REM These scripts are not run by as part of standard database
d;
creation.
select * from table(dbms_xplan.display_awr('&sql_id', NULL, null,
SPO flush_cursor_&&sql_id..txt;
'ALLSTATS LAST'));
----------------------------------
PRO *** before flush ***
Taking
SELECT
PROMPT SQL HINTS
inst_id, from PLAN_TABLE
loaded_versions,
================================ invalidations, address, hash_value
----------------------------------
FROM gv$sqlarea
PROMPT Sql Profiles WHERE sql_id = '&&sql_id.' ORDER BY 1;
SELECT
PROMPT
BEGIN inst_id, child_number, plan_hash_value,
================================ executions,
SELECT
FOR i INregexp_replace(extractvalue(value(d),
is_shareable '/hint'),'''','''''') plan_hint
(SELECT address, hash_value
FROM
set from
linesgv$sql
1000 WHERE
pages sql_idsql_id
9999 = '&&sql_id.' ORDER BY 1, 2;
FROM gv$sqlarea WHERE = '&sql_id.')
BEGIN
col xmltable('/*/outline_data/hint'
name for a30
LOOP
FOR
col passing ( address,
i IN (SELECT
task_exec_name for a16 hash_value
SYS.DBMS_SHARED_POOL.PURGE(i.address||','||i.hash_value, 'C');
FROM
col gv$sqlarea
category forselect
a10 WHERE sql_id = '&&sql_id.')
END LOOP;
LOOP
col
END; created for a30 xmltype(other_xml) as xmlval
/ sql_text for from a150 plan_table
SYS.DBMS_SHARED_POOL.PURGE(i.address||','||i.hash_value,
col 'C');
END LOOP; where other_xml
col signature for 9999999999999999999999999 is not null
END; and plan_id = (select max(plan_id) from plan_table)
and rownum=1 as child , prof.name, prof.category,
/select sql.sql_id,sql.child_number
PRO *** after flush ) ***
prof.created,prof.task_exec_name,prof.FORCE_MATCHING,prof.statu
SELECT ) d;
inst_id,
s,prof.SIGNATURE loaded_versions, invalidations, address, hash_value
FROM
from gv$sqlarea WHERE sql_id = '&&sql_id.' ORDER BY 1;
SELECT inst_id, prof,
dba_sql_profiles child_number, plan_hash_value, executions,
----------------------------------
is_shareable
gv$sql sql
Taking
where SQL
FROM sql.sql_id
gv$sql HINTS
WHEREin from PROFILES
sql_id
('&sql_id') = '&&sql_id.' ORDER BY 1, 2;
----------------------------------
UNDEF sql_id;
-- and sql.child_number=child_number
SPO
-- andOFF; sql.force_matching_signature=prof.SIGNATURE
order by
select hint as outline_hints
created;
from (select p.name, p.signature, p.category, row_number()
over (partition by sd.signature, sd.category order by sd.signature)
row_num,
PROMPT extractValue(value(t),
================ '/hint') hint
from sqlobj$data
PROMPT sd, dba_sql_profiles p,
Sql Baselines
PROMPT table(xmlsequence(extract(xmltype(sd.comp_data),
================
'/outline_data/hint'))) t
where sd.obj_type = 1
coland p.signature =for
SQL_HANDLE sd.signature
a30
coland p.category
origin for a16 = sd.category
coland p.name likefor
last_modified ('&profile_name'))
a30
order by row_num;
col last_verified for a30
undef sid
undef sql_id
undef inst_id
spool off;
"
sample_minute,
and
round(avg(sub1.on_cpu),1) as cpu_avg,
stat_end.stat_name = stat_start.stat_name
round(avg(sub1.waiting),1) as wait_avg,
)
round(avg(sub1.active_sessions),1) as act_avg,
and
-- filter for the statistic we are interested in
round( (variance(sub1.active_sessions)/avg(sub1.active_sessions)),1)
--
as act_var_mean
stat_end.stat_name
column = 'DB time'
sample_hour format a16
from
and
select
( -- sub1: one row per second, the resolution of SAMPLE_TIME
-- join stat_start to snap on FK
to_char(round(sub1.sample_time, 'HH24'), 'YYYY-MM-DD HH24:MI')
select
as--sample_hour,
sample_id,
( stat_start.snap_id = snap.snap_id
round(avg(sub1.on_cpu),1) as cpu_avg,
sample_time,
and
round(avg(sub1.waiting),1) as wait_avg,
sum(decode(session_state, 'ON CPU', 1, 0)) as on_cpu,
stat_start.dbid = snap.dbid
round(avg(sub1.active_sessions),1) as act_avg,
sum(decode(session_state, 'WAITING', 1, 0)) as waiting,
and
count(*)
155 as active_sessions
set stat_start.instance_number
lines = snap.instance_number
round( (variance(sub1.active_sessions)/avg(sub1.active_sessions)),1)
col) from
execs for 999,999,999
as act_var_mean
col v$active_session_history
min_etime for 999,999.99
order
from by
where
colstat_start.snap_id
max_etime for 999,999.99
( -- sub1: one row per second, the resolution of SAMPLE_TIME
col sample_time
avg_etime > sysdate - (&minutes/1440)
for 999,999.999
; select
col group
avg_liobyfor 999,999,999.9
sample_id,
sample_id, for 999,999.9999
col norm_stddev
sample_time,
sample_time
col begin_interval_time for a30
sum(decode(session_state, 'ON CPU', 1, 0)) as on_cpu,
col) sub1
node for 99999
sum(decode(session_state, 'WAITING', 1, 0)) as waiting,
group on
break by plan_hash_value on startup_time skip 1
count(*) as active_sessions
round(sub1.sample_time,
select * from ( 'MI')
from
order by
select sql_id, sum(execs), min(avg_etime) min_etime, max(avg_etime)
dba_hist_active_sess_history
round(sub1.sample_time,
max_etime, 'MI')
stddev_etime/min(avg_etime) norm_stddev
where
;
from (
sample_time > sysdate - (&hours/24)
select sql_id, plan_hash_value, execs, avg_etime,
group by
stddev(avg_etime) over (partition by sql_id) stddev_etime
sample_id,
from (
sample_time
select sql_id, plan_hash_value,
) sub1
sum(nvl(executions_delta,0)) execs,
group by
(sum(elapsed_time_delta)/decode(sum(nvl(executions_delta,0)),0,1,su
round(sub1.sample_time, 'HH24')
m(executions_delta))/1000000) avg_etime
order by
--
round(sub1.sample_time, 'HH24')
sum((buffer_gets_delta/decode(nvl(buffer_gets_delta,0),0,1,executions
;
_delta))) avg_lio
from DBA_HIST_SQLSTAT S, DBA_HIST_SNAPSHOT SS
where ss.snap_id = S.snap_id
and ss.instance_number = S.instance_number
and executions_delta > 0
and elapsed_time_delta > 0
and s.snap_id > nvl('&earliest_snap_id',0)
group by sql_id, plan_hash_value
)
)
group by sql_id, stddev_etime
)
where norm_stddev > nvl(to_number('&min_stddev'),2)
and max_etime > nvl(to_number('&min_etime'),.1)
order by norm_stddev
/
https://orastory.wordpress.com/2009/12/29/plans-gone-awry-an-invashtigation/
select to_char(sample_time,'HH24:MI:SS') time, session_id sid
, session_serial# s#, user_id usr, session_state state
, time_waited waited, blocking_session blk_by,
blocking_session_status blk_stat
, sql_id, sql_child_number child_id, sql_plan_hash_value hash
, sql_plan_operation plan_op
, event, p1text, p1, p2text, p2, p3text p3, wait_class
, top_level_sql_id top_id, sql_exec_start ex_start
, plsql_entry_object_id pl_obj, plsql_entry_subprogram_id pl_prog
from dba_hist_active_sess_history
where sample_time between <start_time> and <end_time>
order by time desc;
SELECT * FROM
TABLE(DBMS_XPLAN.DISPLAY_AWR(<sql_id>,<plan_hash_value>,<
db_id>,<format>));
select
id xms_id,
lpad(' ',depth*1,' ')||operation || ' ' || options xms_plan_step,
object_name xms_object_name,
cost xms_opt_cost,
cardinality xms_opt_card,
bytes xms_opt_bytes,
optimizer xms_optimizer
from
dba_hist_sql_plan
where
plan_hash_value = <plan_hash>
order by id
select
OBJ#,INTCOL#,SAVTIME,NULL_CNT,MINIMUM,MAXIMUM,DISTCNT
,DENSITY,LOWVAL,HIVAL,SAMPLE_DISTCNT,SAMPLE_SIZE
from WRI$_OPTSTAT_HISTHEAD_HISTORY
where OBJ#=925718 and INTCOL#=5
order by SAVTIME;
else
:plsql_call := '[No SQL profile to apply]';
:plsql_backout := '[No SQL profile to back out]';
end if;
end if;
end;
/
set term on
set feed off
prompt
prompt Execute the following PL/SQL block to apply the recommended
SQL profile:
select :plsql_call from dual;
prompt
prompt
prompt To back out this change, execute the following PL/SQL block:
select :plsql_backout from dual;
prompt
prompt
undefine 1
undefine sql_id
@sqlplus_settings.sql
set term on
set pages 500
set
set lines 1000
linesize 750pages 9999
column
column box format9999
sid format a30
column
column serial for 999999
spid format a10
column
column status
username format a15 a30
format
column
column username
program formatformata30
a10
column
column sql_text
os_user format
format a80
a20
column module format a30
col program
select for a30
b.sid,b.serial#,a.spid, substr(b.machine,1,30)
col SQL_EXEC_START
box,b.logon_time for a20
logon_date , to_char
(b.logon_time, 'hh24:mi:ss') logon_time,
SELECT * FROM
substr(b.username,1,30) username,
(SELECT status,inst_id,sid,SESSION_SERIAL#
substr(b.osuser,1,20) os_user,
as
substr(b.program,1,30) program,status,b.last_call_et
Serial,username,sql_id,SQL_PLAN_HASH_VALUE,
AS last_call_et_secs,b.sql_id
MODULE,program,
from v$session b,v$process a
whereTO_CHAR(sql_exec_start,'dd-mon-yyyy
hh24:mi:ss') AS sql_exec_start,
b.paddr = a.addr
<-- For cluster ROUND(elapsed_time/1000000)
and type='USER'
for standalone --> AS "Elapsed
order (s)",
by b.sid;
ROUND(cpu_time /1000000)
AS "CPU (s)",
substr(sql_text,1,30) sql_text
FROM gv$sql_monitor where module not like
overall --> '%emagent%'
set pagesize
<-- ONLY 0 echo off timing off linesize 1000
EXECUTING ORDER BY sql_exec_start desc
trimspool on trim on long 2000000 longchunksize )
2000000 WHERE rownum<=20;
select
set lines 1000 pages 9999
DBMS_SQLTUNE.REPORT_SQL_MONITOR(
SELECT SNAP_ID,report_id Rid,
column sid50000
formatlines
setsql_id=>'&sql_id',
pages 999932767
column
col serial for
report_level=>'ALL',
OPNAME for a10 999999 Missing statements in SQL Monitoring -->
EXTRACTVALUE(XMLType(report_summary),'/report
column
col status
type=>'TEXT')
SID form 9999 format a15
_repository_summary/sql/@sql_id') sql_id,
column
fromSERIAL
col username
dual; format a20
form 9999999
column
col sql_text for
PROGRAM format
a10 a80
EXTRACTVALUE(XMLType(report_summary),'/report
Completed (or)a33 ERROR you can rewrite the sql using below hint
col
col program
USERNAME for for a10
_repository_summary/sql/status') status
col
col SQL_EXEC_START
SQL_TEXT for a40 for a20
FROM dba_hist_reports TO_NUMBER(EXTRACTVALUE(XMLTyp
col START_TIME
WHERE component_name for a10 = 'sqlmonitor' and
SELECT
col * FROM
LAST_UPDATE_TIME for a10 e(report_summary),'/report_repository_su
(EXTRACTVALUE(XMLType(report_summary),'/repor
col (SELECTfor
TARGET status,inst_id,sid,SESSION_SERIAL#
a25 mmary/sql/stats/stat[@name="elapsed_ti
COLUMN sid FORMAT 99999
t_repository_summary/sql/@sql_id'))='&sql_id' and
as
col MESSAGE for a25 me"]'))
COLUMN serial# FORMAT 9999999
snap_id=&snap_id;
Serial,username,sql_id,SQL_PLAN_HASH_VALUE,p
alter session set nls_date_format = 'DD-MM-YYYY COLUMN machine FORMAT A30
rogram,
HH24:MI:SS'; COLUMN progress_pct FORMAT 99999999.00
SELECT TO_CHAR(sql_exec_start,'dd-mon-yyyy
inst_id,sid, serial#, sql_id, opname, COLUMN elapsed FORMAT A10
hh24:mi:ss')target,
username, AS sql_exec_start,
sofar, totalwork, COLUMN remaining FORMAT A10
ROUND(elapsed_time/1000000)
start_time,last_update_time,round(time_remaining/60
AS
,2) "Elapsed (s)",
"REMAIN MINS", round(elapsed_seconds/60,2) SELECT s.sid,
https://community.toadworld.com/platforms/oracle/w/wiki/11372.real-time-sql-monitoring-12c-part-ii
"ELAPSED ROUND(cpu_time
gv$sql_monitor MINS", /1000000) AS s.serial#,
"CPU (s)",
round((time_remaining+elapsed_seconds)/60,2) s.machine,
"TOTAL substr(sql_text,1,30)
MINS", sql_text ROUND(sl.elapsed_seconds/60) || ':' ||
FROM gv$sql_monitor where module not like
ROUND(SOFAR/TOTALWORK*100,2) MOD(sl.elapsed_seconds,60) elapsed,
'%emagent%'
"%_COMPLETE", and message
sid=&sid ROUND(sl.time_remaining/60) || ':' ||
ORDER BY
FROM gv$session_longops sql_exec_start desc MOD(sl.time_remaining,60) remaining,
WHERE ); OPNAME NOT LIKE 'RMAN%' AND ROUND(sl.sofar/sl.totalwork*100, 2)
OPNAME NOT LIKE '%aggregate%' AND progress_pct
TOTALWORK != 0 AND sofar<>totalwork AND FROM gv$session s,
time_remaining > 0 gv$session_longops sl
/ WHERE s.sid = sl.sid
AND s.serial# = sl.serial#;
Overall Waits Time model
col BI for 990
'999,999,990.000'), 18) cpu_secs,
COL
"I/O se.total_waits,
executions_total
instance_number
wait FOR
FOR999,999
9999 HEA HEA 'Execs|
'Inst'; COL end_time HEA 'End Time';
col BS for(s)",
9999 RPAD(LPAD (' ', 2*p.plan_DEPTH) ||
SELECTse.total_timeouts,
Total';
COL end_time
'DBA_HIST'HEA 'End Time'; COL plan_hash_value || ' ' || HEA 'Plan|Hash Value';
col ROUND(application_wait_time/1000000,3)
PI for 99
LPAD(TO_CHAR(ROUND(user_io_wait_time/1e6, AS 3), p.plan_operation p.plan_options,60,'.') ||
COL se.time_waited,
rows_per_exec
plan_hash_value
source,h.instance_number,h.SNAP_ID,
"Appli waitfor (s)", HEAHEA 'Rows Per Exec';
'Plan|Hash Value'; col NVL2(p.plan_object_owner||p.plan_object_name,
sql_id for a15
col status
'999,999,990.000'), a10 18) user_io_wait_secs,
COL
col se.average_wait,
et_secs_per_exec
sql_id for a15 HEA 'Elap Secs|Per Exec'; col
'(' || SQL_PROFILE for a30'.' || p.plan_object_name ||
col ROUND(concurrency_wait_time/1000000,3)
seconds_in_wait for 9990
LPAD(TO_CHAR(ROUND(cluster_wait_time/1e6, AS p.plan_object_owner||
COL se.max_wait,
cpu_secs_per_exec 18)HEA
EXTRACTVALUE(XMLType(s.report_summary),'/repo
col SQL_PROFILE
"Concurrency
col '999,999,990.000'),
PSID for a5 wait for
(s)", a30 'CPU Secs|Per Exec'; COL
') ', '') executions_total
|| FOR 999,999 HEA 'Execs|
3), cluster_wait_secs,
COL se.time_waited_micro
io_secs_per_exec HEA999,999
rt_repository_summary/sql/@sql_exec_start')
executions_total 'IO /1000000,3)
Secs|Per Exec';
select a.inst_id i, a.sid,FOR
ROUND(cluster_wait_time a.serial#, HEA"PSID",
b.qcsid 'Execs|
AS Total';
NVL2(p.plan_COST,'Cost:' || p.plan_COST,'') || ' '
FROM
COL v$session_event
cl_secs_per_exec se,
start_time,
Total';
"Cluster wait a.osuser,
a.username, (s)", a.machine,a.status, Exec';
HEA
LPAD(TO_CHAR(ROUND(application_wait_time/1e6, 'Clus Secs|Per COL
|| rows_per_exec HEA 'Rows |Per Exec';
COL v$session
ap_secs_per_exec
rows_per_exec s
ROUND(physical_read_bytes HEA HEA
'Rows 'App
|PerSecs|Per
Exec'; Exec';
/(1024*1024)) AS select
COL stat_name, value HEA 'Elap Secs|Per Exec';
et_secs_per_exec
NVL2(p.plan_bytes||p.plan_CARDINALITY,'(' ||
sql_id,
3), sql_child_number
'999,999,990.000'), 18)cld, event,
appl_wait_secs,a.last_call_et/60
WHERE s.sid
cc_secs_per_exec= se.sid HEA
EXTRACTVALUE(XMLType(s.report_summary),'/repo
COL et_secs_per_exec HEA 'Conc
'Elap Secs|Per Exec'; from V$SESS_TIME_MODEL
"Phys reads
"RunT (MB)",
(M)",seconds_in_wait/60 "Seconds Exec';
Secs|Per COL cpu_secs_per_exec HEA 'CPU Secs|Per Exec';
p.plan_bytes || ' bytes, ' || p.plan_CARDINALITY || '
AND
COL s.sid = &Session_ID
pl_secs_per_exec
cpu_secs_per_exec HEA
rt_repository_summary/sql/@sql_exec_id')
ROUND(physical_write_bytes HEA 'PLSQL
'CPU Secs|PerExec';
Secs|Per
/(1024*1024)) Exec';
AS where
COL
rows)','') sid|| =' ' &sid
io_secs_per_exec
|| HEA 'IO Secs|Per Exec';
Wait(M)",a.blocking_session
LPAD(TO_CHAR(ROUND(concurrency_wait_time/1e BS,a.blocking_instance
ORDER
COL
sql_exec_id,
"Phys BY se.time_waited
ja_secs_per_exec
io_secs_per_exec
writes (MB)", HEA DESC
'Java
'IO Secs|Per
Secs|Per Exec';
Exec'; order
COL by value desc;
cl_secs_per_exec
NVL2(p.plan_partition_start HEA 'Clus || Secs|Per Exec';
BI 3), '999,999,990.000'), 18) conc_wait_secs,
6,
/ buffer_gets
SELECT
COL h.instance_number,h.SNAP_ID,
cl_secs_per_exec HEA 'ClusAS Secs|Per Exec'; COL ap_secs_per_exec HEA 'App|| Secs|Per Exec';
fromh.sql_id,
gv$session a, gv$px_session
LPAD(TO_CHAR(ROUND(plsql_exec_time/1e6, b "Buffer gets", p.plan_partition_stop,'
column my_sid format PStart:' 999
COL TO_CHAR(CAST(s.begin_interval_time AS
Each'999,999,990.000'), 18) plsql_exec_secs, Exec';
where
3), ap_secs_per_exec
h.plan_hash_value,sql_profile,
Layer time spend
ROUND(plsql_exec_time/1000000,3) HEA 'App Secs|Per AS COL
Explain cc_secs_per_exec
Plan waiting
p.plan_partition_start
column my_ser formatsteps ' HEA
||99999
PStop:''Conc
|| Secs|Per Exec';
DATE),
COL
"Plsql 'DD-MM-YYYY
cc_secs_per_exec
h.executions_total,
exec (s)",
a.last_call_et >0 HH24:MI')
HEA 'Conc snap_time,
Secs|Per Exec'; COL pl_secs_per_exec
p.plan_partition_stop,'')
column my_state format||a30 HEA 'PLSQL Secs|Per AS
LPAD(TO_CHAR(ROUND(java_exec_time/1e6, SELECT ROUND(elapsed_time /1000000)
COL h.sql_id,sql_profile,
pl_secs_per_exec
ROUND(java_exec_time
--and a.status = 'ACTIVE' HEA
TO_CHAR(ROUND(h.rows_processed_total 'PLSQL Secs|PerAS
/1000000,3) Exec';
/ Exec';
column program
NVL2(p.plan_time,
column my_blkr format a30
p.plan_time || '(s)','') AS PLAN
3), '999,999,990.000'), 18) java_exec_secs, "Elapsed (s)", format 999
COL
"Java h.plan_hash_value,
ja_secs_per_exec
h.executions_total),
exec (s)" HEA 'Java
'999,999,999,999')
--andLPAD(TO_CHAR(io_cell_offload_eligible_bytes,
a.username in ('DELPHI') Secs|Per Exec'; COL
column
selectFROMja_secs_per_exec
username format
gv$sql_plan_monitor
to_char(a.sample_time,/1000000,3)HEA
a30 'Java
p Secs|Per
'HH24:MI:SS') Exec';
ROUND(cpu_time AS "CPU
COL h.executions_total,
DISK_READS_TOTAL
rows_per_exec,
FROM HEA 30) 'Disk|reads'; COL
column DISK_READS_TOTAL
sql_id format a13 HEA 'Disk|reads';
--and * gv$sql_monitor
Machine in
'999,999,999,999,999,999,990'),
SELECT WHERE
MY_TIME,a.session_id
(s)", sid=&sid MY_SID,a.session_serial#
COL TO_CHAR(ROUND(h.rows_processed_total
BUFFER_GETS_TOTAL
TO_CHAR(ROUND(h.elapsed_time_total
WHERE sid=&sid and inst_id=&inst_id;
('phxengsas03.ssd.star','phxengsas04.ssd.star') HEA 'Buffer|gets'; / / COL
SELECT BUFFER_GETS_TOTAL
ORDER BY p.plan_line_id, HEA
query_runs.*,
MY_SER,SQL_PLAN_HASH_VALUE,SQL_CHILD_ 'Buffer|gets';
p.plan_parent_id;
io_cell_offload_eligible_bytes,
FROM ROUND(queuing_time /1000000,3) AS
h.executions_total),
h.executions_total
and a.username / '999,999,999,999')
1e6,
is not null 3), '999,990.000') ROUND
NUMBER,(s)", ( (end_time - start_time) * 24, 2) AS
LPAD(TO_CHAR(io_interconnect_bytes,
(SELECT status, "Queuing
rows_per_exec,
select * from
et_secs_per_exec,
and event not( inSELECT
('Streams AQ: waiting select
duration_hrs* from ( SELECT
'999,999,999,999,999,999,990'),
--username, 30) for messages DECODE(a.session_state,
ROUND(application_wait_time/1000000,3) 'WAITING' ,a.event, AS
in theTO_CHAR(ROUND(h.elapsed_time_total
h.instance_number,h.SNAP_ID,
TO_CHAR(ROUND(h.cpu_time_total
v$sqlarea queue')
io_interconnect_bytes,
sql_id, ( ALL ) / / h.instance_number,h.SNAP_ID,
FROM
a.session_state)
ASH wait (s)", MY_STATE,a.xid, a.sql_id,
"Appli
h.executions_total
h.sql_id,sql_profile,
and a.inst_id / 1e6,
= b.inst_id (+) 3), '999,990.000') h.sql_id,sql_profile,
(SELECT u.username, MY_BLKR
a.blocking_session
CASE
sql_exec_id, ROUND(concurrency_wait_time/1000000,3) AS
et_secs_per_exec,
h.plan_hash_value,
cpu_secs_per_exec,
and a.sid = b.sid (+) h.plan_hash_value,
ash.program,
from gv$active_session_history a, dba_users u
WHEN io_cell_offload_eligible_bytes
TO_CHAR(sql_exec_start,'dd-mon-yyyy > "Concurrency wait (s)",
TO_CHAR(ROUND(h.cpu_time_total
orderh.executions_total,
TO_CHAR(ROUND(h.iowait_total
by last_call_et desc / / col
where execs
ash.sql_id, for 999,999,999
h.executions_total,
u.user_id = a.user_id
io_interconnect_bytes
hh24:mi:ss') THEN
AS sql_exec_start, ROUND(cluster_wait_time /1000000,3) AS
h.executions_total
/ / 1e6, 3), '999,990.000')
TO_CHAR(ROUND(h.rows_processed_total / col avg_etime for 999,999
TO_CHAR(ROUND(h.rows_processed_total
ASH.SQL_PLAN_HASH_VALUE
and a.sql_id AS /
LPAD(TO_CHAR(ROUND(
ROUND(elapsed_time/1000000) "Cluster wait =(s)", '&sql_id'
cpu_secs_per_exec,
h.executions_total),
io_secs_per_exec, '999,999,999,999') col avg_lio
h.executions_total),
plan_hash_value, for
andROUND(user_io_wait_time 999,999,999'999,999,999,999')
a.sample_time > SYSTIMESTAMP-(2/1440);
AS "Elapsed(io_cell_offload_eligible_bytes
(s)", - /1000000,3) AS
TO_CHAR(ROUND(h.iowait_total
rows_per_exec,
TO_CHAR(ROUND(h.clwait_total / colASH.SESSION_ID
avg_pio for 999,999,999
rows_per_exec, AS sess#,
io_interconnect_bytes)
v$sql ROUND(cpu_time
( sql_id ) * 100 /
/1000000) AS "User io wait (s)",
TO_CHAR(ROUND(h.elapsed_time_total
h.executions_total / 1e6, 3), '999,990.000') / colASH.SESSION_SERIAL#
begin_interval_time
TO_CHAR(ROUND(h.elapsed_time_total for a30 / AS
AS sess_ser,
io_cell_offload_eligible_bytes
"CPU (s)", ROUND(physical_read_bytes /(1024*1024))
io_secs_per_exec,
h.executions_total / 1e6, colCASTnode (MIN for 99999
cl_secs_per_exec,
, 2), '990.00')||'
buffer_gets, %',3),
8) '999,990.000')
END io_saved h.executions_total
"Phys reads (MB)", / 1e6,
(ASH.SAMPLE_TIME) 3), '999,990.000') AS DATE) AS
TO_CHAR(ROUND(h.clwait_total
et_secs_per_exec,
TO_CHAR(ROUND(h.apwait_total // break on plan_hash_value on startup_time skip 1
et_secs_per_exec,
start_time,
FROM gv$sql
ROUND(physical_read_bytes /(1024*1024)) AS ROUND(physical_write_bytes /(1024*1024)) AS
h.executions_total / 1e6,
TO_CHAR(ROUND(h.cpu_time_total 3), '999,990.000') / select ss.snap_id, ss.instance_number
TO_CHAR(ROUND(h.cpu_time_total
CAST (MAX (ash.sample_time) AS DATE) node,
/ AS
WHERE
"Phys sql_id
reads = '&sql_id'
(MB)", "Phys writes (MB)",
cl_secs_per_exec,
h.executions_total begin_interval_time, sql_id, plan_hash_value,
BY 1, 2; / 1e6, 3), '999,990.000')
ap_secs_per_exec,
ORDER ROUND(physical_write_bytes/(1024*1024)) AS h.executions_total
end_time
buffer_gets / 1e6, 3), '999,990.000')
AS "Buffer gets",
TO_CHAR(ROUND(h.apwait_total
cpu_secs_per_exec,
TO_CHAR(ROUND(h.ccwait_total // nvl(executions_delta,0)
cpu_secs_per_exec,
FROM dba_hist_active_sess_history execs, ash, AS
"Phys writes (MB)"
Elapsed/CPU/Read/Write MB Each ROUND(plsql_exec_time/1000000,3)
Layer time spend
TO_CHAR(ROUND(h.iowait_total
h.executions_total / 1e6, 3),where
'999,990.000') / (elapsed_time_delta/decode(nvl(executions_delta,0)
TO_CHAR(ROUND(h.iowait_total
dba_users u /
FROM gv$sql_monitor sql_id='&sql_id' "Plsql exec (s)",
ap_secs_per_exec,
h.executions_total
cc_secs_per_exec / 1e6, 3), '999,990.000') ,0,1,executions_delta))/1000000
h.executions_total
WHERE u.user_id / 1e6,
= 3), avg_etime,
'999,990.000')
ASH.USER_ID
and inst_id=&inst_id ROUND(java_exec_time /1000000,3) AS
FROMTO_CHAR(ROUND(h.ccwait_total
io_secs_per_exec,
dba_hist_sqlstat h, / (buffer_gets_delta/decode(nvl(buffer_gets_delta,0),0
io_secs_per_exec,
AND exec ash.sql_id
ORDER BY elapsed_time DESC "Java (s)" = lower(trim('&sql_id'))
h.executions_total
dba_hist_reports / 1e6,
TO_CHAR(ROUND(h.clwait_total s 3), '999,990.000') / ,1,executions_delta))
GROUPTO_CHAR(ROUND(h.clwait_total
BY u.username, avg_lio, /
) FROM gv$sql_monitor
cc_secs_per_exec,
h.executions_total
WHERE h.sql_id =/ '&sql_id'
1e6, 3), '999,990.000') ROUND(disk_reads_delta/DECODE(executions_delt
h.executions_total
ash.program, / 1e6, 3), '999,990.000')
WHERE rownum<=20; WHERE sql_id='&sql_id' and inst_id=&inst_id;
TO_CHAR(ROUND(h.plsexec_time_total
cl_secs_per_exec,
AND h.sql_id = / a,0,1, executions_delta),1) avg_pio,
cl_secs_per_exec,
ash.sql_id,
AWR data (More detailed)
h.executions_total / 1e6, 3), '999,990.000') SHORT Report
ROUND(rows_processed_delta/DECODE(execution
(EXTRACTVALUE(XMLType(s.report_summary),'/rep
TO_CHAR(ROUND(h.apwait_total / ASH.SQL_PLAN_HASH_VALUE,
TO_CHAR(ROUND(h.apwait_total /
pl_secs_per_exec,
h.executions_total / 1e6, 3), '999,990.000')
ort_repository_summary/sql/@sql_id')) s_delta,0,
h.executions_total
ASH.SESSION_ID,1, executions_delta), 1) avg_rows,
/ 1e6, 3), '999,990.000')
ANDTO_CHAR(ROUND(h.javexec_time_total
ap_secs_per_exec,
s.snap_id = h.snap_id / round(px_servers_execs_delta/decode(executions_
ap_secs_per_exec,
ASH.SESSION_SERIAL#
h.executions_total
AND s.dbid = h.dbid / 1e6, 3), '999,990.000')
TO_CHAR(ROUND(h.ccwait_total / delta,0,1, executions_delta), 1) avg_px /
TO_CHAR(ROUND(h.ccwait_total
) query_runs
ja_secs_per_exec
h.executions_total
AND s.instance_number / 1e6, 3),= '999,990.000')
h.instance_number from DBA_HIST_SQLSTAT
BY sql_id,/ 1e6, 3), S,
h.executions_total
ORDER '999,990.000')
FROM dba_hist_sqlstat
cc_secs_per_exec,
order by h,
source,snap_id,start_time ; DBA_HIST_SNAPSHOT
cc_secs_per_exec,
start_time; SS
dba_hist_snapshot s
TO_CHAR(ROUND(h.plsexec_time_total / where sql_id = nvl('&sql_id','4dqs2k5tynk61') /
TO_CHAR(ROUND(h.plsexec_time_total
WHERE h.sql_id =/ '&sql_id'
h.executions_total 1e6, 3), '999,990.000') and ss.snap_id = S.snap_id
h.executions_total / 1e6, 3), '999,990.000')
AND s.snap_id = h.snap_id
pl_secs_per_exec, and ss.instance_number = S.instance_number
pl_secs_per_exec,
AND s.dbid = h.dbid
TO_CHAR(ROUND(h.javexec_time_total / and executions_delta >0
TO_CHAR(ROUND(h.javexec_time_total /
AND s.instance_number
h.executions_total / 1e6, 3),= '999,990.000')
h.instance_number order by 1, 2, 3
h.executions_total / 1e6, 3), '999,990.000')
order by SNAP_ID;
ja_secs_per_exec, /ja_secs_per_exec,
TopDISK_READS_TOTAL
I/O Used ,BUFFER_GETS_TOTAL TopDISK_READS_TOTAL
DISK Read ,BUFFER_GETS_TOTAL
FROM dba_hist_sqlstat h FROM dba_hist_sqlstat h
WHERE WHERE
h.snap_id = 11706 h.snap_id = 11706
AND h.executions_total > 0 AND h.executions_total > 0
order by io_secs_per_exec desc ) where rownum order by DISK_READS_TOTAL desc ) where
<=50; rownum <=50;
sql_text bind_variable
greatest(PGA_ALLOCATED
instr(plan_table_output,
run_time))/60 '|', 1, 3)+2, - (
set lines 750 run_time_MIN,
pages 9999
first_value(PGA_ALLOCATED)
(instr(plan_table_output,
READ_IO_BYTES, '|', 1, over (partition by
4)- select
select sql_text from gv$sqlarea where sql_id =
sql_id,sql_exec_id
instr(plan_table_output,
PGA_ALLOCATED '|', order by sample_time
1, 3)-2)), ' ')
PGA_ALLOCATED_BYTES, rows 1 SESSION_ID,SESSION_SERIAL#,sample_id,SQL_I
'&SQL_ID';
preceding),0)
fromTEMP_ALLOCATED
( DELTA_PGA, D,SAMPLE_TIME,IS_SQLID_CURRENT,SQL_CHIL
greatest(TEMP_SPACE_ALLOCATED
SELECT plan_table_output
TEMP_ALLOCATED_BYTES - D_NUMBER,PGA_ALLOCATED,
first_value(TEMP_SPACE_ALLOCATED)
FROM
from ( over greatest(PGA_ALLOCATED -
column sql_text format a800
(partition
select by sql_id,sql_exec_id order by sample_time first_value(PGA_ALLOCATED) over (partition by
TABLE(DBMS_XPLAN.DISPLAY_CURSOR('&sql_id',
rows
null, 1 preceding),0) DELTA_TEMP
'BASIC'))
sql_id, SESSION_ID,SESSION_SERIAL# order by
SELECT sql_text col VALUE_STRING for a50
UNIONfrom ALL
max(sample_time - sql_exec_start) run_time, sample_time rows 1 preceding),0)/power(1024,2)
FROM gv$sql_monitor where SELECT
dba_hist_active_sess_history
SELECT * FROM and
max(sample_time) end_time, "DELTA_PGA_MB"
status='EXECUTING' module not like '%emagent NAME,POSITION,DATATYPE_STRING,VALUE_ST
where
TABLE(dbms_xplan.display_awr('&sql_id',
sql_exec_start starting_time, null, null, from
%' sample_time >= to_date ('2013/04/16 RING FROM gv$sql_bind_capture WHERE
'ALL')) sum(DELTA_READ_IO_BYTES) v$active_session_history
and sql_text not like '%BEGIN%'; sql_id='&sql_id';
00:00:00','YYYY/MM/DD
)
READ_IO_BYTES, HH24:MI:SS') where
where and sample_time
plan_table_output < to_date
sum(DELTA_PGA) PGA_ALLOCATED,like ('2013/04/16
'%INDEX%' IS_SQLID_CURRENT='Y'
03:10:00','YYYY/MM/DD
) sum(DELTA_TEMP)HH24:MI:SS') TEMP_ALLOCATED and sample_time > sysdate-&seconds/86400
ORDER and
fromBYsql_exec_start is not nullindex_name
owner, table_name, order by 1,2,3,4
/ and
( IS_SQLID_CURRENT='Y' )
) group
PGA/TEMP select sql_id,
( History ) PGA by sql_id
groupsample_time,
by sql_id,SQL_EXEC_ID,sql_exec_start having sum(DELTA_PGA_MB) > 0
ordersql_exec_start,
by sql_id )
) DELTA_READ_IO_BYTES, where rank < (&top+1)
wheresql_exec_id,
sql_id = 'btvk5dzpdmadh' order by rank
select s.sid, s.serial#, p.spid, s.username,
ordergreatest(PGA_ALLOCATED
by sql_id, run_time_sec desc; - /
s.program,
first_value(PGA_ALLOCATED) over (partition by t.xidusn, t.used_ublk, t.used_urec, sa.sql_text from
sql_id,sql_exec_id order by sample_time rows 1 v$process p,v$session s, v$sqlarea sa,
preceding),0) DELTA_PGA, v$transaction t
greatest(TEMP_SPACE_ALLOCATED - where s.paddr=p.addr
http://blog.go-faster.co.uk/2016/11/ash-analysis-detecting-and-profiling.html
first_value(TEMP_SPACE_ALLOCATED) over and s.taddr=t.addr
(partition by sql_id,sql_exec_id order by sample_time and s.sql_address=sa.address(+)
rows
select1sql_text,rows_processed
preceding),0) DELTA_TEMP from v$sql and s.sql_hash_value=sa.hash_value(+)
from
where USERS_EXECUTING>0; order by s.sid
dba_hist_active_sess_history /
where
sample_time >= trunc(sysdate)
--and sample_time < to_date ('2013/04/16
03:10:00','YYYY/MM/DD HH24:MI:SS')
and sql_exec_start is not null
selectand sess_io.inst_id,
IS_SQLID_CURRENT='Y'
sess_io.sid,
)
group sess_io.block_gets,
by sql_id,SQL_EXEC_ID,sql_exec_start
order sess_io.consistent_gets,
by sql_id
) sess_io.physical_reads,
where sess_io.block_changes,
sql_id = '&sql_id'
ordersess_io.consistent_changes
by sql_id, run_time_MIN desc;
from gv$sess_io sess_io, gv$session sesion
where sesion.sid = sess_io.sid and
sess_io.inst_id = sesion.inst_id
and sesion.username
select a.sid,b.sql_fulltextisfrom not null ;
V$Session a,
V$SQLAREA b where a.sql_id=b.sql_id and
a.status='ACTIVE';
http://www.artoftuning.net/sql-plan-comparison/
SELECT WAIT_CLASS, SELECT wait_class time_cat, ROUND((time_secs),
TOTAL_WAITS, 2) time_secs,
round(100 * (TOTAL_WAITS / SUM_WAITS),2) ROUND((time_secs) * 100 / SUM(time_secs)
PCT_TOTWAITS, OVER (), 2) pct
ROUND((TIME_WAITED / 100),2) FROM (SELECT wait_class wait_class,
TOT_TIME_WAITED, SUM(time_waited_micro) / 1000000
SET lines 750
round(100 pages 10000 / SUM_TIME),2)
* (TIME_WAITED time_secs
COLUMN
PCT_TIMEwait_class format a30 FROM gv$system_event
COLUMN
FROM event format a60 WHERE wait_class <> 'Idle' AND time_waited >
COLUMN total_waits format 999999
(select WAIT_CLASS, 0
COLUMN
TOTAL_WAITS,total_us%format
Wait Percentage (Only 999999999 WaitGROUP
wait events-NO CPU) PercentageBY wait_class
% (Only wait events-WITH CPU)
COLUMN
TIME_WAITED pct_time format 99.99 SELECTUNIONevent, total_waits,
COLUMN avg_us format 999999.99
FROM V$SYSTEM_WAIT_CLASS ROUND'CPU',
SELECT (time_waited_micro / 1000000)
ROUND((SUM(VALUE) / AS
SET
WHERE echoWAIT_CLASS
on != 'Idle'), time_waited_secs,
1000000), 2) time_secs
(select sum(TOTAL_WAITS) SUM_WAITS, ROUND
FROM (time_waited_micro * 100 /
gv$sys_time_model
SELECT wait_class,SUM_TIME
sum(TIME_WAITED) event, total_waits AS waits,
WHERESUM stat_name
(time_waited_micro) OVERcpu
IN ('background (),2)time',
AS
from V$SYSTEM_WAIT_CLASS / 1000) AS
ROUND (time_waited_micro pct_time
'DB CPU'))
total_ms,
where WAIT_CLASS != 'Idle') FROMBY
ORDER (SELECT
time_secs event, total_waits,
DESC;
ORDER ROUND (time_waited_micro
BY PCT_TIME DESC; * 100 / SUM
time_waited_micro
(time_waited_micro) OVER (), FROM v$system_event
2 WHERE wait_class <> 'Idle'
) AS pct_time, UNION
select
set lines
ROUND ((time_waited_micro / total_waits) / 750 pages
SELECT 9999 NULL, VALUE
stat_name,
1000, 2) AS avg_ms event,
select * FROM
from ( v$sys_time_model
FROM v$system_event time_waited
select WHERE"time_waited(s)",
stat_name IN ('DB CPU',
WHERE wait_class <> 'Idle' case whencpu
WAIT_CLASS
'background time_waited
,time')) = 0 then
ORDER BY time_waited_micro DESC; ORDER 0 BY 3 DESC;
EVENT,
else
count(sample_time) as EST_SECS_IN_WAIT
SELECT NVL(a.event, 'ON CPU') AS event, fromround(time_waited*100
v$active_session_history / sum(time_waited)
COUNT(*) AS total_wait_time Over(), 2)
where sample_time between sysdate - interval '1'
FROM v$active_session_history a hourend "percentage"
and sysdate
WHERE a.sample_time > SYSDATE - 60/2880 -- 30 from
group by WAIT_CLASS,EVENT
mins ( by count(sample_time) desc
order
GROUP BY a.event ) select event, sum(time_waited) time_waited
ORDER BY total_wait_time DESC; wherefromrownumdba_hist_active_sess_history
<6;
where sql_id = '&SQL_ID'
group by event
<-- shared pool (current) )
order by
From AWR --> time_waited desc;
select expl.*
from
gv$sql sql, v$session ses,
SELECT * FROM
TABLE(dbms_xplan.display_cursor(sql.sql_id,
TABLE(DBMS_XPLAN.DISPLAY('','','ALLSTATS
sql.child_number,format=>'typical +predicate')) expl
LAST +OUTLINE +PEEKED_BINDS +PROJECTION
where ses.sql_address = sql.address and ses.sid
+ALIAS +PREDICATE +COST +BYTES'));
= &&1
and sql.optimizer_cost is not null
/
select * from
table(dbms_xplan.display_awr('&sql_id', null, null,
'ALLSTATS LAST'));
SELECT * FROM
table(DBMS_XPLAN.DISPLAY_AWR('&sql_id',&plan
_hash_value));
SELECT o.sid,
o.sql_text,
o.address,
o.hash_value,
o.user_name,
s.schemaname,
o.sql_id
FROM v$open_cursor o, v$session s
WHERE o.saddr = s.saddr AND o.sid = s.sid AND
(O.SID = &sid)
PARSING_SCHEMA_NAME, ELAPSED_TIME FROM V$SQL WHERE UPPER(PARSING_SCHEMA_NAME) ='SYS' ORDER BY ELAPSE
https://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:7143624535091
select t.inst_id
,s.sid
,s.serial#
,s.username
,s.machine
,s.status
,s.lockwait If it returns a value, it means there is a pending
,t.used_ublk transaction.
,t.used_urec
,t.start_time Here is the query:
from gv$transaction t
inner join gv$session s on t.addr = s.taddr; select dbms_transaction.step_id from dual;
L_PROFILE(
SQL_TEXT => sql_txt,
PROFILE_XML =>
DBMS_SMB_INTERNAL.VARR_TO_HINTS_XML(h)
,
name =>
'coe_5273fz2cqkk80_3455548535',
description => 'coe 5273fz2cqkk80
3455548535 '||:signature||' '||:signaturef||'',
CATEGORY => 'DEFAULT',
CREATOR => 'SYS',
VALIDATE
set lines => TRUE,
1000 pages 9999
TYPE for
col name => a30
'PATCH',
FORCE_MATCH for
col task_exec_name => a16
TRUE,
IS_PATCH =>
col category for a10 TRUE);
DBMS_LOB.FREETEMPORARY(sql_txt);
col created for a30
coldbms_output.put_line(output);
sql_text for a150
colEND;
signature for 9999999999999999999999999
https://avdeo.com/2012/12/14/oracle-sql-patch-i/ /
select sql.sql_id,sql.child_number as child ,
ENABLE/DISABLE/DROP prof.name,
sql Profilesprof.category,
for a sql_id prof.created,
prof.task_exec_name,prof.FORCE_MATCHING,
EXEC prof.status, prof.SIGNATURE,prof.SQL_TEXT
DBMS_SQLTUNE.ALTER_SQL_PROFILE('coe_5273 from
fz2cqkk80_3455548535','STATUS','DISABLED'); dba_sql_profiles prof,
gv$sql sql
exec where sql.sql_id in ('&sql_id')
dbms_sqltune.drop_sql_profile('coe_5273fz2cqkk80_ order by
3455548535'); created;
Drop load from cursor
set serveroutput on
DECLARE
i NATURAL;
BEGIN
i :=
SELECT chr(9)||chr(9)||''''|| variable chr(9)||chr(9)||''''||
SELECT sqlid number;
dbms_spm.drop_sql_plan_baseline('SQL_b3d69637a
regexp_replace(extractvalue(value(d), execute :sqlid
regexp_replace(extractvalue(value(d),
a86a8ca');
'/hint'),'''','''''')||''',' :=DBMS_SPM.LOAD_PLANS_FROM_CURSOR_C
'/hint'),'''','''''')||''','
dbms_output.put_line(i);
from ACHE(sql_id=>'5qbbnv0abm2vx',
from
END;
xmltable('/*/outline_data/hint' PLAN_HASH_VALUE=>
xmltable('/*/outline_data/hint' 4197102931,
/passing ( SQL_HANDLE
passing ( => 'SQL_d3318f33dfac7bc2');
Taking
select SQL HINTS from memory Taking
select SQL HINTS from AWR
xmltype(other_xml) as xmlval xmltype(other_xml) as xmlval
from from
v$sql_plan -- v$sql_plan
To see the hints from sql_profile
where dba_hist_sql_plan
select
sql_idhint
like from (
nvl('&sql_id',sql_id) where
select s.sql_id, sd.obj_type,
and child_number = &child_no sql_id like nvl('&sql_id',sql_id)
row_number()
and other_xmlover (partition
is not null by sd.signature, and other_xml is not null
sd.category
) order by sd.signature) row_num, )
extractValue(value(t),
) '/hint') hint )
from
d; sqlobj$data sd, v$sql s, d;
table(xmlsequence(extract(xmltype(sd.comp_data),
'/outline_data/hint'))) t
where sd.obj_type = 1
and s.exact_matching_signature = sd.signature
and s.sql_id = '&sql_id')
order by row_num
/ http://intermediatesql.com/oracle/what-are-sql-profiles-and-why-do-we-
http://expertoracle.com/2015/07/08/flush-bad-sql-plan-from-shared-pool/
AGE,0)) "16",
max(decode(to_char(END_TIME,'HH24'),'17',AVER
AGE,0)) "17",
max(decode(to_char(END_TIME,'HH24'),'18',AVER
AGE,0)) "18",
max(decode(to_char(END_TIME,'HH24'),'19',AVER
AGE,0)) "19",
max(decode(to_char(END_TIME,'HH24'),'20',AVER
AGE,0)) "20",
set pages 100 max(decode(to_char(END_TIME,'HH24'),'21',AVER
select INSTANCE_NUMBER, AGE,0)) "21",
SUM(value), max(decode(to_char(END_TIME,'HH24'),'22',AVER
to_char(trunc(end_time,’HH’),’dd-mm-yyyy hh24:mi’) AGE,0)) "22",
as sample_time max(decode(to_char(END_TIME,'HH24'),'23',AVER
from dba_hist_sysmetric_history AGE,0)) "23"
where metric_name=’Average Active Sessions’ from DBA_HIST_SYSMETRIC_SUMMARY
and end_time between sysdate -1 and sysdate where metric_name='Average Active Sessions' and
group by trunc(end_time,’HH’), INSTANCE_NUMBER INSTANCE_NUMBER = &inst_num
order by 3,1; group by to_char(END_TIME,'DD-Mon');
http://kerryosborne.oracle-guy.com/2008/10/unstable-plans/
y-an-invashtigation/
https://yasu-khan.github.io/Forensic-investigation-sql-performance
http://www.williamrobertson.net/documents/automated-sql-tuning-advice-sqlid.html
Test it before using
Name , program path 'program'
..... ......................................: '||
, plan_hash path 'plan_hash' , px_servers_allocated path
s.SCHEMANAME,
, is_cross_instance path 'px_servers_allocated'
'Program ...............................................:
'is_cross_instance' , duration path
'||s.program,
, dop.................................................:
path 'dop' 'stats/stat[@name="duration"]'
'Module
, instances path 'instances' , elapsed_time path
'|| s.module,
, px_servers_requested path 'stats/stat[@name="elapsed_time"]'
'Action .................................................: '||
'px_servers_requested' , cpu_time path
s.action,
, px_servers_allocated path 'stats/stat[@name="cpu_time"]'
'Terminal ...............................................: '||
'px_servers_allocated' , user_io_wait_time path
s.terminal,
, duration path 'stats/stat[@name="user_io_wait_time"]'
'Client
'stats/stat[@name="duration"]' , application_wait_time path
Machine .........................................: '||
, elapsed_time path 'stats/stat[@name="application_wait_tim
s.machine,
'stats/stat[@name="elapsed_time"]' e"]'
'LAST_CALL_ET ......................................
, cpu_time path , concurrency_wait_time path https://ma
.....: '||s.last_call_et,
'stats/stat[@name="cpu_time"]' 'stats/stat[@name="concurrency_wait_ti uro-
'S.LAST_CALL_ET/3600 ..........................
, user_io_wait_time me"]' pagano.c
..........: '||s.last_call_et/3600path
'stats/stat[@name="user_io_wait_time"]' , cluster_wait_time path SELECT om/2015/
from v$session s, v$process p
, application_wait_time 'stats/stat[@name="cluster_wait_time"]' report_id, 05/04/hist
where p.addr=s.paddr and path
'stats/stat[@name="application_wait_time , plsql_exec_time path key1 orical-sql-
s.sid=nvl('&sid',s.sid) and
"]' 'stats/stat[@name="plsql_exec_time"]' sql_id, monitor-
p.spid=nvl('&spid',p.spid) and
, concurrency_wait_time path , other_wait_time path key2 reports-
nvl(s.process,-1) =
'stats/stat[@name="concurrency_wait_tim 'stats/stat[@name="other_wait_time"]' sql_exec in-12c/
nvl('&ClientPid',nvl(s.process,-1)); http://allappsdba.blogspot.com/2012/04/queries-to-get-session-information.html
e"]' , buffer_gets path _id, key3
, cluster_wait_time path 'stats/stat[@name="buffer_gets"]' sql_exec http://ww
'stats/stat[@name="cluster_wait_time"]' , read_reqs path _start w.toadwor
, plsql_exec_time path 'stats/stat[@name="read_reqs"]' FROM ld.com/pl
'stats/stat[@name="plsql_exec_time"]' , read_bytes path dba_hist_ atforms/or
, other_wait_time path 'stats/stat[@name="read_bytes"]' reports acle/w/wi
'stats/stat[@name="other_wait_time"]' ) x1 WHERE ki/11372.r
, buffer_gets path where x1.elapsed_time/1000000 > 200 compone eal-time-
ALTER SESSION SET
'stats/stat[@name="buffer_gets"]' and t.COMPONENT_NAME = nt_name sql-
"_SQLMON_MAX_PLAN"=4020;
, read_reqs path 'sqlmonitor' = monitorin
ALTER SESSION SET
'stats/stat[@name="read_reqs"]' order by 5 'sqlmonito g-12c-
"_SQLMON_MAX_PLANLINES"=4000;
, read_bytes path / r'; part-ii
'stats/stat[@name="read_bytes"]'
) x1
where x1.elapsed_time/1000000 > 200
and t.COMPONENT_NAME =
'sqlmonitor'
order by 5
/
exec
dbms_stats.flush_database_monitoring_i
nfo;
select * from
table(dbms_xplan.display('ASH_PLAN_T
ABLE','4dszd9dysry0c',null,'dbid=123456
and plan_hash_value = 3412983073'));
select * from
table(dbms_xplan.display('ASH_PLAN_T
ABLE','4dszd9dysry0c','+ADAPTIVE','dbid
=2783210685 and plan_hash_value =
3412983073')); https://hoopercharles.wordpress.com/2010/03/01/dbms_xplan-format-parameters/
http://blog.go-faster.co.uk/2016/11/ash-an
set pagesize 0
set linesize 30
spool kill_old_sess.sh
select '#!/bin/ksh' from dual;
select 'kill -9 ' || spid
select 'ALTER SYSTEM
from v$process KILL SESSION
p, v$SESSTAT
'''||SID||','||SERIAL#||'''IMMEDIATE;'
t,v$sess_io i ,v$session s from
v$session where
where i.sid=s.sid username = 'A' and
STATUS and =p.addr=paddr(+)
'ACTIVE'; http://www.tek-tips.com/viewthread.cfm?qid=1572803
and s.sid=t.sid
and t.statistic#=12
and s.program like 'oraagent%'
and logon_time < sysdate-1
and status <> 'ACTIVE'
order by logon_time desc
/
spool off
E) ='SYS' ORDER BY ELAPSED_TIME DESC
/
YES
SET SERVEROUTPUT ON
DECLARE
l_plans_altered PLS_INTEGER; variable sqlid number;
BEGIN exec :sqlid
l_plans_altered := :=DBMS_SPM.ALTER_SQL_PLAN_BA
DBMS_SPM.alter_sql_plan_baseline( SELINE ( SQL_HANDLE=>
sql_handle => 'SQL_d3318f33dfac7bc2', PLAN_NAME
'SYS_SQL_1447ba3a1d83920f', =>
plan_name => 'SQL_PLAN_d6ccg6ggusyy2ee7f0c12',
'SYS_SQL_PLAN_1d83920fae82cf72', ATTRIBUTE_NAME=> 'enabled',
attribute_name => 'ACCEPTED', ATTRIBUTE_VALUE => 'NO');
attribute_value => 'YES');
DBMS_OUTPUT.put_line('Plans Altered:
' || l_plans_altered); Now fix the plan of 31pux6bymf1d4 to
END;
<= My own sql Patch 5qbbnv0abm2vx
/
5qbbnv0abm2vx
http://www.alfredokriegdba.com/2015/02/
http://www.nocoug.org/download/2008-08/a-tour-of-the-awr-tables.nocoug-Aug-21-2008.abercrombie.html#script-aas-exact
http://www.nocoug.org/download/2008-08/a-tour-of-the-awr-tables.nocoug-Aug-21-
g.go-faster.co.uk/2016/11/ash-analysis-detecting-and-profiling.html
nathanlewis.wordpress.com/2017/06/12/dbms_sqldiag/
Capacity Planning
SGA Allocation
Generate DB Load
Tuning
SHARED_POOL_RESERVED_SIZE
I/O tuning
SORTING
INDEX
Using Oracle Blocks Efficiently
SQL Trace
See hot data files (from a single block read time judge)
View pga proposed
Other DB Tuning
Avg Sql/Database Response Time
system statistics
Metric values by %
top 100 sql queries based on CPU, elapsed time for the past 7 days in
Oracle
oracle_which_sql_caused_wait_event
Performance tuning
Reading tkprof output
tools
TUNING
histograms
STATISTICS
Table statistics
Index statistics
schema Statistics
Database statistics
Stale statistics
automatic stats collection for database formula ( List stale more than
10% )
sql_profile details
Top 10 statements
Top SESSION by CPU usage, wait time and IO time in last 5 minutes
Top SQL by CPU usage, wait time and IO time in last 5 minutes
Top 10 sql by elapsed time
Optimizer
optimizer override
Advisors
advisor recommendation for a taskid
Automatic sql tuning advisor recommendation summary
Table Fragmentation
Jobs/ Scheduler
Others
prompt
RAM SIZE Load is now
= 484 MBbeing generated.
-- This drops the copy table if it exists, and supresses
--
Sothe45error if it does
% should be =not
216exist.
MB
DECLARE
table_nonexistent
split the 216 MM forEXCEPTION;
SGA,PGA,BACKGROUNG PROCESSES
PRAGMA EXCEPTION_INIT(table_nonexistent, -942);
BEGIN
Fixed background process requires = 40 MB
BEGIN
execute immediate
SGA = 'drop 160 MBtable sh.sales_copy';
EXCEPTION
WHEN
PGA table_nonexistent
= 16 MB THEN
NULL;
END;
Table size May be 100 MB
execute immediate 'create table sh.sales_copy as select * from sh.sales';
FOR i IN 1..25 LOOP
execute immediate 'select * from sh.sales_copy';
execute immediate 'delete from sh.sales_copy';
execute immediate 'commit';
execute immediate 'insert into sh.sales_copy select * from sh.sales';
execute immediate 'commit';
END LOOP;
END;
/
WITH hist_snaps
AS (SELECT instance_number,
snap_id,
round(begin_interval_time,'MI') datetime,
( begin_interval_time + 0 - LAG (begin_interval_time + 0)
OVER (PARTITION BY dbid, instance_number ORDER BY snap_id)) * 86400
diff_time
FROM dba_hist_snapshot), hist_stats
AS (SELECT dbid,
instance_number,
snap_id,
stat_name,
VALUE - LAG (VALUE) OVER (PARTITION BY
dbid,instance_number,stat_name ORDER BY snap_id)
delta_value
FROM dba_hist_sysstat
WHERE stat_name IN ('user commits', 'user rollbacks'))
SELECT datetime,
ROUND (SUM (delta_value) / 3600, 2) "Transactions/s"
FROM hist_snaps sn, hist_stats st
WHERE st.instance_number = sn.instance_number
AND st.snap_id = sn.snap_id
AND diff_time IS NOT NULL
GROUP BY datetime
ORDER BY 1 desc;
no rows selected
You set the size of the shared pool with the SHARED_POOL_SIZE initialization
parameter.
It defaults to 8,388,608 bytes (8 MB).
SELECT SUM(250 * users_opening) FROM v$sqlarea;
Keep the ratio of the sum of GETMISSES to the sum of GETS less than 15%:
Using V$DB_CACHE_ADVICE
--------------------------
SELECT
size_for_estimate,buffers_for_estimate,estd_physical_read_factor,estd_physical
_reads
FROM V$DB_CACHE_ADVICE
WHERE name = 'DEFAULT'
AND block_size = ( SELECT value FROM V$PARAMETER
WHERE name = 'db_block_size')
AND advice_status = 'ON';
During peak running times, use the following query to calculate how many
blocks are used by each object:
SQL> SELECT owner#, name, count(*) blocks
FROM v$cache
GROUP BY owner#, name;
TABLE_NAME BLOCKS
---------- ----------
COUNTRIES 14
SELECT name,
1 - (physical_reads / (db_block_gets +
consistent_gets)) "HIT_RATIO"
FROM sys.v$buffer_pool_statistics
WHERE db_block_gets + consistent_gets > 0;
LOG_BUFFER
LOG_CHECKPOINT_INTERVAL
LOG_CHECKPOINT_TIMEOUT
The LGWR process starts a new ARCn process whenever the current number
of ARCn
processes is insufficient to handle the workload. If you anticipate a heavy
workload
for archiving, such as during bulk loading of data, specify multiple archiver
processes
with the LOG_ARCHIVE_MAX_PROCESSES initialization parameter.
• SHARED_POOL_SIZE:
– 8 KB per loaded class
– 50 MB for loading large JAR files
• Configure Oracle Shared Server
• JAVA_POOL_SIZE
– 20 MB default
– 50 MB for medium-sized Java application
SELECT TOTAL_WAITS FROM V$SYSTEM_EVENT WHERE EVENT = 'FREE
BUFFER WAITS';
SQL> select name, value from v$sysstat where name = 'sorts (rows)';
NAME VALUE
----------------- ------------------------------
sorts (rows) 639330
V$LOCK
V$LOCKED_OBJECT
DBA_WAITERS
DBA_BLOCKERS
SQL> SELECT owner, object_id, object_name, object_type,
v$lock.type
FROM dba_objects, v$lock
WHERE object_id = v$lock.id1 and object_name = table_name;
SELECT network , status ,
SUM(OWNED) Clients,
SUM(busy)*100/(SUM(busy)+SUM(idle)) "Busy Rate"
FROM v$dispatcher group by network,status;
As a general guideline, you should create indexes on tables that are often
queried for less than 5% of the table's rows
Recovering Space
-------------------
Below the high-water mark:
• Use the Export and Import utilities to:
– Export the table
– Drop or truncate the table
– Import the table
Or, use the Alter Table Employees Move;
command to move the table
• Above the high-water mark, use the Alter Table
Employees Deallocate Unused; command.
SQL> Explain plan for select last_name from hr.employees;
On some operating systems, the DBA can lock the SGA into real memory by
setting the
LOCK_SGA initialization parameter to TRUE, so it is never paged out to disk.
Obviously,
the Oracle server performs better if the entire SGA is kept in real memory.
This should be used only on systems that have sufficient memory to hold all the
SGA pages
without degrading performance in other areas.
SELECT t.file_name,
t.tablespace_name,
round (s.singleblkrdtim / s.singleblkrds, 2) AS CS,
s.READTIM,
s.WRITETIM
FROM v$filestat s, dba_data_files t
WHERE s.file# = t.file_id and rownum <= 10 order by cs desc ;
SELECT (SELECT ROUND (value/1024/1024, 0) FROM v$parameter
WHERE name = 'pga_aggregate_target') "Current Mb"
, ROUND (pga_target_for_estimate/1024/1024, 0) "Projected Mb"
, ROUND (estd_pga_cache_hit_percentage) "%"
FROM v$pga_target_advice
ORDER BY 2;
select Username,
OSUSER,
Consistent_Gets,
Block_Gets,
Physical_Reads,
100*( Consistent_Gets + Block_Gets - Physical_Reads)/
( Consistent_Gets + Block_Gets ) "Hit Ratio %"
from V$SESSION,V$SESS_IO
where V$SESSION.SID = V$SESS_IO.SID
and ( Consistent_Gets + Block_Gets )>0
and username is not null
order by Username,"Hit Ratio %";
select * from
(
select session_id, session_serial#,count(*)
from v$active_session_history
where session_state='WAITING' and
sample_time > sysdate - interval '5' minute
group by session_id, session_serial#
order by count(*) desc
)
where rownum <= 10;
SELECT sid, serial# , username, event,blocking_session, seconds_in_wait, sql_id FROM v$session WHERE state = 'WAITING
SELECT wait_class_id, wait_class#, wait_class, total_waits, time_waited FROM v$session_wait_class WHERE sid=161;
SELECT metric_name, AVG(value), metric_unit FROM v$sysmetric WHERE metric_unit LIKE '\%%' ESCAPE '\' GROUP BY m
select *
from
(select
sql_text,
sql_id,
elapsed_time,
cpu_time,
user_io_wait_time
from
sys.v_$sqlarea
order by 5 desc)
where rownum < 6;
BEGIN
DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT ();
END;
/
SELECT *
FROM
select * from status,
(SELECT
(select--username,
s.sql_id, RANK() OVER (ORDER BY
(max(s.CPU_TIME_TOTAL/s.executions_total))
sql_id, DESC) cpu_rank,
RANK() OVER (ORDER BY
sql_exec_id,
(max(s.ELAPSED_TIME_TOTAL/s.EXECUTIONS_TOTAL))
TO_CHAR(sql_exec_start,'dd-mon-yyyy hh24:mi:ss') AS DESC)
sql_exec_start,
elapsed_rank
ROUND(elapsed_time/1000000) AS "Elapsed (s)",
from ROUND(cpu_time /1000000) AS "CPU (s)",
dba_hist_sqlstat
buffer_gets, s,
dba_hist_snapshot sn
ROUND(physical_read_bytes /(1024*1024)) AS "Phys reads (MB)",
whereROUND(physical_write_bytes/(1024*1024)) AS "Phys writes (MB)"
sn.begin_interval_time
FROM v$sql_monitorbetween to_date('06-aug-2014 0001','dd-mon-yyyy
hh24mi')
ORDER BY elapsed_time DESC
and )
to_date('13-aug-2014
WHERE rownum<=20; 0600','dd-mon-yyyy hh24mi')
and
sn.snap_id=s.snap_id and s.executions_total >0
group by
s.sql_id
) where cpu_rank <=100 and elapsed_rank<=100;
select
SQL_ID
, PLAN_HASH_VALUE
column "File Total" format 99,999,990
, sum(EXECUTIONS_DELTA) EXECUTIONS
, sum(ROWS_PROCESSED_DELTA) CROWS
set line 132
, trunc(sum(CPU_TIME_DELTA)/1000000/60) CPU_MINS
set pagesize 33
, trunc(sum(ELAPSED_TIME_DELTA)/1000000/60) ELA_MINS
from DBA_HIST_SQLSTAT
ttitle
where " ***** Database:
SQL_ID in ( "db", DataFile's Disk Activity (As of:" tdate " ) *****"
'&sqlid')
select
group by substr(df.file#,1,2) "ID",
SQL_ID , PLAN_HASH_VALUE
rpad(substr(name,1,52),52,'.')
order by SQL_ID, CPU_MINS;"File Name",
rpad(substr(phyrds,1,10),10,'.') "Phy Reads",
rpad(substr(phywrts,1,10),10,'.') "Phy Writes",
http://uralural.blogspot.com/2007/07/oracle-cbo-chooses-wrong-index-although.html
rpad(substr(phyblkrd,1,10),10,'.') "Blk Reads",
rpad(substr(phyblkwrt,1,10),10,'.') "Blk Writes",
rpad(substr(readtim,1,9),9,'.') "Read Time",
rpad(substr(writetim,1,10),10,'.') "Write Time",
(sum(phyrds+phywrts+phyblkrd+phyblkwrt+readtim)) "File Total"
from v$filestat fs, v$datafile df
where fs.file# = df.file#
group by df.file#, df.name, phyrds, phywrts, phyblkrd,
phyblkwrt, readtim, writetim
order by sum(phyrds+phywrts+phyblkrd+phyblkwrt+readtim) desc, df.name;
ttitle off
'SQL*Net more data from client',
'SQL*Net message to client',
'dispatcher timer',
'Null event',
'parallel query dequeue wait',
'parallel query idle wait - Slaves',
'pipe get',
'PL/SQL lock timer',
'slave wait',
'virtual circuit status',
'WMON goes to sleep'
)
AND a.event NOT LIKE 'DFS%'
AND a.event NOT LIKE 'KXFX%'
AND a.sid = b.sid)
order by 6 desc, 1 asc
select
event,
sql_id,
snap_id,
dbid,
instance_number,
sample_time,
session_id,
session_serial#,
user_id,
blocking_session,
program,
(
select
sql_text
from
dba_hist_sqltext
where
sql_id = dba_hist_active_sess_history.sql_id
) sql_text
from
dba_hist_active_sess_history
where
program = 'some.exe'
and
sample_time between
to_timestamp('START_TIME', 'YYYY-MM-DD HH24:MI:SS.FF3') and
to_timestamp('END_TIME', 'YYYY-MM-DD HH24:MI:SS.FF3')
and
event = 'some wait event';
http://gavinsoorma.com/2012/11/ash-and-awr-performance-tuning-scripts/
http://hourim.wordpress.com/2012/09/14/tuning-by-tkprof-a-case-study/
https://sites.google.com/site/embtdbo/wait-event-documentation
http://www.oraclerealworld.com/best-oracle-performance-tools/
select distinct
p.name sql_profile_name,
s.sql_id
from
dba_sql_profiles p,
DBA_HIST_SQLSTAT s
where
p.name=s.sql_profile;
http://nadvi.blogspot.com/2011/10/gather-optimizer-statistics-11g_26.html
exec DBMS_STATS.GATHER_TABLE_STATS (ownname => '&OWNER' , tabname => '&TABLE_NAME',cascade => true, esti
exec dbms_stats.gather_index_stats ( ownname => '&OWNER', indname => '&INDEX_NAME',estimate_percent => dbms_sta
exec DBMS_STATS.GATHER_SCHEMA_STATS (ownname => '&OWNER' , estimate_percent => dbms_stats.auto_sample_s
EXEC DBMS_STATS.GATHER_DATABASE_STATS(ESTIMATE_PERCENT => DBMS_STATS.AUTO_SAMPLE_SIZE, METH
exec dbms_stats.gather_schema_stats ('SYS');
exec dbms_stats.gather_database_stats (gather_sys=>TRUE);
exec dbms_stats.gather_dictionary_stats;
exec dbms_stats.gather_fixed_objects_stats;
Table
dbms_output.put_line('==========================================');
v1 := dbms_stats.get_prefs('AUTOSTATS_TARGET');
dbms_output.put_line(' AUTOSTATS_TARGET: ' || v1);
SELECT TABLES.OWNER, TABLES.TABLE_NAME,
v2 := dbms_stats.get_prefs('CASCADE');
ROUND((DELETES + UPDATES
dbms_output.put_line(' CASCADE:+ INSERTS)/NUM_ROWS*100)
' || v2);
PERCENTAGE
v3 := dbms_stats.get_prefs('DEGREE');
FROM DBA_TABLES TABLES,
dbms_output.put_line(' DEGREE:DBA_TAB_MODIFICATIONS
' || v3); MODIFICATIONS
WHERE TABLES.OWNER = MODIFICATIONS.TABLE_OWNER
v4 := dbms_stats.get_prefs('ESTIMATE_PERCENT');
AND TABLES.TABLE_NAME
dbms_output.put_line(' = MODIFICATIONS.TABLE_NAME
ESTIMATE_PERCENT: ' || v4); AND
NUM_ROWS > 0
v5 := dbms_stats.get_prefs('METHOD_OPT');
AND ROUND ( (DELETES
dbms_output.put_line(' + UPDATES + INSERTS)
METHOD_OPT: ' || v5); / NUM_ROWS * 100) >=
10v6 := dbms_stats.get_prefs('NO_INVALIDATE');
ORDER BY 3 desc
dbms_output.put_line(' NO_INVALIDATE: ' || v6);
/ v7 := dbms_stats.get_prefs('GRANULARITY');
dbms_output.put_line(' GRANULARITY: ' || v7);
v8 := dbms_stats.get_prefs('PUBLISH');
dbms_output.put_line(' PUBLISH: ' || v8);
v9 := dbms_stats.get_prefs('INCREMENTAL');
dbms_output.put_line(' INCREMENTAL: ' || v9);
v10:= dbms_stats.get_prefs('STALE_PERCENT');
dbms_output.put_line(' STALE_PERCENT: ' || v10);
END;
/
DBMS_STATS.RESTORE_DICTIONARY_STATS - Used to restore data
dictionary stats
begin
dbms_stats.gather_schema_stats(
ownname => 'SCOTT',
estimate_percent => dbms_stats.auto_sample_size,
method_opt => 'for all columns size auto',
degree => 7
);
end;
/
begin
dbms_stats.set_table_stats('TESTER'
, 'TEST1'
, numrows=>10000
, numblks=>174
, avgrlen=>110);
end;
/
SELECT session_id,
COUNT(*)
FROM v$active_session_history
WHERE session_state = 'ON CPU'
AND sample_time > sysdate - ( 5 / ( 24 * 60 ) )
GROUP BY session_id
ORDER BY COUNT(*) DESC;
SELECT session_id,
COUNT(*)
FROM v$active_session_history
WHERE session_state = 'WAITING'
AND sample_time > sysdate - ( 5 / ( 24 * 60 ) )
GROUP BY session_id
ORDER BY COUNT(*) DESC;
SELECT event,
COUNT(*)
FROM v$active_session_history
WHERE session_state = 'WAITING'
AND sample_time > sysdate - ( 5 / ( 24 * 60 ) )
GROUP BY event
ORDER BY COUNT(*) DESC;
select
ash.session_id,
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# AND SAMPLE_TIME > SYSDATE - (5/(24*60))
group by session_id,user_id,session_serial#,program
order by sum(decode(session_state,'ON CPU',1,0));
SELECT ash.sql_id,
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)) "WAIT",
SUM(DECODE(ash.session_state, 'WAITING', DECODE(en.wait_class,
'User I/O', 1, 0), 0)) "IO",
SUM(DECODE(ash.session_state, 'ON CPU', 1, 1)) "TOTAL"
FROM v$active_session_history ash,
v$event_name en
WHERE sql_id IS NOT NULL AND SAMPLE_TIME > SYSDATE - (5/(24*60))
AND en.event# = ash.event#
GROUP BY sql_id
ORDER BY SUM(DECODE(session_state, 'ON CPU', 1, 0)) DESC;
select
sql_id,
child_number,
sql_text,
elapsed_time
from
(select
sql_id,child_number,
sql_text,
elapsed_time,
cpu_time,
disk_reads,
rank ()
over
(order by elapsed_time desc)
as
sql_rank
from
gv$sql)
where
sql_rank < 10;
SELECT * FROM
(SELECT SUBSTR(SQL_TEXT,1,40) SQL,
DISK_READS, EXECUTIONS, DISK_READS/EXECUTIONS "READS/EXEC",
HASH_VALUE,ADDRESS
FROM V$SQLAREA
WHERE DISK_READS > 1000
ORDER BY DISK_READS DESC)
WHERE ROWNUM <= 10;
SELECT * FROM
(SELECT SUBSTR(SQL_TEXT,1,40) SQL,
EXECUTIONS, ROWS_PROCESSED, ROWS_PROCESSED/EXECUTIONS
"ROWS/EXEC",
HASH_VALUE,ADDRESS
FROM V$SQLAREA
WHERE EXECUTIONS > 100
ORDER BY EXECUTIONS DESC)
WHERE ROWNUM <= 10;
SELECT * FROM
(SELECT SUBSTR(SQL_TEXT,1,40) SQL,
PARSE_CALLS, EXECUTIONS, HASH_VALUE,ADDRESS
FROM V$SQLAREA
WHERE PARSE_CALLS > 1000
ORDER BY PARSE_CALLS DESC)
WHERE ROWNUM <= 10;
SELECT * FROM
(SELECT SUBSTR(SQL_TEXT,1,40) SQL,
SHARABLE_MEM, EXECUTIONS, HASH_VALUE,ADDRESS
FROM V$SQLAREA
WHERE SHARABLE_MEM > 1048576
ORDER BY SHARABLE_MEM DESC)
WHERE ROWNUM <= 10;
SELECT * FROM
(SELECT SUBSTR(SQL_TEXT,1,40) SQL,
VERSION_COUNT, EXECUTIONS, HASH_VALUE,ADDRESS
FROM V$SQLAREA
WHERE VERSION_COUNT > 20
ORDER BY VERSION_COUNT DESC)
WHERE ROWNUM <= 10;
http://orababy.blogspot.com/2013/08/active-session-history-queries.html
with AASSTAT as (
select
decode(n.wait_class,'User I/O','User I/O',
'Commit','Commit',
'Wait') CLASS,
sum(round(m.time_waited/m.INTSIZE_CSEC,3)) AAS
from v$waitclassmetric m,
v$system_wait_class n
where m.wait_class_id=n.wait_class_id
and n.wait_class != 'Idle'
SELECT group by decode(n.wait_class,'User I/O','User I/O', 'Commit','Commit',
sysmetric_history.sample_time,
'Wait')
cpu/60 AS cpu,
union
bcpu/60 AS bcpu,
DECLARE select 'CPU_ORA_CONSUMED'
DECODE(SIGN((cpu+bcpu)/60-cpu_ora_consumed), CLASS,
-1, 0, ((cpu+bcpu)/60-
l_sql_tune_task_id
cpu_ora_consumed)) VARCHAR2(100);
round(value/100,3)
AS cpu_ora_wait, AAS
BEGIN from v$sysmetric
scheduler/60 AS scheduler,
l_sql_tune_task_id
uio/60 AS where := DBMS_SQLTUNE.create_tuning_task
uio,metric_name='CPU Usage Per Sec' (
sio/60 AS and sql_id => '4pgqpkv31u4nn',
sio,group_id=2
union
concurrency/60 scope => DBMS_SQLTUNE.scope_comprehensive,
AS concurrency,
application/60 time_limit
select 'CPU_OS'
AS => 2100,
application, CLASS ,
AS COMMIT, => '4pgqpkv31u4nn_tuning_task',
task_name
COMMIT/60round((prcnt.busy*parameter.cpu_count)/100,3) AAS
from
configuration/60 description => 'Tuning task for statement d4pgqpkv31u4nn.');
AS configuration,
DBMS_OUTPUT.put_line('l_sql_tune_task_id:
( select value
administrative/60 busy from v$sysmetric where
AS administrative, ' || l_sql_tune_task_id);
metric_name='Host CPU
END;
Utilization
network/60 (%)'
ASand group_id=2 ) prcnt,
network,
/ queueing/60 ( selectASvalue cpu_count from v$parameter where name='cpu_count' )
queueing,
parameter
clust/60 AS clust,
EXEC DBMS_SQLTUNE.execute_tuning_task(task_name
union
other/60 AS other =>
'4pgqpkv31u4nn_tuning_task');
FROM select
(SELECT 'CPU_ORA_DEMAND' CLASS,
select task_name,
nvl(round(status
TRUNC(sample_time,'MI') fromAS dba_advisor_log
sample_time, where
sum(decode(session_state,'ON CPU',1,0))/60,2),0) AAS
task_name='4pgqpkv31u4nn_tuning_task';
from v$active_session_history ash
DECODE(session_state,'ON
where SAMPLE_TIME > sysdate - (60/(24*60*60)) CPU'), wait_class)
CPU',DECODE(session_type,'BACKGROUND','BCPU','ON
SETwait_class
)AS SERVEROUTPUT ON
SET
select
FROMLONG 100000;
v$active_session_history
setWHERE
longchunksize 1000;
( decode(sign(CPU_OS-CPU_ORA_CONSUMED),
sample_time>sysdate-INTERVAL '1' HOUR -1, 0, (CPU_OS -
SET PAGESIZE
CPU_ORA_CONSUMED 1000 )) +
AND sample_time<=TRUNC(SYSDATE,'MI')) ash
SET LINESIZE
CPU_ORA_CONSUMED
PIVOT (COUNT(*)200 FOR wait_class + IN ('ON CPU' AS cpu,'BCPU' AS
SELECT DBMS_SQLTUNE.report_tuning_task('4pgqpkv31u4nn_tuning_task')
decode(sign(CPU_ORA_DEMAND-CPU_ORA_CONSUMED),
bcpu,'Scheduler' AS scheduler,'User I/O' AS uio,'System I/O' AS sio, -1, 0,
AS'Concurrency'
recommendations
(CPU_ORA_DEMAND FROM dual;
- CPU_ORA_CONSUMED
AS concurrency,'Application' ))) CPU_TOTAL, AS
AS application,'Commit'
SET PAGESIZE 24
decode(sign(CPU_OS-CPU_ORA_CONSUMED),
COMMIT,'Configuration' AS configuration, -1, 0, (CPU_OS -
CPU_ORA_CONSUMED )) CPU_OS,
'Administrative' AS administrative,'Network' AS network,'Queueing' AS
CPU_ORA_CONSUMED
queueing,'Cluster' AS clust,'Other'CPU_ORA,
AS other)) ash,
decode(sign(CPU_ORA_DEMAND-CPU_ORA_CONSUMED), -1, 0,
(SELECT
(CPU_ORA_DEMAND
TRUNC(begin_time,'MI') - CPU_ORA_CONSUMED
AS sample_time, )) CPU_ORA_WAIT,
COMMIT, AS cpu_ora_consumed
VALUE/100
READIO,
FROM v$sysmetric_history
WAIT GROUP_ID=2
WHERE
fromAND( metric_name='CPU Usage Per Sec') sysmetric_history
select
WHERE ash.sample_time (+)=sysmetric_history.sample_time
ORDER sum(decode(CLASS,'CPU_ORA_CONSUMED',AAS,0))
BY sample_time;
CPU_ORA_CONSUMED,
sum(decode(CLASS,'CPU_ORA_DEMAND' ,AAS,0))
CPU_ORA_DEMAND,
sum(decode(CLASS,'CPU_OS' ,AAS,0)) CPU_OS,
sum(decode(CLASS,'Commit' ,AAS,0)) COMMIT,
sum(decode(CLASS,'User I/O' ,AAS,0)) READIO,
sum(decode(CLASS,'Wait' ,AAS,0)) WAIT
from AASSTAT)
/
https://jonathanlewis.wordpress.com/2014/12/09/parse-time-2/
select ksppinm name,
ksppstvl value
from sys.x$ksppi x,
sys.x$ksppcv y
where (x.indx = y.indx)
and ksppinm = '_optimizer_aggr_groupby_elim';
Optimizer Evolution
• Oracle 8i – histograms
• Oracle 9i – bind variable peeking
• Oracle 10g – Automatic Optimizer Statistics Collection,Dynamic Sampling
• Oracle 11gR1 – Adaptive Cursor Sharing, Extended statistics (correlated
columns)
• Oracle 11gR2 – Cardinality Feedback
• Oracle 12c – Adaptive Query Optimization
declare
v_sql_text CLOB;
BEGIN
select sql_text into v_sql_text from v$sql where sql_id = 'bu18sp8k0wcvv';
sys.dbms_sqldiag_internal.i_create_patch(
sql_text=>v_sql_text,
hint_text=>'full(@SEL$1 test_dba_tables)',
name=>'tst_patch');
END;
/
exec dbms_sqldiag.DROP_SQL_PATCH('tst_patch');
Advisor names
Enabled or not
Job History
Parameters
select
table_name,round((blocks*8),2) "size (kb)" ,
round((num_rows*avg_row_len/1024),2) "actual_data (kb)",
(round((blocks*8),2) - round((num_rows*avg_row_len/1024),2))
"wasted_space (kb)"
from
dba_tables
where owner='&OWNER' and table_name='&TABLE_NAME' and
(round((blocks*8),2) > round((num_rows*avg_row_len/1024),2))
order by 4 desc;
https://tinky2jed.wordpress.com/technical-stuff/oracle-stuff/changing-the-oracle-database-default-maintenance-window-time/
select window_name, repeat_interval, duration from dba_scheduler_windows;
EXECUTE
DBMS_SCHEDULER.SET_ATTRIBUTE('WEEKNIGHT_WINDOW','repeat_inter
val','freq=daily;byday=MON,TUE,WED,THU,FRI;byhour=05;byminute=0;
bysecond=0');
EXECUTE
DBMS_SCHEDULER.SET_ATTRIBUTE('WEEKEND_WINDOW','repeat_interva
l',' freq=daily;byday=SAT;byhour=07;byminute=0;bysecond=0');
select hsys.SNAP_ID,
hsnap.BEGIN_INTERVAL_TIME,
hsnap.END_INTERVAL_TIME,
hsys.STAT_NAME,
hsys.VALUE,
hsys.VALUE - LAG(hsys.VALUE,1,0) OVER (ORDER BY hsys.SNAP_ID) AS
"VALUE_DIFF",
round((hsys.VALUE - LAG(hsys.VALUE,1,0) OVER (ORDER BY hsys.SNAP_ID)) /
round(abs(extract(hour from (hsnap.END_INTERVAL_TIME -
hsnap.BEGIN_INTERVAL_TIME))*60 +
extract(minute from (hsnap.END_INTERVAL_TIME - hsnap.BEGIN_INTERVAL_TIME)) +
extract(second from (hsnap.END_INTERVAL_TIME -
hsnap.BEGIN_INTERVAL_TIME))/60),1)) "STAT_PER_MIN"
from dba_hist_sysstat hsys, dba_hist_snapshot hsnap
where hsys.snap_id = hsnap.snap_id
and hsnap.instance_number in (select instance_number from v$instance)
and hsnap.instance_number = hsys.instance_number
and hsys.STAT_NAME='user commits'
order by 1;
Instead of creating new table u can try
In a test environment, you can measure shareable memory by selecting the number of open
cursors for a test user. You multiply the resulting value by the total number of users:
Ideally, your application should have a library cache as large as the sum of the numbers
above, plus a small allowance for dynamic SQL.
Note: The last two columns contain 0 unless the TIMED_STATISTICS parameter is set to
TRUE.
Use the following query to monitor these values:
Avoiding Sorts
--------------------
Avoid sort operations whenever possible:
• Use NOSORT to create indexes.
• Use UNION ALL instead of UNION.
• Use index access for table joins.
• Create indexes on columns referenced in the
ORDER BY clause.
• Select the columns for analysis.
• Use ESTIMATE rather than COMPUTE for large
objects.
Create indexes on columns that are frequently referenced with ORDER BY statements.
You can use the following query to set the UNDO_RETENTION parameter and size the undo
tablespace:
You can increase the overall number of locks available for an instance by increasing the
values of the DML_LOCKS and ENQUEUE_RESOURCES parameters. This may be necessary
in a parallel server configuration.
V$LOCK
V$LOCKED_OBJECT
DBA_WAITERS
DBA_BLOCKERS
To find the table name that corresponds to a particular resource ID 1 of the V$LOCK view:
Query the V$DISPATCHER view to determine the usage for selected dispatcher processes.
You identify contention for dispatchers by checking:
A query to report the dispatcher, session, and process mapping using shared servers:
Maintenance Considerations
--------------------------
In a data warehousing environment, data is usually maintained by way of bulk inserts and
updates. Index maintenance is deferred until the end of each DML operation. For example, if
you insert 1,000 rows, then the inserted rows are placed into a sort buffer, and then the
updates of all 1,000 index entries are batched. (This is why SORT_AREA_SIZE must be set
properly for good performance with inserts and updates on bitmap indexes.) Thus, each
bitmap segment is updated only once per DML operation, even if more than one row in that
segment changes.
• Larger extents can have a small performance benefit because the Oracle server can read
one large extent from disk with fewer multiblock reads than would be required to read
many small extents. To avoid partial multiblock reads, set the extent size to a multiple
of 5 × DB_FILE_MULTIBLOCK_READ_COUNT. Multiply by five because the Oracle
server tries to allocate extents on five-block boundaries. By matching extent sizes to the
I/O and space allocation sizes, the performance cost of having many extents in a
segment is minimized. However, for a table that never has a full table scan operation, it
makes no difference in terms of query performance whether the table has one extent or
multiple extents.
n_wait, sql_id FROM v$session WHERE state = 'WAITING' AND wait_class!= 'Idle' ;
x-although.html
NER' , tabname => '&TABLE_NAME',cascade => true, estimate_percent => dbms_stats.auto_sample_size,method_opt=>'FOR ALL COLUM
name => '&INDEX_NAME',estimate_percent => dbms_stats.auto_sample_size, degree => 8);
WNER' , estimate_percent => dbms_stats.auto_sample_size ,method_opt=>'FOR ALL COLUMNS SIZE AUTO', degree => 8);
RCENT => DBMS_STATS.AUTO_SAMPLE_SIZE, METHOD_OPT => 'FOR ALL COLUMNS SIZE AUTO', DEGREE => 8, CASCADE => T
Partition
DECLARE
ObjList dbms_stats.ObjectTab;
BEGIN
dbms_stats.gather_database_stats(objlist=>ObjList, options=>'LIST STALE');
FOR i in ObjList.FIRST..ObjList.LAST
LOOP
dbms_output.put_line(ObjList(i).ownname || '.' || ObjList(i).ObjName || ' ' || ObjList(i).ObjType || ' '
|| ObjList(i).partname);
END LOOP;
END;
/
COL owner FOR A30
COL table_name FOR A30
COL column_name FOR A30
SELECT
owner
table_name,
column_name, count(*)
FROM
dba_tab_histograms
WHERE owner = '&OWNER'
and table_name='&TABLE_NAME'
GROUP BY owner,table_name, column_name
ORDER BY count(*) ASC
/
select blocks allocated_blks,
count( distinct substr(t.rowid,1,8)
||substr(t.rowid,15,4)) used
from user_segments e,
&tab_name t
where e.segment_name=upper ('&tab_name')
and e.segment_type='TABLE'
group by e.blocks;
SELECT *
FROM
TABLE(DBMS_XPLAN.display_sql_plan_baseline(plan_name=>'SYS_SQLPROF_015fdc7edace
0003'));
http://rohitsinhago.blogspot.com/2009/05/tracing-other-sessions.html
https://alexzeng.wordpress.com/2012/09/25/valuate-oracle-awr-automatic-workload-repository/
SELECT sql_id,child_number,sql_text, elapsed_time
FROM (SELECT sql_id, child_number, sql_text, elapsed_time, cpu_time,
disk_reads,
RANK () OVER (ORDER BY elapsed_time DESC) AS elapsed_rank
FROM gv$sql)
WHERE elapsed_rank <= 10;
exec
dbms_sqltune.alter_sql_profile('SYS_SQLPROF_0236d8f37a490001','STATUS','DISABLED');
exec dbms_sqltune.alter_sql_profile('SQL_PROF_FOR_DELETE','STATUS','ENABLED');
EXEC DBMS_SQLTUNE.DROP_SQL_PROFILE('SYS_SQLPROF_02384d2b5e320000');
https://blog.yannickjaquier.com/oracle/visualizing-active-session-history-ash-to-produce-grid-control-charts.html
https://blogs.oracle.com/optimizer/setting-a-session-parameter-overrides-ofe
https://prasanthkothuri.files.wordpress.com/2015/06/who-changed-my-plan.pdf
https://prasanthkothuri.wordpress.com/2015/06/08/sql-patch-fast-way-to-add-a-hint-without-changing-the-code/
SELECT execution_name,task_id,task_name,TO_CHAR(execution_start,'dd-mon-yyyy
hh24:mi:ss') AS execution_start,TO_CHAR(execution_end,'dd-mon-yyyy hh24:mi:ss') AS
execution_end,
status,error_message FROM DBA_ADVISOR_EXECUTIONS
WHERE task_name='SYS_AUTO_SQL_TUNING_TASK'
ORDER BY execution_id DESC;
https://anandmandilwar.com/2016/11/09/collection-of-useful-script-for-oracle-apps-dba/https://www.programering.com/a/MTM3
http://db.geeksinsight.com/2012/10/15/scripts-databasetabletablespace-growth-report-using-awr/
https://grepora.com/2016/05/25/oracle-tps-evaluating-transaction-per-second/ http://dbaclass.com/article/find-user-commits-pe
Guidelines When SHARED_POOL_SIZE Is Too Small
The V$SHARED_POOL_RESERVED fixed table can also
indicate when the value for
SHARED_POOL_SIZE is too small. This may be the case if
REQUEST_FAILURES > 0 and
increasing.
Then, if you have enabled the reserved list, decrease the
value for
SHARED_POOL_RESERVED_SIZE. If you have not enabled
the reserved list, you could
increase SHARED_POOL_SIZE.
show parameter db_cache_size;
Subpartition
ithout-changing-the-code/
SET LINESIZE 80 PAGESIZE 1000 LONG 100000
SELECT
DBMS_SQLTUNE.REPORT_TUNING_TASK('SYS_AUTO_S
QL_TUNING_TASK') FROM DUAL;
work/articles/schumacher-analysis-099313.html
Database
Database Size
Table
Table size in MB
Schema size in GB
Tablespace Free
Db block size
Table fragmentation
http://oracletechdba.blogspot.com/2014/08/oracle-to-find-over-sizedfragmented.html
select table_name,avg_row_len,round(((blocks*16/1024)),2)||'MB' "TOTAL_SIZE",
round((num_rows*avg_row_len/1024/1024),2)||'Mb' "ACTUAL_SIZE",
round(((blocks*16/1024)-(num_rows*avg_row_len/1024/1024)),2) ||'MB'
"FRAGMENTED_SPACE",
(round(((blocks*16/1024)-
(num_rows*avg_row_len/1024/1024)),2)/round(((blocks*16/1024)),2))*100
"percentage"
from all_tables WHERE table_name='&TABLE_NAME';
select con_id,name,SUM(SIZE_MB) from
(
select c.con_id,nvl(p.name, 'CDB') name,
sum(bytes)/1024/1024 SIZE_MB from cdb_data_files c,
CDB WITH
v$pdbs ALL PDB
p where c.con_id=p.con_id(+) GROUP BY
c.con_id,name
UNION
select c.con_id,nvl(p.name, 'CDB') name ,
sum(bytes)/1024/1024 SIZE_MB from cdb_temp_files
c, v$pdbs p where c.con_id=p.con_id(+) GROUP BY
c.con_id,name
)group by con_id,name
order by con_id;
SELECT tablespace_name,
SUM (bytes) / (1024 * 1024) "FREE(MB)"
FROM dba_free_space where
tablespace_name=UPPER('&TABLESPACE_NAME')
GROUP BY tablespace_name;
file_name,
segment_type,
owner||'.'||segment_name segment,
block_id,
blockIdMB
from
select( b.Total_MB,
select
b.Total_MB - round(a.used_blocks*8/1024)
ex.owner owner,
Current_Free_MB,
ex.segment_name segment_name,
round(used_blocks*8/1024)
ex.segment_type segment_type,
Current_Used_MB,
ex.block_id block_id,
round(max_used_blocks*8/1024)
Max_used_MBdf.file_name file_name,
from v$sort_segment a,
trunc((ex.block_id*(ts.block_size))/1024/1024,2)
(select round(sum(bytes)/1024/1024) Total_MB from
blockIdMB
dba_temp_files ) b;
from
dba_extents ex, dba_data_files df,
dba_tablespaces ts
where df.file_id = &file_id
and df.file_id = ex.file_id
and df.tablespace_name =
ts.tablespace_name
order by ex.block_id desc
)
where rownum <= 100
/
gmented.html
col Table_name for a40
select table_name,
round(size_kb/1024) SIZE_MB,
round(actual_data_kb/1024) ACTUAL_DATA_MB,
round(wasted_space_kb/1024) WASTED_SPACE_MB
from (
select
table_name,round((blocks*8),2) size_kb,
round((num_rows*avg_row_len/1024),2)
actual_data_kb,
((round((blocks*8),2) -
round((num_rows*avg_row_len/1024),2)))
wasted_space_kb
from
dba_tables
where owner='&OWNER' and
table_name='&TABLE_NAME' and
(round((blocks*8),2) >
round((num_rows*avg_row_len/1024),2))
order by 4 desc);
Only Segment Based
Relocate services
MAX_PDB_STORAGE
collabn1:/home/oracle[RAC1]$ srvctl add service -d RAC -pdb PDB -s svctest -r RAC1 -a RAC2 -P
BASIC
collabn1:/home/oracle[RAC1]$ srvctl start service -d RAC -s svctest
srvctl status service -d <db_name> -s <service>
srvctl relocate service -d RAC12C -s <service> -oldinst <INST1> -newinst <INST2>
select * from
(
select
srvctl add service -db, --b.con_id,
c.db_unique_name RAC12C -service TAFSRV -preferred RAC12C1 -available
RAC12C2 \
b.name pdb_name,
-tafpolicy BASIC -policy AUTOMATIC -failovertype
to_number(a.property_value)/1024/1024/1024 SELECT -failovermethod
zmax_pdb_storage_GB , BASIC \
-failoverretry 5 -pdb DEMOPDB
c.database_role , c.open_mode -verbose
srvctl start service -d RAC12C -s TAFSRV
from
database_properties a, v$pdbs b , v$database c
WHERE
a.property_name ='MAX_PDB_STORAGE'
) pdb_info ,
(
select a.data_size_GB+b.temp_size_GB "dbfile_total_size_GB" ,
a.max_size_GB+b.max_size_GB as dbfile_max_size_GB , data_size_Gb,
temp_size_GB
from ( select sum(bytes)/1024/1024/1024 data_size_GB ,
sum(maxbytes)/1024/1024/1024 max_size_GB
from dba_data_files ) a,
( select nvl(sum(bytes)/1024/1024/1024,0) temp_size_GB ,
sum(maxbytes)/1024/1024/1024 max_size_GB
from dba_temp_files ) b
) sdf ;
col DB_UNIQUE_NAME format a10
set lines 5000;
set tab off;
set trimspool on;
COL BYTES FORMAT 999,999,999,999,999
COL MAXBYTES FORMAT 999,999,999,999,999
COL ZBYTES FORMAT 999,999,999,999,999
col FILE_NAME format a115
select * from
(
select
c.name dbname , c.db_unique_name ,
--b.con_id,
b.name pdb_name, b.total_size ,
to_number(a.property_value)
zmax_pdb_storage ,
(b.total_size/to_number(a.property_value))
zpdb_pctfull ,
c.database_role , c.open_mode
from
database_properties a, v$pdbs b , v$database c
WHERE
a.property_name ='MAX_PDB_STORAGE'
) pdb_info ,
(
select a.data_size+b.temp_size
"dbfile_total_size" , a.max_size+b.max_size as
dbfile_max_size , data_size, temp_size
from ( select sum(bytes) data_size ,
sum(maxbytes) max_size
from dba_data_files ) a,
( select nvl(sum(bytes),0) temp_size ,
sum(maxbytes) max_size
from dba_temp_files ) b
) sdf;
Rman Tuning
Clone Progress
% completed - Good query
Block Recovery
Oldest backup Available in rman catalog ( this gives result of all datafile
oldest backup)
restore/duplicate throughput
Backup not deleting the archivelog
ORA-19625: error identifying file
ORA-17503: ksfdopn:2 Failed to open file
ORA-15012: ASM file '+BKUP/thread_1_seq_49222.1018.892640727'
does not exist
%FRA Used
Tracing RMAN
https://web.stanford.edu/dept/itss/docs/oracle/10gR2/backup.102/b14191/rcmdupdb006.htm
SELECT INPUT_TYPE,
STATUS,
TO_CHAR(START_TIME,'mm/dd/yy hh24:mi') start_time,
TO_CHAR(END_TIME,'mm/dd/yy hh24:mi') end_time,
INPUT_BYTES_DISPLAY in_size,
round(ELAPSED_SECONDS/3600,3) HRS
FROM V$RMAN_BACKUP_JOB_DETAILS
where sysdate - start_time <= 7;
from
SELECT V$RMAN_BACKUP_JOB_DETAILS
where s.input_file_scan_only =j 'NO'
leftbs.recid
outer join (select
group by d.session_recid,
bs_key d.session_stamp) x
on
, bp.tag d.session_recid,
x.session_recid d.session_stamp,
= j.session_recid and x.session_stamp = j.session_stamp tag
,left outer joinsum(case
DECODE(backup_type when d.controlfile_included
(select o.session_recid, o.session_stamp,= 'YES' then d.pieces
min(inst_id) else 0 end) CF,
inst_id
sum(case when
from GV$RMAN_OUTPUT
, 'L', 'Archived d.controlfile_included
Redo Logs' o = 'NO'
group by
, 'D', 'Datafile and d.backup_type||d.incremental_level
o.session_recid,
Full Backup' o.session_stamp) = 'D' then d.pieces else 0
end) DF,
ro on, 'I',
ro.session_recid = j.session_recid
'Incremental Backup' ) and ro.session_stamp = j.session_stamp
backup_type
where sum(case
j.start_time
, bs.incremental_level when d.backup_type||d.incremental_level = 'D0' then d.pieces
> trunc(next_day(sysdate-6,'SUNDAY'))
else
order0by end) I0,
j.start_time
incremental_level
/ , DECODE( sum(case bp.statuswhen d.backup_type||d.incremental_level = 'I1' then d.pieces
else 0 end) I1,
, 'A', 'Available'
sum(case when d.backup_type = 'L' then d.pieces else 0 end) L
, 'D', 'Deleted'
from
, 'X', 'Expired' ) status
V$BACKUP_SET_DETAILS
, DECODE(bs.controlfile_included, 'NO',d '-', bs.controlfile_included)
controlfile_included join V$BACKUP_SET s on s.set_stamp = d.set_stamp and s.set_count =
d.set_count
, NVL(sp.spfile_included, '-') spfile_included
, bs.pieceswhere s.input_file_scan_only = 'NO' pieces
group by d.session_recid,
, TO_CHAR(bs.start_time, 'mm/dd/yyyy d.session_stamp)
HH24:MI:SS') x start_time
on x.session_recid = j.session_recid
, TO_CHAR(bs.completion_time, and x.session_stamp
'mm/dd/yyyy HH24:MI:SS')= j.session_stamp
completion_time
left outer join
, bs.elapsed_seconds (select o.session_recid, o.session_stamp, min(inst_id) inst_id
elapsed_seconds from GV$RMAN_OUTPUT o
, bs.block_size group by o.session_recid, o.session_stamp) block_size
ro on
, bs.keep ro.session_recid = j.session_recid and keep ro.session_stamp = j.session_stamp
order by j.start_time desc;
, NVL(TO_CHAR(bs.keep_until, 'mm/dd/yyyy HH24:MI:SS'),'') keep_until
, bs.keep_options keep_options
, device_type device_type
FROM
select output
v$backup_set bs
from GV$RMAN_OUTPUT
, (select distinct
whereset_stamp
session_recid = &SESSION_RECID
and, session_stamp
set_count = &SESSION_STAMP
order, tagby recid;
, device_type
, status
from v$backup_piece
where status in ('A','D', 'X')) bp
, (select distinct set_stamp, set_count, 'YES' spfile_included
from v$backup_spfile) sp
select output
WHERE
frombs.set_stamp
v$rman_output = bp.set_stamp
where session_recid==bp.set_count
AND bs.set_count (select max(session_recid) from v$rman_status)
order
ANDby recid ;
bs.set_stamp = sp.set_stamp (+)
AND bs.set_count = sp.set_count (+)
ORDER BY
bs.start_time desc;
https://docs.oracle.com/cd/B10501_01/server.920/a96521/repair.htm
RUN
{
SET DBID 3668200963;
UNREGISTER DATABASE DB_NAME NOPROMPT;
}
select 'SET NEWNAME FOR DATAFILE ' || FILE# || ' TO ''' || '/u03/oradata/&1/' ||
substr(name,instr(name,'/',-
1)+1) || ''';' from v$datafile;
SELECT 'SQL "ALTER DATABASE RENAME FILE '''''|| MEMBER ||'''''' ||chr(10)||'to ''''' ||
member || '''''" ;' FROM
V$LOGFILE;
from v105.rc_database a,v105.bs b
where a.db_key=b.db_key
and b.bck_type is not null having max(start_time) < sysdate - 7
group by a.name,dbid,b.bck_type
) group by db,dbid
union
select 'V112 - ' ||DB NAME,dbid,min(backuptype_db) DBBKP,min(backuptype_arch)
ARCBKP
from (
select a.name DB,dbid,
decode(b.bck_type,'D',max(b.completion_time),'I',
max(b.completion_time)) BACKUPTYPE_db,
decode(b.bck_type,'L',
max(b.completion_time)) BACKUPTYPE_arch
from v112.rc_database a,v112.bs b
where a.db_key=b.db_key
and b.bck_type is not null having max(start_time) < sysdate - 7
group by a.name,dbid,b.bck_type
) group by db,dbid
union
select 'isp102 - ' ||DB NAME,dbid,min(backuptype_db) DBBKP,min(backuptype_arch)
ARCBKP
from (
select a.name DB,dbid,
decode(b.bck_type,'D',max(b.completion_time),'I',
max(b.completion_time)) BACKUPTYPE_db,
decode(b.bck_type,'L',
max(b.completion_time)) BACKUPTYPE_arch
from isp102.rc_database a,isp102.bs b
where a.db_key=b.db_key and a.name not in
('RTL0892','RTL0890','RTL0888','RTL0007','RTL0881')
and b.bck_type is not null having max(start_time) < sysdate - 7
group by a.name,dbid,b.bck_type
) group by db,dbid
;
end if;
b0 := b0+c0;
b1 := b1+c1;
b2 := b2+c2;
b3 := b3+c3;
b4 := b4+c4;
b5 := b5+c5;
b6 := b6+c6;
rows := rows+1;
end loop;
end;
/
set feedback on
set verify on
SELECT
'DUPLICATE/RESTORE THROUGHPUT',
round(SUM(v.value/1024/1024),1) mbytes_sofar,
round(SUM(v.value /1024/1024)/nvl((SELECT MIN(elapsed_seconds)
FROM v\$session_longops
WHERE OPNAME LIKE 'RMAN: aggregate input'
AND SOFAR != TOTALWORK
AND elapsed_seconds IS NOT NULL
),SUM(v.value /1024/1024)),2) mbytes_per_sec,
n.name
FROM gv\$sesstat v,
v\$statname n,
gv\$session s
WHERE v.statistic#=n.statistic#
AND n.name = 'physical write total bytes'
AND v.sid = s.sid
AND v.inst_id=s.inst_id
AND s.program like 'rman@%'
GROUP BY 'DUPLICATE/RESTORE THROUGHPUT',n.name;
SQL> SELECT MEMBER FROM V$LOG G, V$LOGFILE F WHERE G.GROUP# =
F.GROUP#
2 AND G.STATUS = 'CURRENT';
MEMBER
--------------------------------------------------------------------------------
/OraRedo/RedoLogFiles/siamst_log01.dbf
run { a backup control file, start the cancel based recovery. The system may suggest a
Using
allocate channel
non-existing c1 type
archive log --'SBT'
ignore it and specify the log file name {with full path} that you
parms'ENV=(TDPO_OPTFILE=/opt/tivoli/tsm/client/oracle/bin64/tdpo.opt)';
got in the above step
allocate channel c2DATABASE
SQL> RECOVER type 'SBT' USING BACKUP CONTROLFILE UNTIL CANCEL
parms'ENV=(TDPO_OPTFILE=/opt/tivoli/tsm/client/oracle/bin64/tdpo.opt)';
ORA-00279: change 21375038 generated at 09/21/2007 20:12:47 needed for thread 1
backup archivelog
ORA-00289: all skip: /export/pspp/oracle/dbs/arch1_4_633901491.dbf
suggestion inaccessible delete input;
release channel
ORA-00280: c1; 21375038 for thread 1 is in sequence #4
change
release channel c2;
}Specify log: {=suggested | filename | AUTO | CANCEL}
/OraRedo/RedoLogFiles/siamst_log01.dbf
Log applied.
Media recovery complete.
Finally open the database in RESETLOGS mode. It is recommended to reset the online
logs after incomplete recovery or recovery with a backup control file
SQL> ALTER DATABASE OPEN RESETLOGS;
Database altered.
SELECT
ROUND((A.SPACE_LIMIT / 1024 / 1024 / 1024), 2) AS FLASH_IN_GB,
ROUND((A.SPACE_USED / 1024 / 1024 / 1024), 2) AS FLASH_USED_IN_GB,
ROUND((A.SPACE_RECLAIMABLE / 1024 / 1024 / 1024), 2) AS
FLASH_RECLAIMABLE_GB,
SUM(B.PERCENT_SPACE_USED) AS PERCENT_OF_SPACE_USED
FROM
V$RECOVERY_FILE_DEST A,
V$FLASH_RECOVERY_AREA_USAGE B
GROUP BY
SPACE_LIMIT,
SPACE_USED ,
SPACE_RECLAIMABLE ;
run
{
set archivelog destination to '/ora_backup/rman/arch/';
restore archivelog from logseq=8619 until logseq=8632 thread=2;
}
run{
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE;
crosscheck archivelog all;
crosscheck backup;
delete noprompt expired backup;
delete noprompt expired archivelog all;
delete noprompt obsolete;
delete noprompt archivelog all completed before 'sysdate - 1/24';
}
mdupdb006.htm
select sl.sid, sl.opname,
to_char(100*(sofar/totalwork), '990.9')||'%'
pct_done,
sysdate+(TIME_REMAINING/60/60/24)
done_by
from v$session_longops sl, v$session s
where sl.sid = s.sid
and sl.serial# = s.serial#
and sl.sid in (select sid from v$session where
module like 'backup%' or module like 'restore%' or
module like 'rman%')
setand sofar
lines 750!=pages
totalwork
9999
and totalwork heading
col start_time >0 'Started' format a30
/ end_time
col heading 'End' format a30
col time_taken_display heading 'Elapsed|Time'
format a10
Master Note for Handling Oracle Database Corruption Issues (Doc ID 1088018.1)
http://www.pythian.com/blog/oracle-free-block-corruption-test-case/
https://gruffdba.wordpress.com/2012/11/28/oracle-database-corruption-identify-and-correct/
https://alexzeng.wordpress.com/2008/09/17/how-to-recover-or-delete-corrupted-blocks/
http://www.adp-gmbh.ch/ora/admin/scripts/rman_backup_history.html Just test once before running
SELECT DISTINCT dbi.db_name,
v104.ts,
FROM bp.tag
v112.dbinc dbi,
bdf.completion_time,
v104.df,
FROM v92.dbinc
v112.bdf, dbi,
df.file#,
v104.bp,
v92.bdf
v112.ts, bdf,
fname,
SELECT DISTINCT
v104.node, dbi.db_name,
v92.dfatt
v112.df, df,
bp.tag
bdf.completion_time,
v104.site_dfatt
v92.bp
v112.bp,
FROM bp
v102.dbinc dbi, = ts.dbinc_key
WHERE df.file#,
dbi.dbinc_key
WHERE dbi.dbinc_key
v112.node,
v102.bdf bdf, = df.dbinc_key
AND fname,
ts.dbinc_key = =df.dbinc_key
AND bdf.dbinc_key
v112.site_dfatt
v102.dfatt df.dbinc_key
AND tag df,
AND ts.ts#
WHERE
v102.bp
= df.ts#
bdf.file#
bp = dbi,df.file#= ts.dbinc_key
dbi.dbinc_key
FROM
AND v121.dbinc
ts.create_scn
AND
WHERE (bdf.incr_level
ts.dbinc_key
dbi.dbinc_key
v121.bdf, ===df.dbinc_key
df.ts_create_scn
0= OR bdf.incr_level IS
df.dbinc_key
NULL)AND
AND
AND
dbi.dbinc_key
ts.ts# = df.ts#
bdf.dbinc_key
= df.dbinc_key
= df.dbinc_key
v121.ts,
AND bdf.dbinc_key
AND
AND bdf.bs_key
ts.create_scn
bdf.file#
v121.df, == df.ts_create_scn
= df.file#
df.dbinc_key
= bp.bs_key;
AND
AND node.db_key = dbi.db_key
dbi.dbinc_key == df.dbinc_key
AND
AND (bdf.incr_level
v121.bp,
bdf.file# = df.file# 0 OR bdf.incr_level IS
NULL)AND bdf.dbinc_key
v121.node,
AND (bdf.incr_level
= df.dbinc_key
AND node.db_key ==dbi.db_key
0 OR bdf.incr_level IS
NULL)AND
AND
bdf.bs_key
v121.site_dfatt
bdf.file# =
= bp.bs_key;
df.file#
WHERE
AND dbi.dbinc_key
node.site_key = ts.dbinc_key
= site_dfatt.site_key
AND
AND (bdf.incr_level
ts.dbinc_key = =df.dbinc_key
0 OR bdf.incr_level IS
df.df_key =
NULL)AND ts.ts# = df.ts# site_dfatt.df_key
AND bdf.bs_key = bp.bs_key;
AND node.site_key
ts.create_scn == df.ts_create_scn
site_dfatt.site_key
AND df.df_key = site_dfatt.df_key
AND dbi.dbinc_key = df.dbinc_key
AND
AND bdf.bs_key
bdf.dbinc_key = bp.bs_key;
= df.dbinc_key
AND node.db_key = dbi.db_key
AND bdf.file# = df.file#
AND (bdf.incr_level = 0 OR bdf.incr_level IS
NULL)
AND node.site_key = site_dfatt.site_key
AND df.df_key = site_dfatt.df_key
AND bdf.bs_key = bp.bs_key;
http://technopark02.blogspot.com/2007/09/oracle-fixing-ora-01113-file-x-needs.html
ce_file_name
col compression for 990.00 justify right head "COMPRESS|% ORIG"
col est_complete for a20 head "ESTIMATED COMPLETION"
col recid for 9999999 head "ID"
select recid
, output_device_type
, dbsize_mbytes
, input_bytes/1024/1024 input_mbytes
, output_bytes/1024/1024 output_mbytes
, (output_bytes/input_bytes*100) compression
, (mbytes_processed/dbsize_mbytes*100) complete
, to_char(start_time + (sysdate-start_time)/(mbytes_processed/dbsize_mbytes),'DD-MON-YYYY HH24:MI:SS')
est_complete
from v$rman_status rs
, (select sum(bytes)/1024/1024 dbsize_mbytes from v$datafile)
where status='RUNNING'
and output_device_type is not null
/
CF: Number of controlfile backups included in the backup setDF: Number of datafile full backups included in the backup setI0:
ase Corruption Issues (Doc ID 1088018.1)
block-corruption-test-case/
28/oracle-database-corruption-identify-and-correct/
9/17/how-to-recover-or-delete-corrupted-blocks/
AND bdf.bs_key = bp.bs_key
AND df.create_scn IN
(SELECT MAX (create_scn)
FROM v92.dfatt
WHERE df.file# = file# AND DF.DBINC_KEY = dbinc_key)
AND bdf.create_scn IN
(SELECT MAX (create_scn)
FROM v92.bdf bdf2
WHERE bdf.file# = file# AND bDF.DBINC_KEY = dbinc_key);
we have to do a full backup, Any backup prior to missing archives is no longer valid.... 1:51 PM
before that we have to .... 1:51 PM
backup archivelog all skip inaccessible delete input; 1:52 PM
and 1:52 PM
change archivelog all validate.... 1:52 PM
the first will allow the backup of all the archives and skip the missing 1:52 PM
the second will allow the backups to continue normally going forward by marking the archive backups as validated even
though the are missing. 1:53 PM
The fact that we had hard errors on the disk that were not correctable is odd.
09/oracle-fixing-ora-01113-file-x-needs.html
output_size
,
r.output_bytes_per_sec_dis
play output_rate_per_sec
FROM
(select
command_id
, start_time
, end_time
, time_taken_display
, status
, input_type
, output_device_type
, input_bytes_display
, output_bytes_display
,
output_bytes_per_sec_displ
ay
from
v$rman_backup_job_details
order by start_time
DESC
)r
;
restore point check
drop restorepoint
flashback on /off
FRA Usage
FRA size
select
table_name,row_movement from dba_tables
where
owner='ODB'
and
table_name = 'AC_ACTUAL_FLIGHTS';
schema backup
DBA _resumable
expdp
userid='/ as sysdba'
nohup expdp parfile=/dbexports/EXP/dbname/schemaexpdp.par &
dumpfile=WRNAME_exp_dbname_SCOTT.dmp
logfile=WRNAME_exp_w665pr_SCOTT.log
schemas=SCOTT
compression=all
directory=DATA_PUMP_DIR
alter system set event='10298 trace name context forever, level 32' scope=spfile;
scope=spfile;
ew-features/monitoringdatapump
Reverse Engineering
DDL
package ddl
Sequence DDL
Tablespace DDL
Users DDL
Password DDL
Profile
Roles DDL
create a role and assign all privileges to the role
DDL of V$ Tables
Parallel DDL option
GET_DEPENDENT_DDL
http://www.orafaq.com/node/807
http://amit7oracledba.blogspot.com/2013/02/dbmsmetadatagetddl-package-how-to-get.html
declare
userNm varchar2(100);
userpswd varchar2(100);
begin
userNm := upper('&TypeUserNameHere');
select password into userpswd from sys.user$ where name = userNm;
execute immediate ('ALTER PROFILE "FUNCTIONAL_USER" LIMIT
PASSWORD_VERIFY_FUNCTION null
PASSWORD_LIFE_TIME UNLIMITED
PASSWORD_REUSE_TIME UNLIMITED
PASSWORD_REUSE_MAX UNLIMITED');
execute immediate ('alter user '||userNm||' identified by oct152014oct');
execute immediate ('alter user '||userNm||' identified by values '''||userpswd||'''');
set long 20000
execute longchunksize
immediate 20000 pagesize
('ALTER PROFILE 0 linesize 1000 feedback
"FUNCTIONAL_USER" LIMIT off verify off trimspool on
column ddl format a1000
PASSWORD_VERIFY_FUNCTION PASSWDCOMPLEXVERIFICATION');
begin
end;
/ dbms_metadata.set_transform_param (dbms_metadata.session_transform, 'SQLTERMINATOR', true);
dbms_metadata.set_transform_param (dbms_metadata.session_transform, 'PRETTY', true);
end;
SQL> ALTER PROFILE FUNCTIONAL_USER LIMIT PASSWORD_VERIFY_FUNCTION NULL;
/Profile altered.
SQL> alter user trial identified by test;
variable v_role VARCHAR2(30);
User altered.
SQL> conn trial/test;
exec
ALTER :v_role := upper('&1');
PROFILE "FUNCTIONAL_USER" LIMIT PASSWORD_VERIFY_FUNCTION PASSWDCOMPLEXVERIFICATION
select (case
when ((select count(*)
from dba_roles
where role = '&&role') > 0)
then dbms_metadata.get_ddl ('ROLE', '&&role')
else to_clob ('Role does not exist')
end ) Extracted_DDL from dual
UNION ALL
select (case
when ((select count(*)
from dba_role_privs
where grantee = '&&role') > 0)
then dbms_metadata.get_granted_ddl ('ROLE_GRANT', '&&role')
end ) from dual
UNION ALL
select (case
when ((select count(*)
from
selectdba_role_privs
'grant ' || GRANTED_ROLE || ' to ' || ROLE || ';' from
where grantee =where
role_role_privs '&&role') > 0)
role='&ROLE'
then
union dbms_metadata.get_granted_ddl ('DEFAULT_ROLE',
'&&role')
select 'grant ' || PRIVILEGE || ' to ' || ROLE || ';' from role_sys_privs
end
where ) from dual
role='&&ROLE'
UNION
union ALL
select
select (case
'grant ' || PRIVILEGE || ' on ' || OWNER || '.' ||TABLE_NAME
when
|| ' to '((select count(*)
|| GRANTEE || ';' from dba_tab_privs where
from dba_sys_privs
GRANTEE='&&ROLE' ;
where grantee = '&&role') > 0)
then dbms_metadata.get_granted_ddl ('SYSTEM_GRANT',
'&&role')
end ) from dual
UNION ALL
select (case
when ((select count(*)
from dba_tab_privs
where grantee = '&&role') > 0)
then dbms_metadata.get_granted_ddl ('OBJECT_GRANT',
'&&role')
end ) from dual;
select
select
case *when
from level
DBA_TAB_PRIVS
= 1 then own ||where grantee
'.' || obj || ' (' || like
typ || ')' else
upper('%&enter_username%');
lpad (' ', 2*(level-1)) || obj || nvl2 (typ, ' (' || typ || ')', null)
select
end * from DBA_ROLE_PRIVS where grantee like
upper('%&enter_username%');
from
select
( * from DBA_SYS_PRIVS where grantee like
upper('%&enter_username%');
/* THE OBJECTS */
select * from DBA_COL_PRIVS where grantee like
select
upper('%&enter_username%');
null p1,
null p2,
object_name obj,
owner own,
object_type typ
from
dba_objects
where
owner like upper('%&enter_username%')
/* THE OBJECT TO PRIVILEGE RELATIONS */
union
select
table_name p1,
owner p2,
grantee,
grantee,
privilege
from
dba_tab_privs
/* THE ROLES TO ROLES/USERS RELATIONS */
union
select
granted_role p1,
granted_role p2,
grantee,
grantee,
null
from
dba_role_privs
)
start with p1 is null and p2 is null
connect by p1 = prior obj and p2 = prior own;
granted role permissions
select * from ROLE_ROLE_PRIVS where ROLE IN (select
granted_role from USER_ROLE_PRIVS where USERNAME
USER);
select * from ROLE_TAB_PRIVS where ROLE IN (select
granted_role from USER_ROLE_PRIVS where
USERNAME=USER);
select * from ROLE_SYS_PRIVS where ROLE IN (select
granted_role from USER_ROLE_PRIVS where
USERNAME=USER);
http://tech.padipa.net/generating-create-scripts-through-dbms_metadata-package
select dbms_metadata.get_ddl('USER', u.username) AS ddl select
from dba_users u dbms_me
where u.username = :v_username tadata.get
union all _ddl('USE
select dbms_metadata.get_granted_ddl('TABLESPACE_QUOTA', R',
tq.username) AS ddl 'KPHU00
from dba_ts_quotas tq 0') || '/'
where tq.username = :v_username
1_QUESTION_ID:494205100346718343 usercreat
and rownum = 1 e from
union all dual;
select dbms_metadata.get_granted_ddl('ROLE_GRANT', SELECT
rp.grantee) AS ddl DBMS_M
from dba_role_privs rp ETADATA
where rp.grantee = :v_username .GET_GR
and rownum = 1 ANTED_
union all DDL('RO
select dbms_metadata.get_granted_ddl('SYSTEM_GRANT', LE_GRA
sp.grantee) AS ddl NT','KPH
from dba_sys_privs sp U000') ||
where sp.grantee = :v_username '/' FROM
and rownum = 1 DUAL;
union all SELECT
select dbms_metadata.get_granted_ddl('OBJECT_GRANT', DBMS_M
tp.grantee) AS ddl ETADATA
from dba_tab_privs tp .GET_GR
where tp.grantee = :v_username ANTED_
and rownum = 1 DDL('SY
union all STEM_G
select dbms_metadata.get_granted_ddl('DEFAULT_ROLE', RANT','K
rp.grantee) AS ddl PHU000')
from dba_role_privs rp || '/'
where rp.grantee = :v_username FROM
and rp.default_role = 'YES' DUAL;
and rownum = 1 SELECT
union all DBMS_M
select to_clob('/* Start profile creation script in case they are ETADATA
missing') AS ddl .GET_GR
from dba_users u ANTED_
where u.username = :v_username DDL('OBJ
and u.profile <> 'DEFAULT' ECT_GR
and rownum = 1 ANT','KP
union all HU000') ||
select dbms_metadata.get_ddl('PROFILE', u.profile) AS ddl '/' FROM
from dba_users u DUAL;
where u.username = :v_username select
and u.profile <> 'DEFAULT' DBMS_M
union all ETADATA
select to_clob('End profile creation script */') AS ddl .GET_GR
from dba_users u ANTED_
where u.username = :v_username DDL('TAB
and u.profile <> 'DEFAULT' LESPAC
and rownum = 1 E_QUOT
/ A',
'KPHU00
set linesize 80 pagesize 14 feedback on trimspool on verify on 0') '/' from
dual;
-dbms_metadata-package
try this
Reference Object
To Find Lock & Session - Metalink
select owner, table_name, stattype_locked from dba_tab_statistics where stattype_locked is not null and owner not in ('SYS','S
who is querying via dblink?
Courtesy of Tom Kyte, via Mark Bobak
this script can be used at both ends of the database link
to match up which session on the remote database started
the local transaction
the GTXID will match for those sessions
just run the script on both databases
SELECT
s.blocking
_session,
s.sid,
s.serial#,
s.second
s_in_wait
FROM
v$session
s
WHERE
blocking_
session
IS NOT
NULL
https://github.com/gwenshap/Oracle-DBA-Scripts/blob/master/locks.sqlhttp://www.oracle-ckpt.com/scripts-for-locks-and-blockin
;
Trace enable
Trace disable
Trace a module:
DB HUNG - OS level
Database HUNG - db level
10046 Trace
Tracing RMAN
Tracing Oracle process OS level
Tracing SQLPLUS at OS level
Oradebug utility
adrci
Check this
ALTER SESSION SET EVENTS '10046 TRACE NAME CONTEXT FOREVER, LEVEL 12';
-or-
EXEC SYS.DBMS_SYSTEM.SET_EV(SID,SERIAL#,10046,12,'');
-or-
EXEC SYS.DBMS_SUPPORT.START_TRACE_IN_SESSION(SID,SERIAL#,WAITS=>TRUE,BINDS=>FALSE);
-or-
EXEC DBMS_MONITOR.SESSION_TRACE_ENABLE(SESSION_ID=>SID,SERIAL_NUM=>SERIAL#,WAITS=>TRUE,BIND
-or-
EXEC SYS.DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION(SID,SERIAL#,TRUE);
EXECUTE DBMS_MONITOR.SERV_MOD_ACT_TRACE_ENABLE(
service_name=>'vasont.world', module_name=>'VasontU.exe',
action_name=>DBMS_MONITOR.ALL_ACTIONS,waits=>TRUE,
binds=>TRUE,instance_name=>NULL);
EXECUTE DBMS_MONITOR.SERV_MOD_ACT_TRACE_DISABLE(
service_name=>'vasont.world',module_name=>'VasontU.exe');
alter system set events 'sql_trace[SQL:8kybysnu4nn34] plan_stat=all_executions,wait=true,bind=true'; (OR)
alter system set events 'sql_trace[sql: cjrha4bzuupzf] level=12';
10 rows selected.
Now that we have found the Operating System PID and Oracle PID (values 864 and 13 in this case) of SCOTT's session we c
to set trace with the oradebug tool as follows:
So to purge all diagnostic information, including trace files, older than 2 days you would issue the following.
adrci> purge -age 2880
alter session set events '10132 trace name context forever, level 12';
You can also add an identifier to the trace file name for later identification:
ALTER SESSION SET sql_trace = true;
ALTER SESSION SET tracefile_identifier = mysqltrace;
http://www.orafaq.com/wiki/SQL_Trace
https://blog.dbi-services.com/enable-10046-tracing-for-a-specific-sql/
https://avdeo.com/tag/sql-tuning/
https://oracle-base.com/articles/misc/sql-trace-10046-trcsess-and-tkprof
http://www.juliandyke.com/Diagnostics/Trace/EnablingTrace.php
create or replace trigger trace_trigger_scott
AFTER LOGON ON DATABASE
WHEN (USER='SCOTT')
declare
stmt varchar2(100);
hname varchar2(20);
uname varchar2(20);
begin
select sys_context('USERENV','HOST'),
sys_context('USERENV','SESSION_USER')
into hname,uname from dual;
stmt := 'alter session set tracefile_identifier='||hname||'_'||uname;
EXECUTE IMMEDIATE stmt;
EXECUTE IMMEDIATE 'alter session set sql_trace=true';
end;
/
and disable tracing when the user disconnects:
------------------------------------------------
create or replace trigger trace_trigger_off
BEFORE LOGOFF ON DATABASE
when(user='SCOTT')
begin
execute immediate 'alter session set sql_trace=false';
end;
/
https://jonathanlewis.wordpress.com/2006/11/27/event-10132/
http://www.orafaq.com/wiki/TKProf
best
solaris
linux
connect / as sysdba
oradebug setospid 9834
oradebug unlimit
oradebug event 10046 trace name context forever,level 12
oradebug tracefile_name
--wait for 5 mins and then trace off
oradebug event 10046 trace name context off
SQL> declare
p_file utl_file.file_type;
begin
p_file := utl_file.fopen ('MYDIR', 'myfile2.txt', 'w');
end;
/
2 3 4 5 6
declare
*
ERROR at line 1:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 4
https://blog.dbi-services.com/oracle-is-hanging-dont-forget-hanganalyze-and-systemstate/
alter session set tracefile_identifier='mytrace_1089';
alter session set events '10046 trace name context forever,level
12:1089 trace name errorstack level 3';
select * from dual@DBLINK;
alter session set events '10046 trace name context off';
Systemstate
Details of a object
Recomplinig Invalid objects (nonpdb) --> for pdb refer next column
Disable constraint
Disable constraints
Dependency Objects
Dblinks
Rebuild / Fragmentation
Indexes requires rebuild
Rebuild Indexes
Index fragmentation
re-organizing table
select 'alter '||object_type||' '||owner||'."'||object_name||'" compile;'
from dba_objects
where status<>'VALID'
and object_type not in ('PACKAGE BODY','TYPE BODY','UNDEFINED','JAVA CLASS','SYNONYM')
union
select 'alter package '||owner||'.'||object_name||' compile body;'
from dba_objects
where status<>'VALID'
and object_type='PACKAGE BODY'
union
select 'alter type '||owner||'.'||object_name||' compile body;'
selectdba_objects
from owner, object_type, substr(object_name,1,30) object_name, status
from dba_objects
where where status='INVALID' order by object_type;
status<>'VALID'
and object_type='TYPE BODY'
union
set lines 1000 pages 9999
select 'alter materialized
col object_name for a50 view '||owner||'.'||object_name||' compile;'
from
col ownerdba_objects
for a30
where status<>'VALID'
col object_type for a30
and object_type='UNDEFINED'
col STATUS for a30
union
select owner,object_name,object_type,CREATED,STATUS,TO_CHAR(LAST_DDL_TIME,'dd-mon-yyyy
select 'alter java
hh24:mi:ss') class '||owner||'."'||object_name||'"
AS LAST_DDL_TIME from dba_objectsresolve;'
where object_name in
from dba_objects
('&OBJECT_NAME1','&OBJECT_NAME2','&OBJECT_NAME3');
where status<>'VALID'
set
andserveroutput on sizeCLASS'
object_type='JAVA 100000;
declare
union
sqlstring
select varchar2(2000);
'alter synonym '||owner||'.'||object_name||' compile;'
rec_count
from integer;
dba_objects
begin
where status<>'VALID'
dbms_utility.compile_schema('SCHEMA1');
and object_type='SYNONYM'
dbms_utility.compile_schema('SCHEMA2');
and owner<>'PUBLIC'
select count(1) into rec_count from sys.all_objects
union
where'alter
select owner in ('SCHEMA1','SCHEMA2')
public synonym '||object_name||' compile;'
and object_type
from dba_objectsin ('FUNCTION','VIEW','PROCEDURE','TRIGGER') and status = 'INVALID';
if (rec_count
where > 0) then
status<>'VALID'
andfor object_type='SYNONYM'
recs in (select owner, object_type, object_name from sys.dba_objects where owner in
('SCHEMA1','SCHEMA2')
and owner='PUBLIC'; and object_type in ('FUNCTION','VIEW','PROCEDURE','TRIGGER') and status
= 'INVALID')
loop
begin
sqlstring := 'ALTER ' || recs.object_type || ' ' || recs.owner || '.' || recs.object_name || ' COMPILE';
execute immediate (sqlstring);
exception
when others then
dbms_output.put_line(recs.object_type || ' ' || recs.owner || '.' || recs.object_name || ' failed to compile :
' || sqlerrm);
end;
end loop;
end if;
end;
/
SQL> alter view OWNER.VIEW1 compile;
DECLARE
BEGIN
FOR r1 IN ( SELECT 'DROP ' || object_type || ' ' || owner || '."'|| object_name || '"' || DECODE
( object_type, 'TABLE', ' CASCADE CONSTRAINTS PURGE' ) AS v_sql FROM dba_objects
WHERE owner in ('&SCHEMA') and object_type IN ( 'TABLE', 'VIEW', 'PACKAGE', 'TYPE',
'PROCEDURE', 'FUNCTION', 'TRIGGER', 'SEQUENCE', 'MATERIALIZED VIEW', 'JAVA CLASS' )
ORDER BY object_type,
object_name ) LOOP
EXECUTE IMMEDIATE r1.v_sql;
END LOOP;
END;
/
purge dba_recyclebin;
clear break
clear computes
select
table_name,
to_number(
extractvalue(
xmltype(dbms_xmlgen.getxml(‘select count(*) c from ‘||table_name))
,’/ROWSET/ROW/C’)
) for a30
col owner
count
col index_name for a30
colfrom user_tables
table_name order by table_name;
for a30
col column_name for a30
select
owner,b.uniqueness, a.index_name, a.table_name, a.column_name
from dba_ind_columns a, dba_indexes b
where a.index_name=b.index_name
and b.owner='&OWNER'
and a.table_name = upper('&TABLE_NAME')
order by a.table_name, a.index_name, a.column_position;
select 'ALTER TABLE '||OWNER||'.'||TABLE_NAME||' DISABLE CONSTRAINT '||CONSTRAINT_NAME ||';' from dba_constrain
SELECT
'ALTER TABLE '||OWNER||'.'||
TABLE_NAME||' '||var_action||' CONSTRAINT '||CONSTRAINT_NAME AS sql_string,
CONSTRAINT_NAME
FROM
ALL_CONSTRAINTS
WHERE
CONSTRAINT_TYPE='R' AND OWNER=Target_Schema_Name;
Set this below parameter if u want to run the compilation script in PDB
Session altered.
set lines 750 pages 9999
col text for a150
col owner for a15
col name for a50
col position for a10
SELECT e.owner, e.name, TO_CHAR(e.line) || '/' || TO_CHAR(e.position) "POSITION",
e.text
FROM dba_errors e
ORDER BY e.owner, e.name, e.sequence;
https://bommaritollc.com/2012/01/22/debugging-ora-02292-integrity-constraint-owner-constraint-violated-child-record-found/
https://blog.dbi-services.com/how-i-measure-oracle-index-fragmentation/
Table size (with fragmentation)
TABLE_NAME size
------------------------------ ------------------------------------------
BIG1 72952kb
TABLE_NAME size
------------------------------ ------------------------------------------
BIG1 30604.2kb
Running Sql's
undo advisor
Monitoring undo segements
TEMP
sort space usage by sesison
shrink tempfile
http://vsbabu.org/oracle/sect07.html
select inst_id,name,value from gv$parameter where name like '%undo%';
select sql_id,SQL_PLAN_HASH_VALUE,max(TEMP_SPACE_ALLOCATED)/
(1024*1024*1024) gig
from DBA_HIST_ACTIVE_SESS_HISTORY
where
sample_time > sysdate-10 and
TEMP_SPACE_ALLOCATED > (10*1024*1024*1024)
group by sql_id,SQL_PLAN_HASH_VALUE order by sql_id;
ALTER TABLESPACE temp SHRINK TEMPFILE
'+DATA_KRONIA/p1kronia/tempfile/temp.313.868020865' KEEP 500M;
SELECT v$session.SID,
v$session.SERIAL#,r.NAME "Undo Segment
Name", dba_seg.size_mb,
DECODE(TRUNC(SYSDATE - LOGON_TIME), 0,
NULL, TRUNC(SYSDATE - LOGON_TIME) || '
Days' || ' + ') ||
TO_CHAR(TO_DATE(TRUNC(MOD(SYSDATE-
LOGON_TIME,1) * 86400), 'SSSSS'),
'HH24:MI:SS') LOGON,
p.SPID, v$session.process,
v$session.USERNAME, v$session.STATUS,
v$session.OSUSER, v$session.MACHINE,
v$session.PROGRAM, v$session.module, action
FROM v$lock l, v$process p, v$rollname r,
v$session,
(SELECT segment_name, ROUND(bytes/
(1024*1024),2) size_mb FROM dba_segments
WHERE segment_type = 'TYPE2 UNDO' ORDER
BY bytes DESC) dba_seg
WHERE l.SID = p.pid(+) AND
v$session.SID = l.SID AND
TRUNC (l.id1(+)/65536)=r.usn AND
l.TYPE(+) = 'TX' AND
l.lmode(+) = 6
AND r.NAME = dba_seg.segment_name
--AND v$session.username = 'SYSTEM'
--AND status = 'INACTIVE'
ORDER BY size_mb DESC;
https://community.oracle.com/thread/1098943?tstart=0http://www.oracleflash.com/32/Change-or-switch-undo-tablespace-in-Or
If TRUE means it will not show any undo errors , So some times job may complete sucessfully.
select count(status) from dba_undo_extents where
status = 'EXPIRED';
select status, sum(bytes) / 1024 / 1024 || 'MB' from DBA_UNDO_EXTENTS group by status;
SELECT
dbms_undo_adv.required_undo_size(1800,
SYSDATE-30, SYSDATE)
FROM dual;
select maxquerysqlid, maxquerylen from
dba_hist_undostat order by maxquerylen desc;
select maxqueryid, maxquerylen from
v$undostat order by maxquerylen desc;
http://www.williamrobertson.net/documents/undo_tracker.shtml
col sid_serial for a20
SELECT S.sid || ',' || S.serial# sid_serial,
S.username, S.osuser, P.spid, S.module,
S.program, SUM (T.blocks) *
TBS.block_size / 1024 / 1024 mb_used,
T.tablespace,
COUNT(*) sort_ops
FROM v$sort_usage T, v$session S,
dba_tablespaces TBS, v$process P
WHERE T.session_addr = S.saddr
AND S.paddr = P.addr
AND T.tablespace = TBS.tablespace_name
GROUP BY S.sid, S.serial#, S.username,
S.osuser, P.spid, S.module,
S.program, TBS.block_size, T.tablespace
ORDER BY sid_serial;
SELECT distinct rpad(s.sid,3) "SID",S.USERNAME,
E.SEGMENT_NAME,
T.START_TIME "Start",
rpad(T.STATUS,9) "Status",
round((t.used_ublk*8)/1024) "Size(MB)"
--T.USED_UBLK||' Blocks and '||T.USED_UREC||' Records' "Rollback
Usage"
FROM DBA_DATA_FILES DF,
DBA_EXTENTS E,
V$SESSION S,
V$TRANSACTION T
WHERE DF.TABLESPACE_NAME = E.TABLESPACE_NAME AND
DF.FILE_ID = UBAFIL AND
S.SADDR = T.SES_ADDR AND
T.UBABLK BETWEEN E.BLOCK_ID AND E.BLOCK_ID+E.BLOCKS AND
E.SEGMENT_TYPE in( 'ROLLBACK','TYPE2 UNDO');
nts/undo_tracker.shtml
column SQL_EXEC_START for a21
column sql_text format a50
column module format a35
column sql_text format a50
break on report
compute SUM of MB_USED on report
SELECT a.username, a.sid, a.serial#, a.osuser,
(b.blocks*d.block_size)/1048576 MB_USED,a.sql_id,a.sql_child_number
child,c.plan_hash_value,to_char (a.sql_exec_start, 'dd-Mon-yyyy select
hh24:mi:ss') sql_exec_start,c.rows_processed,a.status, ROUND(
-- c.sql_text SUM(tem
substr(c.sql_text,1,50) sql_text pseg_siz
FROM v$session a, v$tempseg_usage b, v$sqlarea c, e)/10485
(select block_size from dba_tablespaces where 76)
tablespace_name='TEMP') d temp_mb
WHERE b.tablespace = 'TEMP' from
and a.saddr = b.session_addr gv$sql_w
AND c.address= a.sql_address orkarea_
AND c.hash_value = a.sql_hash_value active
ORDER BY b.tablespace, 5 desc; WHERE
sid=&sid;
Archivelog
REDO
System altered.
Database altered.
useful link
List Hostnames
target names
OEM sqls
emctl commands
list targets
start blackout
All blackout commands
Commit ;
http://www.oracledbasupport.co.uk/querying-grid-repository-tables/
SELECT distinct(mgmt$target.host_name)
FROM mgmt$target
, mgmt$target_properties
WHERE ( mgmt$target.target_name =
mgmt$target_properties.target_name )
AND ( mgmt$target.target_type =
mgmt$target_properties.target_type )
AND ( mgmt$target_properties.property_name in
( 'CPUCount','DBVersion' ) )
GROUP BY mgmt$target.host_name
, mgmt$target_properties.property_name
, mgmt$target_properties.property_value
order by mgmt$target.host_name;
http://askdba.org/weblog/2011/01/retrieving-database-sidport-information-from-grid-control-repository/
http://www.oracledbasupport.co.uk/querying-grid-repository-tables/
http://satya-dba.blogspot.com/2010/01/emctl-commands.html
oracle@testhost [oemagent] cd
/u01/app/oracle/agent/agent12c/bin
./emctl stop agent
./emctl clearstate agent
./emctl start agent
./emctl upload agent
https://blog.dbi-services.com/querying-the-oracle-management-repository/
select database_name from
select target_name from
sysman.mgmt$db_dbninstanceinfo
sysman.mgmt$db_dbninstanceinfo
having database_name not in (select where target_type =
database_name from
'rac_database';
sysman.mgmt$db_dbninstanceinfo where target_type =
'rac_database')
group by database_name
select
minus target_name from
sysman.mgmt$db_dbninstanceinfo
select database_name from
where target_type = 'oracle_database'
sysman.mgmt$db_dbninstanceinfo and
where
database_name in
lower(database_name) = lower(instance_name)
(select
; database_name from 2nd query will not return properly. May be one or 2 difference will b
sysman.mgmt$db_dbninstanceinfo
where target_type = 'oracle_database'
having database_name not in (select database_name from
emcli argfile Chng_DB_mon_passwd1
sysman.mgmt$db_dbninstanceinfo where target_type =
'rac_database')
group by database_name)
order by database_name;
emcli set_monitoring_credential
-target_type=rac_database -target_name=db_name
-set_name="DBCredsMonitoring" -cred_type="DBCreds"
-attributes="DBUserName:dbsnmp;DBPassword:m0nit0r;D
BRole:NORMAL"
emcli sync
agement-repository/
ly. May be one or 2 difference will be there
agctl location
agctl start
agctl status
agctl relocate
gg status
view report
error
no data found
start extract
others
history command
locate agctl
/opt/oracle/product/emagent/gg/install/xag/bin/agctl start goldengate ggate_prod --node server2
cd /opt/oracle/product/emagent/gg/install/xag/bin
./agctl status goldengate ggate_<uat/prod/bcp>
cd /opt/oracle/product/emagent/gg/install/xag/bin/
./agctl relocate goldengate ggate_prod --node secondnode
check the table name , add "HANDLECOLLISIONS" & "NOHANDLECOLLISIONS" before and after the MAP
statement in parameterfile and restart the EXTRACT/REPLICAT
Once the LAG is zero , stop the replicat & remove the "HANDLECOLLISIONS" & "NOHANDLECOLLISIONS" from
parameter file. Then start the replicat
VIEW GGSEVT
ggsci > sh date
h
h 10
2: start mgr
3: start er *
4: status all
...
29: h 29
30: h 29
MANAGER RUNNING
EXTRACT RUNNING EBATCH 00:00:00 00:00:02
EXTRACT RUNNING ETEST 00:00:00 00:00:03
REPLICAT RUNNING RBATCH 00:00:00 00:00:04
REPLICAT RUNNING RTEST 00:00:00 00:00:05
REPLICAT RUNNING RTESTA 00:00:00 00:00:01
REPLICAT RUNNING RTESTB 00:00:00 00:00:00
Free/Used SGA
amount of session memory used in the shared pool for all sessions
troubleshoot Tool
https://coskan.wordpress.com/2007/09/14/what-i-learned-about-shared-pool-management/
http://yong321.freeshell.org/computer/SharedPoolPurging.html
select
PID,SPID,serial#,USERNAME,PROGRAM,PGA_USED_MEM,PGA_ALLOC_MEM,PGA_F
REEABLE_MEM,PGA_MAX_MEM from v$process order by PGA_USED_MEM desc;
set linesize 750
set pagesize 250
column box format a20
column username format a7
column program format a20
column os_user format a20
http://www.dbas-oracle.com/2013/05/5-Easy-Step-to-Solve-ORA-04031-with-Oracle-
Support-Provided-Tool.html
For 10g:
set pages 999
set lines 130
col component for a25 head "Component"
col status format a10 head "Status"
col initial_size for 999,999,999,999 head "Initial"
col parameter for a25 heading "Parameter"
col final_size for 999,999,999,999 head "Final"
col changed head "Changed At"
Metalink ID 559339.1
SELECT to_char(ssn.sid, '9999') || ' - ' || nvl(ssn.username,
nvl(bgp.name, 'background')) ||
nvl(lower(ssn.machine), ins.host_name) "SESSION",
to_char(prc.spid, '999999999') "PID/THREAD",
to_char((se1.value/1024)/1024, '999G999G990D00') || ' MB' "
CURRENT SIZE",
to_char((se2.value/1024)/1024, '999G999G990D00') || ' MB' "
MAXIMUM SIZE"
FROM v$sesstat se1, v$sesstat se2, v$session ssn,
v$bgprocess bgp, v$process prc,
v$instance ins, v$statname stat1, v$statname stat2
WHERE se1.statistic# = stat1.statistic# and stat1.name =
'session pga memory'
AND se2.statistic# = stat2.statistic# and stat2.name = 'session
pga memory max'
AND se1.sid = ssn.sid
AND se2.sid = ssn.sid
AND se1.sid=&sid
AND ssn.paddr = bgp.paddr (+)
AND ssn.paddr = prc.addr (+); <--For a Single sid
https://bdrouvot.wordpress.com/2013/03/19/link-huge-pga-temp/
The output from this data dictionary query shows that every
connected Oracle session will about 2.5 megabytes of RAM
memory for the Oracle PGA
See all the data file i / o, and if too many files, can be rewritten
for the top 10 select * (order by xx desc) where rownum <= 10
http://www.dba-oracle.com/t_x$ksmlru_x$ksmsp_shared_pool_monitoring.htm
For 11g:
set pages 999
set lines 130
col component for a25 head "Component"
col status format a10 head "Status"
col initial_size for 999,999,999,999 head "Initial"
col parameter for a25 heading "Parameter"
col final_size for 999,999,999,999 head "Final"
col changed head "Changed At"
pdb violations
patch validation
Patch check
componenets status
select
PATCH_ID,PATCH_UID,VERSION,ACTION,ACTION_TIME,STATUS,DESCRIPTION,BUNDLE_SERIES,BUNDLE_
ID,BUNDLE_DATA from dba_registry_sqlpatch;
Database PSUs
CRS PSUs
GI (Grid Infrastructure) PSUs
Enterprise Manager Agent PSUs
col COMP_ID for a25
col COMP_NAME for a60
set lines 700
select COMP_ID,COMP_NAME,VERSION,STATUS from dba_registry;
delete from obj$ where name in (select OBJECT_NAME from dba_objects where status ='INVALID' and owner
='XDB');
commit;
set serveroutput on
execute sys.dbms_regxdb.validatexdb;
select comp_name, version, status from dba_registry where comp_id='XDB';
for i in `crsstat.sh |grep .db| grep -v svc |grep -v .vip|grep -v .lsnr |grep -v .mgmt | grep -v OFFLINE | grep
"Open,STABLE"|cut -d"." -f2`
do
GRID_ENV=`ps -ef|grep pmon|awk '{print $NF}'|grep asm|cut -d_ -f3`
export GRID_ENV
. oraenv $GRID_ENV
NEW_HOME=`srvctl config database -v|grep $i|awk '{print $2}'`
export NEW_HOME
. /opt/oracle/local/bin/oraenv $i
for j in `srvctl status database -d $i | grep "running" | grep -v "not running" |awk '{print $2}' | awk 'NR==1'`
do
node=`srvctl status database -d $i |grep $j| awk '{print $NF}'`
connection="nohup `ssh -q $node "$(typeset -f Datapatch_apply); Datapatch_apply $j "` &"
done
done
<-- status should be SUCCESS
opatch lsinventory -bugs_fixed | egrep -i 'PSU|DATABASE PATCH SET UPDATE'
opatch lsinventory -bugs_fixed | grep -i 'TRACKING BUG' | grep -i 'PSU'
opatch lsinventory -bugs_fixed | grep -i 'GRID INFRASTRUCTURE PATCH SET UPDATE'
opatch lsinventory -bugs_fixed | grep -i 'ENTERPRISE MANAGER' | grep -i 'AGENT'
scheduled job run details
DBA JOBS
SCHEDULED JOBS
select
LOG_ID,LOG_DATE,OWNER,JOB_NAME,STATUS,ERROR#,REQ_START_DATE,ACTUA
L_START_DATE,RUN_DURATION,SESSION_ID,CPU_USED,ADDITIONAL_INFO from
DBA_SCHEDULER_JOB_RUN_DETAILS;
select LOG_ID,LOG_DATE,OWNER,
JOB_NAME,STATUS,USER_NAME,CLIENT_ID,GLOBAL_UID,ADDITIONAL_INFO from
DBA_SCHEDULER_JOB_LOG;
Info.sql
Database Characterset
Finding DBNAME as a normal user
How to see oracle Enterprise edition or not
DBV
ERROR at line 1:
ORA-01565: error in identifying file
Creating Big table
'/ora10gsoft/10.2.0/oradata/sambaar/users01.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
ORA-06512: at line 16
one redo log file deleted on os side.(redolog group contains only one member)
Oracle internal
Profile for OS
dissassembling_the_data_block
Restrict the database logins (To put our database in a single user mode )
create snapshot
Tricks
column separator
ipv6 connectivity
DBMS-insufficient privileges
Product/Component
Automated Storage Management
Oracle Data Mining
Database Vault
Oracle OLAP
Oracle Label Security
Oracle Partitioning
Real Application Cluster
Real Application Testing
Product/Component
Oracle Data Mining
Database Vault
Oracle OLAP
Oracle Label Security
Oracle Partitioning
Real Application Testing
set lines 750 pages 9999
column KSPPINM format a50
column KSPPSTVL format a50
select a.ksppinm, b.ksppstvl FROM x$ksppi a, x$ksppcv b WHERE a.indx=b.indx;
SELECT * FROM SYS.X$KSPPI WHERE SUBSTR(KSPPINM,1,1) = '_';
select object_name from dba_objects where object_name like '%$' and object_name not like 'SYS%'
select distinct table_name from V$INDEXED_FIXED_COLUMN where table_name like 'X$%';
select ksppstvl from x$ksppi join x$ksppcv using (indx) where ksppinm='_high_priority_processes';
select
length(addr)*4 || '-bits' word_length
from
v$process
where
ROWNUM =1;
Procedure created.
no rows selected
SQL>
In my case, I comment out one line starting PROGRAM from listener.ora, and after restarting listener. I can connect
successfully.
SID_LIST_KOREA =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME=korea)
(SID_NAME = KOREA)
(ORACLE_HOME = D:\Applications\oracle\product\10.2.0)
# (PROGRAM = extproc)
)
)
ORA-00350:
while (l_cntlog 1 of instance sambaar (thread 1) needs to be archived
< l_rows)
ORA-00312:
loop online log 1 thread 1:
and we check/*+ its opened*/file descriptors
'/ora10gsoft/10.2.0/oradata/sambaar/redo01a.log'
insert APPEND into bigtab for our file:
ls -l /proc/2661/fd |
select rownum+l_cnt,grep test_rm
lrwx------ 1OWNER,
oracle dba 64 Mar 26 14:02
OBJECT_NAME, 66 -> /var/tmp/test_rm.dbf (deleted)
SUBOBJECT_NAME,
SQL> OBJECT_ID, DATA_OBJECT_ID,
SQL> OBJECT_TYPE, CREATED, LAST_DDL_TIME,
here
SQL>it alter
is: TIMESTAMP,
system checkpoint;
STATUS, TEMPORARY,
ls -l /proc/2661/fd/66
GENERATED, SECONDARY
lrwx------ 1 oracle
System
Run this bigtab dba 64 Mar 26 14:02 /proc/2661/fd/66 -> /var/tmp/test_rm.dbf (deleted)
altered.
from
where rownum <= l_rows-l_cnt;
l_cnt := l_cnt + sql%rowcount;
$ cd $ORACLE_HOME/install
commit;
$ ./changePerm.sh
end loop;
In
SQL>some other
alter unix, lsof
database dropmay be needed
logfile group 1;to map the file descriptor with the deleted file name
end;
alter
/ database drop logfile group 1
*
ERROR
alter table atbigtab
line 1:add constraint
first we setprimary
ORA-00350: a log
symbolic link so that
1 key(id);
of instance oracle(thread
sambaar can see1)itneeds
as it was before
to be the delete:
archived
bigtab_pk
ln -s /proc/2661/fd/66 /var/tmp/test_rm.dbf
ORA-00312: online log 1 thread 1:
'/ora10gsoft/10.2.0/oradata/sambaar/redo01a.log'
here
SQL>data is accessible, but that will be lost if dbwriter closes it file handle (i.e if the database is closed)
SQL> ALTER DATABASE CLEAR UNARCHIVED LOGFILE GROUP 1;
RECOVERaltered.
Database DATABASE UNTIL CANCEL
alter database open resetlogs
SQL> SQL> SQL> SQL> alter database drop logfile group 1;
.
export
Template ORACLE_HOME=/opt/oracle/product/11.1.0/db7
location
Database altered.
PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME/bin:/usr/bin/X11:/sbin:.:/usr/local/bin:${ORACLE_HOME}:$
-------------------
select
{ORACLE_HOME}/bin:${ORACLE_HOME}/OPatch:/oracle/dba/bin
c:\oracle\product\10.2.0\db_1\assistants\dbca\templates
samp.dbid,
SQL>
OEM Scripts
fu.name,
export PATH
------------
samp.version,
export HISTFILE=$HOME/.histdir/$(tty|sed 's-/-_-g')
\\networkdrive\k$\oracle\product\10.2.0\db_1\sysman\admin\emdrep\sql
detected_usages,
export
Database DBA_INIT_INI=/oracle/dba/funcs/dba_init.ini
Creation
total_samples,
-------------------
decode(to_char(last_usage_date, 'MM/DD/YYYY, HH:MI:SS'),
# NMON variable
C:\WINDOWS\system32\cmd
NULL, 'FALSE',to stop oslevel checking
/c call K:\oracle\product\10.2.0\db_1/bin/dbca.bat -progress_only -createDatabase
export NMONAIX=5.2.0.0
-templateName General_Purpose.dbc
to_char(last_sample_date, -gdbNameHH:MI:SS'),
'MM/DD/YYYY, test -sid test'TRUE',
-sysPassword 05f6050bc031e3dc104db3b733a0228c44
-systemPassword
'FALSE') 05f6050bc031e3dc104db3b733a0228c44 -sysmanPassword 05c5f468c03129e8c2b5ed24021b2f7200
export EDITOR=vi 05c5f468c03129e8c2b5ed24021b2f7200 -emConfiguration LOCAL -datafileJarLocation
-dbsnmpPassword
currently_used,
export FPATH=/oracle/dba/funcs
K:\oracle\product\10.2.0\db_1\assistants\dbca\templates
first_usage_date, -datafileDestination K:\oracle\product\10.2.0\oradata
export TNS_ADMIN=/var/opt/oracle
-responseFile
last_usage_date,NO_VALUE -characterset WE8MSWIN1252 -obfuscatedPasswords true -sampleSchema true
export ORACLE_BASE=/opt/oracle
-recoveryAreaDestination
aux_count, NO_VALUE
export ORACLE_ASK=YES
feature_info,
export ORACLE_OWNER=oracle
last_sample_date,
begin
last_sample_period,
sys.dbms_system.ksdwrt(2,
export 'My own message');
NLS_LANG=AMERICAN_AMERICA.UTF8
sample_interval,
end;
export NLS_DATE_FORMAT='YYYY/MM/DD HH24:MI'
mt.description
/
from
ninswri$_dbu_usage_sample samp,
. .kshrc
wri$_dbu_feature_usage fu,
wri$_dbu_feature_metadata mt
#where
Set up machine independent variables
stty erase '^H' =killfu.dbid
samp.dbid "^U" intr
and"^C" eof "^D"
umask 002
samp.version = fu.version and
export
fu.name JAVA_COMPILER=NONE
= mt.name and
export
fu.name HOST=$(uname -n)
not like '_DBFUS_TEST%' and /* filter out test features */
export PWD=`pwd`
bitand(mt.usg_det_method, 4) != 4 /* filter out disabled features */;
export PS1='$ORACLE_SID@$HOST: $PWD> '
if [ -s "$MAIL" ] # This is at Shell startup. In normal
then echo "$MAILMSG" # operation, the Shell checks
fi # periodically.
Sql> alter system suspend;
Sql> select database_status from v$instance;
Database_status
-----------------
Suspended
http://www.orafaq.com/papers/dissassembling_the_data_block.pdf
SQL> select active_state
Sql> alter system resume;from v$instance;
ACTIVE_ST
Sql> select database_status from v$instance;
---------
NORMAL
Database_status
-----------------
SQL>
Active ALTER SYSTEM QUIESCE RESTRICTED;
Sql>startup restrict;
System altered.
Sql>alter system disable restricted session;
Sql> alter system enable restricted session;
SQL> select active_state from v$instance;
ACTIVE_ST
---------
QUIESCED
SQL> select bq.sid, username, osuser, program, machine from v$blocking_quiesce bq, v$session s where bq.sid = s.sid;
no rows selected
System altered.
EXEC DBMS_WORKLOAD_REPOSITORY.create_snapshot;
(connect as SYSTEM)
SQL> alter user APEX_030200 grant connect through system;
User altered.
SQL> alter user apex_030200 account unlock;
User altered.
SQL> connect system[apex_030200]/systempassword
Connected.
SQL> select user from dual;
APEX_030200
jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)
(HOST=[fe80::219:21ff:febb:9aa5]) (PORT=1526))
(CONNECT_DATA=(SERVICE_NAME=D112D1)))
set serveroutput on
set heading off
set feedback off
select sysdate from dual;
exec dbms_output.put_line('------------------------------');
select sysdate from dual;
http://m.blog.itpub.net/17252115/viewspace-1160554/
cd $ORACLE_HOME/rdbms/lib
ar -tv libknlopt.a | grep -c kkxwtp.o
ar -tv libknlopt.a | grep -c kfoff.o
ar -tv libknlopt.a | grep -c ktd.o
ar -tv libknlopt.a | grep -c kxmwsd.o
ar -tv libknlopt.a | grep -c kciwcx.o
ar -tv libknlopt.a | grep -c sllfls.o
ar -tv libknlopt.a | grep -c kprnts.o
ar -tv libknlopt.a | grep -c xsnoolap.o
ar -tv libknlopt.a | grep -c kdzof.o
ar -tv libknlopt.a | grep -c kecnr.o
ar -tv libknlopt.a | grep -c dmndm.o
ar -tv libknlopt.a | grep -c kkpoban.o
ar -tv libknlopt.a | grep -c kcsm.o
ar -tv libknlopt.a | grep -c jox.o
ar -tv libknlopt.a | grep -c kzlilbac.o
ar -tv libknlopt.a | grep -c kzvidv.o
Short Name
ASM
DM
DV
OLAP
OLS
PART
RAC
RAT
Option
dm
dv
olap
lbac
partitioning
rat
SELECT
a.ksppinm Param ,
b.ksppstvl SessionVal ,
c.ksppstvl InstanceVal,
a.ksppdesc Descr
FROM
x$ksppi a , create or replace view all_parameters
x$ksppcv b , as
x$ksppsv c select x.ksppinm name, y.ksppstvl value
WHERE from x$ksppi
select name, value from sys.V$PARAMETER where name like '\_%' escape '\' andxISDEFAULT='FALSE';
, x$ksppcv y
a.indx = b.indx AND where x.indx = y.indx
a.indx = c.indx AND order by x.ksppinm
a.ksppinm LIKE '/_adg%' escape '/' /
ORDER BY grant select on all_parameters to public;
1 create public synonym all_parameters
/ for all_parameters;
Total Pages
Solaris Marked Corrupt-kv: 0
--> /usr/bin/isainfo cd $ORACLE_HOME/bin
Linux --> uname -m file oracl*
Total Pages Influx :0
Automating dbv
http://www.oracle.com/technetwork/articles/saternos-tables-090560.html
http://dbaoracletips.blogspot.com/2011/11/how-to-dropcreate-database-link-from.html
http://www.orafaq.com/wiki/ChangePerm_sh
948061.1
General All
ar -tv libknlopt.a
kfon.o
dmwdm.o
kzvidv.o
xsyeolap.o
kzlilbac.o
kkpoban.o
kcsm.o
kecwr.o
Database Option ON
Partitioning part_on
rg/reference/sys_context.html
OFF
dm_of
dmse_of
dv_of
lbac_of
part_of
rac_of
sdo_of
rat_of
olap_of
asm_of
ctx_of
Pwd verify function extract password
Wallet
--ORA-28365: wallet is not open
Auditing
audited privileges
CREATE statement
disable
enable
Wallet status
http://orafaq.com/node/58
http://www.soonerorlater.hu/index.khtml?article_id=513
http://www.petefinnigan.com/weblog/archives/00001103.htm
set serveroutput on
declare
db_link_password varchar2(500);
begin
db_link_password :=
'06D05F5E36F13A08FD3C5FE489EB89B094701C114FF156A92D84A5724EF5FC2BA4F25BF
BE99146C22075BEF3012D0F9DC6231FBD1A5EFBFA97DCD8FD13737243992EA16AD5A23
B7DC823346DEB4CD69FE6F20B3F15821FEFF9F44430EE40C78CAEE37DF25F25C2BEDE
D1DD2A61C72351E462BF1B844B2599E5125AE0135EAF7';
https://oraganism.wordpress.com/2009/10/06/spoofing-vsession-osuser/
Connect to container and check whether WALLET is OPEN or not ? If it is in OPEN state then
connect to PDB and check the same
--ORA-28365: wallet is not open
select status from v$encryption_wallet;
If the wallet is closed at Contaner DB then OPEN it using below command (run in container):
If the WALLET IS OPENED in container but CLOSED in PDB level, then run below at container
level
set linesize 155
ADMINISTER
col time for a15KEY MANAGEMENT SET KEYSTORE close IDENTIFIED BY abc123
container=all;
col parameter_name format a50
ADMINISTER
col KEY MANAGEMENT
old_value format a30 SET KEYSTORE open IDENTIFIED BY abc123
container=all;
col new_value format a30
break on instance skip 3
Now
selectcheck the wallet status
instance_number at Container
instance, and
snap_id, PBD
time, level:
parameter_name, old_value, new_value from (
select status from v$encryption_wallet;
a.snap_id,to_char(end_interval_time,'DD-MON-YY HH24:MI') TIME, a.instance_number,
parameter_name, value new_value,
lag(parameter_name,1) over (partition by parameter_name, a.instance_number order by
a.snap_id) old_pname,
lag(value,1) over (partition by parameter_name, a.instance_number order by a.snap_id)
old_value ,
decode(substr(parameter_name,1,2),'__',2,1) calc_flag
from dba_hist_parameter a, dba_Hist_snapshot b , v$instance v
where a.snap_id=b.snap_id
and a.instance_number=b.instance_number
and parameter_name like nvl('¶meter_name',parameter_name)
and a.instance_number like nvl('&instance_number',v.instance_number)
)
where
new_value != old_value
and calc_flag not in (decode('&show_calculated','Y',3,2))
order by 1,2
/
http://www.tek-tips.com/viewthread.cfm?qid=1605767
http://www.idevelopment.info/data/Unix/Linux/LINUX_CryptCommand.shtml
http://blog.tanelpoder.com/2009/02/07/when-was-a-table-last-changed/
select INSERTS,UPDATES,DELETES,TABLE_NAME,to_char(TIMESTAMP,'DD-MM-YY
HH24:MI') from dba_tab_modifications where table_owner not like '%SYS%' order by
TIMESTAMP desc;
but for the above statement the table level monitoring should be enabled
http://blog.tanelpoder.com/2009/02/07/when-was-a-table-last-changed/
http://oradb-srv.wlv.ac.uk/E16655_01/server.121/e17608/dvdisabl.htm
SELECT PARAMETER, VALUE FROM V$OPTION WHERE PARAMETER = 'Oracle Database Vault';
EXEC DVSYS.DBMS_MACADM.DISABLE_DV;
EXEC DVSYS.DBMS_MACADM.ENABLE_DV;
SELECT VALUE FROM V$OPTION WHERE PARAMETER = 'Oracle Label Security';
EXEC LBACSYS.CONFIGURE_OLS;
EXEC LBACSYS.OLS_ENFORCEMENT.ENABLE_OLS;
set lines 750 pages 9999
col WRL_PARAMETER for a50
select INST_ID,WRL_TYPE,WRL_PARAMETER,STATUS,WALLET_TYPE from
gv$encryption_wallet;
https://taliphakanozturken.wordpress.com/2012/06/12/the-backdoor-entry-to-oracle-database/
http://murty4all.blogspot.ch/2013/11/decrypting-oracle-database-db-link_29.html
elseadminister key management set keystore close;https://blog.dbi-services.com/encryption-in-oracle-public-cloud/
Database Vault';
Oracle Label security must be enabled before you can use Database Vault. If it is not enabled, then this q
restart required
If it is not enabled, then this query returns FALSE.
tools
oswatcher gui
getting input
reset the input value
DECLARE
L_n NUMBER;
BEGIN
WHILE (TRUE)
LOOP
L_ n:= dbms_random.random();
END LOOP;
END;
/
Oracle
Root
run as root
./tfactl diagcollect -database mydb -from "Nov/16/2017 21:00:00" -to "Nov/17/2017 02:00:00"
start of line
------------------ place ur mouse at the start of the
ctrl + H, select "regular expression " in search mode , first line in ur list.
find with ^ Press Alt + "C"
replace with ' A window gets opened. Enter the
END OF LINE text that u want to add under
----------------- "Text to Insert" and press OK.
ctrl + H, select "regular expression " in search mode , Apply the same procedure for
find with $ adding text at the end of all the
replace with ', lines. https://stackoverflow.com/ques
-level-drilldown-into-sql-response-time/
https://blog.dbi-services.com/oracle-11g-instance-caging-limit-database-cpu-consumption/
$GI_HOME/bin/diagcollection.pl --collect --chmos
--incidenttime 11/04/201702:00:00 --incidentduration 02:00
This will trim and collect all key diagnostics for the past 12
hours.
tfactl diagcollect
(Or) $TFA_HOME/bin/tfactl diagcollect -srdc dbperf TFA Collector - TFA with Database Support Tools Bundle (Doc ID
se Support Tools Bundle (Doc ID 1513912.1)
Oracle Hacking
Monitoring scripts
RAC
optimizer Magic
http://www.scribd.com/doc/2966777/oracle-cheat-SQLPlus-Commands
http://www.oracle-base.com/articles/10g/SQLTrace10046TrcsessAndTkprof10g.php
http://www.blacksheepnetworks.com/security/resources/www.think-forward.com/sqltips.htm
http://www.colestock.com/blogs/labels/Monitoring.html
http://allr1.blackapplehost.com/
http://goodies.dale-emmons.com/Documentation/books/Oracle/
http://search.4shared.com/q/10/oracle%2011g
http://www.slideshare.net/karlarao/performance-scenario-diagnosing-and-resolving-sudden-slow-down-on-two-node-rac
http://www.morganslibrary.com/reference/rac.html
http://yong321.freeshell.org/oranotes/DbParam_CompTimeConst_Map.txt
http://www.perfvision.com/papers.php
http://beginner-sql-tutorial.com/sql-query-tuning.htm
http://sql-tuning.com/oracle-sql-performance-tuning/
https://gavinsoorma.com/2012/11/ash-and-awr-performance-tuning-scripts/
http://dbaclass.com/article/change-the-execution-plan-without-changing-the-sql-query/
http://guyharrison.squarespace.com/opsgsamples/
http://optimizermagic.blogspot.com/
https://coskan.wordpress.com/2011/02/14/plan-stability-through-upgrade-why-is-my-plan-changed-bugfixes-1/
http://www.nocoug.org/download/2008-08/a-tour-of-the-awr-tables.nocoug-Aug-21-2008.abercrombie.html#script-aas-exact
https://blog.tanelpoder.com/2009/05/26/scripts-for-showing-execution-plans-via-plain-sql-and-also-in-oracle-9i/
http://www.williamrobertson.net/documents/index-code.shtml
https://mjsoracleblog.wordpress.com/2012/12/31/sql_sql_id-sql-1-7/
10046_events.pl
Super
Scenarios
Database FULL DB
Database FULL DB
Multiple Schema
Database FULL DB
Database FULL DB
scp algorithm
exclude Table
Exclude Common
Remap Schema
Remap Tablespace
Remap Table
TABLE_EXISTS_ACTION
12c
expdp in Background
exclude=table:"IN('TABLE1','TABLE2','TABLE3')" http://www.acehints.com/2012/11
exclude=TABLE:"LIKE 'EXAM%'"
exclude=TABLES:">'F'"
exclude=SEQUENCE,PROCEDURES,INDEXES,TABLES:"IN ('EMP1','DEPT')"
REMAP_SCHEMA=SCHEMA1:DUPSCHEMA2
TABLE_EXISTS_ACTION=SKIP
Same Schema
remap_table=emp:emp_bkup
different schema
REMAP_SCHEMA=SCHEMA1:DUPSCHEMA2
remap_table=emp:emp_bkup
TRANSFORM=DISABLE_ARCHIVE_LOGGING:Y
SELECT tablespace_name,
SUM (bytes) / (1024 * 1024) "FREE(MB)"
FROM dba_free_space where
tablespace_name=UPPER('&TABLESPACE_NAME')
GROUP BY tablespace_name;
http://www.acehints.com/2012/11/data-pump-impdp-remaptable-option-to.html
Issue
ADR Different Methods to Create IPS Package (Doc ID )
Quick Steps for ADRCI
ORA-04031: troubleshoot Tool
XDB Component has INVALID
SRDC - How to Collect Standard Information for a SQL Performance Problem
TFA Collector - TFA with Database Support Tools Bundle
ID
411.1
443529.1
559339.1
1552438.1
1594386.1
1513912.1