Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Level 1
< FRENCH,FRANCE
Metadata Unload
There are essentially two methods to extract metadata from the data dictionary
in Oracle8i.
The first (and most popular) method involves querying the data dictionary using
SQL statements. This is problematic due to high maintenance costs created by
new object definitions and DDL changes. Also in many cases more than one
select statement has to be written. This increases network traffic.
The second method is to run Export with ROWS=N and then to run Import with
SHOW=Y. This produces a text file from the binary dump file that can be edited
to create SQL scripts. This method can require substantial editing and is not
considered a convenient technique.
The third method involves the OCIDescribeAny interface. This is not widely
used due to drawbacks such as being incapable of retrieving a complete set of
metadata about all database objects. It also does not scale well.
Literal Replacement
The term literal replacement refers to an operation performed by the optimizer
to reduce the overhead of parsing SQL statements containing bind variables.
Rather than executing a bind step each time the statement is executed, the
optimizer substitutes a “real” value (the literal in literal replacement) for the
bind variable when the statement is first parsed. The execution plan developed
using the substituted value is used for all subsequent executions of the
statement.
Safe Literal Replacement
Consider a query like this one, where ID is the primary key
SELECT * from T where id = :variable;
The substitution of any value would produce exactly the same execution plan. It
would, therefore, be safe for the optimizer to use literal replacement before
generating its execution plan for the statement.
Unsafe Literal Replacement
The two following SQL statements could produce different execution plans,
depending on the distribution of values for ID, the availability of statistics,
including histograms, and the available access paths:
SELECT * from T where id <= 20;
SELECT * from T where id <= 5000;
If this statement were written with a bind variable, the optimizer could not select
a good value for literal replacement. Depending on the value chosen, the
execution plan could be different. Only certain bind variable values would
benefit from the execution derived from a specific literal replacement value.
Therefore, this would be an unsafe literal replacement.
Literal Replacement
The value of the initialization parameter CURSOR_SHARING determines how
the optimizer will process statements with bind variables.
• EXACT: Literal replacement disabled completely
• FORCE: Causes sharing for all literals
• SIMILAR: Causes sharing for safe literals only
In previous releases, only the EXACT and FORCE options were available to
you. The SIMILAR option is new in Oracle9i. It causes the optimizer to
examine the statement to ensure that replacement occurs only for safe literals.
Latch Improvements
On systems that are experiencing no, or little, latch contention this advancement
offers no significant improvement. The improvement will be shown on systems
that currently experience a high contention for latches.
Wait Time
Wait time is defined as the amount of time a thread of execution has to wait
before it can acquire a latch. This is the elapsed time starting from the time the
first attempt to obtain the latch failed to the time the latch was actually acquired.
Contention
Contention is the ratio of number of misses to the number of latch gets (stated as
a percentage) on a particular latch. For example 95% contention would mean
that 95 times out of every 100 latch gets we encountered a miss.
However, this percentage does not give information on how long the wait was.
Therefore, although there might have been only a couple of misses (which
would look good on contention), it might be that these few are responsible for
the majority of the wait time.
Cumulative Wait Time
Cumulative wait time stands for the cumulative sum of all the wait or hold times
incurred by all the threads of execution.
CWAIT_TIME is the time a thread of execution actually had to wait from the
time it tried to acquire a latch to the time it actually got the latch. This time
would include:
• The spin and sleep times, if any
• The overhead of context switches that might have occurred due to sleeps or
due to OS scheduler time slicing
• Page faults, interrupts, and other user and system idiosyncrasies that
account for overall system performance
Database
Middle tier
servers
Usage Model
The pool creation and the association of the server handles to the pool handle are done in the
main thread. The threads then start using the connections in the pool via their respective
server handles. So the application need not bind the threads to the server
handles(connections) making less utilization of the connections. The connections are
dynamically allotted from the pool, balancing the load properly thereby increasing the
connection utilization.
The OCI connection pools provide more control over the application than network
connection pooling. However, connection pooling does not work with transparent
application failover (TAF).
Call executions
Multiple threads
Example
OCIHandleAlloc (envhp, (dvoid **)&poolhp,
OCI_HTYPE_CPOOL, (size_t)0, (dvoid **)0))
OCIConnectionPoolCreate ((dvoid *)envhp,
(dvoid*)errhp, (dvoid *)poolhp, (text *)database,
strlen ((char*)database), conMin, conMax, conIncr,
pusername, strlen ((char *)pusername), ppassword,
strlen ((char *)ppassword), & dblink, &
dblink_len, OCI_DEFAULT))
OCIServerAttach (svrhp[i], errhp, (text *)dblink,
(sb4) dblink_len ), OCI_POOL))
/* the server handle is a logical connection but
it works exactly the same a server handle obtained
without using a connection pool */
/* The pool attributes (min, max, incr) can be
changed dynamically using the
OCI_CPOOL_REINITIALIZE mode with the above pool
handle to OCIConnectionPoolCreate call */
OCIConnectionPoolDestroy (poolhp, errhp,
OCI_DEFAULT);
OCIHandleFree (poolhp, OCI_HTYPE_CPOOL);
Usage Guidelines
A few restrictions apply in connection pooling mode. An error is generated if these
conditions are not followed:
• Between OCIStmtExecute() and OCIStmtFetch() the service context
handle should not be changed or deallocated. But, it is valid to set the
OCI_ATTR_SERVER attribute to another server handle belonging to the same pool.
• If OCI_ATTR_NONBLOCKING_MODE is set on the pool handle, an error is
flagged.
• The service context handle should not be changed/deallocated between the
OCIDescribeAny() and OCIAttrGet() calls.
• Between continuing (piece-wise) calls, the attributes should not be changed for the
service context handle. The service context handle must be associated with the same
server handle and same session handle between these calls.
• The following pool attributes cannot be set at run-time:
– OCI_ATTR_CONN_MIN
– OCI_ATTR_CONN_MAX
– OCI_ATTR_CONN_INCR
Functionality
The path name in the CREATE LIBRARY statement supports environment
variable specifications, to be expanded at runtime by the agent. The need for
this can be seen by considering the situation in which agents on multiple
machines are used to run external procedures from multiple instances of a
library. The libraries on the different machines can be in different absolute
directories, but as long as they are in the same directory relative to a common
root directory (specified by an environment variable), the agents can correctly
access the external procedures.
Agent information is passed in a string to the CREATE LIBRARY statement to
specify an agent. A string is passed to the CREATE PROCEDURE and
CREATE FUNCTION statements specifying the name of an argument in which
an agent name will be passed at runtime.
The name of the agent is actually the name of a database link. Since it is passed
as an argument rather than concatenated to the function name, the problem of
local versus remote processing is avoided.
Example
In this example, the agent database link, agent_link, will run any external procedure in the
library plib1.
If no agent is specified, then the default agent (EXTPROC) is used. This ensures backward
compatibility with existing external procedure applications.
Upon first invocation of any procedure in the library, if the agent is not already running, it is
launched.
If the specified agent does not exist it is an error. This is because dedicated agent functionality can
be important enough (transaction support, for example) that some sort of default or fallback agent
in event of this error (EXTPROC, for example) would not, in general, be acceptable.
The file specification, {$EP_LIB_HOME}/plib1.so, includes the environment variable
${EP_LIB_HOME}. Although this format uses UNIX syntax, you use it on any platform. The
Oracle code expands the environment variable contained in the curly braces prior to passing it to
the operating system. This makes it possible to pass agent arguments to external procedures which
must run on different platforms, but with library security that is controlled at the server. The same
CREATE LIBRARY command could therefore be coded on Windows
SQL> CREATE OR REPLACE LIBRARY plib1 IS
2 '${EP_LIB_HOME}\plib1.so'
3 AGENT 'agent_link';
The only difference between the UNIX example, shown on the slide, and this Windows example,
is the direction of the slash between the environment variable and the library name.
Example
The agent with the unique identifier specified in the second parameter is used to
run the external procedure.
Upon first invocation of this procedure, if the agent is not already running, it
will be launched.
If the agent does not exist the procedure fails with an error.
The data type of the named agent argument is not predetermined. PL/SQL
checks only the syntactic validity, but back-end code checks that the argument
is allowable as an agent specification.
If the named agent argument is NULL, the default agent EXTPROC is invoked.
If the named agent argument is not in the formal argument list, an error is
generated at creation time.
The agent named in the agent argument will take precedence over the agent
named in the create library statement for the procedure’s specified library.
If no agent argument is specified, then the agent associated with the procedure’s
library is used, which, if not specified, is the default EXTPROC (compatible
with the implementation in earlier releases).
Security
When all external procedures were processed by an agent on the Oracle database server,
security was relatively simple. In the case of transactional external procedures, they can be
invoked from a different machine. Although the machine on which the listener and the
agent run can be highly secure, it would be possible to connect from a very insecure
machine to the agent and execute any of the external procedures. For instance, anyone
could install a database on their laptop, grant themselves all the necessary privileges and
then invoke any external procedure.
Therefore transaction support for external procedures requires a logon step.
The transaction server (XA) code that implements the transactional functionality logs on to
the non-Oracle system that is accessed by the external procedures. Since an external
procedures requires a database link to identify which agent is used to execute the external
procedures, it uses either the username/password that was used to connect to Oracle, or the
username/password that was specified in the connect as/identified by clause of the create
database link statement.
Thus, although transactional external procedures can be invoked from a different (and
possibly insecure) machine, user verification is employed on the system that is accessed by
the external procedures. M database users connected to Oracle will become one OS user
executing C code, but will end up as N users at the non-Oracle system.
Another issue is that users granted access to a library on a non-Oracle system must be
prevented from invoking C routines in other libraries. This is achieved by allowing access
to only one library per database link per session (each database link gets its own transaction
branch and has its own logon step).
"connect as"
NOS_user4
"connect as"
NOS_user3
Non-Oracle
os_user1
Listener system NOS_user2
(NOS) NOS_user1
Sample Configuration
In the sample configuration shown on the slide, multiple users (db_user1,
db_user2, and db_user3) are logged onto Oracle. Using the listener,
which has been started by os_user1, the db_users can connect to the
AGENT (also running on the system as os_user1). The (single allowed)
library LIB_A, loaded by the AGENT, allows the db_users to access the Non-
Oracle System (NOS), as NOS_user3 and NOS_user4 ("connect as"
users). NOS_user1 and NOS_user2 are logged onto the NOS via some other
means.
Database server
Listener 2 Shared
server
Client process
1
Oracle9i
Dispatcher
3 database
Shared
Pool of shared server
server process
processes
Multi-Threaded HS Agent
In the Oracle8 Heterogeneous Services architecture, agents are started up on a
per user-session and per database link basis. When a user-session tries to access
a non-Oracle system via a particular database link, an agent process is started
up dedicated to that user-session and database link. The agent process
terminates only when the user-session ends or when the database link is closed.
Separate agent processes will be started when the same user-session uses two
different database links to connect to the same non-Oracle system or when two
different user sessions use the same database link to access the same non-
Oracle system.
In the case of the Oracle server, this problem can be solved by starting the
server in multi-threaded mode. The Oracle Shared Server architecture assumes
that even when there are several thousand user-sessions currently open, only a
small percentage of these connections will be active at any given time. The
server in Oracle Shared Server mode has a pool of shared server processes— the
number of these shared server processes is usually considerably less than the
number of user-sessions— and the tasks requested by the user-sessions are put
on a queue and are picked up by the first available shared server process.
However, even if the server is running in Oracle Shared Server mode, the agent
architecture remains one process per user-session. So, any advantages obtained
using the Oracle Shared Server mode could potentially be negated if a large
number of user-sessions use HS.
To solve this problem, the Oracle9i HS agent has multi-threaded abilities. The
architecture is similar to the Oracle Shared Server architecture— with a set of
dispatcher threads to receive requests from Oracle server processes and return
results to them and a pool of task threads to process the requests and compute
results.
HS HS
Dispatcher1 Dispatcher2
HS
agent
Thread1 Thread2 Thread3
Non-Oracle system
Multi-Threaded HS Agent
Each request issued by a user-session is shown with a different type of line.
Note the following:
• All requests from a user-session go through the same dispatcher thread
but they can be serviced by different task threads
• Several task threads could use the same connection to the non-Oracle
system
• max_dispatchers
• tcp_dispatchers
• max_task_threads
• listener_address
• shutdown_address
Oracle
Application
server
TTC support TTC - IIOP - HTTP
event model Oracle names - LDAP - NDS Event model
Naming Naming
services Kerberos - DCE services
Security Biometrics - Radius Security
services services
Networking Networking
Multi-protocol interchange
services services
Failover
Network Load balancing Network
protocol Connection pooling protocol
adapters Multiplexing adapters
VI Proxying VI