0% found this document useful (0 votes)
67 views473 pages

Database Course

Uploaded by

Diwakar Reddy S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views473 pages

Database Course

Uploaded by

Diwakar Reddy S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 473

ORACLE DATABASE ADMINISTRATION

WORKSHOP

ORACLE DATABASE SERVER COMPLETE


UNDERSTANDING

Mallik
You can search mallik034 on YouTube and Google
Follow Me
Oracle Database Course Contents:
https://mallik034.blogspot.com/p/database-training.html

Upcoming-Batch-Schedule and Course Registration


- Course Registration
- Course Duration and Timing
- Course Fees
https://mallik034.blogspot.com/p/upcoming-batch-schedule.html Brief Description

More Details can be found on my blog


https://mallik034.blogspot.com

More Technical sessions and Live webinar can be accessed from my


YouTube Channel
https://youtube.com/mallik034 LinkedIn: https://www.linkedin.com/in/mallik034
YouTube: https://www.youtube.com/c/mallik034
More Technical Discussion join out Telegram Group Fakebook: https://www.facebook.com/mallik034
Blog: https://mallik034.blogspot.com
https://web.telegram.org/#/im?p=@mallik034 twitter: https://twitter.com/mallik034
Instagram: https://www.instagram.com/mallik034
Facebook Page:
https://www.facebook.com/mallik034oracledba
Telegram Group: @mallik034

You can search mallik034 on YouTube and Google


1. Environment Setup:
2. Setting up DNS and DHCP and name resolution
3. Installing 11g / 12c / 19c Oracle Software
4. Creating 11g / 12c / 19c databases (manual)
5. Creating 11g / 12c / 19c databases (GUI mode using dbca)
6. 11g / 12c /19c Architecture.
7. Oracle Administration and management.
8. Tablespaces / Segments / Extents and Data Blocks
9. 12c / 19c Multitenant Database Architecture and New Features
10. Oracle networking
11. ASM Architecture Overview and Administration
Course 12. RMAN Vs Conventional Backup and Recovery
13. RMAN and Conventional Backup
Contents 14. RMAN and Conventional Cloning
15. Applying Patches (PSU/CPU/BP/ONEOFF/MERGE Patch etc)
16. Database upgrade
17. Dataguard Architecture and Standby database / Data guard Understanding
18. Shell Scripting overview.
19. AWR reports / ADDM reports / ASH report
20. Expdp / Impdp backups
21. Real time and Practical Scenarios and excises
22. Proactive Monitoring and Alert mechanism and Maintenance
23. Performance tuning
24. Resume and Cover letter Preparation
25. Interview Questions 26. Mock Interview
1. Dataguard Architecture and Overview (Workshop 1)
2. RAC Architected and Overview (Workshop 2)
Advanced Topics & Workshops 3. 12c and 19c New features (Workshop 3)
4. CDB and PDB Management (Workshop 4)
5. OEM Architecture and Overview (Workshop 5)
LAB
EXERCISES
Environment Setup
a) Software Download
Linux OS ISO image
Oracle Software
Oracle Patches
VMware Workstation Download
Oracle Virtual Box Download
b) VMware Workstation or Oracle Virtual Box Installation
c) Linux Installation (RHEL/OEL/Ubuntu)
Understanding the Linux Partition
Yum repo setup
Installation custom rpms and packages
d) Other tools download installation
Winscp
Putty
MobaXterm
Linux OS ISO image
 We can download OEL from Oracle e-delivery
 RHEL we need to have access to redhat official sites

Oracle Software
 We can download from Oracle e-delivery

Oracle Patches
We can download from Oracle e-delivery

VMware Workstation Download


 We can download from VMware https://www.vmware.com
 This is licensed 0_Lab.txt

Oracle Virtual Box Download


 We can download it from https://www.virtualbox.org
 This does not required license
VMware Workstation or Oracle Virtual Box Installation
Demo

Linux Installation (RHEL/OEL/Ubuntu)


Demo OEL 7 installation
File System

File Allocation Table

New Technology File System


(journaling)

Extended File System

Journaled File System

Extents File System


PARTITIONS
How to create partition on Yum repo setup
new disk and mount it on
Linux server? How to setup yum repository?
Check existing yum repolist
How to find the partition list? yum repolist
fdisk -l
If not goto yum.repos.d directory and download the any
How to find the newly added disk? repository according to Operating system
cd /dev/ cd /etc/yum.repos.d
ls -ltr sd*
Check below Oracle doc for more information
How to create partition on newly added https://yum.oracle.com/getting-started.html
disk?
fdiks /dev/sdb

Format the newly added disk or partition


using ext file system.

Mount the newly created filesystem

Add entry on /etc/fstab


Installation custom rpms and packages

Suppose if you want to install any rpm

yum install telnet

if you want to install rpm from locally downloaded file


rpm -ivh <telnet>

if you want to upgrade rpm from locally downloaded latest rpm:


rpm -Uvh <telnet>

Check whether rpm installed or not?


rpm -qa|grep telnet

How to remove installed rpm?


rpm -qa|grep telnet
rpm -e <telnet>
Other tools download installation.

Winscp
Copying files from windows to linux vice versa

Download and Install winscp from below site:


https://winscp.net/eng/download.php

Putty
Tool Connecting to linux server using ssh via port 22

Download and Install putty from below site:


https://www.putty.org/

MobaXterm
Tool Connecting to linux server using ssh via port 22

Download and Install mobaxterm from below site:


https://mobaxterm.mobatek.net/

Remote Desktop
(Default Comes with Windows Server)
Connecting to Windows server using rdp via port 3389
Setting up DNS and DHCP and name resolution
a) DNS
b) DHCP
c) Nameserver
d) Forward Resolution
e) Reverse Resolution
DNS:
DNS stands for Domain Name System, or Domain Name Server.
Domain Name Service (DNS) is an internet service that maps IP addresses to fully qualified domain names (FQDN) and
vice versa.

BIND stands for Berkley Internet Naming Daemon.


yum install bind*

DHCP:
Dynamic Host Configuration Protocol
- Dynamically allocated the IP address to host

Nameserver:
Nameserver is a server on the internet specialized in handling
queries regarding the location of a domain name's various services.
Nameservers are a fundamental part of the
Domain Name System (DNS).

Forward DNS:
The DNS is queried for the IP address of a hostname.

Reverse DNS:
The DNS is queried for the hostname of a certain IP address
Demo on Host and Network Administration
Forward and Revers zone setup
Installing 11g / 12c / 19c Oracle Software
a) Download Oracle database software
b) Install and configure 11g / 12c /19c Oracle Database Software
GUI mode runInstaller
Silent Mode

Creating 11g / 12c / 19c databases


(manual)

Creating 11g / 12c / 19c databases


(GUI mode using dbca)
Preparing Environment and Creating
Database
(ASM & Database)
Demo on Download Oracle database software
Installing your Oracle Software
1. GI Home for Standalone
2. Install OH in GUI
3. OH Installation in Silent mode
(Optional)
4. Cloning existing OH (Optional)

Database Creation
1. Database creation in manual method (Optional)
2. Database Creation in GUI Mode (DBCA)
3. Cloning Database using RMAN/Other method (expdb,
offline clone)
Installation

Oracle Type

Database
Installation Standalone / Single
RAC / Real Application
Types Instance / Oracle
Restart (ASM)
Cluster

OS File RAW / ASM Disks /


System OCFS /SAN / ASM
Disk Groups
NFS

Install GI using
OUI Silent OUI or Silent ASM GI OUI or Silent

Install (OH) Install (OH)


+ Install (OH) Install(OH) Install (OH) Install (OH)
+ Create
Create(DB)
Create(DB) Create(DB) Create(DB) Create(DB)
We can not install OH without GUI mode?

• True
• False

Quiz We can not create Database without GUI


mode?

• True
• False
Oracle Grid Infrastructure and Oracle
Database Installation: System
Requirements
• Memory requirements:
– 1 GB for the database instance with Oracle
Enterprise Manager Database Control
– 1.5 GB for the ASM instance and Oracle Restart
• Disk space requirements:
– 3 GB of swap space (based on 2 GB RAM)
– 1 GB of disk space in the /tmp directory
– 3.8 GB for the Oracle Database software


4.5 GB for the Grid Infrastructure software
1.7 GB for the preconfigured database (optional)
2_Lab.txt
– 3.4 GB for the fast recovery area (optional)
• Operating system (see documentation)

https://docs.oracle.com/en/database/oracle/oracle-database/19/lad
Preparing the Operating System

Create the required operating system users and groups:


• Groups:
– oinstall
– dba
– Optional groups (if doing separation of duty
across multiple users):

oper

asmdba

asmoper

asmadmin
• Users:
– Software owner, usually oracle
– Can create multiple users for multiple product
installations
Creating Grid Home
ASM Instance

4_Lab.txt
ORACLE UNIVERSAL INSTALLER (OUI)
PART ONE: INSTALLING THE ORACLE GRID
INFRASTRUCTURE FOR STANDALONE SERVER
SELECTING PRODUCT LANGUAGES
CREATING AN ASM DISK GROUP
DEFINING ASM PASSWORDS
DEFINING PRIVILEGED OPERATING
SYSTEM GROUPS
SPECIFYING INSTALLATION LOCATION
CREATING INVENTORY
PERFORMING PREREQUISITE CHECKS
VERIFYING INSTALLATION SUMMARY
DATA
MONITORING INSTALLATION
PROGRESS
EXECUTING ROOT CONFIGURATION
SCRIPTS
EXECUTING CONFIGURATION
ASSISTANTS
FINISHING INSTALLATION
Creating RECO Diskgroup
CONFIGURING THE FRA/RECO DISK
GROUP
Installing Oracle Home using GUI mode
(runInstaller)
PART TWO: INSTALLING THE ORACLE
DATABASE SOFTWARE
CHOOSING THE TYPE OF
INSTALLATION
CHOOSING GRID INSTALLATION
OPTIONS
CHOOSING LANGUAGE SETTINGS
CHOOSING THE DATABASE EDITION
SPECIFYING INSTALLATION LOCATION
CHOOSING OPERATING SYSTEM
GROUPS
PERFORMING PREREQUISITE CHECKS
INSTALLATION SUMMARY PAGE
THE INSTALL PRODUCT PAGE
INSTALLATION FINISHED
Installing Oracle Home in silent mode
 using response file
 using clone existing home
INSTALLATION OPTION: SILENT MODE

• To install and configure Oracle products with OUI in silent mode,


perform the following steps:
1. Prepare a response file:
• Using one of the file templates that are delivered with the Oracle
software
• By recording a response file during an installation process using the
OUI by clicking Save Response File on the summary page
2. Run OUI in silent or suppressed mode.
./runInstaller –silent –responsefile <filename>
If required, run NetCA and the DBCA in silent mode.
INSTALLATION OPTION: SILENT MODE
– CLONE

• https://mallik034.blogspot.com/2020/02/cloning-oracle-home.ht
ml

1) Tar OH
2) Copy to target servre / location and untar
3) Run clone.pl
4) Verify the inventory
A response file is?

• A binary file that can be edited using a binary


editing program
• A binary file that can be created by the installer
Quiz program
• A text file that cannot be edited, but can be created
by the installer program
• A text file that can be edited with a text editor
12C GI INSTALLATION

GI Installation
Creating RECO Disk Group in 12c
12C OH INSTALLATION

12C OH Installation
Creating an Oracle Database
(DBCA)

Manual Database creation.txt


CREATING AN ORACLE DATABASE USING
GUI

11g DB creation using dbca


Database Configuration Assistant (DBCA)

2
USING THE DBCA TO CREATE A
DATABASE
3

4
USING THE DBCA TO CREATE A
DATABASE Enable automatic
maintenance tasks
such as optimizer
5 statistic collection and
proactive advisor
reports.

Configuring Enterprise
Manager for your
database requires a
listener to be configured
as well.
USING THE DBCA TO CREATE A
Choose between
DATABASE
the file system or
ASM (if ASM is
available) 7

Create multiple
copes of your redo
logs and control
files if desired. 8

Adjust file location


variables (ORACLE_BASE,
ORACLE_HOME, DB_NAME,
DB_UNIQUE_NAME, SID) if
needed.
USING THE DBCA TO CREATE A
DATABASE
8

9
USING THE DBCA TO CREATE A
DATABASE

10
B

View and alter


initialization
parameters.
USING THE DBCA TO CREATE A
DATABASE
11

12
CREATE DATABASE SUMMARY

13
PASSWORD MANAGEMENT

14
MODIFYING DATABASE USING DBCA

Create Template
Drop database
USING THE DBCA FOR ADDITIONAL
TASKS
CREATING A DATABASE DESIGN
TEMPLATE
USING THE DBCA TO DELETE A
DATABASE
In order to drop a database using the DROP DATABASE
command, the database must be:

Quiz •

Open and in RESTRICT mode
Mounted exclusively in RESTRICT mode
• Shut down with the immediate option
11
runInstaller
g
Download Unzip /u01/patches
/u01/app/11.2.0.4/grid
GI Software runInstaller

12
GridSetup.sh
c
Unzip /u01/app/
Download
12.2.0/grid /u01/app/12.2.0/grid
GI Software
GridSetup.sh

19 GridSetup.sh
c Unzip /u01/app/
Download
19.3.0/grid /u01/app/19.3.0/grid
GI Software
GridSetup.sh
11
runInstaller
g Download Unzip /u01/patches /u01/app/11.2.0.4/
DB
runInstaller dbhome_1
Software

12
runInstaller
c
Download Unzip
/u01/patches /u01/app/12.2.0/
DB
runInstaller dbhome_1
Software

19
runInstaller
c Unzip
Download /u01/app/19.3.0/
/u01/app/19.3.0/
DB dbhome_1
runInstaller dbhome_1
Software
11g / 12c /19c Architecture.
Complete understanding of 11g and 12c and 19c architecture

Oracle Administration and management.


a) Starting and shutting down database.
b) Understanding control files / datafiles / redo log files / archive
files / temp files
c) Understanding Server parameter file and Parameter files
d) Understanding password files
e) Automatic memory management
f) Different components in SGA and PGA

Tablespaces / Segments / Extents and Data Blocks


a) Dictionary managed vs Locally managed tablespaces.
b) Automatic Segment space management
c) Understanding Segments / extents and blocks and Relationships
d) Data Block parameters
e) Different block Sizes
EXPLORING THE ORACLE DATABASE
ARCHITECTURE
hat is Oracle database server?

y
mor
1
Me
3
2

ess
o c
Pr

Human Information store / Books Instance Database / Storage files

Oracle Database Server

1. Is there any limit to No of DB files?


2. Is there any limit to Size of each DB files?
3. Is there any limit to size of the database?
Standalone Vs RAC
Server A Servers 1 to N

Non-clustered System / Clustered System / RAC


Standalone

I1
I1 I2 I3
I2

D1

D2

Local Storage / database D Shared Storage /


database
Oracle Database server

Oracle Database server


1. How many database servers we can install on a server?
2. Can I have Instance and database on different servers?
3. Multiple database and single instance?
RAC database can not have more than 8
nodes?

• True

Quiz • False

How many RAC nodes/Instance I can have in


a single cluster?
3 Tire Architecture?
ire Architecture with Standalone vs RAC?
Front End Mobil Deskto Mobil Deskto
URL URL p
Client/Web/Mobile e p e
Presentation Layer

Middle Tier APP1 APP2 APP3 APP1 APP2 APP3


Middleware
pps Server + Web Server

I1 I1 I2 I3

Backend
Database Tier Standalone
Data management Tier RAC
DB DB
Select all available architecture in industry?

• One-tier architecture
Quiz • Two-tier architecture
• Three-tier architecture
• Four-tier architecture
nnecting to the Database Instance
tnsnames.ora
MYSID=
Username and Password (DESCRIPTION =
Hostname (ADDRESS_LIST =
DB Server name (ADDRESS = (PROTOCOL = TCP)(HOST = SERVER)(PORT
Port Name = 1521))
)
Protocol (CONNECT_DATA =
(Server = Shared/dedicate)
(SERVICE_NAME = DATABASENAME)
How to
) create?
)
netmgr
netca
OEM
DEMO:
Show tnsnames.ora file from server
What is TNS_ADMIN?

DEMO:
1. ps –ef|grep ora | wc –l
2. connect sqlplus / toad / sqldeveloper
3. ps –ef|grep ora | wc –l
Listener.ora

Server Process:
Dedicated Server process
Shared Server Process

How to
create?
netmgr
netca
LISTENER = OEM
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = SERV era)(PORT
= 1521))
)
)
DEMO:
Show TNS_ADMIN location and listener.ora file
select sid, server from v$session;
necting to the Database Instance

>>> Dedicated Server process


>>> Shared Server Process

All databases ALWAYS run in "dedicated" mode. It is not


really even a "mode", it is a method of connecting.

http://oracle-help.com/oracle-database/how-to-configure-shared-
server-mode/
Can I have more than 1listener for each database?

• True
• False

Quiz
Can I have more than 1 tnsnames for each database?

• True
• False
Oracle Database Server Architecture: Overview

Instance

Java pool Stream


