【转】Oracle Parallel 多线程
对于一个大的任务,一般的做法是利用一个进程,串行的执行,如果系统资源足够,可以采用parallel技术,把一个大的任务分成若干个小的任务,同时启用n个进程/线程,并行的处理这些小的任务,这些并发的进程称为并行执行服务器(parallel executeion? server )
对于一个大的任务,一般的做法是利用一个进程,串行的执行,如果系统资源足够,可以采用parallel技术,把一个大的任务分成若干个小的任务,同时启用n个进程/线程,并行的处理这些小的任务,这些并发的进程称为并行执行服务器(parallel executeion?server),这些并发进程由一个称为并发协调进程的进程来管理。
启用Parallel前的忠告:只有在需要处理一个很大的任务,如需要几十分钟,几个小时的作业中,并且要有足够的系统资源的情况下(这些资源包括cpu,内存,io),您才应该考虑使用parallel。否则,在一个多并发用户下,系统本身资源负担已经很大的情况下,启用parallel,将会导致某一个会话试图占用了所有的资源,其他会话不得不去等待,从而导致系统系能反而下降的情况,一般情况下,oltp系统不要使用parallel,oltp系统中可以考虑去使用。
Parallel分类
l??并行查询parallel query
l??并行dml parallel dml pdml
l??并行ddl parallel ddl pddl
一、 并行查询
并行查询允许将一个sql?select语句划分为多个较小的查询,每个部分的查询并发地运行,然后将各个部分的结果组合起来,提供最终的结果,多用于全表扫描,索引全扫描等,大表的扫描和连接、创建大的索引、分区索引扫描、大批量插入更新和删除
1.??? 启用并行查询
SQL> ALTER TABLE T1 PARALLEL;
告知oracle,对T1启用parallel查询,但并行度要参照系统的资源负载状况来确定。
利用hints提示,启用并行,同时也可以告知明确的并行度,否则oracle自行决定启用的并行度,这些提示只对该sql语句有效。
SQL> select /*+ parallel(t1 8) */ count(*)from t1;
SQL> select degree from user_tables?where?table_name=’T1′;
DEGREE
——————–
??DEFAULT
并行度为Default,其值由下面2个参数决定
SQL> show parameter cpu
NAME????????????????????????????????TYPE???????VALUE
———————————————– ——————————
cpu_count???????????????????????????integer????2
parallel_threads_per_cpu????????????integer????2
cpu_count表示cpu数
parallel_threads_per_cpu表示每个cpu允许的并行进程数
default情况下,并行数为cpu_count*parallel_threads_per_cpu
2.??? 取消并行设置
SQL> alter table t1 noparallel;
SQL> select degree from user_tables wheretable_name=’T1′;
DEGREE
—————————————-
????????1
3.??? 数据字典视图
v$px_session
sid:各个并行会话的sid
qcsid:query coordinator sid,查询协调器sid
二、 并行dml
并行dml包括insert,update,delete,merge,在pdml期间,oracle可以使用多个并行执行服务器来执行insert,update,delete,merge,多个会话同时执行,同时每个会话(并发进程)都有自己的undo段,都是独立的一个事务,这些事务要么由pdml协调器进程提交,要么都rollback。
在一个有充足I/o带宽的多cpu主机中,对于大规模的dml,速度可能会有很大的提升,尤其是在大型的数据仓库环境中。
并行dml需要显示的启用
SQL> alter session enable parallel dml;
Disable并行dml
SQL> alter session disable parallel dml;
三、 并行ddl
并行ddl提供了dba使用全部机器资源的能力,常用的pddl有
create table as select?……
create index
alter index rebuild
alter table move
alter table split
在这些sql语句后面加上parallel子句
例
SQL> alter table t1 move parallel;
Table altered
SQL> create index T1_IDX on T1 (OWNER,OBJECT_TYPE)
?2???tablespace SYSTEM
3????????parallel;
4????????;
1. 用途 强行启用并行度来执行当前SQL。这个在Oracle 9i之后的版本可以使用,之前的版本现在没有环境进行测试。也就是说,加上这个说明,可以强行启用Oracle的多线程处理功能。举例的话,就像电脑装了多核的CPU,但大多情况下都不会完全多核同时启用(2核以上的比较明显),使用parallel说明,就会多核同时工作,来提高效率。 但本身启动这个功能,也是要消耗资源与性能的。所有,一般都会在返回记录数大于100万时使用,效果也会比较明显。 2. 语法 /*+parallel(table_short_name,cash_number)*/ 这个可以加到insert、delete、update、select的后面来使用(和rule的用法差不多,有机会再分享rule的用法) 开启parallel功能的语句是: alter session enable parallel dml; 这个语句是DML语句哦,如果在程序中用,用execute的方法打开。 3. 实例说明 用ERP中的transaction来说明下吧。这个table记录了所有的transaction,而且每天数据量也算相对比较大的(根据企业自身业务量而定)。假设我们现在要查看对比去年一年当中每月的进、销情况,所以,一般都会写成: select to_char(transaction_date,'yyyymm') txn_month, sum( decode( sign(transaction_quantity),1,transaction_quantity,0 ) ) in_qty, sum( decode( sign(transaction_quantity),-1,transaction_quantity,0 ) ) out_qty from mtl_material_transactions mmt where transaction_date >= add_months( to_date( to_char(sysdate,'yyyy')||'0101','yyyymmdd'), -12) and transaction_date <p class="copyright"> 原文地址:【转】Oracle Parallel 多线程, 感谢原作者分享。 </p>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

Oracle database paging uses ROWNUM pseudo-columns or FETCH statements to implement: ROWNUM pseudo-columns are used to filter results by row numbers and are suitable for complex queries. The FETCH statement is used to get the specified number of first rows and is suitable for simple queries.

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

Oracle garbled problems can be solved by checking the database character set to ensure they match the data. Set the client character set to match the database. Convert data or modify column character sets to match database character sets. Use Unicode character sets and avoid multibyte character sets. Check that the language settings of the database and client are correct.
