Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using Data Dictionary and Dynamic Performance Views

Similar presentations


Presentation on theme: "Using Data Dictionary and Dynamic Performance Views"— Presentation transcript:

1 Using Data Dictionary and Dynamic Performance Views

2 Objectives After completing this lesson, you should be able to do the following: Identify built-in database objects Identify the contents and uses of the data dictionary Describe how data dictionary views are created Identify data dictionary view categories Query the data dictionary and dynamic performance views Describe administrative script naming conventions

3 Built-In Database Objects
Other objects created with the database: Data dictionary Performance tables PL/SQL packages Database event triggers Built-In Database Objects In addition to creating the database files, several other structures are created. Data dictionary: Contains descriptions of the objects in the database Dynamic performance tables: Contains information used by the database administrator (DBA) to monitor and tune the database and instance PL/SQL packages: Program units adding functionality to the database. These packages are created when the catproc.sql script is run after the CREATE DATABASE command. PL/SQL packages will not be discussed within the scope of this course. Database event triggers: Triggers are procedures that execute implicitly whenever a table or view is modified, or when some user actions or database system actions occur. Database event triggers will not be discussed within the scope of this course.

4 Data Dictionary tables
Central to every Oracle database Describes the database and its objects Contains read-only tables and views Stored in the SYSTEM tablespace Owned by the user SYS Maintained by the Oracle server Accessed with SELECT Data files Control files Redo Log files Database Data Dictionary One of the most important parts of an Oracle database is its data dictionary, which is a read-only set of tables and views that provides information about its associated database. The data dictionary is updated by the Oracle server whenever a data definition language (DDL) command is executed. In addition, data manipulation language (DML) commands, such as one that causes a table to extend, can update the data dictionary. Not only is the data dictionary central to every Oracle database, it is an important source of information for all users, from end users to application designers and database administrators. SQL statements are used to access the data dictionary. Because the database is read-only, you can issue queries only against the tables and views of the data dictionary. Data Dictionary tables

5 Base Tables and Data Dictionary Views
The data dictionary contains two parts: Base tables Stores description of the database Created with CREATE DATABASE Data dictionary views Used to simplify the base table information Accessed through public synonyms Created with the catalog.sql script Base Tables and Data Dictionary Views The data dictionary contains descriptions of the objects in the database. It includes two types of objects. Base Tables Base tables are underlying tables, which store information about the database. The base tables are the first objects created in any Oracle database. They are automatically created when the Oracle server runs the sql.bsq script at the time the database is created. Only the Oracle server should write to these tables. Users rarely access them directly, because most of the data is stored in a cryptic format. Never use DML commands to update the base tables directly, with the exception of the AUD$ table. An example of a base table is the IND$ table, which contains information about the indexes in the database. Data Dictionary Views Data dictionary views are base table summaries, which provide for a more useful display of base table information. For example, in the data dictionary views, object names are used instead of only object numbers. The data dictionary views are created using the catalog.sql script which is run after the CREATE DATABASE command.

6 Creating Data Dictionary Views
Script Purpose catalog.sql Creates commonly used data dictionary views and synonyms catproc.sql Runs scripts required for server-side PL/SQL Creating Data Dictionary Views The base tables of the data dictionary are automatically created when a database is created. When the database is created using the Oracle Universal Installer, the scripts to create data dictionary and dynamic performance views, and scripts for your Oracle server options are run automatically. You must run these scripts manually when creating a new database manually. In addition, you may need to run them again when upgrading to a new release of the Oracle server. These scripts must be run as the user SYS with the SYSDBA privilege. The scripts are located in the following directories: UNIX: $ORACLE_HOME/rdbms/admin NT: %ORACLE_HOME%\rdbms\admin

7 Data Dictionary Contents
The data dictionary provides information about: Logical and physical database structures Definitions and space allocations of objects Integrity constraints Users Roles Privileges Auditing Data Dictionary Contents A data dictionary contains: The definitions of all schema objects in the database (tables, views, indexes, clusters, synonyms, sequences, procedures, functions, packages, triggers, and so on) How much space has been allocated for, and is currently used by, the schema objects Default values for columns Integrity constraint information The names of Oracle users Privileges and roles each user has been granted Auditing information, such as who has accessed or updated various schema objects

8 How the Data Dictionary Is Used
Primary uses: Oracle server uses it to find information about Users Schema objects Storage structures Oracle server modifies it when a DDL statement is executed. Users and DBAs use it as a read-only reference for information about the database. How the Data Dictionary Is Used How the Oracle Server Uses the Data Dictionary Data in the base tables of the data dictionary are necessary for the Oracle server to function. Therefore, only the Oracle server should write or change data dictionary information. During database operation, the Oracle server reads the data dictionary to ascertain that schema objects exist and that users have proper access to them. The Oracle server also updates the data dictionary continuously to reflect changes in database structures. How Users and DBAs Use the Data Dictionary The views of the data dictionary serve as a reference for all database users. Some views are accessible to all Oracle users. Others are intended for database administrators only.