Shared pool pool

SGA(Memory)
Database
Redo log
Large pool buffer
buffer
cache
PGA
Server
process Background processes
CKPT SMON PMON DBWn LGWR RECO

ARCn
Listener

Server
process

Database
Log1

User
process Log2
Archived redo log
files
Control files Data files Online redo log files
Overview Oracle Database Memory
Structures

Program Global Area (PGA) PGA


Stack User Stack User
Space Global Space Global
Area Area
Server Server
process 1 process 2

KEEP DEMO:
Database
Redo log buffer pool show database memory parameters
Shared pool buffer
cache
buffer SELECT sum(value)/1024/1024 "TOTAL SGA (MB)"
RECYCLE
FROM v$sga;
buffer pool
Stream nK buffer
Large pool Java pool
pool cache

System Global Area (SGA)


Memory region that contains Shared SQL and Library
Cache:

Quiz • Shared Pool


• PGA
• Buffer Cache
• User session data
Overview Process Structures / BG process

Instances (ASM and Database separate)

System Global Area (SGA)


PGA
Server Background processes
process DEMO:
Required: DBWn CKPT LGWR SMON PMON RECO Show database BG process
Optional: ARCn ASMB RBAL Others
Listener
ps –ef|grep ora

select name, value from v$parameter


Grid Infrastructure Processes where name = 'processes';
(ASM and Oracle Restart)
User ohas ocssd diskmon
process

orarootagent oraagent cssdagent


The Process Monitor process (PMON) is responsible
for?

• Performs recovery at instance startup

Quiz • Performs process recovery when a user


process fails
• Automatically resolves all in-doubt
transactions
• Writes the redo log buffer to a redo log file
Overview Database Storage Architecture / File Structures in
Database

Control files Data files Online redo log files DEMO:


Show database files
dba_data_files
ls -ltr

Parameter file Backup files Archived redo log


files

Password file Temp file Alert log and trace files


Demo

1_Lab.txt
What are mandatory files for database to
operate?

• Controlfile
Quiz • Datafile
• Redolog files
• Archivelog files
LOGICAL AND PHYSICAL DATABASE STRUCTURES

Logical Physical

Database

Tablespace Data file

Segment
Storage System
• SAN • NFS
Extent
• NAS • ASM
• Exadata • RAW
Oracle data • File System
block
SEGMENTS, EXTENTS, AND BLOCKS

• Segments exist in a tablespace.


• Segments are collections of extents.
• Extents are collections of data blocks.
• Data blocks are mapped to disk blocks.

Segment Extents Data Disk blocks


blocks (File System
Storage)
Size of the database is determined using?

Quiz • Tablespace
• Datafiles
• Segments
What is the smallest unit of Oracle
database/what are building blocks of my
datafiles?

Quiz • Data Blocks


• Segments
• Extents
• Tablespace
TABLESPACES AND DATA FILES

Tablespace 1 Tablespace 2 (Bigfile)

Datafile 1 Datafile 2 Datafile 3

8Kb 8Kb 8Kb 8Kb 8Kb

8Kb 8Kb 8Kb 8Kb 8Kb


Only 1 datafile
8Kb 8Kb 8Kb 8Kb 8Kb
allowed
<= 128 TB
8Kb 8Kb 8Kb 8Kb 8Kb

Extent Extent
64KB 96KB

Segment
160KB
SYSTEM AND SYSAUX TABLESPACES

• The SYSTEM and SYSAUX tablespaces are mandatory tablespaces that


are created at the time of database creation. They must be online.
• The SYSTEM tablespace is used for core functionality (for example, data SYSTEM
dictionary tables). SYSAUX
• The auxiliary SYSAUX tablespace is used for additional database UNDO
components (such as the Enterprise Manager Repository). TEMP
• The SYSTEM and SYSAUX tablespaces are not recommended to be used USERS
to store application's data. EXAMPLE
What are critical datafiles of my database?

• User datafile

Quiz • System datafile


• Temp datafile
• Sysaux datafile
1_Lab.txt

Demo on Understanding the memory and database structure


Managing Database Storage
Structures
How Table Data Is Stored

Columns Blocks

Table A Table B

Rows

Segment Segment

Table
Tablespace

Row piece Extent


Database Block: Contents

Block header
Growth
Free space

Row data
Tablespaces in the Preconfigured
Database
• SYSTEM • UNDO
• SYSAUX • USERS
• TEMP • EXAMPLE (optional)

Adding Tablespace Altering a Tablespace

Dropping a Tablespace Viewing a Tablespace

6_Lab.txt
Oracle-Managed Files (OMF)

Specify file operations in terms of database objects


rather than file names.

Example:
SQL> ALTER SYSTEM SET DB_CREATE_FILE_DEST = '+DATA';
SQL> CREATE TABLESPACE tbs_1;
OMF will help is ease of managing the database
administration?

Quiz • True
• False
Database Startup and Shutdown
sequences
Dependencies
Standalone and RAC Database
STARTING UP AN ORACLE DATABASE
INSTANCE: NOMOUNT

OPEN
STARTUP

MOUNT

NOMOUNT

Instance
It needs SPFILE / PFILE / INITFILE
started
SHUTDOWN
STARTING UP AN ORACLE DATABASE
INSTANCE:
MOUNT

OPEN
STARTUP

MOUNT

Control file
It needs control file
opened for this
NOMOUNT instance

Instance
started
SHUTDOWN
STARTING UP AN ORACLE DATABASE
INSTANCE:
OPEN

OPEN
STARTUP All files opened as
described by the control
MOUNT file for this instance It needs
datafiles
Control file and redolog
opened for this files
NOMOUNT instance

Instance
started
SHUTDOWN
SQL-Plus Utility SQL> startup --- Open Mode

SQL> startup nomount 1

SQL> alter database mount; 2


3_Lab.txt SQL> alter database open; or
3
SQL> startup
srvctl Utility

$ srvctl start database –d orcl –o nomount 1

$ srvctl start database –d orcl –o mount 2

$ srvctl start database –d orcl –o open 3

$ srvctl start database –d orcl


Startup and shutdown databases using OEM
irrespective if standalone and RAC database
Database to go from nomount to mount mode which
files are needed?

• Spfile
Quiz • Pfile
• Controlfile
• Datafile
SHUTDOWN MODES

Shutdown Modes A I T N

Allows new connections No No No No

Waits until current sessions end No No No Yes

Waits until current transactions end No No Yes Yes

Forces a checkpoint and closes files No Yes Yes Yes

Shutdown modes:
• A = ABORT
• I = IMMEDIATE
• T = TRANSACTIONAL
• N = NORMAL
SHUTDOWN OPTIONS

On the way down: During: On the way up:


• Uncommitted • No instance
SHUTDOWN
changes rolled NORMAL
recovery
back, for or
IMMEDIATE SHUTDOWN
• Database buffer TRANSACTIONA
L
cache written to or
data files SHUTDOWN
• Resources IMMEDIATE
released

Consistent database
SHUTDOWN OPTIONS

On the way down: During: On the way up:


• Modified buffers • Online redo
SHUTDOWN ABORT
not written to or
log files used
data files Instance failure to reapply
• Uncommitted or changes
STARTUP FORCE • Undo
changes not
rolled back segments
used to roll
back
uncommitted
changes
• Resources
Inconsistent database released
SQL-Plus Utility

SQL> shutdown transactional; 1

SQL> shutdown immediate; or


2
SQL> shutdown;

SQL> shutdown abort; 3


srvctl Utility

$ srvctl stop database –d orcl –o transactional 1

$ srvctl stop database –d orcl –o immediate 2

$ srvctl stop database –d orcl –o abort 3

$ srvctl stop database –d orcl


Startup and shutdown databases using OEM
irrespective if standalone and RAC database
Data Dictionary Views

USER_TABLES
ALL_TABLES
DBA_TABLES

USER_INDEXES
ALL_INDEXES
DBA_INDEXES

USER_VIEWS
ALL_VIEWS
DBA_VIEWS S
Data Dictionary: Usage Examples

SELECT table_name, tablespace_name


1
FROM user_tables;

SELECT sequence_name, min_value, max_value,


2 increment_by
FROM all_sequences
WHERE sequence_owner IN ('MDSYS','XDB');

SELECT USERNAME, ACCOUNT_STATUS


3 FROM dba_users
WHERE ACCOUNT_STATUS = 'OPEN';

4 DESCRIBE dba_indexes
Understanding password files
Password File:
$ORACLE_HOME/dbs

Password file – orapwDEVDB

11g:
Pssword is in local storage for both: ASM and DB

12c:
Pssword is in local storage for: DB
Pssword is in DISKGROUP for: ASM

19c
Pssword is in DISKGROUP for both: ASM and DB

9) Creating password file:

orapwd file=orapwDEVDB password=Welcome2020# entries=5

SQL> select * from v$pwfile_users;


Which data dictionary view can be used to find the
names of all tables in the database?

• USER_TABLES
Quiz • ALL_TABLES
• DBA_TABLES
• ANY_TABLES
ASM Architecture Overview and
Administration
a) ASM Architecture
b) Why we need ASM and Its Advantages
c) ASM instance parameters
d) ASM Administration

12c / 19c Multitenant Database Architecture


and New Features
a) Complete Understanding of Multitenant architecture
b) CDB and PDB Understanding
c) Installation of Pluggable database and Cloning Pluggable
Database
Oracle ASM & ASM
Architecture
ASM STORAGE COMPONENTS

ASM

Oracle
ASM
Database ASM file
disk group
datafile

ASM
extent

File system
or ASM allocation
Raw device ASM disk
unit
Software Stack with(out) ASM

APPL1 APPL2 APPL3 APPL1 APPL2 APPL3

DB1 DB2
DB1 DB2
File System …
Logical Volume Manager ASM

OPERATING SYSTEM OPERATING SYSTEM


AUTOMATIC STORAGE MANAGEMENT

• Is a portable and high-performance


cluster file system Oracle
Application Database
• Manages Oracle database files
• Manages application files with
ASM Cluster File System (ACFS)
ASM Cluster
• Spreads data across disks File ASM Files
to balance load System for Oracle
• Mirrors data in case of failures Database
ASM Dynamic
• Solves storage-management Volume
challenges Manager
Automatic Storage Management

https://docs.oracle.com/database/121/OSTMG/ Operating system


GUID-27178C12-40DB-4C8B-82B9-
44A9440F798D.htm#OSTMG58000 https://docs.oracle.com/en/database/oracle/oracle-
database/19/ostmg/steps-manage-
acfs.html#GUID-14BA3BA5-088D-4395-A22F-
Mirroring and Stripping
ORACLE INSTANCE

SGA
Shared RedoBuffer
BufferCache
Pool

ORACLE processes

CONTROL
DATAFILES REDOLOGS
FILES
ASM INSTANCE

ASM Cache SGA


Diskgroup descriptor
cache RedoBuffer
Shared
Metadata block Pool 256k
cache

ORACLE processes

Metadata
ASM Benefits/Advantages?

Quiz • Mirroring
• Stripping
• Ease of management
PROCESS STARTUP SEQUENCE

• Oracle Grid Infrastructure is started by the OS init daemon.

Operating System Grid Infrastructure Grid Infrastructure


Init Daemon Wrapper Script Daemons and Processes
init ohasd.bin
init.ohasd oraagent.bin ASM Instance
(root) Listener
orarootagent.bin
DB Instance
diskmon.bin
User Defined
cssdagent
ocssd.bin
Applications
• Oracle Grid Infrastructure installation modifies the /etc/inittab file to
ensure startup every time machine is started in corresponding run
level.
# cat /etc/inittab
..
h1:35:respawn:/etc/init.d/init.ohasd run >/dev/null 2>&1 </dev/null
Oracle Database Types:
acle Database Types & Differences:
ASM Components:
ASM Instance—Primary Processes
The ASM instance primary processes are responsible for ASM-related
activities.
ASM Instance Initialization Parameters

The ASM instance uses a small subset of the


parameters that an Oracle Database instance uses.
INSTANCE_TYPE = ASM
ASM_POWER_LIMIT = 1
ASM_DISKSTRING = '/dev/sda1','/dev/sdb*'
ASM_DISKGROUPS = DATA2, FRA
ASM_PREFERRED_READ_FAILURE_GROUPS = DATA.FailGroup2
DIAGNOSTIC_DEST = /u01/app/oracle
LARGE_POOL_SIZE = 12M
REMOTE_LOGIN_PASSWORDFILE = EXCLUSIVE
ASM started but none of the database are
starting?
Quiz - Need to check whether DG are mounted or
not
ASM Instance: Dynamic Performance
Views
The ASM instance hosts memory-based metadata tables
presented as dynamic performance views.
• Accessed by ASM utilities to retrieve metadata-only
information using the SQL language
• Contains many dedicated ASM-related views such
as:
V$ASM_ALIAS V$ASM_ATTRIBUTE
V$ASM_CLIENT
V$ASM_DISK V$ASM_DISK_IOSTAT
V$ASM_DISK_STAT
V$ASM_DISKGROUP V$ASM_DISKGROUP_STAT
V$ASM_FILE
V$ASM_OPERATION V$ASM_TEMPLATE
Starting and Stopping ASM Instances
Using SQL*Plus
Using SQL*Plus to start and stop ASM instances is
similar to the way in which you start and stop database
$ . oraenv
instances.
ORACLE_SID = [orcl] ? +ASM
The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/grid
is /u01/app/oracle
$ sqlplus / AS SYSASM
SQL*Plus: Release 11.2.0.1.0 - Production on Wed Jul 8 20:46:46 2009
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ASM instance started

Total System Global Area 284565504 bytes


Fixed Size 1336028 bytes
Variable Size 258063652 bytes
ASM Cache 25165824 bytes
ASM diskgroups mounted
ASM diskgroups volume enabled
SQL> shutdown abort
Starting and Stopping ASM Instances
Using srvctl
The Server Control utility (srvctl) can be used to start
and stop ASM instances.
$ . oraenv
ORACLE_SID = [orcl] ? +ASM
The Oracle base for
ORACLE_HOME=/u01/app/oracle/product/11.2.0/grid is
/u01/app/oracle
$ srvctl start asm -o mount
$ srvctl stop asm -f

The Sever Control utility (srvctl) can be used to check


the status of ASM instances.
$ srvctl status asm
ASM is running on edrsr25p1
Starting and Stopping ASM Instances
Using asmcmd
The asmcmd utility provides a command-line interface to
ASM without using the SQL language.
$ . oraenv
ORACLE_SID = [orcl] ? +ASM
The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/grid
is /u01/app/oracle
$ asmcmd
Connected to an idle instance.
ASMCMD> startup
ASM instance started

Total System Global Area 284565504 bytes


Fixed Size 1336028 bytes
Variable Size 258063652 bytes
ASM Cache 25165824 bytes
ASM diskgroups mounted
ASM diskgroups volume enabled
ASMCMD> shutdown --abort
ASM instance shut down
Connected to an idle instance.
Which parameter is required for an ASM
instance?

Quiz •

INSTANCE_TYPE
ASM_DISKGROUPS
• LARGE_POOL_SIZE
• None of the above
Screen reader hint: This
slide contains a diagram that
is explained in the speaker
notes.

Disk Group Overview


Oracle DB Oracle DB Oracle DB Oracle DB Oracle DB
Instance Instance Instance Instance Instance

ASM Instance ASM Instance ASM Instance ASM Instance ASM Instance

Oracle RAC
Servers
Database Database Database

ASM Clustered Pool of Storage

Disk 1 Disk 2 Disk 3 Disk 4 Disk 5 Disk 6


File 3 File 4
File 1 File 2

Disk Group A Disk Group B


Allocation Units

ASM disks are divided into allocation units (AU):


• AU size is configurable at disk group creation.
• Default AU size is 1 MB:
– Small enough to be cached by database and large
enough for efficient sequential access
• Allowable AU sizes:
– 1, 2, 4, 8, 16, 32, or 64 MB
– Large AUs may be useful in very large database
(VLDB) scenarios or when using specialized storage
hardware
Extent Maps
When ASM creates a file, e.g.
on a request from an RDBMS
instance, it allocates space
Disk Group in extents. Once the file is
ASM File
created, ASM passes
Disk A
the extent map to the RDBMS
1
instance that can then access
5
Extent the file without involving ASM.
Map If a file extent needs to be
Disk B
relocated (e.g. due to a disk
2
group rebalance), ASM would
6
advise RDBMS instance
Disk C
about the modifications to the
extent map.
3
7

Disk D We can access ASM file extent maps


File Extent
4 by querying X$KFFXP in ASM
8 instance
Striping Granularity

ASM separates striping for load balance and striping for


latency:
• Coarse-grain striping concatenates allocation units
for load balancing.
– For example:

2 4 1

3 5
ASM Disk Group
Fine-Grained Striping

Fine-grain striping puts 128 KB stripe units across


groups of allocation units to improve latency.
• Disk group with 8 disks and external redundancy
• Default AU size of 1 MB in use
• First 1 MB extent written as 128 KB stripes across 8
AUs

ASM Disk Group


Fine-Grained Striping

