Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Oracle

Similar presentations


Presentation on theme: "Introduction to Oracle"— Presentation transcript:

1 Introduction to Oracle
Oracle Architecture, SQL* Plus,

2 Oracle A database as a collection of related information
A database management system (DBMS) is a software suite designed to store and manage databases: Provides environment that is both convenient and efficient to use Oracle is a relational database management system (RDBMS)

3 Oracle Architecture Files: Programs: Memory area:
Database files. At least one file per tablespace. Log files. Usually a group of files; the db writes to one file at a time. Control file. Contains information about the database files. Usually 3 copies, for safety. Configuration files: initX.ora Programs: Background process. Pool of processes (/threads) handling incoming requests. Memory area: SGA: Shared Global Area. Contains database buffers, rollback buffers, cursors. External Database Structures Back Up / Recovery Security Basic Database Implementation

4 Database and Instance Database:
Since the physical structures of Oracle are maintained on a computer, they must be stored in files. Logically, the files belong to tablespaces. When a file is used to store data from an Oracle tablespace, it is called a datafile. A datafile belongs to exactly one tablespace, but a tablespace may consist of (/be stored in) several datafiles. Datafiles can be resized, placed in aspecific directory: tuning(DBA)

5 Database and Instance Instance:
A database instance (also known as a server) is a set of memory structures and background processes that access a set of database files One database may be accessed by more than one instance, Note also that when a database has been shut down (assuming a single-instance database), the instance does not exist. The instance is shared by a set of users: No user accesses the database directly; all access goes through the instance. (security, efficiency)

6 Internal database structures
In this context, we define anything stored in datafiles as internal database structures. This includes tables, columns, constraints, data types, users, schemas, indexes, clusters, hash clusters, views, sequences, procedures, functions, packages, triggers, synonyms, privileges, roles, database links, temporary segments and rollback segments.

7 Internal database structures
Tables, columns, constraints and data types: A table, the primary storage structure of an Oracle database, consists of a set of columns. The table has a name, and each column has a name. Tables are related through column contents; the relationships are enforced with referential integrity constraints Tables owned by user SYS constitute the data dictionary (DD) Column characteristics consist of data type and length.

8 Internal database structures
Abstract data types / objects: The SQL command CREATE TYPE ... AS OBJECT is used to create abstract data types in Oracle The data type will behave like an object: Oracle will create a constructor method for it; the constructor is called when an object is inserted in a column with that data type.

9 Internal database structures
Partitions: Tables and indexes may be split into partitions. Each partition can be stored in a particular tablespace, and thereby be directed to a particular disk (through datafile placement). Partitioning is used to ease maintenance and improve performance.

10 Internal database structures
Users and schemas: Objects like tables, indexes, clusters and views are created under particular user accounts. The SYS user owns the data dictionary; the SYSTEM user owns the views used to access the DD. A set of objects that belong to a user account are called a schema, so in many cases oracle use the words user and schema interchangeably.

11 Internal database structures
Indexes: In relational database theory, the ordering of rows in a RDB is irrelevant. When we want to access a particular row, we therefore either have to search through the table from the beginning until we find the row we are looking for, or use an indirect search via an index. Each index entry will consist of values for the indexed columns and the RowID for the row where the values appear. A RowID consists of fileID, block number within the file, and row number within the block. An index is created in a tablespace.

12 Internal database structures
Clusters and hash-clusters: If rows from different tables are accessed together most of the time, we may store them in a cluster instead of in the regular separate tables, in order to speed up access. The related columns in the tables belonging to the cluster will be indexes using a cluster index. We may also use a hash cluster. In this case, we use a hash function (instead of a cluster index) to determine the location of a particular row-set in the cluster.

13 Internal database structures
Views, Sequences: A view is, conceptually, a mask placed on top of one of more tables Sequences are used to simplify programming efforts by providing a sequential list of unique numbers.

