Oracle中开启并行和相关查询

1、并行相关资料整理:

官方参考:VLDB and Partitioning Guide ->How Parallel Execution Works

2、查询并行执行情况:

1)与并行查询相关的数据字典视图

v$px_session|V$pq_sesstat|v$px_process|v$px_sysstat|v$px_process_sysstat v$session column pdml_status,pq_status
ps -ef | grep oracle 

2)top 在系统中可以看到以p开头的进程名字

3)查询脚本

col username for a12
col "QC SID" for A6
col "SID" for A6
col "QC/Slave" for A8
col "Req. DOP" for 9999
col "Actual DOP" for 9999
col "Slaveset" for A8
col "Slave INST" for A9
col "QC INST" for A6
set pages 300 lines 300
col wait_event format a30
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 sw.sid = s.sid  
and sw.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
/


set pages 300 lines 300
col "Username" for a12
col "QC/Slave" for A8
col "Slaveset" for A8
col "Slave INST" for A9
col "QC SID" for A6
col "QC INST" for A6
col "operation_name" for A30
col "target" for A30

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
/ 

3、使用并行

启用并行:

alter table table_name parallel 4; --强制为4个并发也可以更多。
alter table table_name parallel;   --让系统自己动态的调整。

使用提示

SELECT /*+ PARALLEL(a 4),(b 4)*/ a.msisdn_id,b.copyright_id,FROM musicdw.user_list partition(p1) a JOIN musicdw.song_list b ON 1 = 1;

修改session

alter session enable parallel dml;
alter session enable parallel query;
或者
ALTER SESSION FORCE PARALLEL DML PARALLEL 5;
ALTER SESSION FORCE PARALLEL QUERY PARALLEL 5;

若要诊断并行问题:

alter session set "_px_trace"="low","compilation","low","execution","low","messaging";
alter session set events '10053 trace name context forever,level 1';
ALTER SESSION FORCE PARALLEL DML PARALLEL 5;
ALTER SESSION FORCE PARALLEL QUERY PARALLEL 5;

rac系统中设定并行数量,或者把并行设定在一个节点上

PARALLEL_INSTANCE_GROUP

猜你喜欢

转载自blog.csdn.net/u010033674/article/details/107721811