9 Data Dictionary View Categories
Three sets of static views Distinguished by their scope: DBA: What is in all the schemas ALL: What the user can access USER: What is in the user’s schema DBA_xxx All of the objects in the database ALL_xxx Objects accessible by the current user Data Dictionary View Categories Views With the DBA Prefix Views with the DBA prefix show a global view of the entire database. They are meant to be queried only by database administrators. Any user granted the system privilege SELECT ANY TABLE can query the DBA prefixed views of the data dictionary. To query on all objects in the database, the DBA can issue the following statement: SQL> SELECT owner, object_name, object_type 2 FROM dba_objects; Views With the ALL Prefix Views with the ALL prefix refer to the user’s overall perspective of the database. These views return information about schema objects to which the user has access by way of public or explicit grants of privileges and role, in addition to schema objects that the user owns. For example, the following query returns information about all the objects to which a user has access: SELECT owner, object_name, object_type FROM all_objects; USER_xxx Objects owned by the current user

10 Data Dictionary Examples
General overview: DICTIONARY, DICT_COLUMNS Schema objects: DBA_TABLES, DBA_INDEXES, DBA_TAB_COLUMNS, DBA_CONSTRAINTS Space allocation: DBA_SEGMENTS, DBA_EXTENTS Database structure: DBA_TABLESPACES, DBA_DATA_FILES Data Dictionary Examples To get an overview of the data dictionary views, the DICTIONARY view or its synonym DICT can be queried. For example: SQL> SELECT * FROM dictionary; Include the WHERE clause to narrow your responses: SQL> SELECT * FROM dictionary 2 WHERE table_name LIKE ‘DBA_SEG%’ To get a list of columns within a view, use the DESCRIBE keyword: SQL> DESCRIBE dba_users; To get an overview of the columns in the data dictionary views, you can query the DICT_COLUMNS view. To view the contents of a data dictionary view, use the SELECT command. SQL> SELECT * FROM dba_users; Note: Refer to the Oracle9i Database Reference document for a complete list of data dictionary views and their columns.

11 Dynamic Performance Tables
Virtual tables Record current database activity Continually updated while the database is operational Information is accessed from memory and control file Used to monitor and tune the database Owned by SYS user Synonyms begin with V$ Listed in V$FIXED_TABLE Dynamic Performance Tables Throughout its operation, the Oracle server records current database activity in a set of virtual tables called dynamic performance views. These virtual tables exist in memory only when the database is running, to reflect real-time conditions of the database operation. They point to actual sources of information in memory and the control file. These tables are not true tables, and are not to be accessed by most users; however, DBA can query, grant the SELECT privilege, and create views on these views. These views are sometimes called fixed views because they cannot be altered or removed by the DBA. The dynamic performance tables are owned by SYS, and their names all begin with V_$. Views are created on these tables, and then public synonyms are created for the views. The synonym names begin with V$. For example, the V$DATAFILE view contains information about the database’s data files, and the V$FIXED_TABLE view contains information about all of the dynamic performance tables and views in the database. The dynamic performance tables answer questions such as: Is the object online and available? Is the object open? What locks are being held? Is the session active?

12 Dynamic Performance Examples
V$CONTROLFILE V$DATABASE V$DATAFILE V$INSTANCE V$PARAMETER V$SESSION V$SGA $SPPARAMETER V$TABLESPACE V$THREAD V$VERSION Dynamic Performance Examples The V$FIXED_TABLE view can also be queried to get a listing of the dynamic performance views: SQL> SELECT * FROM V$FIXED_TABLE; To get a list of columns within a view, use the DESCRIBE keyword: SQL> DESCRIBE V$INSTANCE; To view the contents of the view, use the SELECT command. SQL> SELECT * from V$INSTANCE;

13 Administrative Script Naming Conventions
cat*.sql dbms*.sql prvt*.plb utl*.sql Description Catalog and data dictionary information Database package specifications Wrapped database package code Views and tables for database utilities Administrative Script Naming Conventions The administrative scripts can be separated into categories by their filenames: cat*.sql These scripts create the 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 catadt.sql script creates data dictionary views for showing metadata information for types and other object features in the ORDBMS. The catnoadt.sql script drops these tables and views. dbms*.sql and prvt*plb: These scripts create objects for predefined Oracle packages that extend the Oracle server functionality. 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, which enables you to display the sizes of objects in the shared pool and mark them to be kept or removed in the SGA in order to reduce shared pool fragmentation.

14 Administrative Script Naming Conventions (continued)
utl*.sql These scripts must be run when the database needs additional views and tables. For example, the utlxplan.sql script creates a table used to view the execution plan of a SQL statement. Note: Most of these scripts must be executed under the user SYS with SYSDBA privilege. The database administrator should examine the scripts to determine which user account must be used to run the scripts.

15 Summary In this lesson, you should have learned how to:
Identify built-in database objects Identify the contents and uses of the data dictionary Describe how data dictionary views are created Identify data dictionary view categories Query the data dictionary and dynamic performance views Describe administrative script naming conventions

16 Practice 5 Overview This practice covers the following topics:
Identifying the components and contents of the data dictionary Querying the data dictionary and dynamic performance views Practice 5 Overview Note: This practice can be accomplished using SQL*Plus or using Oracle Enterprise Manager and SQL*Plus Worksheet.


Download ppt "Using Data Dictionary and Dynamic Performance Views"

Similar presentations


Ads by Google