14 Internal database structures
Procedures, functions and packages: A procedure is a block of PL/SQL statements that is stored in the data dictionary and is called by applications... When the procedure is executed, its statements are executed as a unit The only difference between a function and a procedure is that a function returns a value Packages are used to arrange procedures and functions into logical groupings.

15 Internal database structures
Triggers: Triggers are procedures that are executed when a specified database event takes place against a specified table. You may use them to augment referential integrity, enforce additional security, or enhance the available auditing options.

16 Internal database structures
Synonyms: In order to identify a particular row in an Oracle table, we have to specify the database and the schema to which the table belongs, the table name, and the primary key of the row. The database may be identified by the machine name and the instance name We sometimes want to hide some of these layers of identification to the users, whether they be applications or ad hoc users. This can be done using synonyms.

17 Internal database structures
Privileges and roles: In order to access an object owned by another account, the privilege to access that object must first have been granted Typical access privileges: Table: Select, insert, update, delete. Procedure, function, package: Execute. Snapshot: Select. it may become quite cumbersome to maintain privileges when the number of user accounts and objects increases. The solution is to introduce roles, privilege groups: privilege can be granted to a user or a role, and a role can be granted to a role or a user.

18 Internal database structures
Database links: If an Oracle database is linked to another Oracle database through a network, a user may access objects in the remote database as easily as in the local one This is done through database links By combining database links and synonyms, we may create an environment where the (application or ad hoc) user may mix and match data from local and remote tables without being aware of the physical location of data

19 Segments, extents and blocks
These concepts are used to organise many, but not all, of the internal structures. Segments are the physical counterparts to logical database objects. Segments store data... Because a segment is a physical entity, it must be assigned to a tablespace in the database (and will thus be placed in one of the datafiles of that tablespace) A segment is made up of sections called extents – contiguous sets of Oracle blocks. Once the existing extents in a segment can no longer hold new data, the segment will obtain another extent (until no more free space or internal maximum number of extents per segment ) The size of each block within an extent is determined at database creation time.

20 Special purpose segments
Rollback segments: used to contain a copy of rows as they appeared before being changed by a transaction(to give other users a consistent view of the database. ) Temporary segments: These are used to perform sorting. They may be needed during execution of SELECT statements and creation of indexes.

21 Internal memory structures
Most common ones: System Global Area (SGA), consisting of Data block buffer cache Dictionary cache Redo log buffer Shared SQL pool Context areas Program Global Area (PGA)

22 Internal memory structures
System Global Area: This area acts as the common ground for all the database users; any information that more than one user may need is kept here for efficiency.

23 Internal memory structures
SGA components: Data block buffer cache: Data is read from segments (like tables and indexes) into this cache. Dictionary cache: Information about database objects is stored in the data dictionary tables. This information includes user account data, datafile names, segment names, extent locations, table descriptions, and privileges. When this information is needed by the database, the data dictionary tables are read and the data that is returned is stored in the SGA in the dictionary cache.

24 Internal memory structures
SGA components: Redo log buffer: Redo entries describe the changes that are made to the database. They are written to the online redo log files so that they can be used in roll-forward operations during database recoveries The information being written to the redo log files is first recorded in the redo log buffers in the SGA Shared SQL pool: This contains The dictionary cache The other part is the library cache, which contains “the execution plan and parse tree for SQL statements run against the database

25 Internal memory structures
Context areas: used for private object caches when the object-relational features are used. Program Global Area: Each user process currently connected has its own PGA. each PGA is private for the user.

26 Background processes outlines the interaction between the physical structures, memory structures and processes that constitute an Oracle database When the instance starts, it initiates a range of background processes. Depending on the configuration and options of the installation, different processes may start, but the core set will always be there.

27 Background processes SMON:
The System Monitor is responsible for performing instance recovery on startup This is necessary if the database was shut down using the ABORT option or if it was improperly shut down (for instance due to power failure). PMON: The Process Monitor, as the name implies, monitors user processes and cleans up after failed processes free the resources that the processes were using.

