IBM Support

What is the difference between running a fenced and unfenced external routine?

Question & Answer


Question

What is the difference between running an external routine as fenced rather than unfenced?

Answer

The type of process or thread running the routine differs when a routine is run as fenced as opposed to unfenced. With the exception of Java routines, which always run as fenced, the same routine can be declared as fenced (untrusted) or unfenced (trusted). When a routine is declared as fenced it is run in a different process than the DB2 agent. While a routine will run in the same way when run as fenced or unfenced there are some differences in the effect the routine may have on DB2.

Unfenced

Unfenced routines are run in the DB2 agent process. When running unfenced, the routine running in the DB2 agent process accesses the database directly. In this mode any interruption to or issue with the process caused by the routine may effect the DB2 instance and could even cause DB2 to crash. Also the bitwidth of the routine (whether it is 32 or 64 bit) must match the bitwidth of DB2 meaning that 64 bit DB2 instances cannot run 32 routines unfenced. Since the routine can effect DB2, it is advised that only routines that are considered safe and trusted should be run as unfenced.

Fenced

In the case where the routine is declared as fenced it is run in the fenced process (db2fmp). This process is isolated from the processes that interact with the database, so if something goes wrong with this process while running the routine the database will not be effected.
Since the fenced process does not interact directly with the database the queries issued by the routine are run through the DB2 agent that is servicing the connection. The fenced process has its own mechanism to manage and pool fenced processes for reuse. Since the fenced process is separate from the database it can have a different bitwidth than the DB2 agent and run routines with a different bitwidth.. For example a 64 bit database can run a 32 bit routine when it is fenced. Since issues with the routine are less likely to affect the database when fenced mode is used, applications that are less safe or trusted should be run as fenced.

[{"Product":{"code":"SSEPGG","label":"Db2 for Linux, UNIX and Windows"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":"Routines (SP & UDF) - Internal Routines","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"9.8;9.7;9.5;9.1;10.1;10.5;11.1","Edition":"Advanced Enterprise Server;Advanced Workgroup Server;Enterprise Server;Express;Express-C;Personal;Workgroup Server","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
16 June 2018

UID

swg21678307