常见数据库会话查询脚本

(1)--SQLServer Sessionmaster.sys.sysprocesses

select t.spid, t.kpid, t.blocked, t.status, t.lastwaittype, t.waitresource, t.waittime

    , DB_NAME(t.dbid) DbName, t.last_batch, t.loginame, t.program_name, t.hostname, t.hostprocess

    , t.cmd, t.stmt_start, t.stmt_end, t.request_id, dc.text

from    master.sys.sysprocesses t 

    outer apply master.sys.dm_exec_sql_text(t.sql_handle) dc

where    t.spid >= 50

(2)----Oracle Sessionv$session

select se.inst_id, se.SID, se.SERIAL#, se.Status, se.Event,se.taddr,se.process, se.BLOCKING_SESSION, se.blocking_instance,se.BLOCKING_SESSION_STATUS

       , se.USERNAME, se.MACHINE, se.PROGRAM, se.sql_exec_start, se.seconds_in_wait     

       , NVL(s1.SQL_TEXT, s2.SQL_TEXT) AS sql_text

from gv$session se   

   left join gv$sql s1 on se.inst_id = s1.inst_id and se.SQL_ID = s1.SQL_ID and se.sql_child_number = s1.child_number   

   left join gv$sql s2 on se.inst_id = s2.inst_id and se.PREV_SQL_ID = s2.SQL_ID and se.prev_child_number = s2.child_number

where --se.status!=‘INACTIVE‘ and

--se.program=‘w3wp.exe‘

and se.program=‘JDBC Thin Client‘

order by se.blocking_session,se.sid;

--se.machine

(3)----pg sessionpg_stat_activity

select pid,array_to_string(pg_blocking_pids(pid),‘,‘) blocked,state,wait_event,wait_event_type,

                current_timestamp-query_start AS runtime,datname,

      usename,application_name,client_addr,client_port,query_start,query 

                from pg_stat_activity;

 

(4)----DM sessionV$SESSIONS

select

 SF_GET_EP_SEQNO(A.rowid),A.SESS_ID,A.SQL_TEXT,A.STATE,A.N_STMT,A.SEQ_NO,A.CURR_SCH,A.USER_NAME,A.TRX_ID,A.CREATE_TIME,A.CLNT_TYPE,A.TIME_ZONE,A.CHK_CONS,A.CHK_IDENT,

 A.RDONLY,A.INS_NULL,A.COMPILE_FLAG,A.AUTO_CMT,A.DDL_AUTOCMT,A.RS_FOR_QRY,A.CHK_NET,A.ISO_LEVEL,A.CLNT_HOST,A.APPNAME,A.OSNAME,A.CONN_TYPE,B.PROTOCOL_TYPE,B.IP_ADDR,

  A.CONNECTED,A.PORT_TYPE,A.SRC_SITE,A.MAL_ID

FROM SYS.V$SESSIONS A ,SYS.V$CONNECT B

where A.Sess_id= B.SADDR  ORDER BY SF_GET_EP_SEQNO(A.rowid),A.Sess_id

常见数据库会话查询脚本

上一篇:git clone 提示 fatal: unable to access OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443


下一篇:Python-MySql