SELECT
trx_id AS `事务ID`,
trx_state AS `事务状态`,
trx_requested_lock_id AS `事务需要等待的资源`,
trx_wait_started AS `事务开始等待时间`,
trx_tables_in_use AS `事务使用表`,
trx_tables_locked AS `事务拥有锁`,
trx_rows_locked AS `事务锁定行`,
trx_rows_modified AS `事务更改行`
FROM
information_schema.innodb_trx SELECT
lock_id AS `锁ID`,
lock_trx_id AS `拥有锁的事务ID`,
lock_mode AS `锁模式 `,
lock_type AS `锁类型`,
lock_table AS `被锁的表`,
lock_index AS `被锁的索引`,
lock_space AS `被锁的表空间号`,
lock_page AS `被锁的页号`,
lock_rec AS `被锁的记录号`,
lock_data AS `被锁的数据`
FROM
information_schema.innodb_locks
SELECT
requesting_trx_id AS `请求锁的事务ID`,
requested_lock_id AS `请求锁的锁ID`,
blocking_trx_id AS `当前拥有锁的事务ID`,
blocking_lock_id AS `当前拥有锁的锁ID`
FROM
innodb_lock_waits
转: oracle session通常具有三个特征: (1)一个session可能阻塞多个session; (2)一个session最多被一个session阻塞; (3)session阻塞关系不会形成环路。(环路即死锁,oracle能自动解除)因此session的阻塞关系为一棵树,进而DB系统所有session的BLOCK阻塞关系是一个由若干session阻塞关系树构成的森林,而异常session一定会在故障爆发时成为根(root)。 因此,找寻异常锁表session的过程就是找出异常的root。一般认为异常root有两个特征: (1)block树的规模过大,阻塞树规模即被root层层阻塞的session总数; (2)阻塞的平均等待时间过长。 查找异常session的方法一: OEM—>performance—>Blocking Sessions 查找异常session的方法二: select r.root_sid, s.serial#, r.blocked_num, r.avg_wait_seconds, s.username,s.status,s.event,s.MACHINE, s.PROGRAM,s.sql_id,s.prev_sql_id from (select root_sid, avg(seconds_in_wait) as avg_wait_seconds, count(*) - 1 as blocked_num from (select CONNECT_BY_ROOT sid as root_sid, seconds_in_wait from v$session start with blocking_session is null connect by prior sid = blocking_session) group by root_sid having count(*) >1) r, v$session s where r.root_sid = s.sid order by r.blocked_num desc, r.avg_wait_seconds desc该SQL语句即是根据v$session的字段blocking_session统计阻塞树根阻塞session的计数以及平均阻塞时间、并进行排序,排名最前的往往是异常session。打开全日志后可以看。打开的方法是:
1、5.0的版本
在配置文件的mysqld段中,增加
log=/var/log/mysql.log(或者其他的你想放日志的路径)
然后重启数据库
2、如果是5.1的版本
在配置文件的mysqld段中,增加
general_log_file=/var/log/mysql.log
然后重启数据库
5.1版本也可以不用重启,全局设置一下,方法是:
set global general_log=1
set global general_log_file=/var/log/mysql.log
打开日志后,查看未提交事务的方法为:
连接到数据库后,会分配一个连接id,然后追踪此连接id,找到此连接执行的所有sql,如果有begin,而没有commit,那么这个语句就是未提交的。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)