Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Programming PL SQL.doc
Скачиваний:
3
Добавлен:
01.07.2025
Размер:
5 Мб
Скачать
☆

23.1.2 Architecture of External Procedures

What happens under the covers when you invoke an external procedure? Let's first consider a case such as the example illustrated in the previous section, which uses the default external procedure "agent."

When the PL/SQL runtime engine learns from the compiled code that the program has been implemented externally, it looks for a TNS service named EXTPROC_CONNECTION_DATA, which must be known to the server via some Oracle Net naming method such as the tnsnames.ora file. As shown in Figure 23-1, the Oracle Net listener responds to the request by spawning a session-specific process called extproc, to which it passes the path to the DLL file along with the function name and any arguments. It is extproc that dynamically loads your shared library, sends needed arguments, receives its output, and transmits these results back to the caller. In this arrangement, only one extproc process runs for a given Oracle session; it launches with the first external procedure call and terminates when the session disconnects. For each distinct external procedure you call, this extproc process loads the associated shared library (if it hasn't already been loaded).

Figure 23-1. Invoking an external procedure that uses the default agent

Oracle has provided a number of features to help make external procedures usable and efficient:

Shared DLL

The external C program must be in a shared dynamically linked library rather than in a statically linked module. Although deferring linking until runtime incurs some overhead, there should be memory savings when more than one session uses a shared library; the operating system allows some of the memory pages of the library to be shared by more than one process. Another benefit of using dynamically linked modules is that they can be created and updated more easily than statically linked programs. In addition, there can be many subprograms in a shared library (hence the term "library"). This mitigates the performance overhead by allowing you to load fewer files dynamically.

Separate memory space

Oracle external procedures run in a separatememory space from the main database kernel processes. If the external procedure crashes, it won't step on kernel memory; the extproc process simply returns an error to the PL/SQL engine, which in turn reports it to the application. Writing an external procedure to crash the Oracle server is possible, but it's no easier than doing so from a non-external procedure program.

Full transaction support

External procedures provide full transaction support; that is, they can participate fully in the current transaction. By accepting "context" information from PL/SQL, the procedure can call back to the database to fetch data, make SQL or PL/SQL calls, and raise exceptions. Using these features requires some low-level Oracle Call Interface (OCI) programming . . . but at least it's possible!

23.1.3 Limitations of External Procedures

External procedures are not perfect. Despite the wonders of shared libraries, Oracle's architecture requires an unavoidable amount of interprocess communication. This is the tradeoff required for the safety of separating the external procedure's memory space from that of the database server. Other potential problems arise because each session invoking an external procedure requires its own extproc process, in addition to whatever shadow back-end process it uses to connect to the database server. This is potentially a lot of extra weight. There seems to be no way to allow sessions to share an extproc process.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]