62 - HTTP Server Mod - PLSQL User's Guide
62 - HTTP Server Mod - PLSQL User's Guide
62 - HTTP Server Mod - PLSQL User's Guide
December 2003
Oracle HTTP Server mod_plsql User's Guide, 10g Release 1 (10.1)
The Programs (which include both the software and documentation) contain proprietary information of
Oracle Corporation; they are provided under a license agreement containing restrictions on use and
disclosure and are also protected by copyright, patent and other intellectual and industrial property
laws. Reverse engineering, disassembly or decompilation of the Programs, except to the extent required
to obtain interoperability with other independently created software or as specified by law, is prohibited.
The information contained in this document is subject to change without notice. If you find any problems
in the documentation, please report them to us in writing. Oracle Corporation does not warrant that this
document is error-free. Except as may be expressly permitted in your license agreement for these
Programs, no part of these Programs may be reproduced or transmitted in any form or by any means,
electronic or mechanical, for any purpose, without the express written permission of Oracle Corporation.
If the Programs are delivered to the U.S. Government or anyone licensing or using the programs on
behalf of the U.S. Government, the following notice is applicable:
Restricted Rights Notice Programs delivered subject to the DOD FAR Supplement are "commercial
computer software" and use, duplication, and disclosure of the Programs, including documentation,
shall be subject to the licensing restrictions set forth in the applicable Oracle license agreement.
Otherwise, Programs delivered subject to the Federal Acquisition Regulations are "restricted computer
software" and use, duplication, and disclosure of the Programs shall be subject to the restrictions in FAR
52.227-19, Commercial Computer Software - Restricted Rights (June, 1987). Oracle Corporation, 500
Oracle Parkway, Redwood City, CA 94065.
The Programs are not intended for use in any nuclear, aviation, mass transit, medical, or other inherently
dangerous applications. It shall be the licensee's responsibility to take all appropriate fail-safe, backup,
redundancy, and other measures to ensure the safe use of such applications if the Programs are used for
such purposes, and Oracle Corporation disclaims liability for any damages caused by such use of the
Programs.
Oracle is a registered trademark, and Oracle Store, PL/SQL, SQL*Net, and SQL*Plus are trademarks or
registered trademarks of Oracle Corporation. Other names may be trademarks of their respective
owners.
Contents
Preface............................................................................................................................................................ ix
Related Documentation ......................................................................................................................... x
Documentation Accessibility ................................................................................................................ x
Conventions............................................................................................................................................ xi
Oracle Services and Support ................................................................................................................ xi
1 Understanding mod_plsql
1.1 Processing Client Requests .................................................................................................. 1-1
1.2 Database Access Descriptors (DADs)................................................................................. 1-3
1.3 Invoking mod_plsql ............................................................................................................. 1-3
1.4 Transaction Mode.................................................................................................................. 1-6
1.5 Supported Data Types .......................................................................................................... 1-6
1.6 Parameter Passing ................................................................................................................. 1-6
1.6.1 Parameter Passing by Name (Overloaded Parameters) ........................................... 1-8
1.6.2 Flexible Parameter Passing ........................................................................................... 1-9
1.6.2.1 Two Parameter Interface........................................................................................ 1-9
1.6.2.2 Four Parameter Interface ..................................................................................... 1-10
1.6.3 Large Parameter Passing............................................................................................. 1-11
1.7 File Upload and Download................................................................................................ 1-12
1.7.1 Document Table Definition ........................................................................................ 1-13
1.7.1.1 Semantics of the CONTENT Column ................................................................ 1-13
1.7.1.2 Semantics of the CONTENT_TYPE Column .................................................... 1-14
iii
1.7.1.3 Semantics of the LAST_UPDATED Column .................................................... 1-14
1.7.1.4 Semantics of the DAD_CHARSET Column ...................................................... 1-14
1.7.2 Old Style Document Table Definition ....................................................................... 1-14
1.7.3 Configuration Parameters for Document Upload/Downloading ........................ 1-15
1.7.3.1 PlsqlDocumentTablename ................................................................................... 1-16
1.7.3.2 PlsqlDocumentPath (Document Access Path) .................................................. 1-16
1.7.3.3 PlsqlDocumentProcedure (Document Access Procedure).............................. 1-16
1.7.3.4 PlsqlUploadAsLongRaw...................................................................................... 1-17
1.7.4 File Upload .................................................................................................................... 1-17
1.7.5 Specifying Attributes (Mime Types) of Uploaded Files ......................................... 1-19
1.7.6 Uploading Multiple Files ............................................................................................ 1-20
1.7.7 File Download............................................................................................................... 1-20
1.7.8 Direct BLOB Download............................................................................................... 1-21
1.8 Path Aliasing (Direct Access URLs).................................................................................. 1-22
1.9 Common Gateway Interface (CGI) Environment Variables ......................................... 1-23
1.9.1 Adding and Overriding CGI Environment Variables ............................................ 1-24
1.9.2 PlsqlNLSLanguage....................................................................................................... 1-25
1.9.2.1 REQUEST_CHARSET CGI Environment Variable.......................................... 1-26
1.9.2.2 REQUEST_IANA_CHARSET CGI Environment Variable ............................. 1-26
1.10 Restrictions in mod_plsql ................................................................................................... 1-26
2 Configuring mod_plsql
2.1 Verifying Requirements........................................................................................................ 2-1
2.2 Installing Required Packages............................................................................................... 2-1
2.3 Creating a DAD for Your PL/SQL Application................................................................ 2-4
iv
4 Optimizing PL/SQL Performance
4.1 PL/SQL Performance in Oracle HTTP Server - Overview ............................................. 4-1
4.2 Process-Based and Thread-Based Operation in Oracle HTTP Server ........................... 4-3
4.3 Performance Tuning Issues for mod_plsql........................................................................ 4-3
4.3.1 Connection Pooling with mod_plsql........................................................................... 4-4
4.3.2 Closing Pooled Database Sessions............................................................................... 4-6
4.3.3 Restarting the mod_plsql Connection Pool................................................................ 4-7
4.4 Performance Tuning Areas in mod_plsql.......................................................................... 4-7
4.4.1 PL/SQL Based Web Application Development Considerations ............................ 4-7
4.4.2 Connection Pooling Tips and Oracle HTTP Server Configuration......................... 4-9
4.4.3 Tuning the Number of Database Sessions................................................................ 4-11
4.4.4 Two-Listener Strategy ................................................................................................. 4-12
4.4.5 Overhead Problems ..................................................................................................... 4-14
4.4.5.1 The Describe Overhead........................................................................................ 4-14
4.4.5.2 Avoiding the Describe Overhead ....................................................................... 4-14
4.4.6 The Flexible Parameter Passing (four-parameter) Overhead ................................ 4-15
4.5 Using Caching with PL/SQL Based Web Applications ................................................ 4-16
4.5.1 Using the Validation Technique ................................................................................ 4-17
4.5.1.1 Last-Modified ........................................................................................................ 4-17
4.5.1.2 Entity Tag Method ................................................................................................ 4-17
4.5.1.3 Using the Validation Technique for mod_plsql ............................................... 4-18
4.5.1.4 Second Request Using the Validation Technique ............................................ 4-19
4.5.2 Using the Expires Technique...................................................................................... 4-21
4.5.3 System- and User-level Caching with PL/SQL Based Web Applications........... 4-23
4.6 Tuning File System Cache to Improve Caching Performance ...................................... 4-25
4.6.1 Introducing File System Cache Tuning..................................................................... 4-25
4.6.2 Enabling File System Cache........................................................................................ 4-27
4.6.3 Configuring File System Cache to Reside on a Faster File System ....................... 4-27
4.6.4 Resizing File System Cache ........................................................................................ 4-27
4.6.4.1 Setting the Total Cache Size with PlsqlCacheTotalSize .................................. 4-28
4.6.4.2 Setting the Days of Aging for Cache with PlsqlCacheMaxAge ..................... 4-29
4.6.4.3 Setting the Maximum File Size for a Cache File with PlsqlCacheMaxSize .. 4-29
4.6.5 Configuring Cache Cleanup ....................................................................................... 4-30
4.7 Oracle HTTP Server Directives ......................................................................................... 4-30
v
A Frequently Asked Questions
Index
vi
Send Us Your Comments
Oracle HTTP Server mod_plsql User's Guide, 10g Release 1 (10.1)
Part No. B12303-01
Oracle Corporation welcomes your comments and suggestions on the quality and usefulness of this
document. Your input is an important part of the information used for revision.
■ Did you find any errors?
■ Is the information clearly presented?
■ Do you need more information? If so, where?
■ Are the examples correct? Do you need more examples?
■ What features did you like most?
If you find any errors in this document, or have suggestions for improvement, please send your com-
ments to [email protected]. Please indicate the title and part number of the documenta-
tion and the chapter, section, and page number (if available). If you would like a reply, please give
your name, address, telephone number, and e-mail address.
If you have problems with the software, please contact your local Oracle Support Services.
vii
viii
Preface
New Features
New features in this release of mod_plsql include:
■ Enhanced cache clean up algorithm allowing users to configure the time to
clean up the cache.
■ Enhanced OWA packages to allow better byte-packing of response data from
multibyte databases resulting in fewer round-trips to the database.
■ Reduced PL/SQL function call overheads in heavily called OWA package APIs
like htp.p.
■ Enhanced performance logging in mod_plsql. See "What kinds of logging
facilities are available in mod_plsql?" in Appendix A, "Frequently Asked
Questions" for more information.
ix
■ Enhanced security by obscuring schema passwords in the DAD configuration.
■ Removed the requirement to have /pls in the virtual path for accessing mod_
plsql. It can still be used, but is no longer required. mod_plsql has been
integrated in the Oracle HTTP Server configuration and so a mod_plsql URL no
longer needs to start with a "/pls" prefix.
Related Documentation
You may also find the following manuals useful:
■ Oracle Database Application Developer’s Guide - Fundamentals
■ Oracle HTTP Server Administrator's Guide
Documentation Accessibility
Our goal is to make Oracle products, services, and supporting documentation
accessible, with good usability, to the disabled community. To that end, our
documentation includes features that make information available to users of
assistive technology. This documentation is available in HTML format, and contains
markup to facilitate access by the disabled community. Standards will continue to
evolve over time, and Oracle is actively engaged with other market-leading
technology vendors to address technical obstacles so that our documentation can be
accessible to all of our customers. For additional information, visit the Oracle
Accessibility Program Web site at
http://www.oracle.com/accessibility/
x
Conventions
The following conventions are used in this manual:
Convention Meaning
. Vertical ellipsis points in an example mean that information not
directly related to the example has been omitted.
.
.
... Horizontal ellipsis points in statements or commands mean that
parts of the statement or command not directly related to the
example have been omitted
boldface text Boldface type in text indicates a term defined in the text.
<> Angle brackets enclose user-supplied names.
[] Brackets enclose optional clauses from which you can choose one or
none.
xi
Templates are provided to help you prepare information about your problem
before you call. You will also need your CSI number (if applicable) or complete
contact details, including any special project information.
Customer Service
Global Customer Service contacts are listed at:
http://www.oracle.com/support
xii
1
Understanding mod_plsql
1. The Oracle HTTP Server receives a PL/SQL Server Page request from a client
browser.
2. The Oracle HTTP Server routes the request to mod_plsql.
3. The request is forwarded by mod_plsql to the Oracle Database. By using the
configuration information stored in your DAD, mod_plsql connects to the
database.
4. mod_plsql prepares the call parameters, and invokes the PL/SQL procedure in
the application.
5. The PL/SQL procedure generates an HTML page using data and the PL/SQL
Web Toolkit accessed from the database.
6. The response is returned to mod_plsql.
7. The Oracle HTTP Server sends the response to the client browser.
The procedure that mod_plsql invokes returns the HTTP response to the client. To
simplify this task, mod_plsql includes the PL/SQL Web Toolkit, which contains a
set of packages called the owa packages. Use these packages in your stored
procedure to get information about the request, construct HTML tags, and return
header information to the client. Install the toolkit in a common schema so that all
users can access it.
The Web server running on www.acme.com and listening at port 9000 handles the
request. When the Web server receives the request, it passes the request to mod_
plsql. This is because the /pls/mydad indicates that the Web server is configured
to invoke mod_plsql. It then uses the DAD associated with /pls/mydad and runs
the myproc procedure stored in mypackage.
The Web server running on www.acme.com and listening at port 9000 handles the
request. When the Web server receives the request, it uses the DAD associated with
/pls/mydad and runs the myproc procedure stored in mypackage, and passes
two arguments, a and b, with the values v, and 1 to the procedure.
Example 1–3 Invoking the Default Procedure Stored in the DAD Configuration
http://www.acme.com:9000/pls/mydad
The Web server running on www.acme.com and listening at port 9000 handles the
request. When the Web server receives the request, it uses the DAD associated with
/pls/mydad and invokes the default procedure configured in the DAD. For
example, if the configuration parameter PlsqlDefaultPage in the DAD
/pls/mydad is set to myschema.mypackage.myproc, then the procedure
myschema.mypackage.myproc is invoked for the request.
In this example, the default home page for the mydad DAD (as specified in the
DAD Configuration) is displayed.
■ Mixed Mode - In mod_plsql you can pass some of the parameters in a query
string and the remaining ones as POST data. For example, if you have a
procedure foo (a varchar2, b number), and want to pass values "v" and "1" to 'a'
and 'b' respectively, you could do so in three ways to create URLs:
■ All values are specified as part of the query string.
http://host:port/pls/DAD/foo?a=v&b=1
■ All values are specified as part of the POST data.
http://host:port/pls/DAD/foo, POST data="a=v&b=1"
■ Some of the parameters are specified in the URL and the rest in the POST
data.
http://host:port/pls/DAD/foo?a=v, POST data="b=1"
The URL to invoke the first version of the procedure looks similar to:
http://www.acme.com/pls/mydad/my_pkg.my_proc?valvc2=input
The URL to invoke the second version of the procedure looks similar to:
http://www.acme.com/pls/mydad/my_pkg.my_proc?valnum=34
Each of these procedures has a single parameter of the same name, val.
When mod_plsql gets a request that has only one value for the val parameter, it
invokes the procedure with the scalar data type.
Example 1–4 Send the following URL to execute the scalar version of the procedure:
http://www.acme.com/pls/mydad/my_proc?val=john
When mod_plsql gets a request with more than one value for the val parameter, it
then invokes the procedure with the array data type.
Example 1–5 Send the following URL to execute the array version of the procedure:
http://www.acme.com/pls/mydad/my_proc?val=john&val=sally
To ensure that the array version executes, use hidden form elements on your HTML
page to send dummy values that are checked and discarded in your procedure.
The exclamation mark prefix (!) instructs mod_plsql to use flexible parameter
passing. It invokes procedure scott.myproc and passes it the following two
arguments:
name_array ==> ('x', 'y', 'z')
value_array ==> ('john', '10', 'doe')
Example 1–7 If you send the following URL, where the query_string has duplicate
occurrences of the name "x":
http://www.acme.com/pls/mydad/!scott.my_pkg.my_proc?x=a&y=b&x=c
The exclamation mark prefix (!) instructs mod_plsql to use flexible parameter
passing. It invokes procedure scott.my_pkg.myproc and passes it the following
arguments:
num_entries ==> 3
name_array ==> ('x', 'y', 'x');
value_array ==> ('a', 'b', 'c')
reserved ==> ()
For example, when using flexible parameter passing (described in Section 1.6.2,
"Flexible Parameter Passing"), each name or value in the query_string portion of the
URL gets passed as an element of the name_array or value_array argument to
the procedure being invoked. These names or values can be up to 32KB in size.
This is required to support uploading a set of files that have relative URL
references to each other.
■ Upload multiple files for each form submission.
■ Upload files into LONG RAW and BLOB (Binary Large Object) types of
columns in the document table.
This section discusses the following:
■ Document Table Definition
■ Old Style Document Table Definition
■ Configuration Parameters for Document Upload/Downloading
■ File Upload
■ Specifying Attributes (Mime Types) of Uploaded Files
■ Uploading Multiple Files
■ File Download
■ Direct BLOB Download
then:
■ mod_plsql will retrieve data from, or store to a database table called my_
document_table in the scott schema.
■ All file extensions except .html will be uploaded to the document table as
BLOBs. All files with .html extension will be uploaded as Long Raw.
■ All URLs which have the keyword docs immediately following the DAD
location will result in invocation of the procedure scott.my_doc_download_
procedure.
Typically, this procedure will call wpg_docload.download_file to initiate a file
download for a file whose name is based on the URL specification.
A simple example with the preceding configuration is:
http://www.acme.com/pls/dad/docs/index.html
This results in downloading of the file index.html from the Long Raw column of
the database table scott.my_document_table. Note that the application procedure
has full control on the file download to initiate, and has the flexibility to define a
more complex PlsqlDocumentProcedure that implements file-level access
controls and versioning.
1.7.3.1 PlsqlDocumentTablename
The PlsqlDocumentTablename parameter specifies the table for storing
documents when file uploads are performed through this DAD.
Syntax:
PlsqlDocumentTablename [document_table_name]
PlsqlDocumentTablename my_documents
or,
PlsqlDocumentTablename scott.my_document_table
The mydad is the DAD name and myfile.htm is the file name.
Syntax:
PlsqlDocumentPath [document_access_path_name]
Example 1–9
PlsqlDocumentProcedure my_access_procedure
or,
PlsqlDocumentProcedure scott.my_pkg.my_access_procedure
1.7.3.4 PlsqlUploadAsLongRaw
The DAD parameter, PlsqlUploadAsLongRaw, configures file uploads based on
their file extensions. The value of a PlsqlUploadAsLongRaw DAD parameter is a
one-entry-for-each-line list of file extensions. Files with these extensions are uploaded
by mod_plsql into the content column of LONG RAW type in the document table.
Files with other extensions are uploaded into the BLOB content column.
The file extensions can be text literals (jpeg, gif, and so on) or an asterisk (*) matches
any file whose extension has not been listed in the PlsqlUploadAsLongRaw
setting.
Syntax:
PlsqlUploadAsLongRaw [file_extension]
PlsqlUploadAsLongRaw *
[file_extension] is an extension for a file (with or without the '.' character, for
example, 'txt' or '.txt') or the wildcard character *.
Example 1–10
PlsqlUploadAsLongRaw html
PlsqlUploadAsLongRaw txt
PlsqlUploadAsLongRaw *
1. The browser uploads the file specified by the user as well as other form data to
the server.
2. mod_plsql stores the file contents in the database in the document storage table.
The table name is derived from the PlsqlDocumentTablename DAD setting.
3. The action procedure specified in the action attribute of the FORM is run
(similar to invoking a mod_plsql procedure without file upload).
The following example shows an HTML form that lets a user select a file from the
file system to upload. The form contains other fields to provide information about
the file.
<html>
<head>
<title>test upload</title>
</head>
<body>
<FORM enctype="multipart/form-data"
action="pls/mydad/write_info"
method="POST">
<p>Author's Name:<INPUT type="text" name="who">
<p>Description:<INPUT type="text" name="description"><br>
<p>File to upload:<INPUT type="file" name="file"><br>
<p><INPUT type="submit">
</FORM>
</body>
</html>
3. The procedure writes information from the form fields to a table in the database
and returns a page to the user.
procedure write_info (
who in varchar2,
description in varchar2,
file in varchar2) as
begin
insert into myTable values (who, description, file);
htp.htmlopen;
htp.headopen;
htp.title('File Uploaded');
htp.headclose;
htp.bodyopen;
htp.header(1, 'Upload Status');
htp.print('Uploaded ' || file || ' successfully');
htp.bodyclose;
htp.htmlclose;
end;
The filename obtained from the browser is prefixed with a generated directory
name to reduce the possibility of name conflicts. The "action procedure" specified in
the form renames this name. So, for example, when /private/minutes.txt is
uploaded, the name stored in the table by the mod_plsql is
F9080/private/minutes.txt. The application can rename this in the called
stored procedure. For example, the application can rename it to
scott/minutes.txt.
owa_util.http_header_close;
then, all URLs that have the keyword myalias immediately following the DAD
location will invoke the procedure scott.my_path_alias_procedure. Based on the
URL specification, this procedure can initiate an appropriate response.
■ DOCUMENT_TABLE
■ REMOTE_ADDR
■ REMOTE_HOST
■ REMOTE_USER
■ REQUEST_CHARSET (refer to Section 1.9.2.1, "REQUEST_CHARSET CGI
Environment Variable")
■ REQUEST_IANA_CHARSET (refer to Section 1.9.2.2, "REQUEST_IANA_
CHARSET CGI Environment Variable")
■ REQUEST_METHOD
■ REQUEST_PROTOCOL
■ SCRIPT_NAME
■ SCRIPT_PREFIX
■ SERVER_NAME
■ SERVER_PORT
■ SERVER_PROTOCOL
A PL/SQL application can get the value of a CGI environment variable using the
owa_util.get_cgi_env interface.
Syntax:
owa_util.get_cgi_env(param_name in varchar2) return varchar2;
If no value is specified for the parameter, then the value is obtained from the Oracle
HTTP Server. With Oracle HTTP Server, you can pass the DOCUMENT_ROOT CGI
Environment variable by specifying:
PlsqlCGIEnvironmentList DOCUMENT_ROOT
Example 1–11
PlsqlCGIEnvironmentList SERVER_NAME=myhost.mycompany.com
PlsqlCGIEnvironmentList REMOTE_USER=testuser
Example 1–12
PlsqlCGIEnvironmentList MYENV_VAR=testing
PlsqlCGIEnvironmentList SERVER_NAME=
PlsqlCGIEnvironmentList REMOTE_USER=user2
1.9.2 PlsqlNLSLanguage
For mod_plsql, the National Language Support (NLS) variable (PlsqlNLSLanguage)
can be set either as an environment variable or at the DAD level, the
PlsqlNLSLanguage parameter of the database must match that of the Oracle HTTP
Server, or the PlsqlNLSLanguage parameter of the database and Oracle HTTP Server,
must be of fixed character width and both must be the same size.
If PlsqlNLSLanguage is not configured at the DAD level, the NLS setting is picked up
from the environment. If it does not exist, the default rules apply for NLS_LANG
settings for Oracle.
in. Existing applications that encounter this problem need to be modified in one
of the following ways:
■ Implement wrappers for procedures with OUT parameters so that such
procedures are not invoked directly through a browser URL.
■ Create a local variable that gets assigned the value of the parameter being
passed in, and is then used for all internal changes.
■ The total number of name value pairs that can be passed to a PL/SQL
procedure is 2000.
■ mod_plsql limits the total number of parameters that can be passed to a single
procedure to 2000.
■ mod_plsql limits the size of a single parameter that can be passed to a
procedure to 32000 bytes.
■ It is not possible to use identical DAD locations in different virtual hosts.
This chapter describes how you can set up and use mod_plsql. It contains the
following sections:
■ Verifying Requirements
■ Installing Required Packages
■ Creating a DAD for Your PL/SQL Application
1. Navigate to the directory where the owaload.sql file is located. This directory
is ORACLE_HOME/Apache/modpsql/owa.
2. Using SQL*Plus, login to the Oracle database as the SYS user.
3. You can check the version of the OWA packages currently installed by running
the following query:
select owa_util.get_version from dual;
Note: The owaload script checks the existing version of the OWA
packages in the database and installs a new version only if:
■ No OWA package exists or,
■ Older OWA packages were detected. If your database already
has the latest OWA packages or has a newer version installed,
the owaload script does nothing and reports this in the log file.
6. Do a manual recompile.
After the install, check the version of the OWA packages by running "Select
owa_util.get_version from dual;". Confirm that the version shown is
9.0.4.0.1 or later.
7. Note that public access is now granted to:
■ OWA_CUSTOM
■ OWA
■ HTF
■ HTP
■ OWA_COOKIE
■ OWA_IMAGE
■ OWA_OPT_LOCK
■ OWA_PATTERN
■ OWA_SEC
■ OWA_TEXT
■ OWA_UTIL
■ OWA_CACHE
■ WPG_DOCLOAD
8. Note also that the following public synonyms are created:
■ OWA_CUSTOM for OWA_CUSTOM
■ OWA_GLOBAL for OWA_CUSTOM
■ OWA for OWA
■ HTF for HTF
■ HTP for HTP
■ OWA_COOKIE for OWA_COOKIE
■ OWA_IMAGE for OWA_IMAGE
■ OWA_OPT_LOCK for OWA_OPT_LOCK
■ OWA_PATTERN for OWA_PATTERN
■ OWA_SEC for OWA_SEC
■ OWA_TEXT for OWA_TEXT
■ OWA_UTIL for OWA_UTIL
■ OWA_INIT for OWA_CUSTOM
■ OWA_CACHE for OWA_CACHE
■ WPG_DOCLOAD for WPG_DOCLOAD
This chapter describes how to set up the database and PL/SQL to avoid known
security problems. It covers the following topics:
■ Authenticating Users Through mod_plsql
■ Deauthenticating Users
■ Protecting the PL/SQL Procedures Granted to PUBLIC
3.1.3 Global OWA, Custom OWA, and Per Package (Custom Authentication)
Custom authentication enables applications to authenticate users within the
application itself, not at the database level. Authorization is performed by invoking
a user-written authorization function.
Custom authentication is done using OWA_CUSTOM and cannot be combined with
dynamic username/password authentication. Custom authentication needs to have
a static username/password stored in the DAD configuration file. mod_plsql uses
this DAD username/password to login to the database. Once mod_plsql is logged
in, authentication control is passed back to the application, by calling an
application-level PL/SQL hook. This callback function is implemented by the
application developers. The value returned by the callback function determines the
success or failure of authentication. The value TRUE means success and FALSE
means failure.
Depending on the kind of custom authentication needed, you can place the
authentication function in different locations:
■ Global OWA enables you to invoke the same authentication function for all
users and procedures.
■ Custom OWA enables you to invoke a different authentication function for each
user and for all procedures.
■ Per Package authentication enables you to invoke the authentication function
for all users, but only for procedures in a specific package or for anonymous
procedures.
For example, when using Custom OWA, an authorization function might verify that
a user has logged in as user guest with password welcome, or it might check the
user's IP address to determine access.
Table 3–2 summarizes the parameter values.
With the different levels of authentication, you must protect the execution of the
PL/SQL procedures granted to PUBLIC in the database. These procedures (in the
dbms_% packages, utl_% packages, and all packages under the SYS schema) pose a
security vulnerability when they are executed through a Web browser. Such
packages are intended only for the PL/SQL application developer.
To ensure the best security for PL/SQL procedures that are granted to PUBLIC,
specify the system default settings with the PlsqlExclusionList directive in the
dads.conf file as shown in Example 3–1.
Example 3–1 System Default Settings Specified with the PlsqlExclusionList Directive
PlsqlExclusionList sys.*
PlsqlExclusionList dbms_*
PlsqlExclusionList utl_*
PlsqlExclusionList owa_util.*
PlsqlExclusionList owa.*
PlsqlExclusionList htp.*
PlsqlExclusionList htf.*
PlsqlExclusionList myschema.mypackage*
In addition to the patterns that are specified with this directive, mod_plsql also
disallows any URLs that contain special characters such as tabs, newlines, carriage
returns, single quotation marks ('), or reverse slashes (\). You cannot change this.
This chapter discusses the techniques for improving PL/SQL performance in Oracle
HTTP Server.
This chapter contains the following sections:
■ PL/SQL Performance in Oracle HTTP Server - Overview
■ Process-Based and Thread-Based Operation in Oracle HTTP Server
■ Performance Tuning Issues for mod_plsql
■ Performance Tuning Areas in mod_plsql
■ Using Caching with PL/SQL Based Web Applications
■ Tuning File System Cache to Improve Caching Performance
■ Oracle HTTP Server Directives
Table 4–1 Database Access Descriptor (DAD) Parameters Recommended Setting Summary
Parameter Recommended Setting
PlsqlAlwaysDescribeProcedure Set this to off for best performance.
Default Value: off
PlsqlDatabaseConnectString For newer DADs, use the ServiceNameFormat. Use the
SIDFormat only for backward compatibility.
Note: for HA configurations of the database, it is recommended
that the connect string parameter gets resolved through an LDAP
lookup.
PlsqlFetchBufferSize For multibyte character sets like Japanese or Chinese, setting this
to 256 should provide better performance
Default Value: 128
PlsqlIdleSessionCleanupInterval Increasing this parameter allows pooled database connections to
remain available, in the pool, for the specified time
Default Value: 15 (minutes)
See Also: Section 4.3.3, "Restarting the mod_plsql Connection
Pool"
PlsqlLogEnable This parameter should be set to Off unless recommended by
Oracle support for debugging purposes
Default Value: off
PlsqlMaxRequestsPerSession If the PL/SQL based Web application does not leak resources or
memory, this parameter can be set to a higher value (for example,
5000).
Default Value: 1000
See Also: Section 4.3.2, "Closing Pooled Database Sessions" and
Section 4.4.2, "Connection Pooling Tips and Oracle HTTP Server
Configuration".
PlsqlNLSLanguage Set this parameter to match the database Globalization Support
parameters to eliminate overheads in character set conversions in
Oracle Net Services
PlsqlSessionStateManagement Set this parameter to
StatelessWithFastResetPackageState if the database is
8.1.7.2 or later.
Table 4–2 lists mod_plsql caching options and the sections that describe these
caching options.
a. Each Oracle HTTP Server process serves all types of requests, such as static
files requests, servlet requests, and mod_plsql requests. There is no control
on which Oracle HTTP Server process services the next request.
b. One Oracle HTTP Server process cannot use or share the connection pool
created by another process.
c. Each Oracle HTTP Server process pools at most one database connection for
each DAD.
d. User sessions are switched within a pooled database connection for a DAD.
For DADs based on Oracle Application Server Single Sign-On (SSO), proxy
authentication is used to switch the user session. For non-SSO users, using
HTTP basic authentication with the username and password not in the
DAD, users are re-authenticated on the same connection.
e. Multiple DADs may point to the same database instance, but database
connections are not shared across DADs even within the same process.
f. Unused DADs do not result in any database connections.
In the worst-case scenario, the total number of database connections pooled by
mod_plsql is a factor of the total number of active DADs multiplied by the number
of Oracle HTTP Server (httpd) processes running at any given time for a single
Oracle HTTP Server instance. If you have configured the Oracle HTTP Server
processes to a high number, you need to configure the back-end database to handle
a corresponding number of database sessions, and remember that this configuration
value needs to be multiplied times the number of Oracle HTTP Server instances that
use the back-end database.
For example, if there are three Oracle HTTP Server instances configured to spawn a
maximum of 50 httpd processes each, plus two active DADs, you need to set up
the database to allow 300 (3*50*2) sessions. This number does not include any
sessions that are needed to allow other Web applications to connect.
On UNIX systems, database connections cannot be shared across httpd processes,
and process-based platforms have more of a Connection Reuse feature than
Connection Pooling. Note that this is an artifact of the process-model in Oracle HTTP
Server.
Server is configured so that each Oracle HTTP Server process remains active for
some period of time. An incorrect configuration of Oracle HTTP Server could
result in a setup where Oracle HTTP Server processes are heavily started up
and shut down. Such a configuration would require that each new Oracle HTTP
Server process replenish the connection pool before subsequent requests gain
any benefit of pooling.
Try to restrict the number of DADs that each Oracle HTTP Server node uses.
Note: Performance is not affected if there are DADs that are not
being used.
database session resource leaks do not cause a problem. Make sure that
MaxRequestsPerChild configuration parameter is set to a high number. For
PL/SQL based Web applications, this should not be set to 0.
4. For heavily loaded sites, the Oracle HTTP Server configuration parameter
KeepAlive should be disabled. This ensures that each process is available to
service requests from other clients as soon as a process is done with servicing
the current request. For sites which are not heavily loaded, and where it is
guaranteed that the number of Oracle HTTP Server processes are always
greater than the number of simultaneous requests to the Oracle HTTP Server
listener, enabling the KeepAlive parameter results in performance
improvements. In such cases, make sure to tune the KeepAliveTimeout
parameter appropriately.
5. You may want to lower the value of Timeout in the Oracle HTTP Server
configuration. This ensures that Oracle HTTP Server processes are freed up
earlier if a client is not responding in a timely manner. Do not set this value too
low, otherwise slower responding clients could time out.
6. Most Web sites have many static image files, which are displayed in each screen
for a consistent user interface. Such files rarely change and you can reduce a
considerable load on the system by tagging each image served by the Oracle
HTTP Server listener with mod_expires. You should also consider
front-ending your Web site with Oracle Application Server Web Cache.
■ How do I know if the Web site can benefit from the use of mod_expires?
– Use Netscape, or any browser that enables you to view page caching
information, and visit several heavily accessed Web pages on the site.
On each page, right click the mouse and select View Info from the
pop up menu (or the equivalent command for your browser). If the top
panel in the page information window lists many different images and
static content, then the site could benefit from the use of mod_expires.
– You can also check the Oracle HTTP Server access logs to see what
percentage of requests result in HTTP 304 (Not Modified) status. Use
the grep utility to search for 304 in the access_log and divide this
resulting number of lines by the total number of lines in the access_
log. If this percentage is high, then the site could benefit from the use
of mod_expires.
■ How do I tag static files with the Expires header?
– Locate the Location directive used to serve your static image files.
Add the ExpiresActive and ExpiresDefault directives to it.
Alias /images/ "/u01/app/oracle/myimages/"
<Directory "/u01/app/oracle/myimages/">
AllowOverride None
Order allow, deny
Allow from all
ExpiresActive On
ExpiresDefault A2592000
</Directory>
The browser caches all static files served off the /images path for 30
days from now. Refer to the Oracle HTTP Server Administrator's Guide
for more details.
■ How do I know if the static files are being tagged with the Expires
header?
– Using Netscape, or the browser of your choice, clean up all the cached
files in the browser.
– Visit a Web page that should have images tagged with the Expires
header. Right click the mouse on the page and select View Info, from
the pop up menu. or use the equivalent command for your browser.
– In the top panel of the page information, select an image that should be
tagged with the Expires header.
– Review the information displayed in the bottom panel. The Expires
header should be set to a valid date. If this entry is No date given,
then the file is not being tagged with the Expires header.
c. Configure this listener to forward all mod_plsql requests for this DAD
location to the second listener by adding the following line in dads.conf:
ProxyPass /pls/dad http://mylsnr2.mycompany.com:8888/pls/dad
■ If the URLs are being generated using the CGI environment variable HTTP_
HOST, you need to override the CGI environment variables for the Oracle
HTTP Server listener running on Port 8888. Add the following lines to the
ORACLE_HOME/Apache/modplsql/conf/dads.conf file for each DAD
to override the default CGI environment variables HOST, SERVER_NAME,
and SERVER_PORT:
PlsqlCGIEnvironmentList SERVER_NAME mylsnr1.mycompany.com
PlsqlCGIEnvironmentList SERVER_PORT 7777
PlsqlCGIEnvironmentList HOST mylsnr1.us.oracle.com:7777
In all cases, the intent is to fool the application to generate URLs as if there
never was a second listener.
3. Test the setup and make sure that you can access all the DADs without any
problems.
4. In this setup, the main listener mylsnr1.mycompany.com can be configured
based on the total load on the Oracle HTTP Server listener. The second listener
on mylsnr2.mycompany.com can be fine-tuned based on just the mod_plsql
requests being made.
■ Always ensure that you pass multiple values for arrays. For single values, you
can pass dummy values that are ignored by the procedure.
■ Use the following workaround, which defines a two-parameter style procedure
which defaults the unused variables.
1. Define a scalar equivalent of your procedure, which internally calls the
original procedure. For example, the original package could be similar to
the following example:
CREATE OR REPLACE PACKAGE testpkg AS
TYPE myArrayType is TABLE of VARCHAR2(32767) INDEX BY binary_ integer;
PROCEDURE arrayproc (arr myArrayType);
END testpkg;
/
4.5.1.1 Last-Modified
When a Web page is generated using the HTTP protocol, it contains a
Last-Modified Response Header. This header indicates the date, relative to the
server, of the content that was requested. Browsers save this date information along
with the content. When subsequent requests are made for the URL of the Web page,
the browser then:
1. Determines if it has a cached version.
2. Extracts the date information.
3. Generates the Request Header If-Modified-Since.
4. Sends the request the server.
Cache-enabled servers look for the If-Modified-Since header and compare it to the
date of their content. If the two match, an HTTP Response status header such as
"HTTP/1.1 304 Not Modified" is generated, and no content is streamed. After
receiving this status code, the browser can reuse its cache entry because it has been
validated.
If the two do not match, an HTTP Response header such as "HTTP/1.1 200 OK" is
generated and the new content is streamed, along with a new Last-Modified
Response header. Upon receipt of this status code, the browser must replace its
cache entry with the new content and new date information.
the browser. Servers generate this string based on their type of application. This is a
more generic validation method than the If-Modified-Since header, which can only
contain a date value.
The ETag method works very similar to the Last Modified method. Servers generate
the ETag as part of the Response Header. The browser stores this opaque header
value along with the content that is steamed back. When the next request for this
content arrives, the browser passes the If-Match header with the opaque value that
it stored to the server. Because the server generated this opaque value, it is able to
determine what to send back to the browser. The rest is exactly like the
Last-Modified validation method as described earlier.
2. mod_plsql forwards the same tag and caching level information (from the first
request) to the PL/SQL procedure as part of the CGI environment variables.
3. The PL/SQL procedure uses these caching CGI environment variables to check
if the content has changed. It does so by calling the following owa_cache
functions from the PL/SQL Web Toolkit:
owa_cache.get_etag;
owa_cache.get_level;
4.5.3 System- and User-level Caching with PL/SQL Based Web Applications
A PL/SQL procedure determines whether generated content is system-level content
or user-level. This helps the PL/SQL Gateway cache to store less redundant files if
more than one user is looking at the same content. It decides this by:
■ For system-level content, the procedure passes the string SYSTEM as the
caching level parameter to the owa_cache functions (set_cache for
validation model or set_expires for expires model). This is for every user
that shares the cache.
By using system-level caching, you can save both space in your file system and
time for all users in the system. One example of this would be a Web
application that generates content that is intended for everybody using the Web
application. By caching the content with the system-level setting, only one copy
of the content is cached in the file system. Furthermore, every user on that
system benefits since the content is served directory from the cache.
■ For user-level content, it passes the string USER as the parameter for the
caching level. This is for a specific user that is logged in. The stored cache is
unique for that user. Only that user can use the cache. The type of user is
determined by the authentication mode. Refer to the following table for the
different types of users.
For example, if no user customizes a PL/SQL based Web application, then the
output can be stored in a system-level cache. There will be only one cache copy for
every user on the system. User information is not used since the cache can be used
by multiple users.
However, if a user customizes the application, a user-level cache is stored for that
user only. All other users still use the system level cache. For a user-level cache hit,
the user information is a criteria. A user-level cache always overrides a system-level
cache.
where:
deleted is the number of cache files that got deleted during the cleanup process.
max_age is the number of cache files and total size that got deleted because they
haven't been used for some time.
kept is the number of cache files and total size that was kept after the cleanup
process.
time is the amount of time to perform the cleanup.
limit is the total cache size. This is the value of the PlsqlCacheTotalSize
setting.
Interpret the entries in the error log as follows:
■ If a high number of files are being deleted when compared to the number of
files that were kept, this is a clear indication that your cache size is too small.
You probably need to increase the size of the cache.
■ If a low number of files being deleted when compared to the number of files
that were kept is observed, this is an indication that your cache size is probably
too big. If you have enough disk space, you can chose to leave it as it or you can
decrease the size of the cache to reclaim some disk space.
4.6.4.3 Setting the Maximum File Size for a Cache File with PlsqlCacheMaxSize
Using the PlsqlCacheMaxSize parameter, you can specify the maximum size for
individual files in the cache. Using this parameter prevents the case in which one
cache file fills up the entire cache.
The default value for this parameter is 1048576 (bytes). In general, set this
parameter to a value that represents about 1-3% of the total cache size.
■ What is mod_plsql?
■ What is the PL/SQL Web Toolkit?
■ How do I find the version of mod_plsql?
■ How do I find the version of the OWA packages?
■ How do I install the OWA packages?
■ How do I uninstall the OWA packages?
■ How do I detect and clean up duplicate OWA packages installed in the
database?
■ I am getting HTTP error codes while accessing PL/SQL procedures through
mod_plsql.
■ All my PL/SQL procedures return a "Document contains no data" error in
Netscape, or a blank page in Internet Explorer.
■ I have a performant PL/SQL procedure, but some of my HTTP requests
through mod_plsql take more than 15 seconds.
■ Can I use mod_plsql to run applications on my own database?
■ How do I create a DAD for mod_plsql?
■ What authentication modes are available in mod_plsql?
■ What is the mod_plsql Cleanup Thread?
■ What kind of database connection pooling is present in mod_plsql?
■ How does mod_plsql clean up database sessions?
What is mod_plsql?
mod_plsql is an Oracle HTTP Server plug-in that communicates with the database
by mapping browser requests into database stored procedure calls over a SQL*Net
connection. It is generally indicated by a /pls virtual path. The mod_plsql gateway
provides support for building and deploying PL/SQL-based applications on the
Web. PL/SQL stored procedures can retrieve data from database tables and
generate HTTP responses containing formatted data and HTML code to display in a
Web browser. See the Oracle Database Application Developer’s Guide - Fundamentals for
more information.
This should show the version of the OWA packages. For example, 9.0.4.0.1.
If this query fails, you are having a very old version of OWA packages that does not
have versioning. It is recommended that you upgrade to a newer version.
2. Use SQL*Plus to connect as the owner the OWA packages. This user should be
the SYS user, unless you have an old version of the OWA packages.
3. Invoke the script owadins.sql to uninstall the OWA packages.
OWNER OBJECT_TYPE
----- -----------
SYS PACKAGE
SYS PACKAGE BODY
PUBLIC SYNONYM
If you see more lines than shown in the preceding SQL query, it means that older
OWA packages exist in other schemas, which may cause issues for mod_plsql users.
In such situations, uninstall all versions of the OWA packages from the database,
and reinstall the OWA packages that ship with the product.
3. Issue some URLs to mod_plsql and verify that the file ORACLE_
HOME/Apache/Apache/logs/error_log starts showing entries as
follows:
[Tue Apr 01 14:54:49 2003] [info] mod_plsql: [perf] 130.35.92.145
/pls/app/htp.p status=200 user=scott reqTime=21ms connSU=(null),0ms
connRO=(null),0ms connNSSO=HIT,1ms procTime=17ms sessionTidyTime=0ms
cache=(null) cookie=(null),0ms pageCalls=0,0ms bytes=5 describe=No,0ms
streamTime=0ms pid=175 sessFile=(null) userFile=834\0855
sysFile=470\5949 cacheLevel=(null) cacheTime=0ms dbProcTime=15ms
■ Finally, you can enable debug logging in mod_plsql. This is the highest level of
logging and is not recommended for active sites.
In this mode, debug messages are logged to Oracle HTTP Server's error_log
file and additional mod_plsql specific logs are created under ORACLE_
HOME/Apache/modplsql/logs. Log location is configurable using the
PlsqlLogDirectory directive in ORACLE_
HOME/Apache/modplsql/conf/plsql.conf. To enable debug level
logging:
1. Edit ORACLE_HOME/Apache/modplsql/conf/plsql.conf and set
PlsqlLogEnable to On (default is Off).
2. Restart OHS using the following command:
ORACLE_HOME/opmn/bin/opmnctl restartproc type=ohs
or
tnsping iasdb.us.oracle.com
■ For entries configured with SIDFormat and ServiceNameFormat, ensure that the
hostname, port, and SID/service_name information match for the database
listener. After verifying this, confirm that SQL*Plus can connect to the database
using the DAD username, password, and connect string.
If this does not work, refer to the Oracle SQL*Net documentation on how to
troubleshoot this further.
Numerics D
2 parameter
DAD
flexible parameter passing, 1-9 creating a, 2-4
4 parameter definition, 1-3
flexible parameter passing, 1-10
DAD_charset column, 1-14
direct access URLs, 1-22
A document access path, 1-16
document table definition, 1-13
arrays, 1-8
old style, 1-14
document_path, 1-16
B document_proc, 1-16
BLOB download, 1-12
direct download, 1-21 downloading files, 1-20
document table definition, 1-13 DTD, 1-13
old style, 1-14
C
E
caching
expires technique, 4-21 entity tag caching method, 4-17
owa_cache packages, 4-24 environment variables
system-level, 4-23 CGI, 1-23
user-level, 4-23 expires caching technique, 4-21
validation technique, 4-17
CGI F
environment variables, 1-24
file upload, 1-12, 1-17
client request, 1-1
attributes, 1-19
Index-1
multiple files, 1-20 O
four parameter
flexible parameter passing, 1-10 overloading, 1-8
owa_cache package, 4-24
owa_util PL/SQL web toolkit package, 1-23
G owaload.sql, 2-1
GET method, 1-5
P
H parameters
head method, 1-5 flexible, 1-9
HTTP HEAD requests, 1-5 large, 1-11
HTTP server MaxClients, 4-6
httpd process, 4-4 MaxRequestsPerChild, 4-6
httpd MaxSpareServers, 4-6
HTTP server process, 4-4 MinSpareServers, 4-6
httpd.conf overloaded, 1-8
directives passing, 1-6, 1-9
MaxSpareServers, 4-12 PlsqlIdleSessionCleanupInterval, 4-6
MinSpareServers, 4-12 PlsqlMaxRequestsPerSession, 4-6
StartServers, 4-12 performance
tuning
expires caching, 4-21
K mod_expires, 4-30
KeepAlive httpd.conf directive, 4-30 system-level caching, 4-23
validation caching, 4-18
PL/SQL application
L creating a DAD for, 2-4
language parameter (nls_lang), 1-25 PL/SQL web toolkit functions, 4-24
LAST_UPDATED column, 1-14 POST method, 1-5
LONGRAW
document table definition, 1-13
R
request_charset, 1-26
M REQUEST_IANA_CHARSET, 1-26
mime type, 1-19 restrictions, 1-26
mod_expires, 4-30
mod_plsql
S
invoking, 1-3
system-level caching, 4-23
N
T
nls_lang
definition, 1-25 transaction model, 1-6
tuning
expires caching technique, 4-21
Index-2
system-level caching, 4-23
validation caching, 4-18
two parameter
flexible parameter passing, 1-9
U
upload, 1-12
user-level caching, 4-23
V
validation caching
for mod_plsql, 4-18
technique, 4-17
W
web toolkit, 4-24
Index-3
Index-4