Skip to Main Content
  • Questions
  • Identifying PL/SQL Packages that Maintain State

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Jason.

Asked: June 08, 2011 - 10:23 pm UTC

Last updated: April 11, 2022 - 5:11 am UTC

Version: 11.1.0

Viewed 10K+ times! This question is

You Asked

When using PL/SQL (non OO) I appreciate being able to deploy implementations to a live environment without a downtime. It works great for supporting 24x7 manufacturing facilities operating in Asia, US, and Europe off a single Oracle instance.

The problem comes in when dealing with OO PL/SQL and packages that maintain state via globals. OO PL/SQL like Java is simple enough to identify and makes sense since it maintains state by definition and isn't fully OO (like Smalltalk). But how can I identify all PL/SQL packages in the database that maintain state. Is there a simple way to build this set via a query?

Thanks,
Jason

P.S. Feel free to chastise me for deploying to a live system.

and Tom said...

As for the P.S. - fear no more:

https://asktom.oracle.com/Misc/oramag/a-closer-look-at-the-new-edition.html
https://asktom.oracle.com/Misc/oramag/edition-based-redefinition-part-2.html
https://asktom.oracle.com/Misc/oramag/looking-at-edition-based-redefinition-part-3.html

with edition based redefinition, you can achieve this sort of deployment without the "existing state of packages has been discarded"

That applies to 11g Release 2 and above however, it did not exist in Release 1.


There is no metadata that I'm aware of that will tell you if a package maintains state or not. I do not know of a way to identify that code from the dictionary..

Rating

  (5 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Edition Based Redefinition is nice but...

A reader, June 09, 2011 - 11:47 am UTC

Edition Based Redefinition is nice but in its current state is not very useful for a number of reasons.

1. What about the rest of your application? Your JSP's, Forms, etc. They also use the database. Having to introduce EBR into existing applications can certainly be done but requires additional time and making a PL/SQL implementation change via EBR only adds complexity.

2. EBR Requires a "downtime" for application users to switch to the new edition. They must log off or wait for a new connection in the pool to create a session using the new default edition. Really depends on the other parts (non-db) of your application. Certainly can be done though. But why do it when stateless PL/SQL works?

3. There are non-editionable database objects. I'm sure Oracle is working on this though.

Thank you very much for checking whether or not there is metadata in the database that tracks whether or not a PL/SQL package maintains state. That's what I wanted to know.

Thanks again,
Jason
Tom Kyte
June 09, 2011 - 12:17 pm UTC

1) what about them - for this user here - the one that wants to update database code while the database is up and running - they'd be doing that anyway.

Patching - fixing a view, a grant, a bug in a package, a broken trigger, etc - can be done online in the database now. We are not trying to fix your stuff outside of the database - that is up to that environment to do that.

2) not necessarily. As always - it depends - and in this case - it wouldn't incur downtime. We can have it so that existing sessions use the existing packages and their state - new session use the newly patched package and its new state. When no one is using the old stuff - there you go, you can drop the old edition.

If you can be stateless - by all means DO SO. I'm not a fan of global variables personally. But, also, read the above request - they have stateful code, they did it on purpose, so we have to deal with it.

3) probably not - that would include tables for example. That's a big big big problem. We have a set of tools that allow you to successfully program an online upgrade with these 'non-editionable' items - things like invisible indexes, editioning view, true online index creates, cross edition triggers, etc etc etc. If you check out the 3 part article - I do go through all of that.



Jason, June 09, 2011 - 1:58 pm UTC

"If you can be stateless - by all means DO SO. I'm not a fan of global variables personally. But, also, read the above request - they have stateful code, they did it on purpose, so we have to deal with it."

Actually, I wrote the original question and that review so I am one of those who wrote it "on purpose". However, I'd like to clean it up. Hence, my question about identifying PL/SQL packages that maintain state by querying the metadata. And I understand it has been answered.

Thanks again,
Jason

Related question

A reader, June 09, 2011 - 10:03 pm UTC

Can I ask a sort of philosophical question here? I am not clear why the error "existing state of packages has been discarded" would have even existed in the first place. If a new version of a package has been deployed to an environment, so what? At least shouldnt there be some way when its built to prevent sessions from throwing the 4061 if I as the developer make the call that I dont care to have current sessions throw the error (without having to code exception blocks for each call to it)?

Tom Kyte
June 10, 2011 - 7:57 am UTC

Think about this please.

You, the developer, have written a package. It has a variable X in a package - a global. You put into X some bit of data - counting on that bit of data to be there next time you access it.

Now, someone comes along and create or replaced your package body. Your session state has been "lobotomized" at that point - the package has to be reset (you are running new code, the old code quite simply does not exist).

Do we just silently go on and let you process with X being reset to its default?
Or do we have a responsibility to notify you that your package has been reset - and then let you decide what to do?

I think we have that responsibility. the developer/application decides what to do at this point.

Just like if you replace binaries on a Unix machine, you will get things like "page fault" and the program will crash and burn.

Just like on windows - where by you cannot replace a running binary - it just won't let you.


This is what edition based redefinition lets you "work around". With this new feature - you don't have to overwrite the existing code - we can support multiple versions of the code simultaneously.


As for the last bit - "if i as the developer make the call that i don't care to have..." - then I have to ask - why do you have globals in the first place? If you truly don't care - then why do they exist? It only makes sense to maintain a state if you CARE about the state. If you care not a whit about the state - why does it exist?

So...

Jason, January 03, 2014 - 7:58 pm UTC

Forget state.

Being able to deploy new logic to a live system that hundreds of professionals are running on without first having them stop their work is very valuable. And from what I have seen, PL/SQL provides this ability. One of the few nice things about PL/SQL in my opinion.

Again, there is no state.

So, how do you find those PL/SQL packages without state.

Thanks,
Jason

Andy, April 08, 2022 - 12:50 pm UTC

looks like Tom's links are broken. Would be nice to see the articles he has linked here.
Connor McDonald
April 11, 2022 - 5:11 am UTC

I've updated the links. Since the oracle magazine is no more, we grabbed some historical articles and kept them here

https://asktom.oracle.com/magazine-archive.htm


More to Explore

Administration

Need more information on Administration? Check out the Administrators guide for the Oracle Database