28 Background processes DBWR:
The database writer process is responsible for reading and writing the database files. LGWR: The log writer process reads redo log buffers and writes to the redo log files. redo log buffers are always flushed to disk when a transaction is committed.

29 Background processes CKPT:
A Checkpoint is an instruction to the RDBMS to write all updated database blocks to disk and record the checkpoint timestamp in datafile headers and control files ARCH: The Archiver background process is responsible for copying each redo log file to an archive medium once it has been filled RECO: The Recoverer background process is only used in distributed databases RECO attempts to access databases involved in in-doubt distributed transactions and resolve the transactions SNPn: The optional set of Snapshot background process are responsible for refreshing snapshots and schedule jobs

30 Background processes LCKn:
When the Parallel Server option is being used, the RDBMS needs lock processes to ensure that the different instances accessing the single database do not create inconsistencies by interfering with each other. Dnnn: When the MultiThreaded Server (MTS) option is used, each Dispatcher process will handle several connections for a protocol. Snnn: These processes handle connections that require a dedicated server, and are capable of performing I/O against datafiles just like the DBWR process/es.

31 External database structures
In this section we concentrate on files that are part of the database architecture but do not store user data. Redo logs: We already know that the LGWR background process produces redo log files the files contain every transaction performed against the database The log files are used to recover the database after a SHUTDOWN ABORT or a crash Control files: Control files record control information about all of the files within the database. They are used to maintain internal consistency and guide recovery operation. Diagnostics files: The files that contain diagnostic information about the database consist of the alert log and trace files. The alert log records the commands and command results of major events in the life of the database (vital source of information for day-to-day management of a database ) Each of the background processes running in an instance has a trace file associated with it. The trace file will contain information about significant events encountered by the background process (most useful when attempting to discover the cause of a major failure. )

32 Backup/ recovery Export/ import:
The Export utility queries the database and stores its output in a binary file. We can export a table or set of tables, a user or set of users, or the complete database. The only program that can interpret the binary format of the export file is the Import utility. This program can be used to import a table or set of tables, a user or set of users, or the complete database.

33 Backup/ recovery Offline backup:
We can make a physical backup of the database by shutting it down and making a physical copy of all necessary files. The disadvantage of this backup method is obviously that the database is unavailable for the users during the backup. Online backup: If offline backup is unacceptable, we can run the database in ARCHIVELOG mode and perform online backup.

34 Security Account security:
Oracle users can be allowed access on the basis of their operating system user account or on the basis of an Oracle-controlled password System-level privileges: We can generate our own roles containing system level privileges Object security: The owner of an object can assign access privileges for the object to other users or roles Auditing: Auditing means monitoring the actions of users in the database. we can audit login attempts, table accesses and DBA-privileged activities The results are written to an audit table in the database (or to the operating system, if the OS is capable of it)

35 Basic database implementation
The basic Oracle database will contain a datafile, a control file and two redo log files. Internally, it will contain at least two schemas (SYS and SYSTEM), at least one rollback segment (SYSTEM), at least one tablespace (SYSTEM), and the set of data dictionary tables. The instance will contain an SGA, the SMON, PMON, DBWR and LGWR background processes, and one user process including PGA per user.

36 Basic database implementation
a database with this setup will be useless for most practical purposes – even for demonstrations In order to use the database for something, we need to ensure that it doesn't crash from a full SYSTEM tablespace That developers are able to create tables and other objects that a proper backup and recovery plan is implemented etc.

37 INTRODUCTION TO SQL*PLUS
SQL* PLUS: What is it and what is it for? SQL*PLUS: First glance SQL*PLUS: Features SQL*PLUS: To Run SQL Commands SQL*PLUS: Interactive Model SQL*PLUS: Batch Mode I N D E X  SQL*PLUS: Oracle Control Tables SQL*PLUS: Miscellaneous

38 SQL* PLUS: What is it and what is it for?
Command line SQL and PL\SQL language interface to the database  It can be used as an interactive interface or it can be driven from scripts. Its equivalents in other databases are as: Ingres: SQL Sybase and SQLServer: isql IBM DB2:db2 PostgresQL: psql MySQL:mysql What is it for? Connect to Oracle Create, change, delete database objects and data Ad hoc query data objects and data Verify the functioning of your applications