Example:
• Disk group with 8 disks and external redundancy
• Default AU size of 1 MB in use
• Next 1 MB extent written as 128 KB stripes across
the same 8 allocation units until they are full

ASM Disk Group


ASM Failure Groups

• A set of disks sharing a common resource whose


failure needs to be tolerated
• Mirrored extent copies stored in separate failure
groups
• Storage hardware dictates failure group boundaries
– Example based on isolating disk controllers:
Failure Group 1 Failure Group 2
Controller 1 Controller 2

Disk Group
Stripe and Mirror Example

Normal redundancy disk group with eight disks in total,


spread across two failure groups.

Failure Group 1 Failure Group 2


Disk A Disk B Disk E Disk F

2 5 4 1 4
Disk C Disk D Disk G Disk H

3 1 2 5 3

Disk Group
Secondary Primary
Extent Extent
Failure Example

If disk H fails, then the extents it contained are re-


created on surviving disks from surviving mirrors.

Failure Group 1 Failure Group 2


Disk A Disk B Disk E Disk F

2 5 4 Copy 1 5 4
Disk C Disk D Disk G Disk H

3 1Copy 2 3 5 3
Disk Group
Managing Disk Groups

CREATE DISKGROUP

ASM DROP DISKGROUP


instance

Database
instance

ALTER DISKGROUP
Creating and Dropping Disk Groups
Using SQL*Plus
$ . oraenv
ORACLE_SID = [orcl] ? +ASM
The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.2.0/grid
is /u01/app/oracle
$ sqlplus / AS SYSASM
SQL*Plus: Release 11.2.0.1.0 - Production on Wed Jul 8 20:46:46 2009
Copyright (c) 1982, 2009, Oracle. All rights reserved.
..
SQL> CREATE DISKGROUP dgroupA NORMAL REDUNDANCY
FAILGROUP controller1 DISK
'/devices/A1' NAME diskA1 SIZE 120G FORCE,
'/devices/A2',
FAILGROUP controller2 DISK
'/devices/B1',
'/devices/B2';

SQL> DROP DISKGROUP dgroupA INCLUDING CONTENTS;


Adding Disks to Disk Groups

ALTER DISKGROUP dgroupA ADD DISK


'/dev/sde1' NAME A5,
'/dev/sdf1' NAME A6,
'/dev/sdg1' NAME A7,
'/dev/sdh1' NAME A8;

ALTER DISKGROUP dgroupA ADD DISK '/devices/A*';

Disk formatting

Disk group rebalancing


Miscellaneous ALTER Commands

Remove a disk from dgroupA:

ALTER DISKGROUP dgroupA DROP DISK A5;

Add and drop a disk in a single command:

ALTER DISKGROUP dgroupA


DROP DISK A6
ADD FAILGROUP controller3
DISK '/dev/sdi1' NAME A9;

Cancel a disk drop operation:

ALTER DISKGROUP dgroupA UNDROP DISKS;


Fine-grain striping, by default, is used for
_________ and __________?

• Data files
Quiz •

Control files
Temp files
• Online redo logs
• SPFILE
Managing ASM/Database Instances
Other Oracle Tools Components
> SQL*Plus
Init Params
DB Startup
• SQL*Plus provides an additional interface DB Shutdown
Alert Log
to your database so that you can:
– Perform database management operations
– Execute SQL commands to query, insert, update, and
delete data in your database
• SQL Developer:
– Is a graphical user interface for accessing your
instance of Oracle Database
– Supports development in both SQL and PL/SQL
– Is available in the default installation of Oracle
Database
Using SQL*Plus
SQL*Plus is:
• A command-line tool
• Used interactively or in batch mode

$ sqlplus hr

SQL*Plus: Release 11.2.0.1.0 - Production on Thu Jun 18 05:04:49 2009


Copyright (c) 1982, 2009, Oracle. All rights reserved.
Enter Password: *******

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL> select last_name from employees;


LAST_NAME
-------------------------
Abel
Ande

https://docs.oracle.com/database/121/COMSC/
installation.htm#COMSC001
Calling SQL*Plus from a Shell Script

$ ./batch_sqlplus.sh

SQL*Plus: Release 11.2.0.1.0 - Production on Thu Jun 18 05:10:19 2009


Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Output
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
# Name of this file: batch_sqlplus.sh
SQL> # Count employees and give raise.
COUNT(*) sqlplus hr/hr <<EOF
---------- select count(*) from employees;
107 update employees set salary = salary*1.10;
SQL> commit;
107 rows updated. quit
SQL> EOF
Commit complete.
SQL> Disconnected from Oracle Database 11g Enterprise Edition Release
11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
$
Calling a SQL Script from SQL*Plus

script.sql select * from departments where location_id = 1400;


quit
Output
$ sqlplus hr/hr @script.sql

SQL*Plus: Release 11.2.0.1.0 - Production on Thu Jun 18 05:13:42 2009


Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

DEPARTMENT_ID DEPARTMENT_NAME MANAGER_ID LOCATION_ID


------------- ------------------------------ ---------- -----------
60 IT 103 1400

Disconnected from Oracle Database 11g Enterprise Edition Release


11.2.0.1.0 - Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
Initialization Parameter Files Components
SQL*Plus
> Init Params
DB Startup
DB
Shutdown
Alert Log

spfileorcl.ora
or
initorcl.ora

SQL_and _Shell Lab.txt


Database to start which file is needed?

Quiz •

Spfile
Pfile
Initialization Parameters: Examples
Using SQL*Plus to View Parameters
SQL> SELECT name , value FROM V$PARAMETER;
NAME VALUE
------------ ----------
lock_name_space 2
processes 150
sessions 247
timed_statistics TRUE
timed_os_statistics 0

SQL>SHOW PARAMETER SHARED_POOL_SIZE


NAME TYPE VALUE
------------------------------------ ----------- ---------------------
shared_pool_size big integer 0

SQL> show parameter para


NAME TYPE VALUE
------------------------------------ ----------- ---------------------
fast_start_parallel_rollback string LOW
parallel_adaptive_multi_user boolean TRUE
parallel_automatic_tuning boolean FALSE
parallel_execution_message_size integer 16384
parallel_instance_group string

Changing Initialization Parameter Values

• Static parameters:
– Can be changed only in the parameter file
– Require restarting the instance before taking effect
– Account for about 110 parameters
• Dynamic parameters:
– Can be changed while database is online
– Can be altered at:

Session level

System level
– Are valid for duration of session or based on SCOPE
setting
– Are changed by using ALTER SESSION and ALTER
SYSTEM commands
– Account for about 234 parameters
Changing Parameter Values: Examples
SQL> ALTER SESSION
SET NLS_DATE_FORMAT ='mon dd yyyy';

Session altered.

SQL> SELECT SYSDATE FROM dual;

SYSDATE
----------- 3_Lab.txt
jun 18 2009

SQL> ALTER SYSTEM SET SEC_MAX_FAILED_LOGIN_ATTEMPTS=2


COMMENT='Reduce from 10 for tighter security.' SCOPE=SPFILE;

System altered.
Database can be managed using OEM/sqlplus?

Quiz •

True
False
Many of the database parameters are dynamic and can
be changed without having to shut down the database
instance.

Quiz • True
• False
CDB and PDB
Multitenant Architecture
MULTITENANT ARCHITECTURE
• Architecture Diagram
ORACLE MULTITENANT – BEHIND THE
SCENES
• One SGA
• One set of background processes
• One SPFILE

spfile Redo Control Flashback

PDB$
PDB1 PDB2 PDB3
SEED

CDB
MULTITENANT ARCHITECTURE

• Components of a Multitenant Container Database (CDB)

PDBs
CDB
Root

Pluggable Databases Multitenant Container Database


MULTITENANT ARCHITECTURE

• Multitenant architecture can


currently support up to 252 PDBs

DB Link
• PDB / non-CDB compatibility
guarantee:
GL OE AP You cannot tell, from the
viewpoint of a connected
client, if you’re using a PDB or
a non-CDB
A PLUGGABLE DATABASE IS A
PORTABLE DATABASE
• Unplugging a PDB and plugging it in
PO AP
• Simply unplug from the old
CDB…
• …and plug it into the new CDB
• Moving between CDBs is a
simple case of moving a PDB’s
GL OE AP metadata
• An unplugged PDB carries
with it lineage, opatch,
encryption key info etc.
PLUG INTO ORACLE MULTITENANT

• Different Methods of creating a PDB

Clone from PDB$SEED

Clone from another PDB

Clone from a Remote CDB

Convert a non-CDB to PDB

Plug a unplugged PDB


WAY TO CHOOSE THE CURRENT
CONTAINER
• For admin tasks or connection pooling

alter session set container = PDB1;

• Of course, only a common user can do this because


only a common can be known in both the present container
and the destination container
• This requires the new Set Container system privilege
in the destination container
CONNECTION TO CDB AND PDB

su - oracle sqlplus / as sysdba


ps -ef|grep smon show pdbs
. oraenv alter pluggable database all open
srvctl status database -d orcl instances=all;
echo $ORACLE_BASE show pdbs
echo $ORACLE_SID

Demo1: --- Create PDB from PDB$SEED


======

DEVCDB>>
create pluggable database DEVPDB1 admin user adm1 identified by Welcome2020;

TESTCDB>>
create pluggable database TESTPDB1 admin user adm1 identified by Welcome2020;
CDB - PDB Lab.txt
DEVCDB>>
create user c##my_Administrator identified by mallik container=all;
create user c##mallik identified by mallik container=all;

DEVCDB>>
alter session set container = DEVPDB1;

show pdbs
Show user

create user demo identified by demo;


--- create tables and crease view all ativites under PDB

conn demo/demo
Show user
--- create tables and crease view all ativites under PDB
[oracle@oracle19c admin]$ pwd
/u01/app/oracle/product/19.0.0.0/dbhome_1/network/admin

cat listener.ora
cat listener.ora

lsnrctl status LISTENER

tnsping DEVDB
tnsping PDB1

sqlplus c##_mallik/mallik@DEVDB PDB and CDB Administration Lab.txt

sqlplus mallik/mallik@PDB1

PDB and CDB Datafile Structure Lab.txt


Oracle networking
a) Configuring and maintaining listeners.ora
b) Configuring and maintaining tnsnames.ora
c) Configuring and maintaining sqlnet.ora
d) SQL Developer or Toad Download and Installation
e) How to connect to database using SQL Developer or Toad
Configuring the Oracle Network
Tnsnames.ora, listener.ora &
sqlnet.ora
Oracle Net Services

How to
Application RDBMS create?
netmgr
Oracle Net TCP/IP Oracle Net netca
network OEM
Client or
Listener Database server
middle tier

Oracle Net Oracle Net


configuration files configuration files
Oracle Net Listener

Enterprise Listener
Manager
Database
Control Oracle databases

Oracle Net
configuration files
<Grid_home>/network/admin/listener.ora
./sqlnet.ora
Establishing a Connection

Incoming
connection request
Listener
User Sessions

Server
process

User session PGA

User process

Listener
Tools for Configuring and Managing
the Oracle Network
• Enterprise Manager Net Services Administration
page
• Oracle Net Manager
• Oracle Net Configuration Assistant lsnrctl
tnsping
• Command line
Testing Oracle Net Connectivity

The tnsping utility that tests Oracle Net service


aliases:
• Ensures connectivity between the client and the
Oracle Net Listener
• Does not verify that the requested service is
available
tnsping host01.example.com:1521/orcl
• Supports Easy Connect Names Resolution:

tnsping orcl
• Supports local and directory naming:
Naming Methods

Oracle Net supports several methods of resolving


connection information:
• Easy connect naming: Uses a TCP/IP connect string
• Local naming: Uses a local configuration file
• Directory naming: Uses a centralized
LDAP-compliant directory server
• External naming: Uses a supported non-Oracle
naming service

Client/application server
Oracle Net

Oracle Net configuration files


Easy Connect

• Is enabled by default
• Requires no client-side configuration
• Supports only TCP/IP (no SSL)
• Offers no support for advanced connection options
such as:
– Connect-time failover
– Source routing
– Load balancing

SQL> CONNECT hr/[email protected]:1521/dba11g

No Oracle Net configuration files


Local Naming

• Requires a client-side Names Resolution file


• Supports all Oracle Net protocols
• Supports advanced connection options such as:
– Connect-time failover
– Source routing
– Load balancing

SQL> CONNECT hr/hr@orcl

Oracle Net
configuration files
Directory Naming

• Requires LDAP with Oracle Net Names Resolution


information loaded:
– Oracle Internet Directory
– Microsoft Active Directory Services
• Supports all Oracle Net protocols
• Supports advanced connection options

LDAP directory

SQL> CONNECT hr/hr@orcl

Oracle Net
configuration files
External Naming Method

• Uses a supported non-Oracle naming service


• Includes:
– Network Information Service (NIS) External Naming
– Distributed Computing Environment (DCE) Cell
Directory Services (CDS)

Non-Oracle
naming
service

Oracle Net
5_Lab.txt Configuring Communication
Between Databases
• Sending data or messages between sites requires
network configuration on both sites.
• You must configure the following:
– Network connectivity (for example, TNSNAMES.ora)
– Database links

CREATE DATABASE LINK <remote_global_name>


CONNECT TO <user> IDENTIFIED BY <pwd>
USING '<connect_string_for_remote_db>';
Connecting to Another Database
REMOTE_ORCL = tnsnames.ora
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)
(HOST = host02.example.com)
(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl.example.com)
)
)
CONNECT hr/hr@orcl; SQL*Plus

CREATE DATABASE LINK remote


CONNECT TO HR IDENTIFIED BY HR
USING 'REMOTE_ORCL';

SELECT * FROM employees@remote


Which configuration files are used to configure the
listener?

• listener.ora
• listener.conf
Quiz • tnsnames.ora
• tnsnames.conf
• sqlnet.ora
• sqlnet.conf
Administering User Security

7_Lab.txt
Database User Accounts

Each database user account has:


• A unique username
• An authentication method
• A default tablespace
• A temporary tablespace
• A user profile
• An initial consumer group
• An account status
A schema:
• Is a collection of database objects that are owned
by a database user
• Has the same name as the user account
Predefined Administrative Accounts

• SYS account:
– Is granted the DBA role, as well as several other
roles.
– Has all privileges with ADMIN OPTION
– Is required for startup, shutdown, and some
maintenance commands
– Owns the data dictionary and the Automatic
Workload Repository (AWR)
• SYSTEM account is granted the DBA
Privileges

There are two types of user privileges:


• System: Enables users to perform particular actions
in the database
• Object: Enables users to access and manipulate a
specific object

HR_DBA

Object privilege: System privilege:


Update employees Create session
Revoking System Privileges with ADMIN OPTION

DBA Joe Emily


User

GRANT
Privilege

Object

DBA Joe Emily


REVOKE

REVOKE CREATE
TABLE FROM joe;
Revoking Object Privileges
with GRANT OPTION
Bo Jo Emily
b e
GRANT

REVOKE Bob Joe Emily


Benefits of Roles

• Easier privilege management


• Dynamic privilege management
• Selective availability of privileges
Assigning Privileges to Roles and
Assigning Roles to Users

Users
Jenny David Rachel

Roles HR_MGR HR_CLERK

Privileges Delete Create Update


employees. Job. employees.

Insert Select
employees. employees.
Creating a Role

CREATE ROLES ROLE_EMP_DEP;


GRANT SELECT, INSERT, UPDATE, DELETE ON ORACLE.EMP TO ROLE_EMP_DEP;
GRANT SELECT, INSERT, UPDATE, DELETE ON ORACLE.DEPT TO ROLE_EMP_DEP;

Assigning Roles to Users


CREATE USER TEST1 IDENTIFIED BY TEST1;
GRANT CREATE SESSION TO TEST1;

SELECT * FROM ORACLE.EMP;


SELECT * FROM ORACLE.DEPT;

GRANT ROLE_EMP_DEP TO TEST1;

SELECT * FROM ORACLE.EMP;


