Oracle 查询连接/语句执行进度 sql
查询连接
SELECT object_name, machine, s.sid, s.serial#
FROM gv$locked_object l, dba_objects o, gv$session s
WHERE l.object_id= o.object_id
AND l.session_id = s.sid;
删除连接
ALTER system kill session 'sid, serial#';
查看导入导出信息
SELECT
FROM dba_datapump_jobs
where OPERATION = ‘IMPORT’;
select * from DBA_DATAPUMP_SESSIONS;
sql语句执行进度
SELECT SE.SID,
OPNAME,
TRUNC(SOFAR / TOTALWORK * 100, 2) || '%' AS PCT_WORK,
ELAPSED_SECONDS ELAPSED,
ROUND(ELAPSED_SECONDS * (TOTALWORK - SOFAR) / SOFAR) REMAIN_TIME,
SQL_TEXT
FROM V$SESSION_LONGOPS SL, V$SQLAREA SA, V$SESSION SE
WHERE SL.SQL_HASH_VALUE = SA.HASH_VALUE
AND SL.SID = SE.SID
AND SOFAR != TOTALWORK AND SOFAR>0
ORDER BY START_TIME;
--监控长任务的执行进度, 第一列为完成百分比,time_remaining--预计剩余时间(秒),elapsed_seconds -- 已执行时间(秒)
select ROUND(sofar/totalwork*100,2) "%_COMPLETE", time_remaining,elapsed_seconds, a.* from v$session_longops a WHERE totalwork != 0 AND sofar <> totalwork;
查看索引
select * from user_indexes where table_name=' ' ;
sql执行时间情况
SELECT
temp.*
FROM
(
SELECT
t.MODULE 进程,
t.PARSING_SCHEMA_NAME 用户,
t.EXECUTIONS 执行次数,
trunc ( t.CPU_TIME / 1000 / 1000 / t.EXECUTIONS, 5 ) 平均时间,
t.OPTIMIZER_MODE 优化方式,
t.SQL_TEXT SQL语句,
t.CPU_TIME / 1000 / 1000 CPU_TIME,
t.DISK_READS 读盘次数,
decode( t.COMMAND_TYPE, 3, 'select', 2, 'insert', 6, 'update', 7, 'delete', 'plsql' ) 命令类型,
t.SQL_FULLTEXT 完整SQL,
t.SHARABLE_MEM 占用sharedpool内存,
t.BUFFER_GETS 读取缓冲区的次数
FROM
V$SQLAREA t
WHERE
t.EXECUTIONS > 0
AND t.PARSING_USER_ID NOT IN ( 0, 51 )) temp
WHERE temp."用户"='C_CHERY_LNFP'
ORDER BY
temp.平均时间 DESC,
temp.执行次数 DESC;
常用Sql _ 查看表空间
SELECT
b.file_name 物理文件名,
b.tablespace_name 表空间,
b.bytes / 1024 / 1024 大小 M,
(
b.bytes - sum(
nvl ( a.bytes, 0 ))) / 1024 / 1024 已使用 M,
substr(( b.bytes - sum( nvl ( a.bytes, 0 ))) / ( b.bytes ) * 100, 1, 5 ) 利用率
FROM
dba_free_space a,
dba_data_files b
WHERE
a.file_id = b.file_id
GROUP BY
b.tablespace_name,
b.file_name,
b.bytes
ORDER BY
b.tablespace_name;
在oracle中执行sql文件
在oracle中,执行sql文件,可以写一个批处理文件
sqlplus scott/tiger@orcl @c:\example.sql
表空间使用情况
select f.tablespace_name,
d.file_name "tempfile name",
round((f.bytes_free + f.bytes_used) / 1024 /1024, 2) "total mb",
round(((f.bytes_free + f.bytes_used) -nvl(p.bytes_used, 0)) / 1024 / 1024, 2) "free mb" ,
round(nvl(p.bytes_used, 0)/ 1024 / 1024, 2)"used mb",
round((round(nvl(p.bytes_used, 0)/ 1024 /1024, 2)/round((f.bytes_free + f.bytes_used) / 1024 / 1024, 2))*100,2) as"used_rate(%)"
from sys.v_$temp_space_header f,dba_temp_files d, sys.v_$temp_extent_pool p
where f.tablespace_name(+) = d.tablespace_name
and f.file_id(+) = d.file_id
and p.file_id(+) =d.file_id;