You are on page 1of 86

Oracle Administration

Oracle Administration 11G R2 - Didier LESTRAT 1

Didier LESTRAT
Independent Information System Consultant

Oracle Administration 11G R2 - Didier LESTRAT 2


Architecture of an Enterprise Information System

The principles
u Architecture stand alone
u Architecture 2 tiers
u Architecture 3 tiers
u Architecture n tiers

Oracle Administration 11G R2 - Didier LESTRAT 3

Defining an Application Server

This server is a set of software that is used to separate

The business logic of presentation logic and database logic.


The database can be physically separated from the business logic.

Difficulties to overcome to implement an application server?

u Simultaneous customer access


u Network overload
u Authorization to access databases
u Fault Tolerance, Performance
u Load Balancing
u Privacy Policy

The application server must provide flexibility for data development and
production.
Oracle Administration 11G R2 - Didier LESTRAT 4
Architecture of an Enterprise Information System

Architecture 2-tiers
The two-tier architecture consists of several clients (100 user)
and one server.

The client connects to the server via


Network protocols (TCP / IP).

The server contains business logic and


Stores the data.
The client process collects
Information to the server (business logic).
The server implements business logic and
Validates the data.
Heavy client: part of the business logic is
Moved to the client computer.

Thin Client: The server manages the entire business part.

Oracle Administration 11G R2 - Didier LESTRAT 5

Logic Architecture

Client LAYER

Network access layer

Presentation layer

Application Layer

Data Layer

Oracle Administration 11G R2 - Didier LESTRAT 6


Physical Architecture

Oracle Administration 11G R2 - Didier LESTRAT 7

Oracle Administration 11G R2 - Didier LESTRAT 8


DBMS ?

Aims and Objectives

u Physical Independence of Data


u Logical independence
u Manipulation of data by non-computer scientists
u Access Efficiency
u Coherent administration
u No redundancy
u Consistency of data
u Data Sharing
u Privacy Policy

Oracle Administration 11G R2 - Didier LESTRAT 9

What difference between BDD and DBMS

u BDD : Structured information set

u DBMS : It is the software suite to administer all the information

Oracle Administration 11G R2 - Didier LESTRAT 10


DBMS Objectives and Benefits

What should a DBMS do?


Describe the data, independently of the applications
(intrinsically)
Data definition language

DATA DEFINITION LANGUAGE (DDL)


Data description language (DDL) is a syntax why defining
data structures

DATA MANIPULATION LANGUAGE (DML)


Manipulating data
Query and update the data without specifying an access
algorithm

Oracle Administration 11G R2 - Didier LESTRAT 11

DBMS Objectives and Benefits


What should a SGBD do?
Controlling data
Integrity: Verification of integrity constraints
Example : the salary must be between 4000 euros and
20000 euros
u Confidentiality control of access rights, authorization
⇉ Data control language: DATA CONTROL LANGUAGE
(DCL)
u Sharing
A BD is shared among several users at the same time
⇉ control of concurrent access concept of transaction
The execution of a transaction must preserve the
consistency of the DB
u Sécurity
u Recovery, logging
u Access, availity and performance
u Index (hashage, balanced trees ...)

Oracle Administration 11G R2 - Didier LESTRAT 12


DBMS Objectives and Benefits
What should a SGBD do?

u Physical independence
Be able to modify storage structures or indexes without affecting
the application
Disks, access methods, placement modes, data encoding are not
apparent

Logical independence
Allow different applications to have different views of the same
data
Allow the DBA to modify the logic scheme without affecting the
application level

Oracle Administration 11G R2 - Didier LESTRAT 13

Relational model

u To replace the hierarchical model


The relational data model is based on the notion of relation: a
two-dimensional array containing a set of n-tuplets (the lines).

u When focusing more on storage, relationships are often referred


to as tables and tuples of records.
The entries in the tables are called values.

u Relationships represent entities of the real world (such as


people, objects, etc.) or associations between these entities
Primary and Foreign Key Notions

Oracle Administration 11G R2 - Didier LESTRAT 14


Relational model
u SIMPLICITY OF PRESENTATION:
Table representation
u RELATIONAL OPERATIONS
Relational algebra
u PHYSICAL INDEPENDENCE
Optimization of access
Access strategy determined by the system
u LOGICAL INDEPENDENCE
Concept of VIEWS
u MAINTAINING INTEGRITY
Integrity constraints defined in the schema

Oracle Administration 11G R2 - Didier LESTRAT 15

Market DBMS

Oracle Administration 11G R2 - Didier LESTRAT 16


Evolution of the DBMS of the market

Oracle Administration 11G R2 - Didier LESTRAT 17

PostgreSql

u Compliant with SQL


Works with Solaris, Linux, SunOS, Windows
Administration tools
u Psql : control tool
u PgAdmin : administration tool
u PhpPgAdmin : Web interface administration tool
u Pgpool : Replication

Oracle Administration 11G R2 - Didier LESTRAT 18


MySql
Very developed on all the web applications and the hosts
Compliant with SQL

u Différent motors
u MyIsam :
u InnoDB :
Works with olaris, Linux, SunOS, Windows

Edition MySql 6.5

Administration tool
u MySql administrator
u MySQ query browser
u Mysql Migration toollkit
u Mysql cluster

Oracle Administration 11G R2 - Didier LESTRAT 19

Sql server
u Architecture similar Oracle
u A lot of demand since the implementation of collaborative tools
(SHAREPOINT)
Outils d’administration
u SQL Server Management Studio
u SQL Server Database Tuning Wizard.

Oracle Administration 11G R2 - Didier LESTRAT 20


SyBase

Very stable
Edition 15.5

Administration tools
u Adaptive server Entreprise
u Sql Anywhere

Oracle Administration 11G R2 - Didier LESTRAT 21

Oracle

u Works on all platforms


u Edition 11G 12C
u Well established in companies

Administration tools
u Oracle entreprise manager
u Oracle net Manager
u Oracle installer

Oracle Administration 11G R2 - Didier LESTRAT 22


Oracle DBMS Administration

u Architecture of an ORACLE server


u Oracle Tools Preparation : DBCA, Net configuration, Sqldevelopper,…
u Creating a database
u Administering an Oracle instance

Oracle Administration 11G R2 - Didier LESTRAT 23

Trades
u DBA
u Administrator
u Security manager
u Network and System Administrator
u Application Developer (MCO MOE TMA)
u Business users: edit data, create reports

Oracle Administration 11G R2 - Didier LESTRAT 24


Database administrator
Main tasks

u Installation of products
u A server, client applications
u Oracle Network Components
u Creating / starting / stopping databases
u Management of storage structures
u Management of non-business users (and their rights)
u Backup / Restore.
u Export Import
u Creating operating script
u Optimization and tuning of the bases

Oracle Administration 11G R2 - Didier LESTRAT 25

Database administrator

u Operating Documentation
u Current administration: Monitoring of operating processes,
performance, flow fluidity, availability
u AMOE on the architecture of the bases
u In general, the DBA is in the operating group
Production with the systems and networks team.
It is very rarely in MOE except in large Structures.

Some companies outsource the administration of its DBMS.

Oracle Administration 11G R2 - Didier LESTRAT 26


Course Objectives

After completing this course, you should be abble to :


u Install, Create and administer Oracle Database
u Configure the database for an application
u Employ basic monitoring procedures
u Implement à backup and recovery stratégy
u Move Data between Databases an files

Oracle Administration 11G R2 - Didier LESTRAT 27

Concept
Two possible architectures:
u Client / Server: Client Applications Send SQL or Pl / SQL Queries to a
Server

u N-Third-Party Architecture: Application Servers Relieve Server Load

u A database server is composed of


u One instance = Memory and process area
u From a database
u From several diagrams, assimilated to users: HR, SCOTT

In the case of a machine cluster, Oracle can associate several instances

Oracle Administration 11G R2 - Didier LESTRAT 28


ORACLE architecture

u Connexion : lien de communication entre un


processus utilisateur et l’instance de la base
u Session : c’est le statut d’un profil utilisateur qui se
logue sur une instance (plusieurs instances
simultanée)
u Communication avec une instance Oracle

Processus serveur et un processus utilisateur