SELECT * FROM ORACLE.DEPT;`
Profiles and Users

Users are assigned only one profile at a time.


Profiles:
• Control resource consumption
• Manage account status and password expiration

CREATE PROFILE TEST2 LIMIT


ALTER PROFILE TEST2 LIMIT FAILED_LOGIN_ATTEMPTS 3;
PASSWORD_LIFE_TIME 45
PASSWORD_GRACE_TIME 12
CREATE USER TEST2 IDENTIFIED BY TEST2 PROFILE TEST2;
PASSWORD_REUSE_TIME 3
PASSWORD_REUSE_MAX 5
ALTER USER TEST1 PROFILE TEST2;
FAILED_LOGIN_ATTEMPTS 4
PASSWORD_LOCK_TIME 2
DROP PROFILE TEST2 CASCADE;
CPU_PER_CALL 5000
PRIVATE_SGA 250K
DBA_PROFILES
LOGICAL_READS_PER_CALL 2000;

Note: RESOURCE_LIMIT must be set to TRUE before profiles can impose


resource limitations.
Implementing Password
Security Features

Password
Password complexity
ALTER PROFILE TEST2 LIMIT
history verification FAILED_LOGIN_ATTEMPTS 3;

User Setting up
profiles

Password aging Account


and expiration locking

Note: Do not use profiles that cause the SYS, SYSMAN, and DBSNMP
passwords to expire and the accounts to be locked.
Assigning Quotas to Users

Users who do not have the UNLIMITED TABLESPACE


system privilege must be given a quota before they can
create objects in a tablespace.
Quotas can be:
• A specific value in megabytes or kilobytes
• Unlimited

SELECT TABLESPACE_NAME,
BYTES / 1024 / 1024 "UTILIZIED_SPACE", ALTER USER ORACLE QUOTA 10G ON USERS;
MAX_BYTES / 1024 / 1024
"QUOTA_ALLOCATED" ALTER USER ORACLE QUOTA UNLIMITED ON
FROM dba_ts_quotas
WHERE username = 'ORACLE'; USERS;
RMAN Vs Conventional Backup and Recovery
a) Understanding the Backup strategy
b) Various Types of Backup
c) Complete understanding of RMAN Vs Conventional backups

RMAN and Conventional Backup


a) Conventional Backup
Cold Backup
Hot Backup
Logical Backup
User managed Backups
b) RMAN Backup
Full database Backup
Level 0 Backup
Level 1 Backup (Cumulative and Differential)

RMAN and Conventional Cloning


a) Cloning database using Conventional methods
b) Cloning database using RMAN
Oracle Database Backup and
Recovery Understanding
Ground Rules for Backup and Recovery:
--- We must keep our backup data into separate drive
--- Consistent Backup
--- There should not be any changes while taking the backup
--- Cold Backup
- DB Downtime required
- Incomplete recovery
- Backup is consistent
- You can only recover till the point where you had taken the
backup
--- Database Recovery
- Restore - Copying data from a backup location.
- Recover - Recover the database by applying logs or
archive logs till the point in time
Types of Backup:
1. Logical backup - Table backup
--- Oracle provides different utilities to take logical backup
- Export / Import utility
- Datapump utility

2. Physical backup - OS files (Datafile) backup


Ways to perform backup:
1. User Managed
--- Cold Database Backup
--- Hot Database Backup

Manual Backup:
==============
--- Cold backup and Hot backup are called as manual backup
--- Because backups are performed manually
without using any backup tool

Manual Recovery:
================
--- When backups are performed using manual
backup then we use manual recovery

2. Recovery Manager RMAN


Backup states / Types:
1. Consistent Backup
--- Cold backup
--- No recovery needed

2. Inconsistent Backup
--- Hot backup / RMAN Backups
--- Recovery needed
Recovery:
1. Complete Recovery
--- Recovering the database exactly till the point of failure

2. Incomplete Recovery
--- It cannot recover the database till the point of failure
--- You can recover the database till the time you had taken the
backup
What to back up?
Parameter File / SPFile, Controle file, Archive logs and datafiles etc

What file needed in deferent stages of database:


1. No mount - Parameter files
2. Mount - Control file
3. Open - Datafiles and Redologs
Cold Database Backup:
1. Fully consistent backup
2. Performed when DB is shut down
3. Requires down time
4. User cannot access the database
5. No need to backup redo logs or archive logs
6. A cold backup is performed using OS level Copy command
7. In real time, We rarely perform cold backup

Cold Database recovery:


1. Simulate a failure, All the database files have been deleted
--- Delete pfile / spfile, control files and datafiles
--- Copy pfile/spfile from cold backup location to dbs location - NO
MOUNT STAGE
--- Copy control files from cold backup location to required location -
MOUNT STAGE
--- Copy datafiles & reado from cold backup location to required
location - OPEN STAGE
2. All the transaction happened after the backup was taken will not be there
3. You will recover the database till the point where you have taken the backup
Full Bk bkp (backup database plus
FULL backup
Archivelog)

Incremental Level-0 : Full DB backup (backup level 0)


Backup
Level-1 : Cumulative and Differential (backup
level 1)

1. DB must be in archive mode


2. You can apply archives on both FULL an Incremental backup
 I don’t have level-0 backup and if I tried starting the level-1
backup what happens?

 Somebody has deleted the block change tracking file. What is


the impact on the database?

 Explain the Level 0, Level 1 backups concepts in RMAN?

 Is it possible to take a backup when database is down?

 What all files can be backed up using RMAN?

 Can RMAN take READ ONLY, TEMP and UNDO tablespace


backup?

 Explain the expired backup and obsolete backup


Backup:
--- Backup is a copy of data which helps in restoring data in case of original data is lost
--- Backups should be taken in deferent disks than your original data disks to avoid
loss of data as well as backups in case of hard disk failure.
PART OF YOUR JOB

• The database administrator’s duties are to:


• Protect the database from failure wherever possible
• Increase the mean time between failures (MTBF)
• Protect critical components by redundancy
• Decrease the mean time to recover (MTTR)
• Minimize the loss of data
CATEGORIES OF FAILURE

• Failures can generally be divided into the following categories:


• Statement failure
• User process failure
• Network failure
• User error
• Instance failure
• Media failure
FLASHBACK TECHNOLOGY

• Using Flashback technology:


• Viewing past states of data
• Winding data back and forth in time
• Assisting users in error analysis and recovery

For error analysis: For error recovery:


Oracle Flashback Query Oracle Flashback Transaction Backout
Oracle Flashback Versions Query Oracle Flashback Table
Oracle Flashback Transaction Query Oracle Flashback Drop
Oracle Flashback Database

SELECT * FROM TEST AS OF TIMESTAMP TO_TIMESTAMP(‘2021-03-10 13:34:12', 'YYYY-MM-DD HH24:MI:SS’);


FLASHBACK TABLE flashback_table_test TO SCN 715315;
FLASHBACK DATABASE TO SCN my_scn;
INSTANCE FAILURE

Typical Causes Possible Solutions


Power outage Restart the instance by using the
STARTUP command. Recovering
from instance failure is automatic,
Hardware failure including rolling forward changes in
the redo logs and then rolling back
any uncommitted transactions.
Failure of one of the critical
background processes Investigate the causes of failure by
using the alert log, trace files, and
Emergency shutdown procedures Enterprise Manager.
UNDERSTANDING INSTANCE
RECOVERY:

CHECKPOINT (CKPT) PROCESS
CKPT is responsible for:
• Updating data file headers with SGA
checkpoint information
• Updating control files with Database
checkpoint information buffer cache
• Signaling DBWn at
full checkpoints

DBWn
Database Writer
process

Control
files
CKPT

Checkpoint process Data files


UNDERSTANDING INSTANCE
RECOVERY:
REDO LOG FILES AND LOG WRITER
• Redo log files:
SGA
• Record changes to the
database
Redo log buffer • Should be multiplexed to
protect against loss
• Log Writer writes:
LGWR
• At commit
Log Writer
• When one-third full
• Every three seconds
• Before DBWn writes
Redo log Redo log Redo log
group 1 group 2 group 3 • Before clean shutdowns
UNDERSTANDING INSTANCE
RECOVERY
• Automatic instance or crash recovery:
• Is caused by attempts to open a database whose files are not
synchronized on shutdown
• Uses information stored in redo log groups to synchronize files
• Involves two distinct operations:
• Rolling forward: Redo log changes (both committed and
uncommited) are applied to data files.
• Rolling back: Changes that are made but not committed are returned
to their original state.
PHASES OF INSTANCE RECOVERY

• 1. Startup instance (data Instance


files SGA
are out of sync)
• 2. Roll forward (redo) Background
• 3. Committed and processes
uncommitted data in files
• 4. Database opened Database

• 5. Roll back (undo)


SCN:
• 6. Committed data in files SCN:140 SCN:143 74-101

SCN:
SCN:129 SCN:143 102-143
Undo
SCN: 99
Control Redo log
Data files files group
TUNING INSTANCE RECOVERY
• During instance recovery, the transactions between the checkpoint
position and the end of redo log must be applied to data files.
• You tune instance recovery by controlling the difference between the
checkpoint position and the end of redo log.

Checkpoint position End of redo log


Instance recovery

Transactions

USING THE MTTR ADVISOR


• Specify the desired time in seconds or minutes.
• The default value is 0 (disabled).
• The maximum value is 3,600 seconds (one hour).
MEDIA FAILURE
Typical Causes Possible Solutions
Failure of disk drive 1. Restore the affected file from
backup.
2. Inform the database about a new
Failure of disk controller file location (if necessary).
3. Recover the file by applying redo
information (if necessary).
Deletion or corruption of a file
needed for database operation

CONFIGURING FOR RECOVERABILITY


• To configure your database for maximum recoverability, you must:
• Schedule regular backups
• Multiplex control files
• Multiplex redo log groups
• Retain archived copies of redo logs
CONFIGURING THE FAST RECOVERY
AREA
• Fast recovery area:
• Strongly recommended for simplified backup storage management
• Storage space (separate from working database files)
• Location specified by the DB_RECOVERY_FILE_DEST parameter
• Size specified by the DB_RECOVERY_FILE_DEST_SIZE parameter
• Large enough for backups, archived logs, flashback logs, multiplexed
control files, and multiplexed redo logs
• Automatically managed according to your retention policy
• Configuring the fast recovery area means determining location,
size, and retention policy.
MULTIPLEXING CONTROL FILES

• To protect against database failure, your database should


have multiple copies of the control file.

ASM Storage File System Storage

Best One copy on each disk group At least two copies, each on separate disk
Practice (such as +DATA and +FRA) (at least one on separate disk controller)

Steps to No additional control file 1. Alter the SPFILE with the ALTER
create copies required. SYSTEM SET control_files
additional command.
control 2. Shut down the database.
files 3. Copy control file to a new location.
4. Open the database and verify the
addition of the new control file.
REDO LOG FILES

• Multiplex redo log groups to protect against media failure and


loss of data. This increases database I/O. It is suggested that
redo log groups have:
• At least two members (files) per group
• Each member:
• On a separate disk or
controller if using Member Member Member
file system storage +DATA
a a a
• In a separate disk group
(such as +DATA and +FRA) +FRA Member Member Member
if using ASM b b b
Group 1 Group 2 Group 3

Note: Multiplexing redo logs may impact overall database performance.


ARCHIVE LOG FILES

• To preserve redo information, create archived copies of redo log


files by performing the following steps.
1. Specify archive log file-naming convention.
2. Specify one or more archive log file locations.
3. Switch the database to ARCHIVELOG mode.

Online redo log files Archive log files


ARCHIVER (ARCN) PROCESS

• Archiver (ARCn):
• Is an optional background process
SGA
• Automatically archives online redo
log files when ARCHIVELOG mode is
set for the database Redo log buffer
• Preserves the record of all changes
made to the database
LGWR
Log Writer

Copies of
Redo log Redo log
files files

ARCn
Archiver process
ENABLING ARCHIVELOG MODE

• To place the database in ARCHIVELOG mode, perform the


following steps in Enterprise Manager:
1. Select the ARCHIVELOG Mode check box and click Apply.
The database can be set to ARCHIVELOG mode only from the MOUNT
state.
2. Restart the database (with SYSDBA privileges).
3. (Optional) View the archive status.
4. Back up your database.
• Note: Databases in ARCHIVELOG
• mode have access to the full
sqlplus / as sysdba
• range of backup and recovery
• options. shutdown immediate
startup mount
alter database archivelog;
alter database open;
archive log list
Performing Database Backups
BACKUP SOLUTIONS: OVERVIEW

• Backups can be performed by using:


• Recovery Manager
• Oracle Secure Backup
• User-managed backup

Target
Data files database Image copies

Backup pieces
Archive
log files
Redundant Backup data
archive log
files Fast recovery area
ORACLE SECURE BACKUP

• Oracle Secure Backup and RMAN provide an


end-to-end backup solution for Oracle environments:
• Centralized tape backup management for file system data and the
Oracle database
• Most well-integrated media management layer for RMAN backups
• Backup of any data anywhere on the network
• A single technical support resource for the entire backup solution
expedites problem resolution.
• This ensures reliable data protection at lower cost and complexity.
USER-MANAGED BACKUP

• A user-managed scenario:
• Is a manual process of tracking backup needs and status
• Typically uses your own written scripts
• Requires that database files be put in the correct mode for backup
• Relies on operating system commands to make backups of files
TERMINOLOGY

• Backup strategy may include:


• Entire database (whole)
• Portion of the database (partial)
• Backup type may indicate inclusion of:
• All data blocks within your chosen files (full)
• Only information that has changed since a previous backup
(incremental)
• Cumulative (changes since last level 0)
• Differential (changes since last incremental)
• Backup mode may be:
• Offline (consistent, cold)
• Online (inconsistent, hot)
Control Online
files redo log
Data files Database
files
TERMINOLOGY

• Backups may be stored as:


• Image copies
• Backup sets

Data file #1 Data file #1 Data file #2

Data file #2 Data file #3 Data file #4


Data file #5 Data file #6
Data file #3
Backup set
Data file #4
(Binary, compressed files in
Data file #5 Oracle proprietary format)

Data file #6
Image copies
(Duplicate data and log files in OS format)
RECOVERY MANAGER (RMAN)

• Powerful control and scripting language


• Integrated with Enterprise Manager
• Published API that enables interface with most popular backup
software
• Backing up data, control, archived log, and server parameter files
• Backing up files to the disk or tape

show all;
CONFIGURING BACKUP SETTINGS
Level 0 and level1
SCHEDULING BACKUPS: STRATEGY shell script – crontab

SCHEDULING BACKUPS: OPTIONS


SCHEDULING BACKUPS: SETTINGS
SCHEDULING BACKUPS: SCHEDULE
BACKING UP THE CONTROL FILE TO A TRACE FILE
alter database backup controlfile to trace;
alter database backup controlfile to trace as '/tmp/control.txt';

MANAGING BACKUPS
list backup;
list backup summary;

VIEWING BACKUP REPORTS


list backup;
list backup summary;
USING THE RMAN COMMAND LINE

1 $ rman target /
2 RMAN> CONFIGURE …
3 RMAN> BACKUP DATABASE PLUS ARCHIVELOG;

Copies of

Control
Control Archived log
Data files filesfile SPFILE
file
Performing Database Recovery
Opening a Database

To open a database:
• All control files must be present and synchronized
• All online data files must be present and
synchronized
• At least one member of each redo log group must
be present

OPEN
STARTUP
MOUNT

NOMOUNT

SHUTDOWN
Data Recovery Advisor

• Fast detection, analysis, and repair of failures


• Down-time and run-time failures
• Minimizing disruptions for users
• User interfaces:
– Enterprise Manager
GUI (several paths)
– RMAN command line
• Supported database configurations:
– Single instance
– Not RAC
– Supporting failover to standby, but not analysis and
repair of standby databases
Loss of a Control File

If a control file is lost or corrupted, the instance


normally aborts.
• If control files are stored in ASM disk groups,
recovery options are as follows:
– Perform guided recovery using Enterprise Manager.
– Put database in NOMOUNT mode and use an RMAN
command to restore control file from existing control
RMAN> restore controlfile from
file.
'+DATA/orcl/controlfile/current.260.695209463';

• If control files are stored as regular file system files


then:
– Shut down the database
– Copy existing control file to replace lost control file
Loss of a Redo Log File

If a member of a redo log file group is lost and if the


group still has at least one member, note the following
results:
• Normal operation of the instance is not affected.
• You receive a message in the alert log notifying you
that a member cannot be found.
• You can restore the missing log file by dropping the
lost redo log member and adding a new member.
• If the group with the missing log file has been
archived you can clear the log group to re-create
the missing file.
Loss of a Data File
in NOARCHIVELOG Mode
If the database is in NOARCHIVELOG mode and if any
data file is lost, perform the following tasks:
1. Shut down the instance if it is not already down.
2. Restore the entire database—including all data and
control files—from the backup.
3. Open the database.
4. Have users reenter all changes that were made
since the last backup.

User User User User User


Loss of a Noncritical Data File
in ARCHIVELOG Mode
If a data file is lost or corrupted, and if that file does not
belong to the SYSTEM or UNDO tablespace, you restore
and recover the missing data file.

Users
Loss of a System-Critical Data File
in ARCHIVELOG Mode
If a data file is lost or corrupted, and if that file belongs
to the SYSTEM or UNDO tablespace, perform the following
tasks:
1. The instance may or may not shut down
automatically. If it does not, use SHUTDOWN ABORT to
bring the instance down.
2. Mount the database.
3. Restore and recover the missing data file.
4. Open the database.

Users
Data Failure: Examples

• Inaccessible components: Missing data


files at the OS level, incorrect access
permissions, offline tablespace
• Physical corruptions: Block checksum failures,
invalid block header field values
• Logical corruptions: Inconsistent dictionary;
corrupt row piece, index entry, or transaction
• Inconsistencies: Control file older or newer
than the data files and online redo logs
• I/O failures: Limit on the number of open files
exceeded, inaccessible channels, network or I/O
error
Data Recovery Advisor

1. Assess data failures. Health Monitor

2. List failures by severity.


Data
Recovery
3. Advise on repair. Advisor

4. Choose and execute repair.

5. Perform proactive checks. DBA


Data Recovery Advisor Views

Querying dynamic data dictionary views


• V$IR_FAILURE: Listing of all failures, including
closed ones (result of the LIST FAILURE command)
• V$IR_MANUAL_CHECKLIST: Listing of manual advice
(result of the ADVISE FAILURE command)
• V$IR_REPAIR: Listing of repairs (result of the
ADVISE FAILURE command)
• V$IR_FAILURE_SET: Cross-reference of failure and
advise identifiers
DEMO: Backup

RMAN - Database backup:


=======================
rman target /
CONFIGURE CONTROLFILE AUTOBACKUP ON;
backup database plus archivelog format='/u01/backup/RMAN/database/backup_%d_%T_%U';

RMAN - Archive log backup:


======================
rman target /
backup archivelog all;
backup archivelog all format='/u01/backup/RMAN/database/backup_%d_%T_%U';

backup archivelog all format='+FRA';

RMAN - LEVEL0 and LEVEL1 backup:


==============================
rman target /

backup incremental level 0 database plus archivelog format='/u01/backup/RMAN/LEVEL0/backup_%d_%T_%U';


backup incremental level 1 database plus archivelog format='/u01/backup/RMAN/LEVEL1/backup_%d_%T_%U';

backup incremental level 0 database plus archivelog TAG LEVEL_0 format='/u01/backup/RMAN/LEVEL0/backup_%d_%T_%U';


backup incremental level 1 database plus archivelog TAG LEVEL_1 format='/u01/backup/RMAN/LEVEL0/backup_%d_%T_%U';
DEMO: Recovery
Restore and Recover database:
=============================
rman target /
sql 'alter database mount';
list backup of database summery;
restore database from '/u01/backup/RMAN/LEVEL0';
recover database from '/u01/backup/RMAN/LEVEL1';
RESTORE ARCHIVELOG ALL;
sql 'alter database open';

Restore and Recover database:


=============================
rman target /
restore controlfile from '/u01/backup/RMAN/LEVEL0'
sql 'alter database mount';
list backup of database summery;
restore database from '/u01/backup/RMAN/LEVEL0';
recover database from '/u01/backup/RMAN/LEVEL1';
RESTORE ARCHIVELOG ALL;
sql 'alter database open resetlogs';
DEMO-1:
Performing Cold Backup and Recovery:
- Get the location of all the files to be backed up.
--- parameter file: $ORACLE_HOME/dba
--- select NAME from v$controlfile;
--- select name from v$datafile;
--- select MEMBER from v$logfile;
- Shutdown the Database
- Copy all the files to a Cold backup location
- Start the Database and create some dummy tables
- Simulate the failure by removing all files at OS level
- Shutdown the database (Shut abort or kill the OS level instance process)
- Copy the parameter file from the Cold backup location to original location
- Start the instance in no mount state.
- Copy the control files from Cold backup location to original location
--- You can query show parameter controlfile;
- Take the instance to mount state
- Copy all the datafiles from Cold backup location to original location
- Open the Database
- Check for the dummy table which are created?
--- Dummy table will not be exists due to incomplete recovery
Hot Database Backup:
- Inconsistent backup
- Backup while the database is up and running
- No down time required
- DB Must be in archive log mode to perform Hot Backup
- We must backup all the Archive logs from the time of backup to recover the
database
DEMO-2:
Performing Hot Backup:
- DB must be up and running
- No downtime required
- Put the Database in begin backup mode
- alter database begin backup;
- select distinct status from v$backup
- Copy all the file at OS level to Hot backup location
- Put the Database in end backup mode
- alter database end backup;
- select district status from v$backup;
- Switch the log file
- alter system switch logfile;
- Take the backup of archive logs
DEMO-3:
Hot Database Recovery (All Datafiles were lost):
- Get the location of all the files to be backed up.
- select name from v$datafile;
- Delete all the data file from OS level
- Shutdown the database (Shut abort or kill the OS level instance process)
- Copy/Restore all the data files from the hot backup location (Restoring from
backup)
- Startup mount
- Recover database (This part if applying archive logs/redo logs)
- Alter database open;
DEMO-4:
Hot Database Recovery (All Datafiles and Control files were
lost):
- Get the location of all the files to be backed up.
- select name from v$confilfile;
- select name from v$datafile;
- Delete all the data files and confilfile from OS level
- shutdown the database (Shut abort or kill the OS level instance process)
- Copy/Restore all the data & Control files from the hot backup location (restoring from backup)
- Startup mount
- recover database using backup controlfile until cancel; (applying archive logs/redo logs)
- AUTO
- recover database using backup controlfile until cancel;
- CANCEL
- Alter database open resetlogs;
(resetlogs will reset the log sequence the start the archive log sequence starting from 1.
Database new in- carnation is started)

- login to database check the archive log sequence


- archive log list
DEMO-5:
Performing Hot Backup and Recovery (All Datafiles and Control files
were lost):
- DB must be up and running
- No downtime required
- Put the Database in begin backup mode
- alter database begin backup;
- select distinct status from v$backup
- Copy all the file at OS level to Hot backup location
- Put the Database in end backup mode
- alter database end backup;
- select distinct status from v$backup;
- Switch the log file
- alter system switch logfile;
- Take the backup of archive logs
- Create a new user and create a dummy table
- Simulate failure of controlefile and datafile loss and recover the Database
- Check if new user and dummy table exists or not
RMAN:
- Recovery Manager
- Oracle Database backup and recovery automation
- It Introduced in Oracle 8i version
- It performs block level backup
- Parallelism
- Detecting corruption in datafiles
- Validating the backup
- Incremental Backup
- Recovery Catalog etc
- Multi Destination Backups
- Archive log mode is must to use RMAN
RMAN:

RMAN is faster because it takes block level backups


RMAN is faster because we can initiate parallel processes
RMAN will data block corruptions and repair it for you
RMAN stores backup metadata information in the database controlfile, you can also store the
information into deferent database on different server which is called as RECOVERY catalog
RMAN Incremental Recovery
- Level 0 - Full database backup
- Level 1 - Backup of only changed blocks taken by referring data block header for
updated SCN
- As per recovery, we must only restore the database from level 0 and recovery the Database
using level 1. When you try to take level 1 backup, RMAN checks if already you have level 0
backup or not. If not then it will take level 0 backup automatically.
Recovery is of two parts:
- Restore and Recover - We cannot perform recovery without restore. Hence Level 0 is
used for restore and level 1 is used for recovery.
RMAN configuration Items
- show all;
RMAN Backup Methodology:
- Full Backup
- Entire Database backup
- Cannot apply Incremental backup on full backup

- Incremental Backup
- Level 0 - FULL Database backup
- Level 1 - Backup changes only from last incremental backup

Connecting to RMAN utility:


-RMAN utility comes with Oracle Binaries
-No special installation or license required for using RMAN
-At command prompt just type rman
-It defaults connects to database environmental variables defined
-RMAN utility can be used only when your DB is in at least MOUNT stage
- RMAN is used while the DB is up and running and have very little performance impact if
the backup is running
Components of RMAN:
- RMAN Prompt
- Target Database
- Recovery Catalog
- Auxiliary Database --- When cloning, Clone DB is called as auxiliary Database
- Media Management Layer --- layer between RMAN 3rd part vendor backup tools
netbackup, Veritos and Tape backups
- RMAN Channels
RMAN Configuration Parameter:
- RETENTION POLICY - tells till what date our backup will be stored which we can
use for recovery
- Redundancy -- How many backups to be retained
- Recover Window -- How many days backup to be retained
- Channels -- You can define channel to take backup to disk or tape
- Controlfile auto backup -- includes controlfile and spfile autobackup
- Parallelism -- Creates multiple processes to speed up backup
- Encryption -- to secure the backup
DEMO-6:
RMAN DB FULL back-up on Disk:
- rman target /
- set controlfile autobackup on;
- backup database plus archivelog format='/loc';

- Checking backups
- list backup;
- list backup of database summary;
DEMO-7:
Database level 0 Incremental Backup on disk:
- rman target /
- backup incremental level 0 database plus archivelog format='/loc';
- backup incremental level 1 database plus archivelog format='/loc';
- BACKUP INCREMENTAL LEVEL 0 DATABASE plus archivelog;

Recovering DB from Incremental Backup:


- rman target /
- restore controlfile from '<backup loc>'
- sql 'alter database mount';
- list backup of database summery;
- restore database from tag '<level 0 Tag>';
- recover database from tag '<level 1 Tag>';
- sql 'alter database open resetlogs';
RMAN Cloning

RMAN Clone.txt
Applying Patches
(PSU/CPU/BP/ONEOFF/MERGE Patch etc)
a) Different types of Patches
b) OPatch patching tool
c) How to apply patch at binary level (Oracle Home).
d) How to apply patch at database level.
Datapump
(Export and Import)
MOVING DATA:
GENERAL ARCHITECTURE

SQL*Loader
expdp impdp Other clients
(sqlldr)

Data Pump

DBMS_DATAPUMP
Data/Metadata Movement Engine

Oracle Oracle
Loader DataPump Direct Path API Metadata API

External Table API


ORACLE DATA PUMP:
OVERVIEW
• As a server-based facility for high-speed data and metadata
movement, Oracle Data Pump:
• Is callable via DBMS_DATAPUMP
• Provides the following tools:
• expdp
• impdp
• Web-based interface
• Provides four data movement methods:
• Data file copying
• Direct path
• External tables
• Network link support
• Detaches from and reattaches to long-running jobs
• Restarts Data Pump jobs
ORACLE DATA PUMP: BENEFITS

• Data Pump offers many benefits and some new features over
earlier data movement tools, such as:
• Fine-grained object and data selection
• Explicit specification of database version
• Parallel execution
• Estimation of export job space consumption
• Network mode in a distributed environment
• Remapping capabilities
• Data sampling and metadata compression
• Compression of data during a Data Pump export
• Security through encryption
• Ability to export XMLType data as CLOBs
• Legacy mode to support old import and export files
DATA PUMP EXPORT AND IMPORT
CLIENTS: OVERVIEW
expdp Database
client link

Source Target
Data Pump Server
job process
Database Database
Master Dump Dump Master
table file set file set table

“Network mode”

Server Data Pump


process job

impdp
client
DATA PUMP UTILITY: INTERFACES AND
MODES

• Data Pump Export and Import interfaces:


• Command line
• Parameter file
• Interactive command line
• Enterprise Manager
• Data Pump Export and Import modes:
• Full
• Schema
• Table
• Tablespace
• Transportable tablespace
DATA PUMP IMPORT: TRANSFORMATIONS

• You can remap:


• Data files by using REMAP_DATAFILE
• Tablespaces by using REMAP_TABLESPACE
• Schemas by using REMAP_SCHEMA
• Tables by using REMAP_TABLE
• Data by using REMAP_DATA

REMAP_TABLE = 'EMPLOYEES':'EMP'
DEMO:
CONN / AS SYSDBA

CREATE OR REPLACE DIRECTORY test_dir AS '/u01/app/oracle/oradata/';


GRANT READ, WRITE ON DIRECTORY test_dir TO oracle;

expdp oracle/oracle@ORCL tables=EMP,DEPT directory=TEST_DIR dumpfile=EMP_DEPT.dmp logfile=expdpEMP_DEPT.log


impdp oracle/oracle@ORCL tables=EMP,DEPT directory=TEST_DIR dumpfile=EMP_DEPT.dmp logfile=impdpEMP_DEPT.log

expdp oracle/oracle@ORCL schemas=oracle directory=TEST_DIR dumpfile=oracle.dmp logfile=expdporacle.log


impdp oracle/oracle@ORCL schemas=oracle directory=TEST_DIR dumpfile=oracle.dmp logfile=impdporacle.log

expdp system/password@ORCL full=Y directory=TEST_DIR dumpfile=ORCL.dmp logfile=expdpORCL.log


impdp system/password@ORCL full=Y directory=TEST_DIR dumpfile=ORCL.dmp logfile=impdpORCL.log

expdp oracle/oracle@ORCL schemas=oracle include=TABLE:"IN ('EMP', 'DEPT')" directory=TEST_DIR dumpfile=oracle.dmp


logfile=expdporacle.log
expdp oracle/oracle@ORCL schemas=oracle exclude=TABLE:"= 'BONUS'" directory=TEST_DIR dumpfile=oracle.dmp logfile=expdporacle.log

Over DB Link:
=============
CONN / AS SYSDBA
GRANT CREATE DATABASE LINK TO test;

CONN test/test
CREATE DATABASE LINK remote_oracle CONNECT TO oracle IDENTIFIED BY oracle USING 'DEV';

expdp test/test@ORCL tables=oracle.EMP network_link=REMOTE_oracle directory=TEST_DIR dumpfile=EMP.dmp logfile=expdpEMP.log


impdp test/test@ORCL tables=oracle.EMP network_link=REMOTE_oracle directory=TEST_DIR logfile=impdporacle.log
remap_schema=oracle:TEST
SQL*LOADER: OVERVIEW

Input data files Control file

SQL*Loader Rejected
Field processing
Discarded Accepted
Record selection
Selected
Bad
Oracle server file
Discard file Rejected
Inserted
(optional)

Log file
SQL*LOADER CONTROL FILE

• The SQL*Loader control file instructs SQL*Loader about:


• Location of the data to be loaded
• Data format
• Configuration details:
• Memory management
• Record rejection
• Interrupted load handling details
• Data manipulation details
LOADING METHODS

Data Block
insert writes

Table
HWM

Conventional Load Direct Path Load


Uses COMMIT Uses data saves (faster operation)

Always generates redo entries Generates redo only under specific conditions

Enforces all constraints Enforces only PRIMARY KEY, UNIQUE, and NOT NULL

Fires INSERT triggers Does not fire INSERT triggers

Can load into clustered tables Does not load into clusters

Allows other users to modify tables during Prevents other users from making changes to tables during
load operation load operation

Maintains index entries on each insert Merges new index entries at the end of the load
EXTERNAL TABLES

• External tables are read-only tables stored as files on the


operating system outside of the Oracle database.

PGA
Server ORACLE_LOADER
process driver

(Text)
ext_table
(Metadata Only)

ORACLE_DATAPUMP
driver

Database (Binary)
EXTERNAL TABLE BENEFITS

• Data can be used directly from the external file


or loaded into another database.
• External data can be queried and joined directly
in parallel with tables residing in the database,
without requiring it to be loaded first.
• The results of a complex query can be unloaded
to an external file.
• You can combine generated files from different
sources for loading purposes.
From Oracle Database From external file
DEFINING AN EXTERNAL TABLES WITH
ORACLE_LOADER

• CREATE TABLE extab_employees


• (employee_id NUMBER(4),
• first_name VARCHAR2(20),
• last_name
VARCHAR2(25),
• hire_date DATE)
• ORGANIZATION EXTERNAL
• ( TYPE ORACLE_LOADER DEFAULT DIRECTORY extab_dat_dir
• ACCESS PARAMETERS
• ( records delimited by newline
• badfile extab_bad_dir:'empxt%a_%p.bad'
• logfile extab_log_dir:'empxt%a_%p.log'
• fields terminated by ','
• missing field values are null
• ( employee_id, first_name, last_name,
• hire_date char date_format date mask "dd-mon-yyyy“))
• LOCATION ('empxt1.dat', 'empxt2.dat') )
• PARALLEL REJECT LIMIT UNLIMITED;
EXTERNAL TABLE POPULATION WITH
ORACLE_DATAPUMP

CREATE TABLE ext_emp_query_results


(first_name, last_name, department_name)
ORGANIZATION EXTERNAL
(
TYPE ORACLE_DATAPUMP
DEFAULT DIRECTORY ext_dir
LOCATION ('emp1.exp','emp2.exp','emp3.exp')
)
PARALLEL
AS
SELECT e.first_name,e.last_name,d.department_name
FROM employees e, departments d
WHERE e.department_id = d.department_id AND
d.department_name in
('Marketing', 'Purchasing');
USING EXTERNAL TABLES

• Querying and external table:

SQL> SELECT * FROM extab_employees;

• Querying and joining an external table with an internal table

SQL> SELECT e.employee_id, e.first_name, e.last_name,


d.department_name FROM
departments
• Appending d,
dataextab_employees e
to an internal table from an external table
WHERE d.department_id = e.department_id;

SQL> INSERT /*+ APPEND */ INTO hr.employees SELECT * FROM


extab_employees;
DATA DICTIONARY

• View information about external tables in:


• [DBA| ALL| USER]_EXTERNAL_TABLES
• [DBA| ALL| USER]_EXTERNAL_LOCATIONS
• [DBA| ALL| USER]_TABLES
• [DBA| ALL| USER]_TAB_COLUMNS
• [DBA| ALL]_DIRECTORIES
DEMO: email.dat

1,[email protected]
sqlldr parfile=parameter_file.par 2,[email protected]
3,[email protected]
Asasas
Asas
email.ctl
CREATE TABLE emails load data into table emails
( email_id NUMBER PRIMARY KEY, insert fields terminated by ","
email VARCHAR2(150) NOT NULL ); ( email_id, email )

email.par
sqlldr parfile=email.par
userid=oracle@ORCL/oracle
control=email.ctl
log=email.log
bad=email.bad
data=email.dat
direct=true
Monitoring
Database
(Monitoring Automation using
script)
nmap -p 22 -Pn ex01db01
Daily Monitoring commands: telnet 192.168.1.100 22
netstat -an | grep LISTEN | grep 8015
ps -ef | grep smon netstat -anp |grep 8015
ps -ef | grep listener
lsnrctl status mount -a
cd /backup/export/ rpm -q oracle
ls -ltrh watch -n 2 "ps -ef|grep smon"
df -h
df -k | grep oraarch vmstat 100
watch -n 2 date
export ORACLE_SID=<service_name> top
sqlplus / as sysdba
select instance_name, status from v$instance;
select name, open_mode from v$database;

CPU Information:
cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
cat /proc/cpuinfo | grep "cpu cores" | uniq
DR Log shipping monitor:
select instance_name, status from v$instance;
select max(sequence#) from v$log;
select max(sequence#) from v$archived_log;
select * from v$archive_gap;
select sequence#,applied,status from v$archived_log where applied='NO';
select current_scn from v$database;
Open files in linux:
[mallikarjun.ramadurg@s616455s233 ~]$ cat /proc/sys/fs/file-max
6815744

[mallikarjun.ramadurg@s616455s233 ~]$ cat /etc/sysctl.conf |grep file-max


# oracle-ebs-server-R12-preinstall setting for fs.file-max is 6815744
fs.file-max = 6815744

To find out how many files are currently open


[mallikarjun.ramadurg@s616455s233 ~]$ lsof |wc
-l Linux commands:
7257 grep -c ^processor /proc/cpuinfo
free -g
cat /etc/redhat-release
ps -ef|grep smon

cat /proc/cpuinfo | grep 'model name' | sort |


uniq
cat /proc/cpuinfo | grep 'physical id' | sort | uniq
| wc -l
cat /proc/cpuinfo | grep cores | sort | uniq
Metadata / Skeleton:

Command to check max sequence number: set long 1000000


SQL> select max(Sequence#) from v$log; select dbms_metadata.get_ddl ('<OBJECT>', '<OBJECT_NAME>',
MAX(SEQUENCE#) '<OWNER>') from dual;
--------------
set heading off;
78753 set echo off;
Set pages 999;
set long 90000;
spool ddl_list.sql
select dbms_metadata.get_ddl('TABLESPACE',tb.tablespace_name) from
dba_tablespaces tb;
spool off
DB Link:
desc dba_db_links; set long 1000000
select * from dba_db_links; select dbms_metadata.get_ddl ('<OBJECT>', '<OBJECT_NAME>',
CREATE DATABASE LINK "TRAXDOC_LINK" CONNECT TO "ODB" IDENTIFIED '<OWNER>') from dual;
BY "ODB" USING '<db_name>';

set pages 1000


set lines 1000
col OWNER for a10
col DB_LINK for a10
col USERNAME for a10
col HOST for a50
col CREATED for a10
select * from dba_db_links;

ckinstance.sh ora_error.sh lsnrctl status.sh filesystem_size_monitor.sh archived_gap.sh tablespace_quota.sh


Find unusbale indexes:
Rebuild Index Online:
alter index odb.P_PN_CONTROl rebuild online; set lines 160 pages 200
SELECT owner, index_name, status,tablespace_name
Rebuild Index offline: FROM dba_indexes
alter index XXLG.XLG_AED_TRANSACTIONS_STG_U2 coalesce WHERE status = 'UNUSABLE';
alter index XXLG.XLG_AED_TRANSACTIONS_STG_U2 rebuild
check index status for multiple schemas
parallel nologging
set lines 160 pages 200
alter index XXLG.XLG_AED_TRANSACTIONS_STG_U2 noparallel SELECT owner, index_name, status,tablespace_name
logging FROM dba_indexes
WHERE owner in (‘ORACLE’,’TEST1’);
alter index XXLG.XLG_AED_TRANSACTIONS_STG_U3 coalesce
alter index XXLG.XLG_AED_TRANSACTIONS_STG_U3 rebuild check index status for one schema
parallel nologging select count(*) FROM dba_indexes WHERE owner='XLA';
alter index XXLG.XLG_AED_TRANSACTIONS_STG_U3 noparallel
logging check index count
select count(*) FROM dba_indexes WHERE owner='GL';
alter index XXLG.XLG_AED_TRANS_STG_N1 coalesce
alter index XXLG.XLG_AED_TRANS_STG_N1 rebuild parallel
Gather Stats / Analyze Table:
nologging exec DBMS_STATS.GATHER_TABLE_STATS(ownname=>'ODB',
alter index XXLG.XLG_AED_TRANS_STG_N1 noparallel logging tabname=>'PN_CONTROL', estimate_percent => 100, degree=> 4, method_opt
Gather stats on fixed object and system objects: => 'FOR ALL COLUMNS SIZE 1', cascade => TRUE );

EXEC DBMS_STATS.GATHER_SYSTEM_STATS;
EXEC DBMS_STATS.gather_fixed_objects_stats;

Table movement:
user exists or not:
alter table XXLG.XLG_FAH_BULK_UPLOAD_TRANS move parallel select USERNAME from dba_users where username =
nologging; 'DEVNW_MDS';
alter table XXLG.XLG_FAH_BULK_UPLOAD_TRANS noparallel select USERNAME from dba_users where username =
logging; 'TD20NW_MDS'
select USERNAME from dba_users where username =
'TD20NW_BIPLATFORM'
Database 12c and 19c
New Features
Oracle Database 12c Release 1 (12.1.0.2) New Features
https://docs.oracle.com/database/121/NEWFT/chapter12102.htm#NEWFT003

Oracle Database 12c Release 2 (12.2) New Features


https://docs.oracle.com/en/database/oracle/oracle-database/12.2/newft/new-features.html#GUID-
3A8E2A84-4ACB-4354-9DB1-53EE6F608F6D

Oracle Database Release 19c New Features


https://docs.oracle.com/en/database/oracle/oracle-database/19/newft/new-features.html#GUID-
5490FE65-562B-49DC-9246-661592C630F9
12c: 19c:
CDB and PDB
Automatic Indexing
Full Database Caching
Real-Time Statistics
In-Memory Column Store
Active Data Guard DML Redirection
Rapid Home Provisioning
Automatic Resolution of SQL Plan Regressions
Online Data file Movement
Finer granularity Supplemental Logging
DDL Logging
Dry-Run Validation of Clusterware Upgrade
Temporary UNDO for Temporary Tablespace
AutoUpgrade for Oracle Database
RMAN Table level Recovery
Flashback Standby when Primary is flashed
PGA Sizing Limitation
back
Flex Cluster Supported for Oracle RAC Architecture
Propagate Restore Points from Primary to
MGMT Database
Standby
12c_New_Features.txt 19c_New-Features.txt

New in Oracle 12c is the Multitenant Architecture, as well as the ability to restore one table from an
RMAN backup. This blog post explains how to do a restore of one table in a pluggable database.
Setup the test:
1.) Create a user – tables cannot be restored in the SYS schema
2.) Create a table for that user
3.) Take a backup – a backup of the table has to exist; it can’t just be in archive logs.
4.) Drop the table
5.) Restore the table
6.) Check that the table has been restored

1. Create a User
This user is being created in one pluggable database.
Tables cannot be restored in the SYS schema.
Alter session set container=PDB2

create user example

identified by "example"

default tablespace users

temporary tablespace temp

profile default

account unlock

grant create session, create table to example

alter user example quota 50M on users

grant execute on dbms_flashback to example

2. Create a Table
SQL> conn example/example@pdb2

create table test_restore (col1 number)

Table created.

SQL> insert into test_restore values (1)

2 /
Oracle User
Management
Database User Accounts

Each database user account has:


• A unique username
• An authentication method
• A default tablespace
• A temporary tablespace
• A user profile
• An initial consumer group
• An account status
A schema:
• Is a collection of database objects that are owned
by a database user
• Has the same name as the user account
Users
There are 4 main accounts that are created during install sys, system, sysman and dbmsmp

SYS Owns all internal tables

SYSTEM Has additional tables and views


SYSMAN Use by OEM to monitor and gather performance stats, which are stored in the sysaux tablespace

DBSNMP Same as sys but for the OEM, owns all internal tables in the sysaux tablespace.

create
create user TEST1 identified by TEST1;

create user TEST2 identified by TEST2 default tablespace users temporary


tablespace temp quota 10m on users;

Drop:
drop user TEST1 ;
drop user TEST2 cascade;
Creating a Role

CREATE ROLES ROLE_EMP_DEP;


GRANT SELECT, INSERT, UPDATE, DELETE ON TEST1.EMP TO ROLE_EMP_DEP;
GRANT SELECT, INSERT, UPDATE, DELETE ON ORACLE.DEPT TO ROLE_EMP_DEP;

Assigning Roles to Users


CREATE USER TEST1 IDENTIFIED BY TEST1;
GRANT CREATE SESSION TO TEST1;

SELECT * FROM ORACLE.EMP;


SELECT * FROM ORACLE.DEPT;

GRANT ROLE_EMP_DEP TO TEST1;

SELECT * FROM ORACLE.EMP;


SELECT * FROM ORACLE.DEPT;`
create user TEST1 identified by TEST1;
Creating
create user TEST1 identified by TEST1 default tablespace users temporary tablespace temp quota 100m on users;

