Tải bản đầy đủ (.pdf) (40 trang)

oracle 8 database administration volume 1 instruction guide phần 5 doc

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (227.5 KB, 40 trang )

Data Dictionary Structure
......................................................................................................................................................

Base Tables and Data
Dictionary Views

Data dictionary views:
- Views simplify the base table information
- Created with the catalog.sql script

Base tables:
- Normalized
- Created with the sql.bsq script
5-4

Copyright © Oracle Corporation, 1998. All rights reserved.

The data dictionary, located in the SYSTEM tablespace and owned by the
user SYS, contains two parts:
• Base tables
• Data dictionary views
Base Tables
The foundation of the data dictionary is a set of base or underlying tables.
The Oracle server writes and reads these tables. Database users rarely access
them directly because they are normalized and the information is encoded.
For example, you would query the IND$ table to get information about the
indexes that are defined in the database, or select from the OBJ$ table to
display the objects defined in the database.
Never use DML commands such as INSERT, UPDATE, and DELETE to
update the base data dictionary tables directly, with the exception of the
AUD$ table (see the lesson “Auditing”).



......................................................................................................................................................
Oracle8: Database Administration
5-5


Lesson 5: Creating Data Dictionary Views and Standard Packages
......................................................................................................................................................

Data Dictionary Views
The data dictionary views are created by running the catalog.sql script.
These views decode and summarize the information in the base data
dictionary tables. Public synonyms are created on the data dictionary views
so that users can access them easily.
Most users examine the data dictionary by selecting from the views rather
than the base tables.

......................................................................................................................................................
5-6
Oracle8: Database Administration


Data Dictionary Structure
......................................................................................................................................................

Data Dictionary Views
DBA_xxx

objects of the entire database
ALL_xxx


objects can be accessed by the user
USER_xxx

objects owned by the user

5-5

Copyright © Oracle Corporation, 1998. All rights reserved.

Data Dictionary View Categories
The data dictionary views are split into three categories. In many cases the
views contain similar information and can be distinguished from each other
by their prefixes.
The Prefix USER
These views are accessible by any user and generally refer to objects owned
by a user—for example, USER_TABLES contains information on all tables
owned by the user. These views return a subset of the information in the
ALL_ views.
The Prefix ALL
Views with the prefix ALL are accessible by any user and usually include the column
OWNER. These views return information about objects to which the user has access via
public or explicit grants of privileges and roles, including the objects that the user owns.
The Prefix DBA
Views with the prefix DBA give information on all the objects in the database and usually
include the column OWNER. These views are queried by the database administrator or
any user granted the system privilege SELECT ANY TABLE (see the lesson “Managing
Privileges”). Synonyms are created for these views so that every user with the SELECT
ANY TABLE privilege can query them.


......................................................................................................................................................
Oracle8: Database Administration
5-7


Lesson 5: Creating Data Dictionary Views and Standard Packages
......................................................................................................................................................

Data Dictionary: Views
Examples and Categories
Views

Description

dictionary
dict_columns

General overview

dba_tables
dba_objects
dba_lobs
dba_tab_columns
dba_constraints

Information related to the user
objects such as tables, constraints,
large objects and columns

dba_users

dba_sys_privs
dba_roles

Information about user privileges
and roles

Copyright © Oracle Corporation, 1998. All rights reserved.

5-6

Data Dictionary Views:
Examples and Categories
Views

Description

dba_extents
dba_free_space
dba_segments

Space allocation for database
objects

dba_rollback_segs
dba_data_files
dba_tablespaces

General database structures

dba_audit_trail

dba_audit_objects
dba_audit_obj_opts
5-7

Auditing information

Copyright © Oracle Corporation, 1998. All rights reserved.

......................................................................................................................................................
5-8
Oracle8: Database Administration


Data Dictionary Structure
......................................................................................................................................................

To get an overview of the data dictionary views, their columns, and the
dynamic performance views, you can query the DICTIONARY or
DICT_COLUMNS view.
SVRMGR>SELECT *
2> FROM dictionary
3> WHERE table_name
TABLE_NAME
-------------------ALL_ALL_TABLES
ALL_NESTED_TABLES
ALL_OBJECT_TABLES
ALL_PART_TABLES
ALL_TABLES
ALL_UPDATABLE_COLUMNS
DBA_ALL_TABLES

DBA_NESTED_TABLES
DBA_OBJECT_TABLES