Principe :
u Le serveur récupère les valeurs des données et sont
stockées dans le Buffer Cache
u Le processus serveur modifie les données dans le
Buffer cache
u Si la transaction est correcte, le lien se fait par un
retour de message, sinon un message d’erreur est
activé. Ora 1020 … une liste de descriptions d’erreur
à visualiser pour analyser l’erreur
Oracle Administration 11G R2 - Didier LESTRAT 29

Exploring the ORACLE Database Architecture

Oracle Administration 11G R2 - Didier LESTRAT 30


Process server et process user

Oracle Administration 11G R2 - Didier LESTRAT 31

Connecting to the Database

u Connection : communication between a user process and and an instance


u Session : specific connection of a user to an instance through a user process

u Server process and a user process


Principle:
The server retrieves the data values and is stored in the Buffer Cache
The server process modifies the data in the buffer cache
If the transaction is correct, the link is made by a message return, otherwise an error
message is activated. Ora 1020 ... a list of error descriptions to be visualized to analyze the
error

Oracle Administration 11G R2 - Didier LESTRAT 32


Logical and physical Architecture

Oracle Administration 11G R2 - Didier LESTRAT 33

DBMS Structure

u Share memory : SGA


u Regions mémory for process server or backgroud process : PGA
u Physic Database : write database files, ans databse log, save parameters file

u Important : Share Memory SGA and physical database may be contains on


different computer
u SGA on the server and physical database on the SAN or NAS.

Oracle Administration 11G R2 - Didier LESTRAT 34


Structure da la mémoire : SGA (System Global Area)

After starting an instance, the Oracle Software associates the instance with a specific database
Database mounted, opened, accessible to autthorized uers.
A multiple instance can execute on the same computer, each accessing its own physical Database
u Shared by all users
u The SGA is allocated at the start of the instance and released when the instance is stopped.
u It is sized by a set of parameters defined in the parameter file.
u The maximum size of the SGA is limited by the SGA_MAX_SIZE parameter

Quand vous lancez SQL plus ou OEM, la SGA alloue une espace dédié et unique. Paramètres SGA : SGA_MAX_SIZE

Oracle Administration 11G R2 - Didier LESTRAT 35

Structure da la mémoire
SGA (System Global Area)
La SGA is the memory area that contains data control information for the
instance
1. Database Buffer Cache : Caches block of Data retrieved from the database

2. Redo Log Buffer : Cache redo informations until it can be written to the
physical redo lod file files stored on the disk
3. Shared Pool : Caches various cosntructs that can be shared among users

4. Large Pool : Optional area tht provides large memory allocations for
certain large processes, such as Oracle backup and recovery operations,
and I/O server processes

5. Java Pool : Memory area used for all session specific Java code and Data
in the Jvava Virtual Machine (JVM)

6. Streams Pool : zone de mémoire utilisée pour stocker de l’information des


séquences spécifiques

7. Result Cache (nouveau en version 11) : cache pour le résultat des


requêtes SQL ou des fonctions PL/SQL.
Quand vous lancez SQL plus ou OEM, la SGA alloue une espace dédié et unique. Paramètres SGA : SGA_MAX_SIZE

Oracle Administration 11G R2 - Didier LESTRAT 36


Database Buffer Cache
u Is part of the SGA
u Holds copies of data blocks that are read from data files
u Is shared by all concurrentt users

The database buffer is the portion of SGA that holds copies of data blocks that
are read from data files.
All uers who arre concurrently connected to the instance share access to the
dtabase buffer cache.
The firts time an Oracle Dtabase user process requires a particular piece of data,
its searches for the data in the dtabase buffer cache. If the process finds the
data already in the cache. It can reda the data directly from memory (more
speed)
If the process cannot find the data in the buffre cache; it muts copy the dta
block from a dta file into the buffer

Used Parameters :
u DB_CACHE_SIZE: cache size for block size
u DB_nK_CACHE_SIZE: size of blocks of nKo (values of n 2, 4, 8, 16, 32)

Oracle Administration 11G R2 - Didier LESTRAT 37

Database Buffer Cache

Oracle Administration 11G R2 - Didier LESTRAT 38


Redo Log Buffer
u Is a circular buffer in the SGA
u Holds information about changes made to the database
u Contains redo entries that have the information to rdo changes made by
operations such as DML and DDL
u Redo entries contain the information necessary to reconstruct changes that are
made to the database by DML, DDL.
u Redo entries are used for database recovery if necessary

u Redo Log Buffer parameters : Log_Buffer

!T the redo log buffer is really important, it's the heart of the database, it handles
transactions.
In case of a server failure, it is in this memory space that we will recover the
transcations

Oracle Administration 11G R2 - Didier LESTRAT 39

Redo Log Buffer

Oracle Administration 11G R2 - Didier LESTRAT 40


Shared Pool
u Is a portion of the SGA
Contains :
Library Cache : Shared SQL area, space more used SQL et Pl/SQL
Each SQL statement that it runs with a shared SQL area
u Data dictionnary cache : is a collection of database tables and views
containing reference information about the database; its structures, and
its users
u Control structures

Used parameters : SHARED_POOL_SIZE

Oracle Administration 11G R2 - Didier LESTRAT 41

Shared Pool (continued)

u Is a portion of the SGA


Contains :
Oracle processes PL/SQL : Owner of oracle
Execution PL/SQL, program units : procedures, function,
packages, triggers,…

Oracle Administration 11G R2 - Didier LESTRAT 42


Shared Pool (continued)

Oracle Administration 11G R2 - Didier LESTRAT 43

Large Pool

Provides large memory allocations for :


u Session memory for shared server and the Oracle XA interface
u I/O server process
u Oracle Database backup and restore operations

Oracle Administration 11G R2 - Didier LESTRAT 44


Large Pool

Oracle Administration 11G R2 - Didier LESTRAT 45

PGA ( Program Global Area)

Memory regions that contains data and control information for a server or
background process.
A PGA is nonshared memeory created by Oracle Dtabase when a server or
background process is started.
Each server process and background process has its own PGA.

Process server is a service to answer to respond to queries


Customers.

Oracle Administration 11G R2 - Didier LESTRAT 46


PGA ( Program Global Area)

Oracle Administration 11G R2 - Didier LESTRAT 47

Process Architecture

u User Process : is started when a database user or a batch process


connects to Oracle Databse

Database processes :
u Server process : connects to the Oracle instance and is started when a
user establishes a session

u Background processes : are started when an Oracle instance is started

Oracle Administration 11G R2 - Didier LESTRAT 48


Process Architecture

Oracle Administration 11G R2 - Didier LESTRAT 49

Oracle Administration 11G R2 - Didier LESTRAT 50


Process structures

Oracle Administration 11G R2 - Didier LESTRAT 51

Process structures

u Server process : Oracle Database creates server processes to handle the


request of user processes connected to the instance.
u Combine the user process with a server process
We can have several user process and server process
u Background process : to maximize performance and accommodate many
users.
u An Oracle Database instance can have many background process

Oracle Administration 11G R2 - Didier LESTRAT 52


Mapping the Treatment Structure

u Data writer process (DBWn) :

Writes the contents of buffers to Data files


It triggers:
u When there is no space in the buffer
u Periodically, with the checkpoint process

Oracle Administration 11G R2 - Didier LESTRAT 53

Data writer process (DBWn) :

Oracle Administration 11G R2 - Didier LESTRAT 54


Log Writer (LGWR)

u Writes the redo log buffer to a redo log file on disk

Writes :
u When a user porcess commits a transaction
u When the redo log is one-third full
u Before a DBWn process writes modified buffers to disk
u Every 3 seconds : automatic

Oracle Administration 11G R2 - Didier LESTRAT 55

Log Writer (LGWR):

Oracle Administration 11G R2 - Didier LESTRAT 56


Mapping the Treatment Structure
Checkpoint :
This is the synchronization mechanism for writing headers to data files or control files.

It characterizes the point of resumption


of a transaction
(structure data with a unique SCN number).

It is important for any reconstruction


of a base following an incident.

Oracle Administration 11G R2 - Didier LESTRAT 57

SMON (system monitor)

u It recovers an instance after an abnormal shutdown.


