PL/SQL application wide state - 09-29-2003 , 12:29 PM
I'm a wonderin...
I have an application that will implement key business logic in PL/SQL,
and uses various configuration values, as stored in various database
tables, to control certain aspects of it's operations.
Is there not some way to read these configuration values into some
sort of persistent application wide memory cache?
Like, if I were writing a C++, java, or C# application, I'd read the
various configuration tables at startup, (or on first use), and populate
a single application wide cache that would be used subsequently.
Is there no corresponding mechanism with PL/SQL?
Packages provide each individual session with it's own copy of whatever
package variables are defined, and that's a good thing, but it seems like
there needs to be some other intra-session store that can be used on
an application wide basis. No?
Do I have to re-read the tables each time? Maybe this is OK since PL/SQL
runs in the server, but it still seems wasteful. Can certain tables be
"pinned" or something like that?
I could use package variables, but this would duplicate the values for
each user session. Worse, it would be very much more complicated to
resyncronize these many caches in the event that the data is updated
(rare - but can happen)
Thanks for any thoughts and suggestions
Re: PL/SQL application wide state - 09-29-2003 , 02:59 PM
On Mon, 29 Sep 2003 17:29:45 GMT, roger <xrsr (AT) rogerware (DOT) com> wrote:
Maybe this is OK since PL/SQL
pool on 8.0 higher.
You seem to think I/O is bad, and that the buffer cache doesn't exist.
Sybrand Bakker, Senior Oracle DBA
To reply remove -verwijderdit from my e-mail address
Re: PL/SQL application wide state - 09-29-2003 , 03:43 PM
Sybrand Bakker <gooiditweg (AT) sybrandb (DOT) demon.nl> wrote in
news:hh3hnvcltbqmtphvdgh4ft364k1uuim5b5 (AT) 4ax (DOT) com:
Performance aside, the other reason one might wish to extract
these table-resident values, rather than re-select them every time,
they are needed, would be to provide a more convenient and robust
API for using them.
OOps, that must be my "crap 3gl" background showing through.
Sorry, I'll have to try and remember to shut off that half
of my brain when posting here in the future.
Seems a pity.
Re: PL/SQL application wide state - 09-29-2003 , 06:21 PM
can be used to execute code and pin it in memory on startup and Oracle's
section that, used in conjunction with the triggers, can maintain
persistent memory in variables during a
(replace 'x' with a 'u' to reply)
Re: PL/SQL application wide state - 09-29-2003 , 11:13 PM
Daniel Morgan <email@example.com> wrote in news:1064877684.182592
How they help me here is a bit more elusive...
"Execute code and pin it in memory"
Let's see. I guess you mean some PL/SQL code that I would
supply, and that what gets pinned in memory would not be
the code, but whatever my code would want to put there.
So, what's that mechanism then? Buffer caches as mentioned
previously? Or is there some other mechanism available here?
About all I can find is the CACHE clause for create table,
For data that is accessed frequently, this clause indicates that the
blocks retrieved for this table are placed at the most recently used
end of the least recently used (LRU) list in the buffer cache when a
full table scan is performed. This attribute is useful for small
That sounds like a good start and easy enough to do.
Is there anything more clever/subtle that I should be
looking for here?
(it's that old needle/haystack thing again)
I said previously that I didn't think package variables,
which I understand to be per-session, were appropriate
for my purposes.
Were you suggesting that there is yet some way to use
package variables to share state across sessions?
Re: PL/SQL application wide state - 09-30-2003 , 05:43 PM
See globally accessed application context in the documentation. You can
set these up on a user and/or client basis or across all users. They
are designed to be secure by specifying a single package or procedure
that can modify their state but you can specify sys.dbms_session to
essentially make them unsecure. For example ...
create context my_context using sys.dbms_session accessed globally;
dbms_session.set_context('MY_CONTEXT', 'MY_ATTRIBUTE', 'MY_VALUE');
then anytime anybody connects you can use the SYS_CONTEXT function to
retrieve values ...
value := sys_context('MY_CONTEXT', 'MY_ATTRIBUTE');
As I said, you can also make them user and client specific (see the
documentation for more information). Have a look at the GLOBAL_CONTEXT
system view as well.
Re: PL/SQL application wide state - 10-01-2003 , 01:24 AM
roger <xrsr (AT) rogerware (DOT) com> wrote
their for. But they are butt ugly when dealing with parameters, right?
Solution: PL/SQL Object wrappers. Makes the implementation many times
neater and flexible. Instead of dealing with SQL and tables, you deal
with an object class called something like TParamater, e.g. very
create or replace type TParameter as object
constructor function TParameter( name$ varchar2 )
return self as result,
member function AsDate return Date,
member function AsBoolean return Boolean,
member function AsInteger return Number,
member function Exist return Boolean,
member procedure Save
I leave the body type to your imagination. :-)
The PL/SQL will look someting like this:
p$ := NEW TParameter('LAST PROCESS RUN');
if p$.AsDate < blah blah
The second solution is using the namespace feature of Oracle called
context. A context contains name-value pairs. A context is much like a
Unix/NT environment containing environmental variables. What is really
nifty is that you can bind a single PL/SQL procedure to that context
to populate it. Thus, no one can change the context - they have to run
the procedure (aka read-only .profile/autoexec.bat) to populate the
context with name-value pairs. This makes the context trusted and a
great tool for implementing security (like Fine Grained Access
Again - this can (and should) also be wrapped in PL/SQL OO wrappers.
Making the actual implementation of the parameters (as tables or as
namespace) totally transparent to the PL/SQL developer.