笔记,笔记。
-----数据库操作
--监控当前数据库连接数;
select count(*)
from v$session
where status = 'ACTIVE'
and username = 'xxxx';
---查看当前SQL执行时间
SELECT sid "SID",
ELAPSED_SECONDS "秒 已经执行",
TIME_REMAINING "秒 预计完成时间",
jindu "进度",SQL_TEXT
FROM (SELECT A.USERNAME,
A.SID,
A.SERIAL#,
A.OPNAME,
a.TARGET,
a.START_TIME,
a.last_update_time,
C.OSUSER,
C.MACHINE,
C.PROGRAM,
ROUND(A.SOFAR * 100 / TOTALWORK, 0) || '%' AS jindu,
A.TIME_REMAINING,
a.ELAPSED_SECONDS,
B.SQL_TEXT
FROM gV$SESSION_LONGOPS A, gV$SQL B, gV$SESSION C
WHERE A.SQL_ADDRESS = B.ADDRESS
AND A.SQL_HASH_VALUE = B.HASH_VALUE
AND A.SID = C.SID
AND C.STATUS = 'ACTIVE'
-- AND a.ELAPSED_SECONDS > 1
--AND a.last_update_time BETWEEN TRUNC (SYSDATE) + 9 / 24
-- AND TRUNC (SYSDATE) + 21 / 24
)
WHERE jindu != '100%';
--查找当前正在执行的SQL语句;
select a.program, b.spid, c.sql_text,c.SQL_ID
from v$session a, v$process b, v$sqlarea c
where a.paddr = b.addr
and a.sql_hash_value = c.hash_value
and a.username is not null;
----查询Oracle正在执行的sql语句及执行该语句的用户
SELECT b.sid oracleID,
b.username 登录Oracle用户名,
b.serial#,
spid 操作系统ID,
paddr,
sql_text 正在执行的SQL,
b.machine 计算机名
FROM v$process a, v$session b, v$sqlarea c
WHERE a.addr = b.paddr
AND b.sql_hash_value = c.hash_value
--查出oracle当前的被锁对象
SELECT l.session_id sid,
s.serial#,
l.locked_mode 锁模式,
l.oracle_username 登录用户,
l.os_user_name 登录机器用户名,
s.machine 机器名,
s.terminal 终端用户名,
o.object_name 被锁对象名,
s.logon_time 登录数据库时间
FROM v$locked_object l, all_objects o, v$session s
WHERE l.object_id = o.object_id
AND l.session_id = s.sid
ORDER BY sid, s.serial#;
--查看被锁的表
SELECT P.SPID,
A.SERIAL#,
C.OBJECT_NAME,
B.SESSION_ID,
B.ORACLE_USERNAME,
B.OS_USER_NAME
FROM V$PROCESS P, V$SESSION A, V$LOCKED_OBJECT B, ALL_OBJECTS C
WHERE P.ADDR = A.PADDR
AND A.PROCESS = B.PROCESS
AND C.OBJECT_ID = B.OBJECT_ID;
--查看数据库引起锁表的SQL语句:
SELECT A.USERNAME,
A.MACHINE,
A.PROGRAM,
A.SID,
A.SERIAL#,
A.STATUS,
C.PIECE,
C.SQL_TEXT,
c.SQL_ID
FROM V$SESSION A, V$SQLTEXT C
WHERE A.SID IN (SELECT DISTINCT T2.SID
FROM V$LOCKED_OBJECT T1, V$SESSION T2
WHERE T1.SESSION_ID = T2.SID)
AND A.SQL_ADDRESS = C.ADDRESS(+)
ORDER BY C.PIECE;
--杀掉进程
--'SID,SERIAL#';
ALTER SYSTEM KILL SESSION '16197,30839';
--去除换行
update tablename set col = replace(col,ch