u It cleans temporary segments
u Roll Back: Removal of uncommitted transaction data
u Roll forward updates data after a transaction
committed before the instance was stopped

Oracle Administration 11G R2 - Didier LESTRAT 58


PMON (process monitor)
u It cleans up after a crash of a user process or after a too long delay.
It releases the locks.

Oracle Administration 11G R2 - Didier LESTRAT 59

Mapping the Treatment Structure


RECO (Recover Process)

Oracle Administration 11G R2 - Didier LESTRAT 60


ARCn (Archiver process)

u Writes redo log file to redo log archiv


u The database is either in archive log mode or in noarchivelog mode.
u The Archivelog mode takes up a lot of space on the disks, there is the parameter
LOG_ARCHIVE_MAX_PROCESS for automatic management of the deletions of the
oldest archives.
u Important for Availability and data loss

Oracle Administration 11G R2 - Didier LESTRAT 61

Database storage architecture

Oracle Administration 11G R2 - Didier LESTRAT 62


Database storage architecture
Control files : It includes all information about the integrity of a database and its
structure
Data files : Stores data
It contains the objects of the users or the data of application of the database, they
store the data dictionary.

Parameter file : We find the information

u One instance.
u Name of the data base
u The paths to the database control files

Oracle Administration 11G R2 - Didier LESTRAT 63

Architecture du stockage de la base de


données

u Password file : Privilèges sysdba, sysoper and sysman

u Backup files : Used to restore a database.

u archived redo log files

u Trace files : Lists all processing errors, important for the DBA.

u Alert log File : Chronology of errors, a file to check regularly

Oracle Administration 11G R2 - Didier LESTRAT 64


Practice 1
u View Oracle Home and Oracle BASE
u View the Oracle software tree
u Find the following files:
u Redo log Files
u Datafiles
u Control files
u Parameters files
u Trace files
u Init.ora

u Give the full path of Oracle Home and Oracle BASE


Directory containing Oracle tools : DBCA, NETCA, SQL
DEVELOPER

Oracle Administration 11G R2 - Didier LESTRAT 65

Review the structure of


Oracle

Oracle Administration 11G R2 - Didier LESTRAT 66


Structure logique et physique
d’une base de données

A schema is a collection of database objects that are owned by a


database user. Schema Objects are the logical structures that
directly refer to the database’s data
HR schema, Sys schema, Scott schema
Schema objects include Tables, views, proceures, sequences, indexes,
clusters and database links

Tablespaces
u A database is divided into logical storage units called Tablespaces.
u You may have a tablespace for the data et a another for indexes.

Tablespaces system and sysaux


u System tablespace : Used for basic functionality, dictionary data
u Sysaux : Used to add components of the database (such as the OEM
repository)
u It is two tablespaces are automatically created when a database is
created.
Oracle Administration 11G R2 - Didier LESTRAT 67

Logical and physical Database


Structures

Oracle Administration 11G R2 - Didier LESTRAT 68


Logical structure
u Data Blocks : at the finest level granularity, the data is stored in Data
blocks. 8 KO by default
u One data block corresponds to a specific number of bytes of physical
database space of disk.

u L’extent Is a contiguous set of blocks


Note: Extents are added when the segment
is full. This is an Oracle automation.
u Tablespace : Groups a set of objects to facilitate administration and
performance
It can reach 8 exabytes
A tablespace can group one or more data files

Oracle Administration 11G R2 - Didier LESTRAT 69

Logical Structure
Le Segment : the level of logical database storage above
an extent is called a segment
This is the space used by a logical structure: tables,
indexes
The different types of segments are as follows :
u Table
u Cluster
u Index
u Partition d'index
u Index lob
u Rollback segment
u Tempory Segment
u Starting segment

Oracle Administration 11G R2 - Didier LESTRAT 70


Physical Structure

Data files: the physical space on the server's disk that


stores all data in the database

u One or more data files are created for each tablespace


on a physical storage.
u The maximum size is the block size for the tablespace
multiplied by 236 , or 128TB for a block size of 32KB.

Oracle Administration 11G R2 - Didier LESTRAT 71

Oracle Administration 11G R2 - Didier LESTRAT 72


Content of a Schema

u Owner of a user
Set of user objects manipulable in SQL
Tables, indexes, clusters, triggers, views, dimensions
An object corresponds to

u Several extents
u A tablespace
u One or more physical disk files.

Oracle Administration 11G R2 - Didier LESTRAT 73

GOALS
u Describe your role as a database administrator (DBA)
u Plan an Oracle Database installation
u Use Optimal Flexible Architecture (OFA)
u Install the Oracle software by using Oracle Universal Installer (OUI)

Oracle Administration 11G R2 - Didier LESTRAT 74


Tools for administering an oracle database

u Oracle Universal Installer (OUI)


u Database Configuration Assistant
u Database Upgrade Assistant
u Oracle Net Manager
u Oracle Entreprise Manager (OEM)
u Recovery Manager
u Oracle Secure Backup
u Data Pump
u SQl*Loader

Oracle Administration 11G R2 - Didier LESTRAT 75

DBA account

Oracle Administration Accounts

It is desirable to create multiple administrator accounts


u Daily administration
u Exporting / importing databases
u Backup / Restore
u Restricted Administrator

An Oracle database always contains two accounts with administrator privileges


u SYS (default password: change_on_install);
u SYSTEM (default password: manager).
u SYS is the owner of the data dictionary
u SYSTEM can be the owner of additional tables used by Oracle tools.

Oracle Administration 11G R2 - Didier LESTRAT 76


DBA account
Since Oracle9i Release 2, these default passwords can be Changed when
creating the database.

These accounts can be used equally for the administration


(User management, storage, etc.) only When the base is started.
A special additional privilege (SYSDBA or SYSOPER) is
Necessary for certain operations (starting, stopping, etc.).
Furthermore,

Activation of this SYSDBA or SYSOPER privilege requires a


Authentication mechanism, since the database
May not be available.
This authentication is carried out either by the
Operating system, or by a password file.

Do not confuse privileges and account

Oracle Administration 11G R2 - Didier LESTRAT 77

SYSDBA and SYSOPER Privilege

The SYSDBA privilege allows all "heavy" administration

u The creation of a database


u Stops and starts
u Creating a server parameter file
u Recovery, etc.
u It gives access to all data in the database.
u The connection is implicit in the SYS schema.

The SYSOPER privilege gives about the same rights as SYSDBA, with the
notable exception of creating the database.

u However, access is restricted to data dictionary data only. Connection is


implicit in the PUBLIC schema.
Oracle Administration 11G R2 - Didier LESTRAT 78
Connection Principle

Operating system connection

u White room
u Network connection tool: VNC, Pc anywhere ...
u Control tools: cmd
u Secure or unsecured channel: SSL ...
u Connection rights and role on servers

Oracle Administration 11G R2 - Didier LESTRAT 79

Connection Principle
Connexion à l’instance Oracle
u Direct connection via a control tool
u CONNECT account/password AS { SYSDBA | SYSOPER }

u Connecting via a password file


To use authentication with a password file, you must set the
initialization parameter
REMOTE_LOGIN_PASSWORDFILE to EXCLUSIVE(défaut) ou SHARED

Create a password file using the orapwd utility provided by Oracle.

Oracle Administration 11G R2 - Didier LESTRAT 80


Other DBA accounts

When creating a database, other


Oracle accounts can be created, including SYSMAN and DBSNMP.

SYSMAN (default password CHANGE_ON_INSTALL) is an account that can


be used to perform administrative tasks in Oracle Enterprise Manager.
SYSMAN is a DBA account.

DBSNMP (default password DBSNMP) is an account used by the Oracle


Enterprise Manager agent to monitor and manage a database.

Many other "administrative" accounts can be created based on the


options installed in the database.

Oracle Administration 11G R2 - Didier LESTRAT 81

Server and software installation

To get started, it's good to know


u The basic principles of an ORACLE installation
u To rely on the publisher's recommendations
u On file naming
u The tree on the disk.
u Settings
u Documentation oracle

Oracle Administration 11G R2 - Didier LESTRAT 82