drop user TEST1;


Remove drop user TEST1 cascade;
Note: the cascade option will remove all the users objects as well.
alter user TEST1 idenitfied by newpassword;
Alter
alter user TEST1 quota 200m on users;

alter user TEST1 identified by password;


alter user TEST1 identified externally;
alter user TEST1 identified globally as extname;

Password options Note:


identified by - the password will be kept in the data dicitonary
identified externally - authenication will be performed by the O/S
idenitified globally as extname - authenication will be performed by external app i.e radius
a user is only allowed to change is his/her password

Expire password alter user TEST1 password expire;


alter user TEST1 account lock;
Lock/unlock
alter user TEST1 account unlock;
grant create session to TEST1;
Connecting
Note: this allows the user to connect to the database
Revoke access revoke create session from TEST1;
alter user TEST1 quota 100m on users;
Quota alter user TEST1 quota unlimited on users;
grant unlimited tablespace to TEST1;
select username, sid, serial# from v$session;
Kill a users session
alter system kill session '<session_id>,<session-serial>';
User connection
type select username, program, server from v$session;
(decicated/shared)
Profiles and Users

Profiles are used to limit a users resource,

•connect_time - limits session to number of minutes


•cpu_per_call - limits cpu time by any single database call
•cpu_per_session - limit cpu by session
•idle_time - limit session to idle time, allows user to rollback or commit before logging off
•logical_reads_per_call - caps the amount of work by any single database call
•logical_reads_per_session - caps the amount of work by any session
•private_sga - limits memory when using shared servers
•sessions_per_user - limits the number of sessions a user can have
•composite_limit - calculated by cpu_per_session, logical_reads_per_session, connection_time and private_sga
Profiles and Users

