12c的两个监控session脚本
Posted renfengjun
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了12c的两个监控session脚本相关的知识,希望对你有一定的参考价值。
集群
这里注意QWERTY是密码需要自己填写
SCANADDR需要自己根据自己集群的scan命名规则填写,或者直接填写定植
root@cube:/scripts# cat 12cRACsession.sh
#!/usr/bin/bash
OLDPATH=
P
A
T
H
e
x
p
o
r
t
P
A
T
H
=
PATH export PATH=
PATHexportPATH=PATH:/usr/local/bin
SCRIPTDIR=/oracle/src/scripts/monitoring
SCANADDR=$(hostname | awk -F- 'print $1"-"$2"-"KaTeX parse error: Expected 'EOF', got '' at position 9: 3"-scan"̲') QWERTY=xxxxx…(ps -eaf | grep -i smon | cut -d_ -f3 | grep +)
#Use ORAENV_ASK set to NO to prevent prompting, but instead use the SID value set above
ORAENV_ASK=NO
. oraenv
function DBUNIQ_Selection
#echo function DBUNIQ_Selectioon
clear
ARRAY=
(
s
r
v
c
t
l
c
o
n
f
i
g
d
a
t
a
b
a
s
e
∣
g
r
e
p
−
v
A
S
)
e
c
h
o
"
h
e
l
l
o
w
o
r
l
d
"
E
L
E
M
E
N
T
S
=
(srvctl config database|grep -v AS) echo "helloworld" ELEMENTS=
(srvctlconfigdatabase∣grep−vAS)echo"helloworld"ELEMENTS=#ARRAY[@]
echo -e “\\vPlease select the Database you wish to use”
echo “=========================================”
select DBU in $(echo $ARRAY[@])
do
echo
D
B
U
i
f
[
‘
e
c
h
o
"
X
"
DBU if [ `echo "X"
DBUif[‘echo"X"DBU` == “X” ]
then
echo "Invalid Selection "
exit 0 ;
fi
insid=$DBU
clear
break
done
clear
return 0
DBUNIQ_Selection
echo -e “SID of database session to fetch full details:” “\\c”
read sid
if [ $sid ]
then
sqlplus -s sys/" Q W E R T Y " @ QWERTY"@ QWERTY"@SCANADDR: P O R T / PORT/ PORT/insid as sysdba <<DOIT
column end newline;
set head off
set lines 2000
set head off
select
‘SID :’ || S1.sid end,
‘CON_NAME :’ || (select name from v$pdbs where con_id=s1.con_id) end,
‘Username :’ || s1.username end,
‘App Machine :’ || s1.machine end,
‘Serial number :’ || s1.serial# end,
‘Current Status :’ || s1.status end,
‘SQL ID current :’ || s1.sql_id end,
‘Previous SQL ID :’ || s1.prev_sql_id end,
‘KCML Partition No :’ || s1.module end,
‘Program name :’ || s1.program end,
‘Client Information :’ || s1.client_info end
from v$session s1
where s1.sid=$sid;
set serveroutput on
set feedback off
BEGIN
DBMS_OUTPUT.PUT_LINE(‘Current SQL TEXT :’);
END;
/
set feedback on
select
s3.sql_text end
from v$sql s3,v$session s1 where s1.sql_id = s3.sql_id and
s1.sid=$sid;
set serveroutput on
set feedback off
BEGIN
DBMS_OUTPUT.PUT_LINE(‘Previous SQL TEXT :’);
END;
/
select
s4.sql_text end
from v$sql s4,v$session s1 where s1.prev_sql_id = s4.sql_id and
s1.sid=$sid;
exit
DOIT
fi
单机
差不多一样的东西
root@cube:/scripts# cat 12csession.sh
#!/usr/bin/bash
OLDPATH=
P
A
T
H
e
x
p
o
r
t
P
A
T
H
=
PATH export PATH=
PATHexportPATH=PATH:/usr/local/bin
SCRIPTDIR=/oracle/src/scripts/monitoring
ORACLE_SID=$(ps -eaf | grep -i smon | cut -d_ -f3 | grep -v -)
#Use ORAENV_ASK set to NO to prevent prompting, but instead use the SID value set above
ORAENV_ASK=NO
. oraenv
function DBUNIQ_Selection
#echo function DBUNIQ_Selectioon
clear
ARRAY=
(
s
r
v
c
t
l
c
o
n
f
i
g
d
a
t
a
b
a
s
e
∣
g
r
e
p
:
N
/
e
t
c
/
o
r
a
t
a
b
∣
c
u
t
−
d
:
−
f
1
)
e
c
h
o
"
h
e
l
l
o
w
o
r
l
d
"
E
L
E
M
E
N
T
S
=
(srvctl config database|grep :N /etc/oratab | cut -d: -f1) echo "helloworld" ELEMENTS=
(srvctlconfigdatabase∣grep:N/etc/oratab∣cut−d:−f1)echo"helloworld"ELEMENTS=#ARRAY[@]
echo -e “\\vPlease select the Database you wish to use”
echo “=========================================”
select DBU in $(echo $ARRAY[@])
do
echo
D
B
U
i
f
[
‘
e
c
h
o
"
X
"
DBU if [ `echo "X"
DBUif[‘echo"X"DBU` == “X” ]
then
echo "Invalid Selection "
exit 0 ;
fi
insid=$DBU
clear
break
done
clear
return 0
DBUNIQ_Selection
echo -e “SID of database session to fetch full details:” “\\c”
read sid
if [ $sid ]
then
sqlplus -s / as sysdba <<DOIT
column end newline;
set head off
set lines 2000
set head off
select
‘SID :’ || S1.sid end,
‘CON_NAME :’ || (select name from v$pdbs where con_id=s1.con_id) end,
‘Username :’ || s1.username end,
‘App Machine :’ || s1.machine end,
‘Serial number :’ || s1.serial# end,
‘Current Status :’ || s1.status end,
‘SQL ID current :’ || s1.sql_id end,
‘Previous SQL ID :’ || s1.prev_sql_id end,
‘KCML Partition No :’ || s1.module end,
‘Program name :’ || s1.program end,
‘Client Information :’ || s1.client_info end
from v$session s1
where s1.sid=$sid;
set serveroutput on
set feedback off
BEGIN
DBMS_OUTPUT.PUT_LINE(‘Current SQL TEXT :’);
END;
/
set feedback on
select
s3.sql_text end
from v$sql s3,v$session s1 where s1.sql_id = s3.sql_id and
s1.sid=$sid;
set serveroutput on
set feedback off
BEGIN
DBMS_OUTPUT.PUT_LINE(‘Previous SQL TEXT :’);
END;
/
select
s4.sql_text end
from v$sql s4,v$session s1 where s1.prev_sql_id = s4.sql_id and
s1.sid=$sid;
exit
DOIT
fi
效果嘛就自己尝试吧。
以上是关于12c的两个监控session脚本的主要内容,如果未能解决你的问题,请参考以下文章
分享一个前两天写的自动监控blocking 的脚本(基于12C)