Building database
At the beginning
u MCD: Creating the Conceptual Data Model
u Reflection on tables, indexes to come, estimate their size
u Memory space and physical space
u Choose character encoding
u Determine the size of the data blocks
u Choose the cancellation management mode
u Dedicated Tablespace
u Roll Back segment
u Backup and archiving strategy
u Availability and performance ( 99,99%)

Oracle Administration 11G R2 - Didier LESTRAT 83

OFA (optimal flexible architecture)

Refer to OFA for

u Better organization
u Facilitating administration
u Facilitate the relationship between several ORACLE
databases
u Administer and manage database scaling
u Separate administrative files and data files
u To have multiple versions of Oracle installed on the server

Oracle Administration 11G R2 - Didier LESTRAT 84


Oracle directories
Two directories play a particular role

On Windows

u Oracle Base: Oracle tree root directory


u Oracle Home: Oracle Base Directory containing the software
In the base directory, we can have several versions of ORACLE
Note: Checking the file names in the registry Of Windows

On Unix or Linux

u Oracle Base: / ora01 / app / oracle


u Oracle Home: /ora01/app/oracle/product/11.2.0/db_1
(Storage of software and applications oracle)
Oracle Base contains other directories

u Oradata: database files


u Admin: Administration files
u Cfgtoollogs: facility logs
Diag: Diagnostic Repository
Oracle Administration 11G R2 - Didier LESTRAT 85

Installation agreement
Tree and Names
Under the user Oracle
/ORA01
u Directories
u /ora01/app/oracle
u /ora01/app/oracle/product/11.2.0/db_1

u Files
u Control files : /ora01/app/oracle/oradata-nom_instance/controln.ctl
u Redo log files : /ora01/app/oracle/oradata/nom_instance/redo.log
u Data Files : /ora01/app/oracle/oradata/nom_instance/tn.dbf
(N is an order number)

Oracle Administration 11G R2 - Didier LESTRAT 86


The environment variables
u ORACLE_BASE : spécifies the base of Oracle directory structure for
OFA
u ORACLE_HOME : spécifies the directory containing the Oracle
software
u ORACLE_SID : Initial name of the instance
u NLS_LANG : Specifies supported language
u Select * from nls_session_parameters

Oracle Administration 11G R2 - Didier LESTRAT 87

ORACLE Universal Installer (oui) via Interface


You must be a system administrator or a member of an administrator group to install
the Oracle software and its tools

It is located in the products folder


And runs with ./runinstaller with the Oracle account

Oracle Administration 11G R2 - Didier LESTRAT 88


Prerequisites Windows

u Os Supported : Window 2008 et w2012 server


u Mémory : 1GB /instance
u Minimum server requirements 1,5GB de mémoire
u 400 MB disk space
u 1,5GB et 3,5 Gb for oracle toold
u 1, 2 Gb / for the database

Oracle Administration 11G R2 - Didier LESTRAT 89

Prerequisites Unix- Linux


Os Supported
u Oracle enterprise 4 or Redhat enterprise 4 (noyau2.6.9)
u Oracle enterprise 5 or Redhat enterprise 5 (noyau2.6.18)
u SUSE enterprise linux 10 (noyau 2.6.16.21)
u Cent OS 7 cent OS 6

The serveur
u Mémory : 1GB /instance
u Minimum server requirements
u 1,5GB de mémoire
u 400 MB espace disque
u 1,5GB et 3,5 Gb for Oracle tools
u 1, 2 Gb / for the database
u 2,4 GB for the restore

Oracle Administration 11G R2 - Didier LESTRAT 90


Creating a base manually
Etape 1
Give the Oracle instance a name and create it
Sous UNIX et Linux
ORACLE_SID = Mynewdb(max 12 caractères)
export ORACLE_SID = Mynewdb
Etape2 : Choosing the Deployment Platform
Viewing OS prerequisites
Etape3 : Choose the authentication method
u Password file
u A System Authentication
Etape 4 : Create a PFILE parameter file
Create a parameter text file named init.ora and drop it in the default folder of
Oracle
u STARTUP (PFILE=le_fichier_init.ora (de MA_BASE) If your file is not in the default
folder)
Oracle Administration 11G R2 - Didier LESTRAT 91

Creating a base manually


We can create the SFILE file from the PFILE file
CREATE SPFILE = ora01/app/oracle/admin/new_dossier/pfile/initmynewdb.ora' FROM
PFILE ‘ora01/app/oracle/product/11.2.0/db_1/dbs/init.ora';

Plateforme Nom du fichier Emplacement/défaut

UNIX and Linux initORACLE_SID.ora ORACLE_HOME/dbs

Windows initORACLE_SID.ora ORACLE_HOME\database

Etape5 : Create Instance(Windows only)


Outil ORADIM :
oradim -NEW -SID sid(nom de l’instance : mynewdb) -STARTMODE MANUAL -PFILE pfile

Etape 6 : connect to the instance


#export ORACLE_SID=orcl
$ sqlplus /nolog
SQL> CONNECT SYS AS SYSDBA

Etape7 : Create a parameter file for the database


Oracle Administration 11G R2 - Didier LESTRAT 92
u Etape8 : Start Instance
STARTUP NOMOUNT

u Etape 9 Creating the database, preparing the script


CREATE DATABASE mynewdb
USER SYS IDENTIFIED BY sys_password
USER SYSTEM IDENTIFIED BY system_password
LOGFILE GROUP 1 ('/u01/app/oracle/oradata/mynewdb/redo01.log') SIZE 100M,
GROUP 2 ('/u01/app/oracle/oradata/mynewdb/redo02.log') SIZE 100M,
GROUP 3 ('/u01/app/oracle/oradata/mynewdb/redo03.log') SIZE 100M
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXLOGHISTORY 1
MAXDATAFILES 100
CHARACTER SET US7ASCII
NATIONAL CHARACTER SET AL16UTF16
EXTENT MANAGEMENT LOCAL
DATAFILE '/ora01/app/oracle/oradata/mynewdb/system01.dbf' SIZE 325M REUSE
SYSAUX DATAFILE '/ ora01 /app/oracle/oradata/mynewdb/sysaux01.dbf' SIZE 325M REUSE
DEFAULT TABLESPACE users
DATAFILE '/ ora01 /app/oracle/oradata/mynewdb/users01.dbf'
SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
DEFAULT TEMPORARY TABLESPACE tempts1
TEMPFILE '/ ora01 /app/oracle/oradata/mynewdb/temp01.dbf'
SIZE 20M REUSE
UNDO TABLESPACE undotbs
DATAFILE '/ ora01 app/oracle/oradata/mynewdb/undotbs01.dbf'
Oracle Administration 11G
SIZER2200M
- Didier LESTRAT
REUSE AUTOEXTEND ON MAXSIZE UNLIMITED; 93

Launching the script


u sql>start script_base.sql
Etape 10 : Addition of tablespaces

Create new tablespace : USERS, INDEX


CREATE TABLESPACE apps_tbs LOGGING
DATAFILE '/ora01/app/oracle/oradata/mynewdb/apps01.dbf'
SIZE 500M REUSE Addition of AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL;
-- create a tablespace for indexes, separate from user tablespace (optional)
CREATE TABLESPACE indx_tbs LOGGING
DATAFILE '/ora01/app/oracle/oradata/mynewdb/indx01.dbf'
SIZE 100M REUSE AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT
LOCAL;

Oracle Administration 11G R2 - Didier LESTRAT 94


Creating a base manually

u Run the scripts necessary to build data dictionary views, synonyms, and PL/SQL
packages, and to support proper functioning of SQL*Plus
u @?/rdbms/admin/catalog.sql
u @?/rdbms/admin/catproc.sql
u @?/sqlplus/admin/pupbld.sql
u EXIT

u Create a full backup of the installation

Oracle Administration 11G R2 - Didier LESTRAT 95

Practice 3 Creating a base manually

• Delete the database created in Workshop 2

• Creating a database manually with a script

• Qualify the new database connection

On a web interface typing : Creating a Database with the CREATE DATABASE


Statement

Oracle Administration 11G R2 - Didier LESTRAT 96


Instance parameters
u Database name Less than 8 characters
u Create at least two control files (different disk)
u Let Oracle handle block sizes