Users are assigned only one profile at a time.


Profiles:
• Control resource consumption
• Manage account status and password expiration

CREATE PROFILE TEST2 LIMIT


ALTER PROFILE TEST2 LIMIT FAILED_LOGIN_ATTEMPTS 2;
PASSWORD_LIFE_TIME 45
PASSWORD_GRACE_TIME 12
CREATE USER TEST2 IDENTIFIED BY TEST2 PROFILE TEST2;
PASSWORD_REUSE_TIME 3
PASSWORD_REUSE_MAX 5
ALTER USER TEST1 PROFILE TEST2;
FAILED_LOGIN_ATTEMPTS 4
PASSWORD_LOCK_TIME 2
DROP PROFILE TEST2 CASCADE;
CPU_PER_CALL 5000
PRIVATE_SGA 250K
DBA_PROFILES
LOGICAL_READS_PER_CALL 2000;

Note: RESOURCE_LIMIT must be set to TRUE before profiles can impose


resource limitations.
Assigning Quotas to Users

Users who do not have the UNLIMITED TABLESPACE


system privilege must be given a quota before they can
create objects in a tablespace.
Quotas can be:
• A specific value in megabytes or kilobytes
• Unlimited

SELECT TABLESPACE_NAME,
BYTES / 1024 / 1024 "UTILIZIED_SPACE", ALTER USER TEST1 QUOTA 10M ON USERS;
MAX_BYTES / 1024 / 1024
"QUOTA_ALLOCATED" ALTER USER TEST2 QUOTA UNLIMITED ON USERS;
FROM dba_ts_quotas
WHERE username = 'TEST2';
DataPump
(expdp and impdp)
DEMO:
CONN / AS SYSDBA

CREATE OR REPLACE DIRECTORY test_dir AS '/u01/app/oracle/oradata/';


GRANT READ, WRITE ON DIRECTORY test_dir TO oracle;

expdp oracle/oracle@ORCL tables=EMP,DEPT directory=TEST_DIR dumpfile=EMP_DEPT.dmp logfile=expdpEMP_DEPT.log


impdp oracle/oracle@ORCL tables=EMP,DEPT directory=TEST_DIR dumpfile=EMP_DEPT.dmp logfile=impdpEMP_DEPT.log

expdp oracle/oracle@ORCL schemas=oracle directory=TEST_DIR dumpfile=oracle.dmp logfile=expdporacle.log


impdp oracle/oracle@ORCL schemas=oracle directory=TEST_DIR dumpfile=oracle.dmp logfile=impdporacle.log

expdp system/password@ORCL full=Y directory=TEST_DIR dumpfile=ORCL.dmp logfile=expdpORCL.log


impdp system/password@ORCL full=Y directory=TEST_DIR dumpfile=ORCL.dmp logfile=impdpORCL.log

expdp oracle/oracle@ORCL schemas=oracle include=TABLE:"IN ('EMP', 'DEPT')" directory=TEST_DIR dumpfile=oracle.dmp


logfile=expdporacle.log
expdp oracle/oracle@ORCL schemas=oracle exclude=TABLE:"= 'BONUS'" directory=TEST_DIR dumpfile=oracle.dmp logfile=expdporacle.log

Over DB Link:
=============
CONN / AS SYSDBA
GRANT CREATE DATABASE LINK TO test;

CONN test/test
CREATE DATABASE LINK remote_oracle CONNECT TO oracle IDENTIFIED BY oracle USING 'DEV';

expdp test/test@ORCL tables=oracle.EMP network_link=REMOTE_oracle directory=TEST_DIR dumpfile=EMP.dmp logfile=expdpEMP.log


impdp test/test@ORCL tables=oracle.EMP network_link=REMOTE_oracle directory=TEST_DIR logfile=impdporacle.log
remap_schema=oracle:TEST
Datapump
(Export and Import)
MOVING DATA:
GENERAL ARCHITECTURE

SQL*Loader
expdp impdp Other clients
(sqlldr)

Data Pump

DBMS_DATAPUMP
Data/Metadata Movement Engine

Oracle Oracle
Loader DataPump Direct Path API Metadata API

External Table API


ORACLE DATA PUMP:
OVERVIEW
• As a server-based facility for high-speed data and metadata
movement, Oracle Data Pump:
• Is callable via DBMS_DATAPUMP
• Provides the following tools:
• expdp
• impdp
• Web-based interface
• Provides four data movement methods:
• Data file copying
• Direct path
• External tables
• Network link support
• Detaches from and reattaches to long-running jobs
• Restarts Data Pump jobs
ORACLE DATA PUMP: BENEFITS

• Data Pump offers many benefits and some new features over
earlier data movement tools, such as:
• Fine-grained object and data selection
• Explicit specification of database version
• Parallel execution
• Estimation of export job space consumption
• Network mode in a distributed environment
• Remapping capabilities
• Data sampling and metadata compression
• Compression of data during a Data Pump export
• Security through encryption
• Ability to export XMLType data as CLOBs
• Legacy mode to support old import and export files
DATA PUMP EXPORT AND IMPORT
CLIENTS: OVERVIEW
expdp Database
client link

Source Target
Data Pump Server
job process
Database Database
Master Dump Dump Master
table file set file set table

“Network mode”

Server Data Pump


process job

impdp
client
DATA PUMP UTILITY: INTERFACES AND
MODES

• Data Pump Export and Import interfaces:


• Command line
• Parameter file
• Interactive command line
• Enterprise Manager
• Data Pump Export and Import modes:
• Full
• Schema
• Table
• Tablespace
• Transportable tablespace
DATA PUMP IMPORT: TRANSFORMATIONS

• You can remap:


• Data files by using REMAP_DATAFILE
• Tablespaces by using REMAP_TABLESPACE
• Schemas by using REMAP_SCHEMA
• Tables by using REMAP_TABLE
• Data by using REMAP_DATA

REMAP_TABLE = 'EMPLOYEES':'EMP'
DEMO:
CONN / AS SYSDBA

CREATE OR REPLACE DIRECTORY test_dir AS '/u01/app/oracle/oradata/';


GRANT READ, WRITE ON DIRECTORY test_dir TO TEST1;

expdp TEST1/TEST1@DEVDB tables=EMP directory=TEST_DIR dumpfile=EMP.dmp logfile=expdpEMP.log


