设为首页 收藏本站
查看: 692|回复: 0

[经验分享] Oracle 11g PL/SQL and Java Automatic Native Compilation(原创)

[复制链接]

尚未签到

发表于 2016-8-5 17:47:28 | 显示全部楼层 |阅读模式
  PL/SQL and Java Automatic Native Compilation
Up until the Oracle Database 11g release, the database always transformed PL/SQL code to C code first before executing it. This meant you needed a third-party C compiler to execute the C code. In Oracle Database 11g, the database skips the C compiler by directly translating PL/SQL source code to DLL for the server. The feature is called PL/SQL native compilation. Oracle also performs the linking and delinking itself and bypasses the file system directories for doing that. Oracle claims that its test show performance improvements as large as two-fold, with the native compilation of PL/SQL.
  The really good news for DBAs is that it is extremely easy to take advantage of the native PL/SQL compilation capability. You simply set the appropriate value for the new initialization parameter plsql_code_type to turn automatic native PL/SQL compilation on, as the next section explains.
Using Real Native Compilation
Use the initialization parameter plsql_code_type to specify the compilation mode for PL/SQL library units. The parameter can take two values, interpreted and native.

  • INTERPRETED: PL/SQL library units will be compiled to PL/SQL bytecode format. Such modules are executed by the PL/SQL interpreter engine.
  • NATIVE: PL/SQL library units (with the possible exception of top-level anonymous PL/SQL blocks) will be compiled to native (machine) code. Such modules will be executed natively without incurring any interpreter overhead.
  Setting the value of this parameter to compiled produces the default behavior where the database compiles PL/SQL code first to a PL/SQL bytecode format using the C compiler. The PL/SQL interpreter engine then executes the bytecode. By setting the parameter to the value native, you let the database compile the PL/SQL code to machine code and execute it natively without the need for an interpreter. The database stores the DLLs it generates from the PL/SQL source code in the database catalog, from where the Oracle executable loads the code directly without first using a file system to stage them.
  When the value of this parameter is changed, it has no effect on PL/SQL library units that have already been compiled. The value of this parameter is stored persistently with each library unit.If a PL/SQL library unit is compiled native, all subsequent automatic recompilations of that library unit will use native compilation.
By default, the plsql_code_type parameter is set to the value interpreted, and you can turn native PL/SQL compilation on in the database by setting the plsql_code_type parameter to native, as shown here: plsql_code_type=native
You can check that the database is using the correct mode of PL/SQL compilation by issuing the following statement:
SQL> select name, value from v$parameter where
     name like '%plsql%;
NAME                          VALUE
---------------------     ------------
plsql_code_type            INTERPRETED
plsql_optimize_level       2
...
9 rows selected.
You can also use the alter system or alter session statements to change the value for the plsql_code_type parameter dynamically, without restarting the database. Any PL/SQL units that are already compiled won’t be affected by a change in the compilation mode. Also, even after you change the compilation mode, say from compiled to native, PL/SQL units that the database has already compiled will be recompiled in the original compilation mode.
Setting Up a PL/SQL Program Unit for Native Compilation
In order to set up a single PL/SQL program unit for native compilation, you must change the value of the plsql_code_type parameter to native from its default value of interpreted, by making the change and restarting the database or by using the alter system/session statement to change the value of the parameter. You can also issue the alter <PLSQL unit type> statement to enable native compilation for a single PL/SQL program unit. Let’s use a simple example that illustrates how to do this:
1.  First, create a simple procedure, called TEST_NATIVE.
SQL> create or replace procedure test_native as
  2   begin
  3   dbms_output.put_line('Test Procedure.');
  4*  end test_native;
SQL> /
Procedure created.
2. Check the current PL/SQL compilation mode by issuing the following statement:
SQL> select plsql_code_type
  2  from all_plsql_object_settings
  3  where name='TEST_NATIVE';
PLSQL_CODE_TYPE
----------------
INTERPRETED
The query shows that, currently, the procedure TEST_NATIVE is set for interpreted compiling and not native compilation.
3. Issue the following alter procedure statement to change the compilation mode to native for just the TEST_NATIVE procedure.
SQL> alter procedure test_native compile plsql_code_type=native;
Procedure altered.
4. Confirm that the procedure TEST_NATIVE will now use native compilation, by issuing the following query on the DBA_PLSQL_OBJECT_SETTINGS view:
SQL> select plsql_code_type
  2  from all_plsql_object_settings
  3* where name='TEST_NATIVE';
