您现在的位置是:亿华云 > 应用开发

详解Oracle数据库并行操作常见等待事件及脚本

亿华云2025-10-03 02:55:14【应用开发】6人已围观

简介今天主要介绍Oracle数据库在并行操作过程中 slave 进程和 QC 进程经常遇到的等待事件及常用脚本。一、PX Deq: Execution Msg,PX Deq: Execute Reply等

今天主要介绍Oracle数据库在并行操作过程中 slave 进程和 QC 进程经常遇到的详解行操等待事件及常用脚本。

一、数据PX Deq: Execution Msg,库并PX Deq: Execute Reply等待事件

1. PX Deq: Execution Msg

Occurs when a parallel slave is 作常waiting to be told what to do. This is normally considered an idle event, but can cause excessive CPU in some cases.

该事件是并行查询中的常见事件。当PQ slave进程在等待QC告诉它要做什么的见等件及脚本时候就会出现此事件(eg: when waiting to be told parse / execute / fetch etc..)

v$session_wait 中该等待事件对应的参数:

P1 = sleeptime/senderid P2 = passes P3 = not used

我们可以使用如下语句获取转换sleeptime/senderid的相关信息:

set SERVEROUTPUT on undef p1 declare  inst varchar(20);  sender varchar(20); begin  select bitand(&&p1, 16711680) - 65535 as SNDRINST,  decode(bitand(&&p1, 65535),65535, QC, P||to_char(bitand(&&p1, 65535),fm000) ) as SNDR  into inst , sender  from dual  where bitand(&&p1, 268435456) = 268435456;  dbms_output.put_line(Instance = ||inst);  dbms_output.put_line(Sender = ||sender ); end; /

如果P1的值为空,则意味slave 不需要等待任何进程

比如p1的待事值为268501004,则上面的详解行操sql会返回:

Instance = 1  Sender = P012 

passes 进程在得到信息之前循环轮转等待的次数

该等待事件是一个空闲等待事件,网站模板当此等待事件出现,数据进程会持续等待并逐渐增加等待次数直到获取信息!

解决方法:

作为 Coordinator 的 Process 在获取 Slave 进程的数据时,反应太慢了,库并导致某些 Slave进行因为 Queue 满而不得不等待,作常进而拖慢了整个并行执行的见等件及脚本速度。

这常常是待事由于 CPU 数目不足或者 系统中运行的 进程太多导致。可考虑 减小并行度。详解行操

2. PX Deq: Execute Reply

Occurs when the query coordinator is 数据waiting for a response from a parallel slave. This is normally considered an idle event, but can cause excessive CPU in some cases.

Waiting Process: QC

协调器正在等待一个 从slaves 进程对控制信息的响应(确认通知)或者期望从slave进程集中获取数据。这个等待事件意味着QC等待slaves结束执行sql 并且将结果集发送给QC

v$session_wait 中该等待事件对应的库并参数:

P1 = sleeptime/senderid P2 = passes P3 = not used

我们可以使用如下语句获取转换sleeptime/senderid的相关信息:

set SERVEROUTPUT on undef p1 declare  inst varchar(20);  sender varchar(20); begin  select bitand(&&p1, 16711680) - 65535 as SNDRINST,  decode(bitand(&&p1, 65535),65535, QC, P||to_char(bitand(&&p1, 65535),fm000) ) as SNDR  into inst , sender  from dual  where bitand(&&p1, 268435456) = 268435456;  dbms_output.put_line(Instance = ||inst);  dbms_output.put_line(Sender = ||sender ); end; /

如果P1的值为空,服务器租用则意味slave 不需要等待任何进程

比如p1的值为268501004,则上面的sql会返回:

Instance = 1 Sender = P012 

等待时间:这是非空闲等待时间,QC 等待从slave 的响应或者查询的数据结果

解决办法:非优化的sql语句肯能是导致此等待事件的原因:slaves 需要花费很长时间来执行sql 语句而qc又在等待slave返回数据。

优化sql,查看slave 在执行的语句以及其执行计划,并做出尽量的优化,以便减少slave执行sql语句的时间!

二、站群服务器相关脚本

1. gives an overview of all running parallel queries with all slaves.It shows the if a slave is waiting and for what event it waits.