impdp TEST2/ TEST2 tables=EMP directory=TEST_DIR dumpfile=EMP.dmp logfile=impdpEMP.log

expdp oracle/oracle@ORCL schemas=oracle directory=TEST_DIR dumpfile=oracle.dmp logfile=expdporacle.log


impdp oracle/oracle@ORCL schemas=oracle directory=TEST_DIR dumpfile=oracle.dmp logfile=impdporacle.log

expdp system/password@ORCL full=Y directory=TEST_DIR dumpfile=ORCL.dmp logfile=expdpORCL.log


impdp system/password@ORCL full=Y directory=TEST_DIR dumpfile=ORCL.dmp logfile=impdpORCL.log

expdp oracle/oracle@ORCL schemas=oracle include=TABLE:"IN ('EMP', 'DEPT')" directory=TEST_DIR dumpfile=oracle.dmp


logfile=expdporacle.log
expdp oracle/oracle@ORCL schemas=oracle exclude=TABLE:"= 'BONUS'" directory=TEST_DIR dumpfile=oracle.dmp logfile=expdporacle.log

Over DB Link:
=============
CONN / AS SYSDBA
GRANT CREATE DATABASE LINK TO test;

CONN test/test
CREATE DATABASE LINK remote_oracle CONNECT TO oracle IDENTIFIED BY oracle USING 'DEV';

expdp test/test@ORCL tables=oracle.EMP network_link=REMOTE_oracle directory=TEST_DIR dumpfile=EMP.dmp logfile=expdpEMP.log


impdp test/test@ORCL tables=oracle.EMP network_link=REMOTE_oracle directory=TEST_DIR logfile=impdporacle.log
remap_schema=oracle:TEST
Dataguard
Standby Database
Data Guard Notes
Without Data Guard
Production

Primary
Database LGWR

Online
Redo
Log

ARCn

LOG_ARCHIVE_DEST_1

Archived
Redo
Logs
With Data Guard
Production DR

Primary Redo MRP Standby


Database LGWR LNSn RFS Database
/ LSP

Online Standby
Redo Redo
Log Log

ARCn ARCn

LOG_ARCHIVE_DEST_1

Archived Archived
Redo Redo
Logs Logs
Standby Database
Types
 Physical Standby Databases

 Logical Standby Databases

 Snapshot Standby Databases


DATA GUARD
PHYSICAL STANDBY

• Standby is identical copy of primary


database
• Redo changes
– transported from primary to standby
– applied on standby (Redo Apply)
• Can switch operations to standby
– Planned (switchover / switchback)
– Unplanned (failover)
DATA GUARD
LOGICAL STANDBY
• Redo copied from primary to standby
• Changes converted into logical change records (LCR)
• Logical change records applied on standby (SQL
Apply)
• Standby database can be opened for updates
– Can modify propagated objects
– Can create new indexes for propagated objects
• May need larger system for logical standby
– LCR apply can be less efficient than redo apply
– Array updates on primary become single row updates on
standby
DATA GUARD
REDO LOG SHIPPING
• ARCH background process
– Copies completed redo log files to standby
• LGWR background process - modes are:
– ASYNC - asynchronous
– redo written by LGWR to local disk
– read from disk by LNSn background process
– SYNC - synchronous
• Redo written to standby by LGWR - modes are:
– AFFIRM - wait for confirmation redo written to disk
– NOAFFIRM - do not wait
DATA GUARD
ARCH REDO TRANSMISSION

Production DR

MRP Standby
Primary LGWR RFS Database
/ LSP
Database

2_
ST
DE
_
VE
Online Standby

I
CH
Redo Redo

AR
Log

G_
Log

LO
ARC0 ARC1 ARCn

LOG_ARCHIVE_DEST_1

Archived Archived
Redo Redo
Logs Logs
DATA GUARD
LGWR REDO (ASYNC) TRANSMISSION

Production DR

Primary MRP Standby


Database LGWR RFS Database
/ LSP

Real
Time
Online Standby Apply
Redo LNSn Redo
Log Log

ARCn ARCn

LOG_ARCHIVE_DEST_1

Archived Archived
Redo Redo
Logs Logs
DATA GUARD
LGWR REDO (SYNC) TRANSMISSION

Production DR

Primary MRP Standby


Database LGWR LNSn RFS Database
LSP

Real
Time
Online Standby Apply
Redo Redo
Log Log

ARCn ARCn

LOG_ARCHIVE_DEST_1

Archived Archived
Redo Redo
Logs Logs
DATA GUARD
SWITCHOVER

Before Switchover After Switchover

CHICAGO BOSTON CHICAGO BOSTON

Primary Physical Physical Primary


Standby Standby
Instance Redo Instance Instance Redo Instance

Database Database Database Database

Primary Standby Standby Primary


Database Database Database Database
DATA GUARD
FAILOVER

Before Failover After Failover

Chicago Boston Chicago Boston


Primary Physical Primary Physical
Primary
Standby Standby
Instance Redo Instance Instance Redo Instance

Database Database Database Database

Primary Standby Unavailable Standby


Primary
Database Database Database
Databas
Performance Tuning
PERFORMANCE MONITORING

Memory
allocation
issues

Input/ Resource
output contention
device
contention
?
DBA
Application Network
code bottlenecks
problems
MANAGING MEMORY
COMPONENTS
• Automatic Memory Management (AMM)
• Enables you to specify total memory allocated to instance (including
both SGA and PGA)
• Automatic Shared Memory Management (ASMM):
• Enables you to specify total SGA memory through one initialization
parameter
• Enables the Oracle server to manage the amount of memory
allocated to the shared pool, Java pool, buffer cache, streams pool,
and large pool
• Manually setting shared memory management:
• Sizes the components through multiple individual initialization
parameters
• Uses the appropriate Memory Advisor to make recommendations
DYNAMIC PERFORMANCE STATISTICS

Systemwide Session specific Service specific

V$SYSSTAT V$SESSTAT V$SERVICE_STATS


• statistic# • sid • service_name_hash
• statistic# • service_name
• name • stat_id
• class • value
• stat_name
• value • value
• stat_id

V$SYSTEM_EVENT V$SESSION_EVENT V$SERVICE_EVENT


• event • sid • service_name
• total_waits • event • service_name_hash
• total_timeouts • total_waits • event
• time_waited • total_timeouts • event_id
• average_wait • time_waited • total_waits
• time_waited_micro • average_wait • total_timeouts
• max_wait • time_waited
• time_waited_micro • average_wait
Cumulative stats
• event_id • time_waited_micro
Wait events
TROUBLESHOOTING AND TUNING
VIEWS

Instance/Database Disk
V$DATABASE V$DATAFILE
V$INSTANCE V$FILESTAT
V$PARAMETER V$LOG
V$SPPARAMETER V$LOG_HISTORY
V$SYSTEM_PARAMETER V$DBFILE
V$PROCESS V$TEMPFILE
V$BGPROCESS V$TEMPSEG_USAGE
V$PX_PROCESS_SYSSTAT V$SEGMENT_STATISTICS

V$SYSTEM_EVENT Contention
Memory V$LOCK
V$BUFFER_POOL_STATISTICS V$UNDOSTAT
V$LIBRARYCACHE V$WAITSTAT
V$SGAINFO V$LATCH
V$PGASTAT
INVALID AND UNUSABLE OBJECTS

• Effect on performance:
• PL/SQL code objects are recompiled.
• Indexes are rebuilt.
RECOMMENDATIONS

Patching
>>> opatch lsinventory

Dictionary stats and fixed objects stats.


exec DBMS_STATS.GATHER_DICTIONARY_STATS;
exec DBMS_STATS.GATHER_FIXED_OBJECTS_STATS;

Table move and Table shrink


alter table XXLG.XLG_FAH_BULK_UPLOAD_TRANS move parallel nologging;
alter table XXLG.XLG_FAH_BULK_UPLOAD_TRANS noparallel logging;
alter table XXLG.XLG_FAH_BULK_UPLOAD_TRANS ENABLE ROW MOVEMENT;
alter table XXLG.XLG_FAH_BULK_UPLOAD_TRANS SHRINK SPACE cascade;
alter table XXLG.XLG_FAH_BULK_UPLOAD_TRANS DISABLE ROW MOVEMENT;
Rebuild index.
alter index PROD_DW.WC_GL_GROUP_AACCOUNT_DH_N1 coalesce;
alter index PROD_DW.WC_GL_GROUP_AACCOUNT_DH_N1 rebuild parallel nologging;
alter index PROD_DW.WC_GL_GROUP_AACCOUNT_DH_N1 noparallel logging;

alter index PROD_DW.WC_GL_GROUP_AACCOUNT_DH_N1 rebuild online;

Collect stats on the table with 100%.