LIKE ’%TABLE%’;
COMMENTS
---------------------------------------Description of all object and relational
tables accessible to the user
Description of nested tables in tables
accessible to the user
Description of all object tables
accessible to the user
Description of relational tables accessible
to the user
Descriptionofallupdatablecolumns
Description of all object and relational
tables in the database
Description of nested tables contained in
all tables
Description of all object tables in the
database

...

......................................................................................................................................................
Oracle8: Database Administration
5-9


Lesson 5: Creating Data Dictionary Views and Standard Packages
......................................................................................................................................................


Note
There is a synonym DICT for the data dictionary view DICTIONARY.
SVRMGR>SELECT column_name, comments
2> FROM dict_columns
3> WHERE table_name=’DBA_TABLES’;
COLUMN_NAME
--------------OWNER
TABLE_NAME
TABLESPACE_NAME
CLUSTER_NAME
IOT_NAME

COMMENTS
--------------------------------------------Owner of the table
Name of the table
Nameofthetablespacecontainingthetable
Name of the cluster, if any, to which the table
belongs
Name of the index-only table, if any, to which
the overflow entry belongs

Note
For a detailed description of the views and their columns, see the Oracle8
Server reference manual.

......................................................................................................................................................
5-10
Oracle8: Database Administration



Constructing the Data Dictionary
......................................................................................................................................................

Constructing the Data Dictionary

Creating Data Dictionary Views
Script

Purpose

catalog.sql

Creates commonly used data dictionary
views

catproc.sql

Runs all scripts required for PL/SQL on the
server

5-8

Copyright © Oracle Corporation, 1998. All rights reserved.

After database creation, the catalog.sql and catproc.sql scripts must be run
as the user SYS. They are located in the $ORACLE_HOME/rdbms/admin
directory on UNIX and in the %ORACLE_HOME%\rdbms80\admin
directory on NT.
The catalog.sql Script

The catalog.sql script creates the views on the base tables, views on the
dynamic performance views and their synonyms. It starts scripts, such as
those to create views and objects for the Server Manager utility, for auditing,
for the Export and Import utility, and for the partitioning and object options.
It runs the standard.sql script, which creates the basic PL/SQL environment.
The standard.sql script declares types, exceptions, and subprograms, which
are automatically available to every PL/SQL program. For example, it
declares the built-in function named BITAND, which returns the result of
the bit operation and of its arguments:
function BITAND (LEFT binary_integer, RIGHT binary_integer)
return binary_integer;

......................................................................................................................................................
Oracle8: Database Administration
5-11


Lesson 5: Creating Data Dictionary Views and Standard Packages
......................................................................................................................................................

The catproc.sql Script
The catproc.sql script establishes the usage of the PL/SQL functionality. In
addition, it creates several PL/SQL packages that are used to extend the
RDBMS functionality. The catproc.sql script also creates additional views
for the advanced queuing option, tablespace point-in-time recovery, and the
use of LOBs.
Note
You may use additional scripts to support other extended Oracle
functionality, as discussed in the next section.


......................................................................................................................................................
5-12
Oracle8: Database Administration


Using Administrative Scripts
......................................................................................................................................................

Using Administrative Scripts

Administrative Scripts
The following naming conventions exist
for the sql scripts:
Convention

Description

cat*.sql

Catalog and data dictionary information

dbms*.sql

Database package specifications

prvt*.plb

Wrapped database package code

utl*.sql


Views and tables for database utilities

5-9

Copyright © Oracle Corporation, 1998. All rights reserved.

The $ORACLE_HOME/rdbms/admin directory on UNIX (or
%ORACLE_HOME%\rdbms80\admin on NT ) contains administrative
scripts, which can be separated into four categories of files:
• utl*.sql
• cat*.sql
• dbms*.sql
• prvt*.plb
The utl*.sql Scripts
The utl*.sql scripts must be run when the database needs additional views
and tables.
For example, the script utlsampl.sql creates and populates the sample tables
EMP, DEPT, SALGRADE, and BONUS under the user SCOTT.

......................................................................................................................................................
Oracle8: Database Administration
5-13


Lesson 5: Creating Data Dictionary Views and Standard Packages
......................................................................................................................................................

The cat*.sql Scripts
The cat*.sql scripts create data dictionary views.