39 SQL*PLUS: First glance
Start Up: In Windows Environment: Go to start—All Programs– Oracle– Applications Development—sql Plus Then SQL* Plus asks for your username and password You are now entering the application tool and ready to execute any ad hoc SQL command.

40 SQL*PLUS: First glance
Changing your password: You can use SQL* Plus to change your password in Oracle by At the SQL* Plus prompt (SQL prompt is SQL>) type: SQL>  ALTER USER [userid] IDENTIFIED BY [newpasswd]; User altered. Please note that the [userid] here does NOT and the password is case-insensitive and is NOT cover by quote (').

41 SQL*PLUS: First glance
Exit: To exit, at the SQL* Plus prompt type: SQL>  exit Disconnected from Oracle10g Enterprise Edition Release Production With the Partitioning, OLAP and Oracle  Data Mining  options 

42 SQL*PLUS: Features Use with any SQL commands: create, drop, insert, select, update, delete and etc. Commands are case-insensitive except string constants/literals. Example: select name, class, major from Student where name = 'John'; is equivalent to: SELECT Name, CLaSs, MaJor From student where NaMe = 'John'; but not: select name, class, major from Student where name = 'JOHN';

43 SQL*PLUS: To Run SQL Commands
Two ways to run sql commands: Interactive mode: type commands directly at the SQL prompt. Batch: create a set of commands in a file and run it in SQL*PLUS.

44 SQL*PLUS: Interactive Model
At the SQL*PLUS prompt, you can type in any SQL query. The query will be sent to the Oracle server for executing and the results will be given back to your terminal interactively. For instance to create a table 'STUDENT', type at prompt: SQL> CREATE TABLE Student 2 ( Name VARCHAR2(30), 3 StudentNumber NUMBER(4) NOT NULL, 4 Class NUMBER(4), 5 Major VARCHAR2(4), 6 Primary key (StudentNumber) 7 ); Table created. SQL-Command Note: It is suggested that we use VARCHAR2 instead of VARCHAR

45 SQL*PLUS: Batch Mode Use your favorite editor to create a file with extension '.sql' containing your SQL command(s). From the batch file, you can run it by typing at prompt: @[filename] or start [filename] Note that the file extension '.sql' can be omitted.

46 I N D E X SQL*PLUS Commands @ Connect Describe Disconnect Edit
Exit or Quit List Prompt Remark Set Save Spool Start   SQL Commands Data Definition Commands - Alter Table - Create Table - Create View - Drop Table - Drop View Data Manipulation Commands - Delete - Insert - Select - Update Transaction Control - Commit - Rollback

47 SQL*PLUS: Oracle Control Tables
Internally, Oracle keeps its data catalog in the form of tables. There are quite a number of these tables. The followings are some that might be useful for you. Some Useful Control Tables: User_Catalog: user table catalog (e.g., table name, type --table, view) User_Tables: table detail (e.g., Identification, Space, Statistics-related) User_Views: views detail User_TS_Quotas: space allocation User_Users: your account information User_Sys_Privs: your privilege You can use 'describe' to show the structures of these tables and use 'select' to view their contents.

48 SQL*PLUS: Miscellaneous
This is the closing page for the SQL*PLUS. Some useful miscellaneous items are listed here: Save your last SQL stmt. SQL> SAVE [filename] Spool the screen to a file SQL> SPOOL [filename] the SQL*PLUS will start recording your displayed output into your specific [filename] with the default file extension '.lst'. To stop spooling and save the file: SQL> SPOOL OFF For more information on SQL *PLUS, view SQL* Plus HELP (SQL> help [topic])

49 For More Information on Oracle
Visit the Oracle Technology Center: For Free video Tutorial on Oracle Database:


Download ppt "Introduction to Oracle"

Similar presentations


Ads by Google