execute dbms_stats.gather_table_stats(ownname =>'PROD_DW',tabname
=>'WC_GL_BALANCE_F_S1',estimate_percent =>100, method_opt =>'FOR ALL COLUMNS
SIZE AUTO',CASCADE=>TRUE);
EXECUTION PLAN

Uses the EXPLAIN PLAN command and the DBMS_XPLAN.DISPLAY function.

EXPLAIN PLAN FOR select * from dba_users;

select plan_table_output from table(dbms_xplan.display('plan_table',null,'basic'));

Generating and displaying the execution plan for the last SQL statement executed in a session:

select * from dba_users;

select plan_table_output from table(dbms_xplan.display_cursor(null,null,'basic'));


OS ANALYSIS
top analysis
vmstat analysis top
memory analysis
iostat analysis The ‘top’ command shows not only the current tasks being serviced by
sar analysis the kernel but also some broad statistical data about the state of a
host.
it automatically updates this data every five seconds

$top
vmstat

The ‘vmstat’ command gives a snapshot of current


CPU, IO, processes and memory usage. Similar to the
top command, it dynamically updates and can be
free executed with this command:

The ‘free’ command shows memory $ vmstat 10


statistics for both main memory and
swap.

$free -g
iostat

The ‘iostat’ command (provided via the sysstat package on Ubuntu


and Red Hat/Fedora) offers three reports. These are CPU utilization,
device utilization, and network file system utilization. In case of
running the command without options,it will display all three
reports. The individual reports can be specified with the -c, -d and -
h switches respectively.

$iostat

sar

Use the ‘sar’ command line tool to collect, view and record
performance data. This command is considerably more
sophisticated than all the commands discussed above. It can
collect and display data over longer periods.
AWR
1.Issue with Database Machine. OS
analysis.
AWR Report --- top, free, vmstat, iostat, sar and os watcher (Covered
in Last Session)

2.If Database performance issue,


--- Then AWR Report is the place to look at.
The AWR collects and stores database statistics relating to problem detection and tuning.
AWR is a replacement for the statspack utility which helps gather database performance
statistics. AWR generates snapshots of key performance data, such as system and
session statistics, segment-usage statistics, time-model statistics, high-load statistics and
stores it in the Sysaux tablespace.

AWR provides statistics in two formats


temporary - in memory collection of statistics in the SGA, accessible via the V$views
persistent - type of performance data in the form of regular AWR snapshots which you
access via the DBA_ views

The MMON process is responsible for collecting the statistics in the SGA and saving them
to the Sysaux tablespaces.
Recommendations before getting an AWR Report. AWR_Report_Setting.txt

1 1. Collect Multiple AWR Reports


2 --- Check AWR current snapshot setting
2. Stick to Particular Time SQL> select
3. Split Large AWR Report into extract( day from snap_interval) *24*60+
Smaller Reports (30 mins) extract( hour from snap_interval) *60+
extract( minute from snap_interval )
snapshot_interval,
extract( day from retention) *24*60+
extract( hour from retention) *60+
extract( minute from retention )
How to Run?
3 retention_interval,
topnsql
@?/rdbms/admin/awrrpt.sql; from dba_hist_wr_control;

@?/rdbms/admin/awrrpti.sql --- Change snapshot interval to 30 mins


SQL> EXEC
@?/rdbms/admin/awrgrpt.sql dbms_workload_repository.modify_snapshot_sett
; ings(interval=>30);
@?/rdbms/admin/
awrgrpti.sql;
FAQ: How to Use AWR reports to Diagnose Database
Performance Issues (Doc ID 1359094.1)

FAQ: Automatic Workload Repository (AWR) Reports (Doc


ID 1599440.1)

How To Understand AWR Report / Statspack Report [ID


842884.1]
Performance Management
PERFORMANCE MONITORING

Memory
allocation
issues

Input/ Resource
output contention
device
contention
?
DBA
Application Network
code bottlenecks
problems
MANAGING MEMORY
COMPONENTS
• Automatic Memory Management (AMM)
• Enables you to specify total memory allocated to instance (including
both SGA and PGA)
• Automatic Shared Memory Management (ASMM):
• Enables you to specify total SGA memory through one initialization
parameter
• Enables the Oracle server to manage the amount of memory
allocated to the shared pool, Java pool, buffer cache, streams pool,
and large pool
• Manually setting shared memory management:
• Sizes the components through multiple individual initialization
parameters
• Uses the appropriate Memory Advisor to make recommendations
DYNAMIC PERFORMANCE STATISTICS

Systemwide Session specific Service specific

V$SYSSTAT V$SESSTAT V$SERVICE_STATS


• statistic# • sid • service_name_hash
• statistic# • service_name
• name • stat_id
• class • value
• stat_name
• value • value
• stat_id

V$SYSTEM_EVENT V$SESSION_EVENT V$SERVICE_EVENT


• event • sid • service_name
• total_waits • event • service_name_hash
• total_timeouts • total_waits • event
• time_waited • total_timeouts • event_id
• average_wait • time_waited • total_waits
• time_waited_micro • average_wait • total_timeouts
• max_wait • time_waited
• time_waited_micro • average_wait
Cumulative stats
• event_id • time_waited_micro
Wait events
TROUBLESHOOTING AND TUNING
VIEWS

Instance/Database Disk
V$DATABASE V$DATAFILE
V$INSTANCE V$FILESTAT
V$PARAMETER V$LOG
V$SPPARAMETER V$LOG_HISTORY
V$SYSTEM_PARAMETER V$DBFILE
V$PROCESS V$TEMPFILE
V$BGPROCESS V$TEMPSEG_USAGE
V$PX_PROCESS_SYSSTAT V$SEGMENT_STATISTICS

V$SYSTEM_EVENT Contention
Memory V$LOCK
V$BUFFER_POOL_STATISTICS V$UNDOSTAT
V$LIBRARYCACHE V$WAITSTAT
V$SGAINFO V$LATCH
V$PGASTAT
INVALID AND UNUSABLE OBJECTS

• Effect on performance:
• PL/SQL code objects are recompiled.
• Indexes are rebuilt.
XVII
I

Moving Data
Moving Data:
General Architecture

SQL*Loader
expdp impdp Other clients
(sqlldr)

Data Pump

DBMS_DATAPUMP
Data/Metadata Movement Engine

Oracle Oracle
Loader DataPump Direct Path API Metadata API

External Table API


Oracle Data Pump: Overview

As a server-based facility for high-speed data and


metadata movement, Oracle Data Pump:
• Is callable via DBMS_DATAPUMP
• Provides the following tools:
– expdp
– impdp
– Web-based interface
• Provides four data movement methods:
– Data file copying
– Direct path
– External tables
– Network link support
• Detaches from and reattaches to long-running jobs
• Restarts Data Pump jobs
Oracle Data Pump: Benefits

Data Pump offers many benefits and some new features


over earlier data movement tools, such as:
• Fine-grained object and data selection
• Explicit specification of database version
• Parallel execution
• Estimation of export job space consumption
• Network mode in a distributed environment
• Remapping capabilities
• Data sampling and metadata compression
• Compression of data during a Data Pump export
• Security through encryption
• Ability to export XMLType data as CLOBs
• Legacy mode to support old import and export files
Data Pump Export and Import Clients:
Overview
expdp Database
client link

Source Target
Data Pump Server
job process
Database Database
Master Dump Dump Master
table file set file set table

“Network mode”

Server Data Pump


process job

impdp
client
Data Pump Utility: Interfaces and Modes

• Data Pump Export and Import interfaces:


– Command line
– Parameter file
– Interactive command line
– Enterprise Manager
• Data Pump Export and Import modes:
– Full
– Schema
– Table
– Tablespace
– Transportable tablespace
Data Pump Import Example: impdp

Data Pump can be invoked on the command line to


allow further command line options to be specified.
$ impdp hr DIRECTORY=DATA_PUMP_DIR \
DUMPFILE=HR_SCHEMA.DMP \
PARALLEL=1 \
CONTENT=ALL \
TABLES="EMPLOYEES" \
LOGFILE=DATA_PUMP_DIR:import_hr_employees.log \
JOB_NAME=importHR \
TRANSFORM=STORAGE:n
Data Pump Import: Transformations

You can remap:


• Data files by using REMAP_DATAFILE
• Tablespaces by using REMAP_TABLESPACE
• Schemas by using REMAP_SCHEMA
• Tables by using REMAP_TABLE
• Data by using REMAP_DATA

REMAP_TABLE = 'EMPLOYEES':'EMP'
Migration with Data Pump Legacy Mode

• Assistance in transitioning from imp and exp


utilities to impdp and expdp utilities
• Data Pump in legacy mode:
1. Encounters unique imp or exp parameter and enters
legacy mode
2. Attempts to map the old syntax to the new syntax
3. Displays new syntax
4. Exits legacy mode
Best practice tip: Oracle strongly recommends that you
view the new syntax and make script changes as time
permits.
Data Pump Legacy Mode

The Data Pump export and import utilities:


• Read and write files only in Data Pump format
• Accept exp and imp utility commands in legacy
mode
• Include legacy mode parameters that:
– Can be identical to the new syntax:
FILESIZE=integer[B | K | M | G]
– Can be similar:
QUERY= query_clause
– Are ignored, when the command is superceded by
Data Pump defaults
BUFFER=integer
COMPRESS={y|n}
DIRECT={y|n}
– Cause an error when old and new syntax is mixed
Data Pump Legacy Mode

• Legacy mode parameters:


– Are mapped to Data Pump parameters, if possible:
consistent={y|n} -> FLASHBACK_TIME
GRANTS=n -> EXCLUDE=CONSTRAINTS
INDEXES=n -> EXCLUDE=INDEX
LOG=filename -> LOGFILE=filename
FILE=filename -> dumpfile=directory-object:filename
– Can be similar, but not identical:
FEEDBACK=integer -> STATUS
– Cause an error when incompatible with new Data
Pump:
VOLSIZE=integer
Managing File Locations

• Original exp and imp utilities: Fully qualified file


names
• Data Pump directory object for file locations
– Default (in prior versions): DATA_PUMP_DIR parameter
– New optional DATA_PUMP_DIR_schema-name directory
object
– Managed with the CREATE DIRECTORY and GRANT SQL
commands
– Default location (independent of legacy mode),
when:

Command line without DIRECTORY parameter

User without EXP_FULL_DATABASE privilege
Managing Data Concurrency
Locks

• Prevent multiple sessions from changing the same


data at the same time
• Are automatically obtained at the lowest possible
level for a given statement
• Do not escalate

Transaction 1 Transaction 2
SQL> UPDATE employees SQL> UPDATE employees
2 SET salary=salary+100 2 SET salary=salary*1.1
3 WHERE employee_id=100; 3 WHERE employee_id=100;
Locking Mechanism

• High level of data concurrency:


– Row-level locks for inserts, updates, and deletes
– No locks required for queries
• Automatic queue management
• Locks held until the transaction ends (with the
COMMIT or ROLLBACK operation)
Example
Assume that the rows for employee_id 100 and 101 reside in the same
block:

Transaction 1 Transaction 2
SQL> UPDATE employees SQL> UPDATE employees
2 SET salary=salary+100 2 SET salary=salary*1.1
3 WHERE employee_id=100; 3 WHERE employee_id=101;
Data Concurrency
DML Locks

Transaction 1 Transaction 2
SQL> UPDATE employees SQL> UPDATE employees
2 SET salary=salary*1.1 2 SET salary=salary*1.1
3 WHERE employee_id= 107; 3 WHERE employee_id= 106;
1 row updated. 1 row updated.

Each DML transaction must acquire two locks:


• EXCLUSIVE row lock on the row or rows being
updated
• Table lock (TM) in ROW EXCLUSIVE (RX) mode on
the table containing the rows
Lock Conflicts

Transaction 1 Time Transaction 2


Possible Causes of Lock Conflicts
• Uncommitted changes
• Long-running transactions
• Unnecessarily high locking levels

Resolving Lock Conflicts

To resolve a lock conflict:


• Have the session holding the lock commit or roll
back
• Terminate the session holding the lock (in an
emergency)
Resolving Lock Conflicts with SQL

SQL statements can be used to determine the blocking


session and kill it.

SQL> select SID, SERIAL#, USERNAME


1 from V$SESSION where SID in
(select BLOCKING_SESSION from V$SESSION)

Result:

2 SQL> alter system kill session '144,8982' immediate;


Deadlocks

Transaction 1 Transaction 2

UPDATE employees UPDATE employees


SET salary = salary x 1.1 9:00 SET manager = 1342
WHERE employee_id = 1000; WHERE employee_id = 2000;
UPDATE employees UPDATE employees
SET salary = salary x 1.1 9:15 SET manager = 1342
WHERE employee_id = 2000; WHERE employee_id = 1000;
ORA-00060:
Deadlock detected while 9:16
waiting for resource
When the deadlock occurs, Oracle database
automatically:

• Waits 300 seconds before terminating both


sessions
Quiz • Terminates one statement with an error in one
session
• Terminates the statements with an error in both
sessions
• Takes no action by default and leaves it to DBA
Managing Undo Data
Undo Data

Undo data is:


• A copy of original, premodified data
• Captured for every transaction that changes data
• Retained at least until the transaction is ended
• Used to support:
– Rollback operations
– Read-consistent queries
– Oracle Flashback Query, Oracle Flashback
Transaction, and Oracle Flashback Table
– Recovery from failed transactions

User
Transactions and Undo Data

Undo
segment
Data in Undo “old” data
buffer cache in undo tablespace

UPDATE
Redo log New change details
DML operations Redo log
buffer in Redo log files
files

• Each transaction is assigned to only one undo


segment.
• An undo segment can service more than one
transaction at a time.
Storing Undo Information

Undo information is stored in undo segments, which are


stored in an undo tablespace. Undo tablespaces:
• Are used only for undo segments
• Have special recovery considerations
• May be associated with only a single instance
• Require that only one of them be the current
writable undo tablespace for a given instance at
any given time
Undo Data Versus Redo Data

Undo
segment
Redo log
files
Managing Undo

Automatic undo management:


• Fully automated management of undo data and
space in a dedicated undo tablespace
• For all sessions
• Self-tuning in AUTOEXTEND tablespaces to satisfy
long-running queries
• Self-tuning in fixed-size tablespaces for best
retention
DBA tasks in support of Flashback operations:
• Configuring undo retention
• Changing undo tablespace to a fixed size
• Avoiding space and “snapshot too old” errors
Configuring Undo Retention

UNDO_RETENTION specifies (in seconds) how long


already committed undo information is to be retained.
The only time you must set this parameter is when:
• The undo tablespace has the AUTOEXTEND option
enabled
• You want to set undo retention for LOBs
• You want to guarantee retention

DBA
Guaranteeing Undo Retention

SQL> ALTER TABLESPACE undotbs1 RETENTION GUARANTEE;

Retention guarantee:
15 minutes

Undo data in
undo
tablespace

SELECT statements A transaction will fail


running 15 minutes or less if it generates more undo
are always satisfied. than there is space.
Note: This example is based on an UNDO_RETENTION setting of 900 seconds
(15 minutes).
Changing an Undo Tablespace
to a Fixed Size
Reasons:
• Supporting Flashback operations
• Limiting tablespace growth
Workflow:
1. Run regular workload.
2. Self-tuning mechanism establishes
minimum required size.
3. (Optional) Use Undo Advisor, which calculates
required size for future growth.
4. (Optional) Change undo tablespace to a fixed size.
All you need to do to guarantee that all queries under
15 minutes will find the undo data needed for read
consistency, is set the UNDO_RETENTION parameter to
15 minutes
Quiz
• True
• False
Implementing Oracle Database
Auditing
Separation of Responsibilities

• Users with DBA privileges must be trusted.


– Abuse of trust
– Audit trails protecting the trusted position
• DBA responsibilities must be shared.
• Accounts must never be shared.
• The DBA and the system administrator must be
different people.
• Separate operator and DBA responsibilities.
Database Security

A secure system ensures the confidentiality of the data


that it contains. There are several aspects of security:
• Restricting access to data and services
• Authenticating users
• Monitoring for suspicious activity
Standard Database Auditing

1 Enable
database Parameter
DBA auditing. User
file executes
2 Specify audit options. command.

Database
Server
process
Audit
Generate
options
audit trail.
3 Review audit
information.
Audit
trail OS or XML
4 Maintain audit audit
trail. trail
Uniform Audit Trails

STATEMENTID,
AUDIT_TRAIL=DB, EXTENDED
ENTRYID

DBA_AUDIT_TRAIL DBA_FGA_AUDIT_TRAIL

EXTENDED_TIMESTAMP,
PROXY_SESSIONID, GLOBAL_UID,
INSTANCE_NUMBER, OS_PROCESS, TRANSACTIONID,
SCN, SQL_BIND, SQL_TEXT

DBA_COMMON_AUDIT_TRAIL
Default Auditing
Value-Based Auditing

A user makes a The trigger fires. Audit record is


change. created by the trigger.

User’s change Audit record is


is made. inserted into an audit
trail table.
Fine-Grained Auditing

• Monitors data access on the basis of content


• Audits SELECT, INSERT, UPDATE, DELETE, and MERGE
• Can be linked to one or more columns in a table or
view
• May execute a procedure
• Is administered with the DBMS_FGA package

Policy: AUDIT_EMPS_SALARY
SELECT name, salary
FROM employees
WHERE
employees
department_id = 10;
Audited DML Statement: Considerations

• Records are audited if the FGA predicate is satisfied


and the relevant columns are referenced.
• DELETE statements are audited regardless of
columns specified.
• MERGE statements are audited with the Not audited because none
underlying INSERT, UPDATE, and DELETEof the records involved are
for department 10.
generated statements.
UPDATE hr.employees
SET salary = 1000
WHERE commission_pct = .2;

UPDATE hr.employees
SET salary = 1000
WHERE employee_id = 200;
Oracle Audit Vault

• Consolidate and secure


audit data
– Oracle 9i Release 2 and
higher
– SQL Server 2000, 2005
– IBM DB2 UDB 8.5 & 9.2
– Sybase ASE 12.5 - 15.0
– Secure and scalable
– Cleanup of source Oracle
audit data
• Centralized reporting
– Updated reports interface Sybase
using widely popular Oracle ASE
Application Express
– Standard reports for
compliance
IBM
– New custom reports Oracle DB2
• Alert on security threats Database Microsoft
– SQL Server
Detect and alert on
security
relevant events
Database Maintenance
Database Maintenance

Automatic Automated Proactive Reactive


tasks

Advisory Server Critical


framework alerts errors

Automatic Automatic
Workload Diagnostic
Repository Efficient Repository

Data warehouse Automatic collection Direct memory


of the database of important statistics access
Terminology

• Automatic Workload Repository (AWR):


Infrastructure for data gathering, analysis, and
solutions recommendations
• AWR Baseline: A set of AWR snapshots for
performance comparison
• Metric: Rate of change in a cumulative statistic
• Statistics: Data collections providing database and
object detail
– Optimizer statistics: Used by query optimizer
– Database statistics: Used for performance
• Threshold: A boundary value against
which metric values are compared
Oracle Optimizer: Overview

The Oracle optimizer determines the most efficient


execution plan and is the most important step in the
processing of any SQL statement.
The optimizer:
• Evaluates expressions and conditions
• Uses object and system statistics
• Decides how to access the data
• Decides how to join tables
• Determines the most efficient path
Optimizer Statistics

Optimizer statistics are:


• A snapshot at a point in time
• Persistent across instance restarts
• Collected automatically

SQL> SELECT COUNT(*) FROM hr.employees;


COUNT(*)
----------
214
SQL> SELECT num_rows FROM dba_tables
2 WHERE owner='HR' AND table_name = 'EMPLOYEES';
NUM_ROWS
----------
107
Preferences for Gathering Statistics

SCOPE
STATEMENT LEVEL
PREFERENCES
TABLE LEVEL
CASCADE
SCHEMA LEVEL DEGREE
Optimizer
statistics ESTIMATE_PERCENT
DATABASE LEVEL
gathering
NO_INVALIDATE
task GLOBAL LEVEL
METHOD_OPT
GRANULARITY
INCREMENTAL
DBA PUBLISH
DBMS_STATS
STALE_PERCENT
set | get | delete | export | import

exec dbms_stats.set_table_prefs('SH','SALES','STALE_PERCENT','13');
AUTOMATIC WORKLOAD REPOSITORY
(AWR)
• Built-in repository of performance
information
• Snapshots of database metrics taken every 60 minutes and retained
for eight days
• Foundation for all self-management functions

In-memory 60 minutes
statistics MMON Snapshots
SGA
AWR
AWR INFRASTRUCTURE

External clients
EM SQL*Plus …

SGA
Efficient V$ DBA_*
in-memory AWR
statistics snapshots
collection MMON

Self-tuning … Self-tuning
ADDM
Internal clients component component
AWR BASELINES

Relevant period
in the past

DBMS_WORKLOAD_REPOSITORY.CREATE_BASELINE ( -
start_snap_id IN NUMBER,
end_snap_id IN NUMBER,
baseline_name IN VARCHAR2);
MANAGING THE AWR

• Retention period
• Default: Eight days
• Consider storage needs
• Collection interval
• Default: 60 minutes
• Consider storage needs
and performance impact
• Collection level
• Basic (disables most ADDM functionality)
• Typical (recommended)
• All (adds additional SQL tuning information to snapshots)
STATISTIC LEVELS

STATISTICS_LEVEL

BASIC TYPICAL ALL

Additional statistics
Self-tuning Recommended
for manual
capabilities disabled default value
SQL diagnostics
AUTOMATIC DATABASE
DIAGNOSTIC MONITOR (ADDM)
• Runs after each AWR snapshot
• Monitors the instance; detects bottlenecks
• Stores results in the AWR

Snapshots

EM ADDM
ADDM results
AWR
AUTOMATED MAINTENANCE TASKS

• Autotask maintenance process:


1. Maintenance Window opens.
2. Autotask background process schedules jobs.
3. Scheduler initiates jobs.
4. Resource Manager limits impact of Autotask jobs.
• Default Autotask maintenance jobs:
• Gathering optimizer statistics
• Automatic Segment Advisor
• Automatic SQL Advisor
XIX

Working with
Support
Using the Support Workbench

View critical
1 error alerts in
Enterprise Manager.

7 Close incidents. 2 View problem


details.

Track the service Gather additional


6 request and 3 diagnostic
implement repairs. information.

Package and upload


4
Create a
diagnostic data service request.
to Oracle Support.
5
Creating a Service Request
Working with Oracle Support

• Oracle Support Services (OSS) provides 24  7


solution support.
• Support is delivered in the following ways:
– My Oracle Support Web site
– Telephone
– Oracle Direct Connect (ODC) remote diagnostic tool
• The Customer Support Identifier (CSI) number is
used to track the software and support that are
licensed to each customer.
My Oracle Support Integration

• Enterprise Manager automatically alerts users to


new critical patches.
• The Enterprise Manager patch wizard can be used
to select an interim patch.
• You can review the patch’s README file from within
Enterprise Manager.
• You can download the selected patches from My
Oracle Support into the Enterprise Manager patch
cache.
Using My Oracle Support
Researching an Issue

To research an issue on My Oracle Support, perform the


following steps:
1. Perform a keyword search.
2. Review the documentation.
3. Use the self-service toolkits.
4. Use the automated diagnostic tests and business
flows.
5. Search for applicable patches.
6. Log a service request (SR).
Logging Service Requests

• Log an SR by clicking the Service Request tab on


the My Oracle Support home page.
• My Oracle Support performs searches based on the
CSI number and SR profile.
• Provide the following information when logging an
SR:
– Explanation of the issue, including error messages
– Steps taken to troubleshoot the issue
– Software version
– Steps required to reproduce the problem
– Business impact of the issue
Managing Patches

Kinds of patches
• Interim patches
– For specific issues
– No regression testing
• CPUs (Critical Patch Updates)
– Critical security issues
– Regression testing
– Does not advance version number
• Patch releases
Applying a Patch Release

• Patch releases are fully tested product fixes that:


– Do not include new functionality
– Affect only the software residing in your Oracle home
on installation
– Contain individual bug fixes
– Carry version numbers
• To apply a patch:
1. Determine your Oracle software environment.
2. Set your My Oracle Support login credentials.
3. Stage the patch release.
Online Patching: Overview

For a bug fix or diagnostic patch on a running Oracle


instance, online patching provides the ability to do the
following:
• Install
• Enable
• Disable
Installing an Online Patch

• Applying an online patch does not require instance


shutdown, relinking of the Oracle binary, or
instance restart.
• OPatch can be used to install or uninstall an online
patch.
• OPatch detects conflicts between two online
patches, as well as between an online patch and a
conventional patch.
• To determine if a patch is an online patch:
opatch query -is_online_patch <patch location>
OR
opatch query <patch location> -all
Benefits of Online Patching

• No down time and no interruption of business


• Extremely fast installation and uninstallation times
• Integrated with OPatch:
– Conflict detection
– Listed in patch inventory
– Works in RAC environment
• Persist across instance shutdown and startup
Conventional Patching and Online
Patching

Conventional Patches Online Patches


Require down time to apply Do not require down time to apply or
or remove remove
Installed and uninstalled Installed and uninstalled
via OPatch via OPatch
Persist across instance startup and Persist across instance startup
shutdown and shutdown
Take several minutes to install or Take only a few seconds to install or
uninstall uninstall

You might also like