In addition to the catalog.sql and catproc.sql scripts, there are scripts that
create information for Oracle utilities. For example, the catrman.sql script
creates recovery catalog tables and views for the Recovery Manager. The
catnormn.sql script drops these tables and views.
The dbms*.sql and prvt*.plb Scripts
The dbms*.sql and prvt*.plb scripts contain information about predefined
Oracle packages (see the next section), which extend the Oracle
functionality by providing stored database procedures and functions. These
programs simplify the task of administering the database.
Most SQL scripts are run during the execution of the catproc.sql script. A
few additional scripts must be executed by the database administrator. An
example is the dbmspool.sql script enables you to display the sizes of objects
in the shared pool and mark them for keeping or unkeeping in order to
reduce shared pool fragmentation.
Note
Most of these scripts must be executed under the user SYS. The database
administrator should examine the scripts to find out which user account must
be used to run the scripts.
Instructor Note
Point out that there are also useful sample and demo scripts in the following
directories on NT:
• %ORACLE_HOME%\RDBMS80\AQ
• %ORACLE_HOME%\RDBMS80\LOADER
• %ORACLE_HOME%\RDBMS80\RMAN
These explain the advanced queuing, Loader, and Recovery Manager
functionality.
On UNIX, these scripts are located in the $ORACLE_HOME/rdbms/demo
directory.

......................................................................................................................................................

5-14
Oracle8: Database Administration


Administering Stored Procedures and Packages
......................................................................................................................................................

Administering Stored Procedures and Packages

Stored Procedures
and Packages
Instance

Database applications
Shared pool
DBMS_SESSION

begin
...
dbms_session.set_role(..)

SGA

SET_ROLE
begin...
end;

...
end;


PLUS>execute dbms_session.set_role(..)
SVRMGR>execute dbms_session.set_role(..)
5-10

Copyright © Oracle Corporation, 1998. All rights reserved.

Users can store PL/SQL program units in the database and execute them
using Oracle tools such as SQL*Plus, Server Manager, or Enterprise
Manager, or to execute them from an Oracle application. Stored procedures,
including procedures and functions, and packages are examples of PL/SQL
program units.
Stored procedures and packages are database objects that are created and
removed from the schema of a user with a CREATE or DROP command.
Packages are very useful for administrative tasks.
In the example, the DBMS_SESSION.SET_ROLE procedure is executed
using SQL*Plus and Server Manager, and from an Oracle application.
Note
The procedure DBMS_SESSION.SET_ROLE will be explained in a
subsequent section.

......................................................................................................................................................
Oracle8: Database Administration
5-15


Lesson 5: Creating Data Dictionary Views and Standard Packages
......................................................................................................................................................

Benefits
Stored program units provide the following advantages:

• They are stored in the shared pool and reduce disk retrieval.
• Data security is enforced because users can access only data through
procedures and functions.
• For execution, multiple users can share a single copy of the procedures.
Note
This section presents an overview of the stored procedures to enable you to
administer the stored units. Developing and maintaining stored procedures
and packages is covered in detail in the course PL/SQL Program Units.

......................................................................................................................................................
5-16
Oracle8: Database Administration


Administering Stored Procedures and Packages
......................................................................................................................................................

What Are Stored Procedures?
• Are procedures or functions
• Are stored in the data dictionary
• Can be used by many users
• Can accept and return parameters
• Can be used in SQL functions

5-11

Copyright © Oracle Corporation, 1998. All rights reserved.

A stored procedure is a procedure or function that is created and stored in
the data dictionary as a schema object. It consists of a set of SQL and

PL/SQL constructs. Once created and compiled, it is a named object that can
be executed without recompiling. Additionally, dependency information is
stored in the data dictionary to verify the validity of each stored procedure.
The user can also include stored functions in SQL expressions. They are
used in the same manner as built-in Oracle functions such as UPPER and
SUBSTR.
Procedures and functions provide parameters that can be input only (IN),
output only (OUT), or both input and output parameters (IN OUT). The IN
mode is the default.

......................................................................................................................................................
Oracle8: Database Administration
5-17


Lesson 5: Creating Data Dictionary Views and Standard Packages
......................................................................................................................................................

What Are Packages?
• Group logically related PL/SQL types,
items, and subprograms
• Have two parts:
– A specification
– A body

• Allow Oracle to read multiple objects
into memory at once

5-12


Copyright © Oracle Corporation, 1998. All rights reserved.

A package usually has a specification and a body stored separately in the
database:
• The specification is the interface to the application and declares the
types, variables, constants, exceptions, cursors, and subprograms
available for use.
• The body implements the specification.
The functionality of a package is similar to that of stored procedures. Once
written and compiled, the contents can be shared by many applications.One
major benefit is that the first time a package construct is called, the whole
package is loaded into memory.

......................................................................................................................................................
5-18
Oracle8: Database Administration


