SERIALLY_REUSABLE packages [message #40625] |
Thu, 24 October 2002 08:19  |
Xenofon Grigoriadis
Messages: 33 Registered: May 2002
|
Member |
|
|
Hi there!
I just read about SERIALLY_REUSABLE packages.
What I read there is very interesting. SERIALLY_REUSABLE packages are really beeing reinstantiated every time they are beeing used, even during a open session?
If this is so, as the Oracle documentation says, then could this be perhaps a solution for the problem, that all user instantiations of package become invalid, when the package is beeing recompiled?
In other words, what would happen in the following situation?
1) user 'u1' opens a session and uses package p1, the session remains opened.
2) user 'u2' opens a session and recompiles package p1, the session remains opened.
3) user 'u1' tried to use the package p1 again.
Normaly action (3) causes the 0RA-4068 error once and forces the session to reinstatiate the package. Repeating action (3) should be successful.
Now using SERIALLY_REUSABLE packages, could it be that I don't get the ORA-4068 error any more, because the session reinstantiates the package every time it is used?
(Very important issues in high-availibility and zero-down time systems)
Thanks a lot in advance,
Xenofon
|
|
|
Re: SERIALLY_REUSABLE packages [message #40629 is a reply to message #40625] |
Thu, 24 October 2002 10:09   |
andrew again
Messages: 2577 Registered: March 2000
|
Senior Member |
|
|
Xenofon
I haven't read about them but will now that you mention them. Two thoughts though - it seems that if it got re-instantiated each time then you'd loose and state which you'd set in their globals (one of the big advantages of packages). Secondly - the scenario you are refering to where people are re-compiling code is usually not a problem in production. I'm not sure whether online re-definition breaks code or not.
|
|
|
Re: SERIALLY_REUSABLE packages [message #40632 is a reply to message #40629] |
Thu, 24 October 2002 12:09   |
Rick Cale
Messages: 111 Registered: February 2002
|
Senior Member |
|
|
Hopefully this snippet will answer most questions.
Serially Reusable PL/SQL Packages
PL/SQL packages normally consume user global area (UGA) memory corresponding to the number of package variables and cursors in the package. This limits scalability because the memory increases linearly with the number of users. The solution is to allow some packages to be marked as SERIALLY_REUSABLE (using pragma syntax).
For serially reusable packages, the package global memory is not kept in the UGA per user, but instead it is kept in a small pool and reused for different users. This means that the global memory for such a package is only used within a unit of work. At the end of that unit of work, the memory can therefore be released to the pool to be reused by another user (after running the initialization code for all the global variables).
The unit of work for serially reusable packages is implicitly a CALL to the server, for example, an OCI call to the server, or a PL/SQL client-to-server RPC call or server-to-server RPC call.
Package States
The state of a nonreusable package (one not marked SERIALLY_REUSABLE) persists for the lifetime of a session. A package's state includes global variables, cursors, and so on.
The state of a serially reusable package persists only for the lifetime of a CALL to the server. On a subsequent call to the server, if a reference is made to the serially reusable package, Oracle creates a new instantiation (described below) of the serially reusable package and initializes all the global variables to NULL or to the default values provided. Any changes made to the serially reusable package state in the previous CALLs to the server are not visible.
Note: Creating a new instantiation of a serially reusable package on a CALL to the server does not necessarily imply that Oracle allocates memory or configures the instantiation object. Oracle simply looks for an available instantiation work area (which is allocated and configured) for this package in a least-recently used (LRU) pool in SGA. At the end of the CALL to the server this work area is returned back to the LRU pool. The reason for keeping the pool in the SGA is that the work area can be reused across users who have requests for the same package.
Why Serially Reusable Packages?
Since the state of a non-reusable package persists for the lifetime of the session, this locks up UGA memory for the whole session. In applications such as Oracle Office a log-on session can typically exist for days together. Applications often need to use certain packages only for certain localized periods in the session and would ideally like to de-instantiate the package state in the middle of the session once they are done using the package.
With SERIALLY_REUSABLE packages the application developers have a way of modelling their applications to manage their memory better for scalability. Package state that they care about only for the duration of a CALL to the server should be captured in SERIALLY_REUSABLE packages.
|
|
|
Re: SERIALLY_REUSABLE packages [message #567338 is a reply to message #40625] |
Wed, 26 September 2012 15:12   |
 |
Matthew Moisen
Messages: 2 Registered: September 2012
|
Junior Member |
|
|
Hi Xenofon Grigoriadis,
Yep, it looks like making your packages serially reusable will prevent the package from becoming invalid when it gets recompiled.
I was getting this problem when making simple adjustments to a package body, like to a debugging message from DBMS_OUTPUT.PUT_LINE. After recompiling the package and then executing a procedure from it, I would receive the ORA-04068 / ORA-04061, existing state of package/body has been discarded/invalidated, and ORA-04065 / ORA-06508. The next try of course would work, but this was annoying nonetheless.
After adding the PRAGMA SERIALLY_REUSABLE line to both the package and package body, I stopped receiving this error.
Of course if your package is designed to not be serially reusable, then this would be a bad idea. At the same time, if your package is designed to be serially reusuable, we should be issuing this pragma anyways...
Thank you,
Matthew Moisen
|
|
|
|
Re: SERIALLY_REUSABLE packages [message #567341 is a reply to message #567339] |
Wed, 26 September 2012 18:05  |
 |
Matthew Moisen
Messages: 2 Registered: September 2012
|
Junior Member |
|
|
*Facepalm*
My apologies. This was one of the first results to pop up in Google under the search string "when to use serially reusable packages," so I assumed this thread must have been recent, rather than 10 years old... I (usually) know how to operate on a forum, but I will definitely check on those rules before posting again! Thank you.
Matthew Moisen
|
|
|