SGA
u Set a maximum size
u Fix these components
u Set the number of user processes
u Choose a cancellation management mode, before the COMMIT
u Automatic: Managed in a tablespace
u Handbook; Managed in the cancellation segments

Oracle Administration 11G R2 - Didier LESTRAT 97

Complements

If the creation of the database fails:


u Stop instance
u Delete created files
To delete a database
u Drop database
The base must be mounted and closed

To change settings
ALTER SYSTEM for instance
ALTER DATABASE to return to the CREATE DATABASE choices
To view database information
Sql>Show parameters
Sql>select * from V$DATABASE;

Oracle Administration 11G R2 - Didier LESTRAT 98


Configuring Network oracle

Rôle du Listener :
Listen and transmit data sent between the client and the server
Par défaut le fichier listener.ora file est dans le dossier
u $ORACLE_HOME/network/admin sous Unix
u %ORACLE_HOME%\network\admin sous Windows

Fichier tnsname.ora : You can keep the file and deploy it on


All Oracle clients because it is not client-specific.

Oracle Administration 11G R2 - Didier LESTRAT 99

Oracle Listener

Oracle Administration 11G R2 - Didier LESTRAT 100


u Server-side configuration: listener.ora

Installation with Oracle net configuration


You can also create a listener.ora script

u Under the tree:


/ora01/app/oracle/ product/ 11.2.0 /db_1/
network/ ADMIN
TP: create a file listener.ora

Client-Side Configuration: tnsname.ora

Oracle Administration 11G R2 - Didier LESTRAT 101

Commande : >lsnrctl start(status-stop) LISTENER


LSNRCTL> help

LSNRCTL>
Configuration côté client
u sélectionner les méthodes de résolution, elles sont stockées dans le fichier sql.ora
u Lancer Oracle net configuration et suivre les instructions
u Visualiser le fichier tnsname.ora
u Lancer la commande tnsping pour visualiser la connexion réseau
Nota : le fichier tnsname.ora n’est pas fixé à un client. Vous pouvez le dupliquer sur
d’autres machines clients en le maintenant dans un dossier de distribution

Plusieurs connexion sont envisagées pour une connexion client/instance base


u Connexion locale
u SQL> connect user/password@instance
u SQL> connect sys/manager@orcl
u Connexion réseau : TCP/IP
u SQL> connect user/password@<hostname>:listenerport/servicename
u SQL> connect user/password@server.esaip.org:1521/orcl

Tester avec le commande TNSPING


Local : >tnsping nom_instance
Oracle Administration 11G R2 - Didier LESTRAT 102
Via réseau >tnsping server.esaip.org:1521/orcl
Practice 4
Create Listener and TNSname

Oracle Administration 11G R2 - Didier LESTRAT 103

Managing the instance and a database

1. Démarrage de l’instance
2. Montage de la base de données
3. Ouverture de la base
Oracle Administration 11G R2 - Didier LESTRAT 104
Managing the instance and a database

1. Start the instance


2. Mounting the database
3. Open the database

STARTUP [NOMOUNT | MOUNT [name] | OPEN [name]]


[RESTRICT] [PFILE=nom_fichier]Avec

NOMOUNT | MOUNT | OPEN

$ Export ORACLE_SID=orcl

$ sqlplus /nolog

SQL> CONNECT /AS SYSDBA

SQL>STARTUP

Nota : ALTER DATABASE Allows to switch from one mode to


another
Oracle Administration 11G R2 - Didier LESTRAT 105

SHUTDOWN Instance and database


Syntaxe
u SHUTDOWN [NORMAL | IMMEDIATE | TRANSACTIONAL | ABORT]Options :

u NORMAL
Oracle waits for all users to be disconnected (no new connections allowed) and
then properly closes the database.
IMMEDIATE
Oracle disconnects all users (by performing a ROLLBACK of any transactions in
progress) and then closes the database cleanly.

TRANSACTIONAL
Oracle waits for all current transactions to end before disconnecting users (no new
transactions allowed) and then properly closes the database.

Oracle Administration 11G R2 - Didier LESTRAT 106


SHUTDOWN Instance and database

u ABORT
Oracle disconnects all users (without performing any ROLLBACK of any
transactions in progress) and closes the database "brutally" without
performing a checkpoint. A recovery of the instance will be necessary
the next time you start

Nota : To check if users are connected.


Sql>SELECT sid,serial#,username,DECODE(taddr,NULL,’’,’Oui’) trans
2 FROM v$session

Oracle Administration 11G R2 - Didier LESTRAT 107

TRANSACTIONA
Database Behavior ABORT IMMEDIATE L NORMAL
NEW connections No No No No
Waiting for Sessions No No No Yes
Waiting for No No Yes Yes
Transactions
Performs a No Yes Yes Yes
checkpoint
and closes open
files

Oracle Administration 11G R2 - Didier LESTRAT 108


Practice 5
Start the Instance
Nomount
Mount
Open

SHUTDOWN
NORMAL
IMMEDIATE
TRANSACTIONAL
ABORT

Oracle Administration 11G R2 - Didier LESTRAT 109

Management of the structure of the database

Oracle Administration 11G R2 - Didier LESTRAT 110


How are the data in a table stored ?
A segment is created when a table is created and inserted into a tablespace
Logically, a table consists of rows and columns. A row is stored and stored in a data
block.
We write an entire line, but if the line is too large we write the remainder in another
block.
Oracle puts a pointer to indicate the sequence of the line

Oracle Administration 11G R2 - Didier LESTRAT 111

Logical spaces and the physical data files

Un tablespace Is a storage logical unit consisting of one or more physical


files.
There are at least two tablespaces: 1 tablespace system and sysaux
u SYSAUX.DBF
u SYSTEM.DBF

Oracle Administration 11G R2 - Didier LESTRAT 112


Create a new tablespace

Before creating the tablespace, you must create a folder and


choose the physical storage location

CREATE TABLESPACE
u Exemple :
u CREATE TABLESPACE lmtbsb DATAFILE
'/ora01/oracle/data/lmtbsb01.dbf' SIZE 50MEXTENT
MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;

Information about tablespaces and data files


u Tablespaces : DBA_TABLESPACES, V$TABLESPACE
u Data files : DBA_DATA_FILES, V$DATAFILE

Oracle Administration 11G R2 - Didier LESTRAT 113

Oracle Administration 11G R2 - Didier LESTRAT 114


Practice 6

Create 2 tablespaces
u 1 for the index
u 1 for the user

Modify a tablespace : ALTER Tablespace


u Skip tablespace to OFFLINE
u Modify la TABLE SPACE, modify the storage
u Pass the tablespace as read or read / write

Remove tablespaces created above

Oracle Administration 11G R2 - Didier LESTRAT 115

Management of users and their rights


Oracle defined:

u Users who can connect to the database


u Assign rights to users
u Rights to objects and system
u Oracle talks about privileges for user rights
u A role is a grouping of privileges

Oracle Administration 11G R2 - Didier LESTRAT 116


Order : Create user