Administering Stored Procedures and Packages
......................................................................................................................................................

Package
Package
specification

Package
body

Procedure A
declaration


Procedure B
definition
Procedure A
definition
Local
variable

5-13

Copyright © Oracle Corporation, 1998. All rights reserved.

Example
Package
specification
from
dbmsutil.sql

Package
body from
prvtutil.plb

5-14

create or replace package
dbms_session is
procedure set_role
(role_cmd varchar2);

create or replace package body

dbms_session wrapped
0
abcd
abcd
abcd
abcd ...

Copyright © Oracle Corporation, 1998. All rights reserved.

......................................................................................................................................................
Oracle8: Database Administration
5-19


Lesson 5: Creating Data Dictionary Views and Standard Packages
......................................................................................................................................................

In the example, the DBMS_SESSION package specification is located in the
dbmsutil.sql script and the package body is located in the prvtutil.plb script.
The package body in the prvtutil.plb script (plb, PL/SQL binary, is the
default extension) has been created with the Wrapper Oracle utility.
The PL/SQL Wrapper hides application internals by converting PL/SQL
source code into mnemonics.
1 Because this is not an additional functionality, it is not required to run
the two scripts to create the database packages.
2 Execute the package procedure SET_ROLE with the required IN
parameter value, the name of the role, in SQL*Plus or in Server
Manager:
SVRMGRL>execute DBMS_SESSION.SET_ROLE('APP1');
Statement processed.


This generates the SET ROLE command, appending the text APP1 to
"SET ROLE " and then executing as an SQL command. This command
enables or disables roles and will be covered in detail in the lesson
“Managing Roles.”

......................................................................................................................................................
5-20
Oracle8: Database Administration


......................................................................................................................................................

Oracle-Supplied Packages


DBMS_LOB—Provides routines for operations on
BLOB and CLOB datatypes



DBMS_SESSION—Generates SQL commands like
ALTER SESSION or SET ROLE




DBMS_UTILITY—Provides various utility routines





DBMS_ROWID—Provides ROWID information

DBMS_SPACE—Provides segment space
availability information
DBMS_SHARED_POOL—Keeps and unkeeps
information in the shared pool
5-15

Copyright © Oracle Corporation, 1998. All rights reserved.

The packages described in the slide are examples of Oracle-supplied
packages.
DBMS_SPACE, DBMS_UTILITY, DBMS_ROWID, DBMS_SESSION,
and DBMS_LOB are created during the execution of the catproc.sql script.
DBMS_SPACE, DBMS_UTILITY, DBMS_ROWID, and
DBMS_SESSION are defined by the scripts dbmsutil.sql and prvtutil.plb,
while DBMS_LOB is defined by dbmslob.sql and prvtlob.plb.
Another utility, the DBMS_SHARED_POOL package, keeps objects in the
shared pool so that they will not be aged out with the normal LRU
algorithm. It is created by running the dbmspool.sql script.

......................................................................................................................................................
Oracle8: Database Administration
5-21


Lesson 5: Creating Data Dictionary Views and Standard Packages
......................................................................................................................................................


Examples for Package Procedures
Package
DBMS_SESSION

DBMS_UTILITY

DBMS_ROWID
DBMS_SPACE
DBMS_SHARED_POOL

Package procedures
SET_ROLE
SET_SQL_TRACE
SET_NLS
ANALYZE_SCHEMA
COMPILE_SCHEMA
DB_VERSION
ROWID_INFO
UNUSED_SPACE
FREE_BLOCKS
KEEP
UNKEEP

Note
Most of the Oracle supplied packages are explained in detail in
Oracle-supplied Oracle8 Server Application Developer’s Guide and in
Oracle8 PL/SQL User’s Guide and Reference.

......................................................................................................................................................

5-22
Oracle8: Database Administration


Obtaining Information
......................................................................................................................................................

Obtaining Information

Obtaining Information About
Stored Objects
• Data dictionary view DBA_OBJECTS:
– OWNER
OBJECT_NAME
OBJECT_TYPE
STATUS (VALID, INVALID)

ã DESCRIBE command:
describe dbms_session.set_role
5-16

Copyright â Oracle Corporation, 1998. All rights reserved.

Dependencies
Oracle automatically records dependencies among objects in the data
dictionary. For example, a procedure can be dependent on a view, and a view
again is dependent on a table. If the table on which the view is built is
dropped, Oracle sets the STATUS column of the data dictionary view
DBA_OBJECTS for the dependent view and procedure to INVALID.
All schema objects in a database have a status of VALID or INVALID.

