Professional Documents
Culture Documents
Managing Code in
the Database
Steven Feuerstein
The Oracle data dictionary is a jungle—lushly full of incredible information, but
often with less than clear pathways to your destination. In this article, Steven
Feuerstein shows the way by exploring the use of some of the more useful Oracle
dictionary views.
W
HEN you CREATE OR REPLACE a PL/SQL program, the source
code for that program, along with other representations of that
software, is stored in the database itself and exposed through a
wide range of data dictionary views. This is a tremendous advantage for two May 2005
key reasons: Volume 12, Number 5
• Information about that code is available to you via the SQL language. I
can write queries and even entire PL/SQL programs to read the contents 1 Managing Code in
of these data dictionary views and obtain lots of fascinating and useful the Database
information about my code base. Steven Feuerstein
• The database manages dependencies between your stored objects. For 7 Gently Down the Stream,
example, if a stored function relies on a certain table, and that table’s Part 4
structure is changed, the status of that function is automatically set to Darryl Hurley
INVALID. Recompilation then takes place automatically when someone
12 Getting DDL with
tries to execute that function. DBMS_METADATA
Al Hetzel
This SQL interface to your code base allows you to manage your code
repository—running analyses on your code, documenting what has been 16 May 2005 Downloads
written and changed, and so on. This article reviews some of the commonly
used and useful of these data dictionary views (including some very useful
views added in Oracle9i and Oracle10g), and offers a variety of examples
showing how the views can be applied to answer important questions about Indicates accompanying files are available online at
www.pinnaclepublishing.com.
your code base. Continues on page 3
AD:
AGE
LL P O
FU N X
Q
l_overloads overload_aat ;
T
Streams CAPTURE C001 started with pid=20, OS id=1480
HE first three articles in this series explained how to Thu Jan 27 22:08:45 2005
set up and run a capture process, including moving LOGMINER: Parameters summary for session# = 175
LOGMINER: ReqParallelism = 3, EagerThreshold = 1
forward through redo logs. In this one, I’ll wrap LOGMINER: StopMiningThreshold = 1M, MemorySize = 10M
up the discussion of capture processes by providing LOGMINER: MaxLogLookback = 10M
LOGMINER: session# = 175, reader process P002 started
some notes on monitoring and configuration that I’ve with pid=25 OS id=1556
found useful, including checking for errors and LOGMINER: session# = 175, builder process P003 started
with pid=26 OS id=1516
configuring memory. LOGMINER: session# = 175, preparer process P004 started
with pid=27 OS id=1576
Scheduled stops
I’ve found that letting capture processes run for
One way to manage how long a capture process runs is
one hour (3,600 seconds) at a time requires the fewest
to force regular restarts whenever a certain number of
unscheduled manual restarts (your results may vary, of
messages have been captured or a number of seconds
course). So what could necessitate an unscheduled start?
have passed. Once the specified limit is reached, the
Just a few things, which I’ll discuss next.
capture process will stop. The parameter DISABLE_
ON_LIMIT controls the behavior after the stoppage: If set
Unscheduled stops
to ‘Y’ it won’t restart, and if set to ‘N’ it will automatically
I have to admit that capture processes are surprisingly
restart. Details of the starts and stops can optionally be
stable, although they do encounter errors from time to
written to the alert log as well. Listing 1 demonstrates
time. The good news is they can usually just be restarted
setting these values.
to carry on. The really good news is the cause of the
stoppage is easily gleaned from the DBA_CAPTURE view.
Listing 1. Setting time limit and write to alert log.
SQL> SELECT status,
2 status_change_time,
SQL> BEGIN
3 error_number,
2 DBMS_CAPTURE_ADM.SET_PARAMETER('CAPTURE',
4 error_message
3 'TIME_LIMIT', 5 FROM dba_capture;
4 '3600');
5 END; STATUS STATUS_CH ERROR ERROR_MESSAGE
6 / ------- --------- ----- -------------------------------
ABORTED 27-JAN-05 1280 ORA-01280: Fatal LogMiner Error
PL/SQL procedure successfully completed.
SQL> SELECT high_water_mark, The most common cause of failure for propagations
2 acknowledgement,
3 elapsed_rule_time,
is the destination apply queue being unreachable. For
4 elapsed_enqueue_time example, if the destination was in another Oracle database
5 FROM v$propagation_receiver
6 / and the Listener was down, it would be impossible to
connect in order to propagate LCRs.
HWM ACK RULE_TIME ENQUEUE_TIME
---- ---- ---------- ------------ That’s really all there is to cover with regards to
17 17 0 0 propagation processes. They’re relatively simple to set
up and monitor compared to capture processes, as I
The key thing to note here is that the same number of discussed previously, and apply processes, which I’ll
messages (17) has been received. Also of note is the time start covering in the next installment of this series. See
the receiver process has spent evaluating the rule and to you then. ▲
enqueue the LCR in the apply queue. So far it’s been so
fast that no time has been recorded. Darryl Hurley has been working with Oracle technology for 15 years with
An overview of the propagation is shown in this a significant focus on database administration and PL/SQL development.
query showing the time spent propagating, the number His days are spent as the Senior Database Developer for MDSI Mobile
of messages propagated, and the number of failures to Data Solutions Inc. (www.mdsi-advantex.com), and his spare time is spent
propagate (thankfully, zero so far). writing articles and teaching under the moniker of ImpleStrat Solutions
(www.implestrat.com). He has written several articles for the Oracle
SQL> SELECT propagation_name, Development Tools User Group (www.odtug.com) and contributed to
2 total_time,
3 total_number, several Oracle books from O’Reilly (www.ora.com). dhurley@mdsi.ca or
4 failures darryl.hurley@implestrat.com.
Participate in three dynamic Webinars, offering in-depth With Pinnacle’s Webinars, you can receive quality, cost-
training with world-renowned Oracle PL/SQL author Steven effective online training at your fingertips. Why spend training
Feuerstein, on key features of the PL/SQL language. dollars on travel, when you can learn from the experts from
your desk or conference room? Our Webinars make it
Webinar #1: “Spotlight on Collections” possible to offer expert training to large numbers of developers
June 8, 2005: 8:00 am-10:00 am (CT), 2:00 pm-4:00 pm (CT) in your organization. You no longer have to send a single
Webinar #2: “Spotlight on Native Dynamic SQL” “representative,” who must then return and attempt to pass on
June 23, 2005: 8:00 am-10:00 am (CT), 2:00 pm-4:00 pm (CT) what he or she learned. Everyone can attend!
Webinar #3: “Spotlight on Exception Handling” Visit www.pinpub.com/op for complete event details and
July 13, 2005: 8:00 am-10:00 am (CT), 2:00 pm-4:00 pm (CT) online registration.
P
RIOR to Oracle9i, getting the DDL for a database
Listing 1. The GET_DDL function
object was something of a challenge. You could
DESC a table to get the column information. dbms_metadata.get_ddl(
However, you would still need the indexes, foreign <object_type>,
<object_name>,
keys, and constraints. Getting this information could be <schema_name>,
extremely time-consuming, since there were only three <version>,
<model>,
main ways to do it: <transform> )
• Use the export utility (EXP). By setting ROWS=NO,
you could get the DDL by exporting the tables. The object_type refers to the type of database object
However, the results were poorly formatted. You that’s being reverse engineered. This type will be one of
would have to pull out the DDL and then reformat it the Oracle standard objects. A complete list of the objects
before being able to use it. that can be retrieved through the GET_DDL function is
• Create a dictionary script. All of the object definitions shown in the “Identifying potential objects” section of this
are contained in one or more SYSTEM tables. You article. The object_type is a required parameter.
could create a script to search through those tables The object_name refers to the actual name of the
and painstakingly reconstruct the object. Of course, object. Since each name must be unique within a schema,
you had to know which SYSTEM tables to use and the object_name will identify the specific object. This
how to put the data together. Also, you could only get parameter is also required.
those objects for which you had created a script. The schema_name refers to the schema that holds the
• Use a third-party tool. If you didn’t want to deal with object. Using this parameter, object_type, and object_
the problems with the first two solutions, you could name, any single object on the database can be identified.
buy a third-party tool. Some of these tools were This parameter is optional. If it’s not included, then the
extremely useful even though you did have to buy current schema is used as the default.
and configure them for use with your database. The version refers to the specific database version
Unfortunately, not all of the tools provided of the DDL. This parameter is used for backwards
everything you needed. Some might give you the compatibility since it will only extract the DDL that’s
constraints but not the storage parameters. Some compatible with the specified version. The three legal
might give you the primary and foreign keys but values for this parameter are COMPATIBLE, which
nothing else. corresponds to the database compatibility level (must be
set to 9.0.1 or higher), LATEST, which corresponds to the
With Oracle9i and 10g, we now have a new built-in current database version, or a specific database version
package called DBMS_METADATA. This package will (for example, 9.0.1). This parameter is optional. If it’s not
Figure 1. Default
CLOB returned.
dbms_metadata.set_transform_param(
<transform_handle>,
<parameter_name>,
<boolean_value> )
The transform_handle is a
numeric value that represents the
specific session. You don’t need to
know this number. Instead, you can
use the SESSION_TRANSFORM
variable from the DBMS_
METADATA package. This number
is required to use the procedure.
The parameter_name is the
specific parameter that you want to
change. There are 20 different
parameters than can be set with this Figure 2. CLOB with some different settings.
Pinnacle, A Division of Lawrence Ragan Communications, Inc. ▲ 800-493-4867 x.4209 or 312-960-4100 ▲ Fax 312-960-4106
For access to current and archive content and source code, log in at www.pinnaclepublishing.com.
Subscription rates This publication is intended as a general guide. It covers a highly technical and complex
subject and should not be used for making decisions concerning specific products or
applications. This publication is sold as is, without warranty of any kind, either express or
United States: One year (12 issues): $199; two years (24 issues): $348 implied, respecting the contents of this publication, including but not limited to implied
Other:* One year: $229; two years: $408 warranties for the publication, performance, quality, merchantability, or fitness for any particular
purpose. Lawrence Ragan Communications, Inc., shall not be liable to the purchaser or any
Single issue rate: other person or entity with respect to any liability, loss, or damage caused or alleged to be
caused directly or indirectly by this publication. Articles published in Oracle Professional
$27.50 ($32.50 outside United States)* reflect the views of their authors; they may or may not reflect the view of Lawrence Ragan
Communications, Inc. Inclusion of advertising inserts does not constitute an endorsement by
* Funds must be in U.S. currency. Lawrence Ragan Communications, Inc., or Oracle Professional.