&5($7(86(5PHWLHU
,'(17,),('%<PHWLHUBHVDLS
'()$8/77$%/(63$&(WEVBXVHUV
4827$021WEVBXVHUV
7(0325$5<7$%/(63$&(WHPS
4827$021V\VWHP
352),/(DSSBXVHU
3$66:25'(;3,5(

Oracle Administration 11G R2 - Didier LESTRAT 117

Modify user

$/7(586(5PHWLHU
,'(17,),('%<QHZBSDVVZG
'()$8/77$%/(63$&(WEVBXVHUV

Oracle Administration 11G R2 - Didier LESTRAT 118


Practice 7
Sql plus
u Create user : job connected to HR Database
u Modify password
u Lock an account
u UnLock an account
u View users parameters
u Allocation of a quota
u Change tablespace

Oracle Administration 11G R2 - Didier LESTRAT 119

Privileges
A privilege is a right to execute a particular type of SQL statement or to access another
user’s object

There are two kinds of privileges :


u Rights on system tools : System privileges
u Rights to objects in the database : Object privileges

System privileges
u Create role : affecte un rôle à un utilisateur
u Create user : droit de créer un utilisateur

Object privileges
u Insert
u Delete
u Update
u Select

Oracle Administration 11G R2 - Didier LESTRAT 120


Privileges
The SQL syntaxe for system privileges
u Grant <system_privileges TO <grantee_clause> WITH ADMIN OPTION

The SQL syntaxe for object privilege


Grant <object_privileges> ON <object> TO <grantee_clause> WITH ADMIN
OPTION

u With admin option : Assigns the user the right to assign, remove,
modify, and in turn delete the received role privileges

u with the ALL PRIVILEGES option. It grants almost unlimited rights to the
user who inherits it, with the security risks that this entails

Oracle Administration 11G R2 - Didier LESTRAT 121

Roles
A role is a grouping of privileges that is assigned to one or more users
u Easier privilege management
u Dynamic privilege management
u Selective availability of privileges

Oracle Administration 11G R2 - Didier LESTRAT 122


Create Role

&5($7(52/(GEDBH[SORLW

Oracle Administration 11G R2 - Didier LESTRAT 123

Oracle Administration 11G R2 - Didier LESTRAT 124


the rules
u Create Role
u Assign privileges to roles
u Insert users into role
Example
1 CREATE ROLE comptabilite ;
2 GRANT SELECT, INSERT, UPDATE, DELETE ON CPT.FACTURE TO comptabilite ;
GRANT SELECT, INSERT, UPDATE, DELETE ON CPT.LIG_FAC TO comptabilite ;
GRANT SELECT, INSERT, UPDATE, DELETE ON CPT.JOURNAL TO comptabilite ;
3 GRANT comptabilite TO user_name;

Oracle Administration 11G R2 - Didier LESTRAT 125

Oracle Administration 11G R2 - Didier LESTRAT 126


practice7
u Create 4 user
u Create 2 role
u Role 1 (2 users) : delete et insert On the HR employees table
u Role 2 (2 uers) : update, select On the HR employees table

u Create role dba_exploit


u System privilege : create, modify, Remove users, give privileges
u Create role dba_exp : export and import databases

u Check in tables and system views and send results to a text file

Make a query to supervise logged-in users

Oracle Administration 11G R2 - Didier LESTRAT 127

Profile Management
A set that limits the resources assigned to a user

u Cpu time per call or per session


u Number of logical reads
u Limited logon for a user
u Inactivity time per session

Since version 8: Implementation of a password policy


u Locking Accounts
u Lifespan of passwords
u Complexity of the password

Oracle Administration 11G R2 - Didier LESTRAT 128


Ressource_parameters
u SESSIONS_PER_USER Specify the number of concurrent sessions to which you want to
limit the user.
u CPU_PER_SESSION Specify the CPU time limit for a session, expressed in hundredth
of seconds.
u CPU_PER_CALL Specify the CPU time limit for a call (a parse, execute, or fetch),
expressed in hundredths of seconds.
u CONNECT_TIME Specify the total elapsed time limit for a session, expressed in
minutes.
u IDLE_TIME Specify the permitted periods of continuous inactive time during a
session, expressed in minutes. Long-running queries and other operations are not
subject to this limit.
u LOGICAL_READS_PER_SESSION Specify the permitted number of data blocks read in a
session, including blocks read from memory and disk.
u LOGICAL_READS_PER_CALL Specify the permitted number of data blocks read for a
call to process a SQL statement (a parse, execute, or fetch).
u PRIVATE_SGA Specify the amount of private space a session can allocate in the
shared pool of the system global area (SGA). Please refer to size_clause for
information on that clause.

Oracle Administration 11G R2 - Didier LESTRAT 129

Oracle Administration 11G R2 - Didier LESTRAT 130


Practice 8
u Create 6 Business users, 3 roles and privilèges

u Create 3 role
u Role 1 named admin_job :
u Create table, create user, Lauching procdures, create index
u Role named user_job1 :
u Update On columns first_name et last_name Of HR employee table
u Select Of HR employee table

u Role named user_job2 :


u Insert on columns phone_number et salary Of HR employee table
u Select Of HR employee table

Creating profiles for business users


u Change password: No re-use of the same password before 60 days
u Possibility to re-use the same password after 5 new passwords
u Maximum connection time 30 mn
u Concurrent session 20
u Dedicated space for a session: 30K

Check in tables and system views and send results to a text file

Oracle Administration 11G R2 - Didier LESTRAT 131

A schema

u A schema is a set of objects belonging to a single user

Example sys schema, system schema, HR schema, Scott schema

Other schemas are installed during the oracle installation:


u HR
u SCOTT
u BI
u OE
u IX
u PM
u SH

Oracle Administration 11G R2 - Didier LESTRAT 132


The tables

Oracle Administration 11G R2 - Didier LESTRAT 133

The data types in the tables

TYPE VALEURS
BINARY-INTEGER entiers allant de –2**31 à 2**31)
POSITIVE / entiers positifs allant jusqu’à 2**31 -1
NATURAL
NUMBER Numérique (entre –2**418 à 2**418)
INTEGER Entier stocké en binaire (entre –2**126 à 2**126)
CHAR (n) Chaîne fixe de 1 à 32767 caractères (différent pour une colonne de table)
VARCHAR2 (n) Chaîne variable (1 à 32767 caractères)
Chaîne variable (1 à 32767 caractères) (maximum 2 gigaoctets)
DATE Date (ex. 01/01/1996 ou 01-01-1996 ou 01-JAN-96 ...)
CLOB Grand objet caractère. Objets de type long stockés en binaire (maximum 4 giga
octets)
BLOB Grand objet binaire. Objets de type long (maximum 4 giga octets)
NCLOB Support en langage nationale (NLS) des grands
objets caractères. Déclare une variable gérant un
pointeur sur un grand bloc de caractères utilisant
un jeu de caractères mono-octets, multi-octets de
longueur fixe ou encore multi-octets de longueur
variable et stocké en base de données

Oracle Administration 11G R2 - Didier LESTRAT 134


The data types in the tables
ROWID Composé de 6 octets binaires permettre d’identifier une ligne
par son adresse physique dans la base de données.

UROWID Le U de UROWID signifie Universel, une variable de ce type


peut contenir n’importe quel type de ROWID de n’importe quel
type de table

FLOAT(p) Nombre flottant

BINARY_FLOAT Nombre flottant sur 32 bytes

BINARY_DOUBLE Nombre flottant sur 64 bytes

BFILE Stocker vers un fichier en dehors de la base

TIMESTAMP Etendre le type date en conservant les secondes – par


défaut la précision est sur 6 chiffres et peut être étendue à
9 chiffres

Oracle Administration 11G R2 - Didier LESTRAT 135

Create and modify tables


Via la commande
u CREATE TABLE hr.classes (
classe_id NUMBER(5),
name VARCHAR2(15) NOT NULL,
nombre_elev NUMBER(9) ENCRYPT,
Spe_classe VARCHAR2(30),
DATE DEFAULT (sysdate),
Photo_classe BLOB, )
TABLESPACE admin_tbs STORAGE ( INITIAL 50K);

ALTER TABLE hr.classes ADD annee NUMBER (6);

Oracle Administration 11G R2 - Didier LESTRAT 136


PRACTICE 8
Making a SQL script from the following elements
Create a table in the SCOTT schema ‘customer ‘:
u Id client
u customer name
u Customer first name
u Customer address
u Postal code
u city
u invoice amount
u date of invoice

Table options and constraints

u Clé primaire sur l’id


u Manually fix allocated space in blocks
u Compress data
u Tablespace allocated specifically for this table
u Create an index on two columns of the table (name - firstname)
Oracle Administration 11G R2 - Didier LESTRAT 137

Backup and Recovery


Principes
u Ensuring data security is one of the main tasks of the
administrator.
u Implementation of protection of the sensitive files of the
database:
u Control files
u Log files.
u Files of parameters
u Data files

u Adapted to the constraints of the company; Tested and


documented.
u Coherent or inconsistent

Oracle Administration 11G R2 - Didier LESTRAT 138


Questions to Ask
u Is it okay to lose data?
u Is it possible to stop the base periodically?

u Is it possible to perform a full backup of the database during shutdown?

u Is the data updated on a daily basis by users?


This is typically the case in a transactional application.
u Are the data updated periodically (every night, every week) and simply consulted
during the day?
This is typically the case with a decisional application.

Oracle Administration 11G R2 - Didier LESTRAT 139

the principles

u Protection of sensitive files:


u Control Files
u Log Files
u Files of parameters
u Data files

u A backup / restore strategy


u Adapted to the company
u Qualified and documented

u Solutions:
u RMAN tool
u System Command with SQL Queries

Oracle Administration 11G R2 - Didier LESTRAT 140


Archiving log files

u Guarantee no loss of data


u ARCHIVELOG mode

Principe
u To : Backup of data files
u Archiving enabled
u T1 : Incident occurs and the data file is lost

Data recovery :
u Taking the Last Backup
u Apply archived log files on this backup

Oracle Administration 11G R2 - Didier LESTRAT 141

Scenarios
u Full backup closed base (consistent)
u Full backup open database (inconsistent)
u Partially open backup
u Incremental backup

What strategy to take : Archivelog ou Noarchivelog

Loss of data

Yes No
yes Archivelog Archivelog
Noarchivelog
Backup closed base?
No Archivelog Archivelog

Oracle Administration 11G R2 - Didier LESTRAT 142


Backup and Recovery

RMAN Tool:

1. Base off line


2. Startup mount
3. Backup..(terms)
Order :

u rman target /
u Rman>

The tool is installed in EM (enterprise manager)

Oracle Administration 11G R2 - Didier LESTRAT 143

Configurer RMAN
Configuration actuelle
u RMAN>show all
Configurer la destination de la sauvegarde
CONFIGURE CHANNEL DEVICE TYPE DISK options
Ram >CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT \home\oracle\sauve\%u
MAXPIECESSIZE 4 G;
(taille des fichiers de sauvegarde est limité à 4 GO, le jeu comprendra plusieurs jeu)
Pour revenir à la configuration par défaut
Rman>CONFIGURE CHANNEL DEVICE TYPE DISK CLEAR

Configurer la politique de conservation


Permet de prévoir combien de jours, vous souhaitez revenir

Fenêtre de restauration
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF n DAYS;

Redondance
CONFIGURE RETENTION POLICY TO REDUNDANCY n;
Oracle Administration 11G R2 - Didier LESTRAT 144
Les index
Les types d’index :
u B-tree Index
u Bitmap Index
But d’indexer une table
u Performance des requêtes
u Accès plus rapide dans les colonnes
u Eviter le FULL Scan des tables
Les index peut également améliorer dans l'application des clés primaires et uniques.

Création d’index
CREATE INDEX employees_idx1 ON employees (last_name, job_id);
CREATE INDEX employees_idx2 ON employees (job_id, last_name);

Oracle Administration 11G R2 - Didier LESTRAT 145

Structure d’un index B-TREE


u Les données des index sont stockés dans des blocs réservés aux
index
Structure d’un bloc :
u Un bloc d’index comprend les données et des informations de
contrôle
u Un bloc peut contenir plusieurs index
u Le remplissage du bloc est contrôlé par le paramètre PCTFREE
u Pas de PCTUSED pour les index
Avantages :
u Améliore la performance des requêtes (SELECT, UPDATE et DELETE)
qui utilisent la clé d’index.
u Oracle maintient l’arborescence au fur et à mesure des entrées
des index

u Inconvénient :
u Dégrade les performances pour les mises à jour

Oracle Administration 11G R2 - Didier LESTRAT 146


Création d’index B-TREE
u Les colonnes souvent sollicitées par la cause WHERE
u La requête ramène moins de 5 à10% de lignes de la table
u Pas d’indexation sur les petites tables
u S’assurer que les requêtes soient bien écrites
u Les valeurs NULL, LIKE (si le début de chaîne n’est pas connu ‘%tel’),
NOT IN SUBSTR, ne sont pas indexées

u Stockage des index et tablespace : même attribut que pour les tables
u Attribut pour le STORAGE : INITIAL, NEXT, MINEXTENTS, MAXEXTENTS,
PCTINCREASE
CREATE INDEX emp_ename ON emp(ename)
TABLESPACE users
STORAGE (INITIAL 20K
NEXT 20k
PCTFREE 20);
u Index d’une contrainte de clé primaire

Oracle Administration 11G R2 - Didier LESTRAT 147

Index d’une contrainte de clé primaire ou unique


u Le stockage de l’index d’une clé primaire ou unique est spécifié à
la création de la contrainte ou en ajoutant une contrainte
u Spécifier un Index déjà existant
u Avec l’attribut USING INDEX
u Avec les attributs de l’index
CREATE TABLE c(c1 INT, c2 INT); CREATE INDEX ci ON c (c1, c2);
ALTER TABLE c ADD CONSTRAINT cpk PRIMARY KEY (c1)
USING INDEX ci;
ALTER TABLE hr ADD CONTRAINT hr_index1 PRIMARY KEY
USING INDEX
TABLESPACE indx
PCTFREE 10
STORAGE INITIALM 2 M;
La vue DB_CONTRAINTS a deux colonnes : INDEX_OWNER et
INDEX_NAME qui fait le lien entre l’index et la contrainte

Oracle Administration 11G R2 - Didier LESTRAT 148


Gestion des tables et des index

Sur tous les objets d’une base, ce sont les tables et les index qui occupent de
la place

Les tables et les index sont des segments et le stockage est géré par
extensions et par les caractéristiques des tablespaces

L’organisation du stockage dans les blocs est important


Ecritures des lignes dans les blocs

Index : Il existe plusieurs types d’index


u Index B-TREE
u Index BITMAP
u Index à clé inversée
u Index basé sur les fonctions

Oracle Administration 11G R2 - Didier LESTRAT 149

Contenu d’un bloc de données

Header
Il contient l’information générale : bloc de données, bloc d’index, rollback…
Table Directory :Informations sur la table
Row Directory : Cette partie du bloc de données contient des informations sur les lignes réelles dans
le bloc
Free Space
Espace pour l’insertion de nouvelles données
Row Data
Contenu des données des tables ou index
Oracle Administration 11G R2 - Didier LESTRAT 150
Oracle Administration 11G R2 - Didier LESTRAT 151

Organisation du stockage dans les blocs de données

Header
Il contient l’information générale : bloc de données, bloc d’index, rollback…
Table Directory :Informations sur la table
Row Directory : Cette partie du bloc de données contient des informations sur les lignes réelles dans le
bloc
Free Space
Espace pour l’insertion de nouvelles données
Row Data
Contenu des données des tables ou index

HWM High Water Mark

Oracle Administration 11G R2 - Didier LESTRAT 152


Oracle Administration 11G R2 - Didier LESTRAT 153

Oracle Administration 11G R2 - Didier LESTRAT 154


Oracle Administration 11G R2 - Didier LESTRAT 155

Structure d’un bloc

Header : adresse du bloc, le type de segment, un répertoire des


tables, un répertoire des lignes
La taille est variable : de 100 à 200 octets
Structure d’une ligne : l’en-tête d’une ligne contient des
informations sur la ligne et les données insérées
Taille variable 3 octets minimum
Chaque colonne est stockées avec un en-tête de colonne : 1 à 3
octets pour la longueur de la colonne et suivi de la valeur de la
colonne

Oracle Administration 11G R2 - Didier LESTRAT 156


Gestion de l’espace dans les blocs

L’espace libre peut gérer soit automatiquement ou manuellement


Gestion manuelle avec deux paramètres PCTFREE et PCTUSED
PCTFREE : spécifie le pourcentage de l’espace libre pour les
modifications de lignes stockées dans les blocs.
Il permet de ne pas remplir le bloc à 100% et de conserver de
l’espace
PCTUSED : spécifie le pourcentage d’occupation dans le bloc

En gestion automatique Oracle utilise un BITMAP pour gérer


ces 2 paramètres
u 0 à 25% d’espace libre
u 25 à 50% d’espace libre
u 50 à 75% d’espace libre

Oracle Administration 11G R2 - Didier LESTRAT 157

Gestion des tables

Le ROWID est une colonne virtuelle qui est présente dans chaque table
u Donne la localisation de l’adresse physique de stockage de la ligne
On peut requêter sur cet valeur
u SQL> select ROWID …..
u Ou sql> UPDATE …. Where ROWID = ‘abc’
u Augmente la performance dans une application dans les clauses
WHERE

Chaînage et migration
Une ligne complète est stockée en totalité dans un bloc
Si la ligne est trop grande, Oracle l’insère dans d’autres blocs
u Chaînage d’une ligne
u Lit plusieurs blocs
u Pointeur entre bloc
u Perte en performance

Oracle Administration 11G R2 - Didier LESTRAT 158


Spécifier le stockage d’une table

u Spécifier lors de la création d’une table


u Ordre SQL
SQL>CREATE TABLE ….
STORAGE INITIALE VALEUR
MAXEXTENTS
PCTFREE

u La clause PCTFREE par défaut : 10 par défaut


u La clause PCTUSED par défaut : 40 par défaut
La somme des deux doit strictement inférieure à 100
u La clause COMPRESS : compresse les données dans les blocs
(DIRECT_LOAD), par défaut ALL
u La clause LOGGING : permet de ne pas journaliser certaines
opérations

Oracle Administration 11G R2 - Didier LESTRAT 159

Recommandations pour le stockage d’une table

u Stocker les tables dans un ou plusieurs tablespaces dédiées


u Utiliser des tablespaces gérées localement avec une gestion
automatique des extensions (EXTENT MANAGMENT LOCAL
AUTOALLOCATE)

u Régler correctement le PCTFREE


u Allouer un espace initial à la table en prévoyant son évolution sur
1,2 ou 3 ans
Suivant les critères : Table statique, petite, volumineuse, à croissance
régulière

Oracle Administration 11G R2 - Didier LESTRAT 160


Gestion des index

u C’est un objet dédié sur une ou plusieurs colonnes


u Accès rapide aux lignes basées sur la clé de l’index
u Indépendant de la table
u Unique et non unique
u Tablespaces spécifiques

Oracle Administration 11G R2 - Didier LESTRAT 161

Oracle Administration 11G R2 - Didier LESTRAT 162


Configurer RMAN
Configuration de la sauvegarde automatique des fichiers de contrôles
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘format’;;

Utilisation de la zone de récupération rapide


u Conseillé
u Quota d ’espace alloué : paramètre DB_RECOVERY_FILE_DEST_SIZE
u Répertoires définis par oracle ou sont stockés les fichiers générés

Commande VALIDATE
VALIDATE clause
DATABASE, DATAFILE_LIST, CURRENT, SPFILE…..
Détecter les problèmes de corruption ou de fichiers manquants

Oracle Administration 11G R2 - Didier LESTRAT 163

Sauvegarde
Base montée : fichiers de contrôle ouverts
Sauvegarde base ouverte si la base fonctionne en ARCHIVELOG
Fichiers de données, contrôle, fichiers de journalisation archivé, paramètres,…

1. Shutdown de la base
2. Startup mount
3. Backup..(conditions)
Syntaxe
BACKUP mode quoi [option]
Mode :
u INCREMENTATE LEVEL n [CUMUTATIVE]
u VALIDATE
u AS COPY AS [COMPRESSED] BACKUPSET
u Option : DATABASE, DATAFILE cible,….

Oracle Administration 11G R2 - Didier LESTRAT 164


Sauvegarde incrémentielle
Sauvegarde que les blocs modifiés
Sauvegarde
Incrémentale de Niveau 0 : sauvegarde tous les blocs, correspond à une sauvegarde
totale
Incrémentale différentielle de Niveau 1 : sauvegarde tous les blocs modifiés depuis la
sauvegarde niveau 0 ou 1
Incrémentale cumulative de Niveau 1 : sauvegarde tous les blocs modifiés
Scénario 1 : base ouverte (ARCHIVELOG)
Dimanche : BACKUP INCREMENTAL LEVEL 0 DATABASE;
Lundi au samedi : BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;

Scénario 1 : base ferme (NOARCHIVELOG)


On ajoute les commande
Shutdown immediate;
Startup mount;
Backup….
SQL>alter database open;
Dimanche : BACKUP INCREMENTAL LEVEL 0 DATABASE;
Lundi au samedi : BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;
Oracle Administration 11G R2 - Didier LESTRAT 165

Practice 10
&UHDWHXVHU

64/!FUHDWH WDEOHVSDFH UPDQBWVBGDWD GDWDILOH ILOHV50$1UPDQBWV


BGDWDGEI VL]H 0 
7DEOHVSDFH &UHDWHG
64/!FUHDWH XVHU UPDQ LGHQWLILHG E\ RUDFOH GHIDXOW WDEOHVSDFH 50$1
B76B'$7$
8VHU FUHDWHG
64/!JUDQW FRQQHFW UHVRXUFH UHFRYHU\BFDWDORJBRZQHU WR UPDQ
*UDQW VXFFHHGHG

/DXFK 50$1WRRO
64/!VKXWGRZQLPPHGLDWH
64/!VWDUWXSPRXQW
6TO!H[LW
UPDQ WDUJHW

Viewing RMAN Settings


5PDQ!6KRZDOO

Changing RMAN Settings


5DP!&21),*85(ಹಹ

1. Change the backup path


2. Make a full backup of the database
3. Make a backup of the control files
Oracle Administration 11G R2 - Didier LESTRAT 166
Parctice 11

Make a backup with the open database


Switch to ARCHIVELOG mode

connect /as sysdba


sql>shutdown;
startup mount;

# Enable database ARCHIVELOG mode


alter database archivelog;

# Shutdown and restart the database instance.


Sql>shutdown immediate
Sql>startup

RMAN> BACKUP DATABASE

Oracle Administration 11G R2 - Didier LESTRAT 167

Other tools

u DATA PUMP
Move data or metadata between Oracle databases
u EXPORT
Export to a binary file: complete, or partial
u IMPORT : complet, ou partiel
u SQL*LOADER
Lets you load into a table of stored ACII files, or flat file

Oracle Administration 11G R2 - Didier LESTRAT 168


DATA PUMP

u DATA PUMP Architecture


u PL/SQL DBMS_DATAPUMP package
u PL/SQL DBMS_METADATA package

Two control tools


u expdp

u Impdp

The two control tools


Serves as an interface with the package
DBMS_DATAPUMP

Oracle Administration 11G R2 - Didier LESTRAT 169

Les modes EXPORT ou IMPORT


u Full
u Diagram
u Table
u tablespace

For each mode, it is possible to specify more precisely the objects


u expdp
Impdp

Oracle Administration 11G R2 - Didier LESTRAT 170


Implementation
u Create User ; dba_exp ou dba_imp
u Privileges : EXP_FULL_DATABASE or IMP_FULL_DATABASE
u Have access to directory and operating files
u CREATE ou REPLACE DIRECTORY repertory name AS ‘directory_path’
u Add a privilege to the user
u Grant ‘privilege’ On DIRECTORY To user

Syntaxe expdp paramètres ou impdp


Expdp dba_expl/oracle@nom_base DIRECTORY=dir_exp FULL=y
DUMPFILE=exp.dmp

Practice

u Export of the HR database


u Export of 20% of the HR base
u Export the HR Employees table

Oracle Administration 11G R2 - Didier LESTRAT 171

Practice : /* Export d'une base de données/*


u /*Create user*/

u DROP user dba_exp;

u CREATE user dba_exp IDENTIFIED BY oracle;

u /* Privileges */

u GRANT EXP_FULL_DATABASE TO dba_exp;

u /* */

u alter user dba_exp quota 100M on users;

u create directory dump as '/home/oracle/Documents/dir_exp/';

u grant read,write on directory dump to dba_exp;

u /7.1* Export 100% de comptable */

u expdp dba_exp/oracle@orcl DIRECTORY=dp SCHEMAS=HR DUMPFILE=comptable_full.dmp LOGFILE=comptable_full.log


FULL=y;

u /7.2* Export 20% employees table of hr */

u expdp dba_exp/oracle@orcl DIRECTORY=dp SAMPLE=hr.employees:20 DUMPFILE=employees.dmp LOGFILE=employees.log;

u /7.2* Export 20% jobs table of hr */

u expdp dba_exp/oracle@orcl DIRECTORY=dp TABLES=hr.jobs SAMPLE=20 DUMPFILE=jobs.dmp LOGFILE=jobs.log;

You might also like