PLSQL_CODE_TYPE
---------------
NATIVE
The value of native for the PLSQL_CODE_TYPE column means that from here on, the database will use native compilation for the TEST_NATIVE procedure. Recompiling a Database for PL/SQL Native Compilation You can use the dbmsupgnv.sql script provided with Oracle Database 11g to recompile all the PL/SQL modules in the database to compile natively. Follow these steps to recompile all the PL/SQL modules:
1.Shut down the database using the shutdown normal or shutdown immediate commands.
SQL> shutdown immediate;
In the initialization parameter file, set the plsql_code_type parameter to native so it will allow native compilation. plsql_code_type=native
2. You must also check to ensure that the value of the plsql_optimize_level parameter is at least 2. The default value for this parameter is 2.plsql_optimize_level=3 Because the value of the plsql_optimize_level parameter is more than 2, you don’t have to change the setting of this parameter.
3. Start the database with the startup upgrade command, which you specify when upgrading to a new release of the Oracle database.
SQL> connect sys/sammyy1 as sysdba
Connected to an idle instance.
SQL> startup upgrade
ORACLE instance started.
...
Database opened.
4.After the database is opened in the upgrade mode, execute the script dbmsupgnv.sql, located in the $ORACLE_HOME/rdbms/admin directory.
SQL> @$ORACLE_HOME/rdbms/admin/dbmsupgnv.sql
OC>#########################################################
DOC>########################################################
DOC>   dbmsupgnv.sql completed successfully.
DOC> All PL/SQL procedures, functions, type bodies, triggers,
DOC> and type bodies objects in the database have been
DOC> invalidated and their settings set to native.
DOC>
DOC>   Shut down and restart the database in normal mode and
DOC>   run utlrp.sql to recompile invalid objects.
SQL>
When the dbmsupgnv.sql script completes executing, all PL/SQL procedures in the database are natively compiled.
5. Once the script finishes running, shut down the database and start it back up again. Run the utlrp.sql script located in the $ORACLE_HOME/rdbms/
admin directory to recompile the invalidated PL/SQL program units.
SQL> shutdown immediate;
SQL> startup
ORACLE instance started.
...
Database opened.
SQL> @$ORACLE_HOME/rdbms/admin/utlrp.sql
...
SQL> Rem END utlrp.sql
As a result of upgrading the database and compiling all PL/SQL units in the native mode, you don’t need to individually enable PL/SQL procedures for native compilation. You can always change the compilation mode back to the default value of interpreted by reversing the recompilation process shown here. You follow a procedure similar to the one shown here to compile all PL/SQL program units in the interpreted mode by running the script dbmsupgin.sql, also located in the $ORACLE_HOME/rdbms/admin directory.
  Java Native Compilation
  Oracle Database 11g uses the new initialization parameter java_jit_enabled to set the Java compilation mode. By default, the value of the java_jit_enabled initialization parameter is true, meaning Java native compilation is enabled in the database. As in the case of the PL/SQL native compilation, this feature allows the database to compile Java in the database natively without using a C compiler. Oracle claims that native compilation offers a 100 percent faster performance for both pure PL/SQL and Java code. Oracle’s Java native compilation is similar to that of the Java Development Kit and runs as an independent session in the server process that is transparent to the user. There’s only one compiler session per Oracle instance and the database stores the Java code for future recompilations. Java native compilation offers you the high performance of pure Java execution and is very easy to implement because you can enable it for the entire database, not merely when you actually execute the Java code in the database. The absence of a C compiler means you save on licensing and other costs involved in maintaining the compiler.
  
  参考至: 《McGraw.Hill.OCP.Oracle.Database.11g.New.Features.for.Administrators.Exam.Guide.Apr.2008》           
    http://docs.oracle.com/cd/E11882_01/server.112/e40402/initparams196.htm#REFRN10253本文原创,转载请注明出处、作者
  如有错误,欢迎指正
  邮箱:czmcj@163.com

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-253470-1-1.html 上篇帖子: [置顶] oracle本机访问局域网的其他电脑 下篇帖子: 本机oracle供局域网的其他电脑访问(转)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表