select decode(px.qcinst_id,  NULL,  username,   -  ||  lower(substr(pp.SERVER_NAME, length(pp.SERVER_NAME) - 4, 4))) "Username",  decode(px.qcinst_id, NULL, QC, (Slave)) "QC/Slave",  to_char(px.server_set) "SlaveSet",  to_char(s.sid) "SID",  to_char(px.inst_id) "Slave INST",  decode(sw.state, WAITING, WAIT, NOT WAIT) as STATE,  case sw.state  WHEN WAITING THEN  substr(sw.event, 1, 30)  ELSE  NULL  end as wait_event,  decode(px.qcinst_id, NULL, to_char(s.sid), px.qcsid) "QC SID",  to_char(px.qcinst_id) "QC INST",  px.req_degree "Req. DOP",  px.degree "Actual DOP"  from gv$px_session px, gv$session s, gv$px_process pp, gv$session_wait sw  where px.sid = s.sid(+)  and px.serial# = s.serial#(+)  and px.inst_id = s.inst_id(+)  and px.sid = pp.sid(+)  and px.serial# = pp.serial#(+)  and ssw.sid = s.sid  and ssw.inst_id = s.inst_id  order by decode(px.QCINST_ID, NULL, px.INST_ID, px.QCINST_ID),  px.QCSID,  decode(px.SERVER_GROUP, NULL, 0, px.SERVER_GROUP),  px.SERVER_SET,  px.INST_ID /

2. shows for the PX Deq events the processes that are exchange data.

select sw.SID as RCVSID,  decode(pp.server_name, NULL, A QC, pp.server_name) as RCVR,  sw.inst_id as RCVRINST,  case sw.state  WHEN WAITING THEN  substr(sw.event, 1, 30)  ELSE  NULL  end as wait_event,  decode(bitand(p1, 65535),  65535,  QC,  P || to_char(bitand(p1, 65535), fm000)) as SNDR,  bitand(p1, 16711680) - 65535 as SNDRINST,  decode(bitand(p1, 65535),  65535,  ps.qcsid,  (select sid  from gv$px_process  where server_name =  P || to_char(bitand(sw.p1, 65535), fm000)  and inst_id = bitand(sw.p1, 16711680) - 65535)) as SNDRSID,  decode(sw.state, WAITING, WAIT, NOT WAIT) as STATE  from gv$session_wait sw, gv$px_process pp, gv$px_session ps  where sw.sid = pp.sid(+)  and sw.inst_id = pp.inst_id(+)  and sw.sid = ps.sid(+)  and sw.inst_id = ps.inst_id(+)  and p1text = sleeptime/senderid  and bitand(p1, 268435456) = 268435456  order by decode(ps.QCINST_ID, NULL, ps.INST_ID, ps.QCINST_ID),  ps.QCSID,  decode(ps.SERVER_GROUP, NULL, 0, ps.SERVER_GROUP),  ps.SERVER_SET,  ps.INST_ID

3. shows for long running processes what are the slaves do.

select decode(px.qcinst_id,  NULL,  username,   -  ||  lower(substr(pp.SERVER_NAME, length(pp.SERVER_NAME) - 4, 4))) "Username",  decode(px.qcinst_id, NULL, QC, (Slave)) "QC/Slave",  to_char(px.server_set) "SlaveSet",  to_char(px.inst_id) "Slave INST",  substr(opname, 1, 30) operation_name,  substr(target, 1, 30) target,  sofar,  totalwork,  units,  start_time,  timestamp,  decode(px.qcinst_id, NULL, to_char(s.sid), px.qcsid) "QC SID",  to_char(px.qcinst_id) "QC INST"  from gv$px_session px, gv$px_process pp, gv$session_longops s  where px.sid = s.sid  and px.serial# = s.serial#  and px.inst_id = s.inst_id  and px.sid = pp.sid(+)  and px.serial# = pp.serial#(+)  order by decode(px.QCINST_ID, NULL, px.INST_ID, px.QCINST_ID),  px.QCSID,  decode(px.SERVER_GROUP, NULL, 0, px.SERVER_GROUP),  px.SERVER_SET,  px.INST_ID

很赞哦!(89996)