• VALID: The object has been compiled and can be immediately used
when referenced.
• INVALID: The object must be compiled before it can be used. In the
case of procedures, functions, and packages, this means compiling the
object. In the case of views, this means that the view must be reparsed. If
these objects are still invalid after recompiling, syntax errors may have
occurred.

......................................................................................................................................................
Oracle8: Database Administration
5-23


Lesson 5: Creating Data Dictionary Views and Standard Packages
......................................................................................................................................................

Query the data dictionary view DBA_OBJECTS to obtain information about
the owner, name, type, and status of the objects in the database.
SVRMGR> SELECT object_name, object_type, status
2> FROM dba_objects WHERE object_name like ’DBMS_%’
OBJECT_NAME
-------------------DBMS_ALERT
DBMS_ALERT
DBMS_ALERT_INFO
DBMS_APPLICATION_INF
DBMS_APPLICATION_INF
DBMS_AQ
DBMS_AQ
...


OBJECT_TYPE
--------------PACKAGE
PACKAGE BODY
TABLE
PACKAGE
PACKAGE BODY
PACKAGE
PACKAGE BODY

STATUS
-------VALID
VALID
VALID
VALID
VALID
VALID
VALID

Run the DESCRIBE command in Server Manager for information about
parameters used:
SVRMGR> DESCRIBE dbms_session.set_role
procedure SET_ROLE (ROLE_CMD VARCHAR2);

......................................................................................................................................................
5-24
Oracle8: Database Administration


Obtaining Information
......................................................................................................................................................


Note
The execution of the DESCRIBE command in the Server Manager utility
with only the package name, without a procedure or function name, shows
all procedures and functions of the DBMS_SESSION package:
svrmgr> describe dbms_session
package dbms_session is
------------- OVERVIEW
-- This package provides access to SQL "alter session"
-- statements, and other session information from, stored
-- procedures.
----------------------------- PROCEDURES AND FUNCTIONS
procedure set_role(role_cmd varchar2);
-- Equivalent to SQL "SET ROLE ...".
-- Input arguments:
-role_cmd
-- This text is appended to "set role " and then executed as
-- SQL.
procedure set_sql_trace(sql_trace boolean);
-- Equivalent to SQL "ALTER SESSION SET SQL_TRACE ..."
-- Input arguments:
-sql_trace
-TRUE or FALSE. Turns tracing on or off.
procedure set_nls(param varchar2, value varchar2);

......................................................................................................................................................
Oracle8: Database Administration
5-25



Lesson 5: Creating Data Dictionary Views and Standard Packages
......................................................................................................................................................

Troubleshooting

Troubleshooting
The status of dependent objects may be
INVALID:
• If DDL commands are executed on
referenced objects
ã After creating the objects using the
IMPORT utility

5-17

Copyright â Oracle Corporation, 1998. All rights reserved.

After the execution of DDL commands such as ALTER TABLE ADD,
RENAME, DROP, and CREATE OR REPLACE, the status of the dependent
objects changes to INVALID.
Also, loading dependent views and stored procedures with the Import utility
may lead to INVALID object status, because the Import utility may not be
able to create the dependent objects after creating the referenced objects.
The Oracle server automatically recompiles an invalid view or PL/SQL
program unit the next time it is used. In addition, the user can force the
Oracle server to recompile a view, stored procedure, or package by using the
appropriate SQL command.
Note
• Using the Import utility is covered in more detail in the lesson “Loading
and Reorganizing Data.”

• Recompiling stored procedures and packages is covered in the course
PL/SQL Program Units.

......................................................................................................................................................
5-26
Oracle8: Database Administration


Summary
......................................................................................................................................................

Summary

Summary
• Creating and using the data dictionary
views

• Using the administrative scripts
ã Obtaining information about stored
procedures and packages

5-18

Copyright â Oracle Corporation, 1998. All rights reserved.

Quick Reference
Context
Initialization parameters
Dynamic performance views
Data dictionary views


Reference
None
None
DICTIONARY
DICT
DICT_COLUMNS

Commands
Packaged procedures and
functions

DBA_OBJECTS
None
DBMS_SESSION.SET_ROLE

......................................................................................................................................................
Oracle8: Database Administration
5-27


Lesson 5: Creating Data Dictionary Views and Standard Packages
......................................................................................................................................................

......................................................................................................................................................
5-28
Oracle8: Database Administration


6

................................

Maintaining the
Control File


×