Database Course
Database Course
WORKSHOP
Mallik
You can search mallik034 on YouTube and Google
Follow Me
Oracle Database Course Contents:
https://mallik034.blogspot.com/p/database-training.html
Oracle Software
We can download from Oracle e-delivery
Oracle Patches
We can download from Oracle e-delivery
Winscp
Copying files from windows to linux vice versa
Putty
Tool Connecting to linux server using ssh via port 22
MobaXterm
Tool Connecting to linux server using ssh via port 22
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.
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
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
Install GI using
OUI Silent OUI or Silent ASM GI OUI or Silent
• True
• False
• 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
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
• 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?
GI Installation
Creating RECO Disk Group in 12c
12C OH INSTALLATION
12C OH Installation
Creating an Oracle Database
(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
9
USING THE DBCA TO CREATE A
DATABASE
10
B
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
y
mor
1
Me
3
2
ess
o c
Pr
I1
I1 I2 I3
I2
D1
D2
• True
Quiz • False
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
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
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
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
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
Segment
Storage System
• SAN • NFS
Extent
• NAS • ASM
• Exadata • RAW
Oracle data • File System
block
SEGMENTS, EXTENTS, AND BLOCKS
Quiz • Tablespace
• Datafiles
• Segments
What is the smallest unit of Oracle
database/what are building blocks of my
datafiles?
Extent Extent
64KB 96KB
Segment
160KB
SYSTEM AND SYSAUX TABLESPACES
• User datafile
Columns Blocks
Table A Table B
Rows
Segment Segment
Table
Tablespace
Block header
Growth
Free space
Row data
Tablespaces in the Preconfigured
Database
• SYSTEM • UNDO
• SYSAUX • USERS
• TEMP • EXAMPLE (optional)
6_Lab.txt
Oracle-Managed Files (OMF)
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
• Spfile
Quiz • Pfile
• Controlfile
• Datafile
SHUTDOWN MODES
Shutdown Modes A I T N
Shutdown modes:
• A = ABORT
• I = IMMEDIATE
• T = TRANSACTIONAL
• N = NORMAL
SHUTDOWN OPTIONS
Consistent database
SHUTDOWN OPTIONS
USER_TABLES
ALL_TABLES
DBA_TABLES
USER_INDEXES
ALL_INDEXES
DBA_INDEXES
USER_VIEWS
ALL_VIEWS
DBA_VIEWS S
Data Dictionary: Usage Examples
4 DESCRIBE dba_indexes
Understanding password files
Password File:
$ORACLE_HOME/dbs
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
• 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
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
DB1 DB2
DB1 DB2
File System …
Logical Volume Manager ASM
SGA
Shared RedoBuffer
BufferCache
Pool
ORACLE processes
CONTROL
DATAFILES REDOLOGS
FILES
ASM INSTANCE
ORACLE processes
Metadata
ASM Benefits/Advantages?
Quiz • Mirroring
• Stripping
• Ease of management
PROCESS STARTUP SEQUENCE
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.
ASM Instance ASM Instance ASM Instance ASM Instance ASM Instance
Oracle RAC
Servers
Database Database Database
2 4 1
3 5
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
Disk Group
Stripe and Mirror Example
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
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
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';
Disk formatting
• 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
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
https://docs.oracle.com/database/121/COMSC/
installation.htm#COMSC001
Calling SQL*Plus from a Shell Script
$ ./batch_sqlplus.sh
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
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
spfileorcl.ora
or
initorcl.ora
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
…
• 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.
SYSDATE
----------- 3_Lab.txt
jun 18 2009
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
PDB$
PDB1 PDB2 PDB3
SEED
CDB
MULTITENANT ARCHITECTURE
PDBs
CDB
Root
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
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
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
tnsping DEVDB
tnsping PDB1
sqlplus mallik/mallik@PDB1
How to
Application RDBMS create?
netmgr
Oracle Net TCP/IP Oracle Net netca
network OEM
Client or
Listener Database server
middle tier
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 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
tnsping orcl
• Supports local and directory naming:
Naming Methods
Client/application server
Oracle Net
• 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
Oracle Net
configuration files
Directory Naming
LDAP directory
Oracle Net
configuration files
External Naming Method
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
• listener.ora
• listener.conf
Quiz • tnsnames.ora
• tnsnames.conf
• sqlnet.ora
• sqlnet.conf
Administering User Security
7_Lab.txt
Database User 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
HR_DBA
GRANT
Privilege
Object
REVOKE CREATE
TABLE FROM joe;
Revoking Object Privileges
with GRANT OPTION
Bo Jo Emily
b e
GRANT
Users
Jenny David Rachel
Insert Select
employees. employees.
Creating a Role
Password
Password complexity
ALTER PROFILE TEST2 LIMIT
history verification FAILED_LOGIN_ATTEMPTS 3;
User Setting up
profiles
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
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
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. 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
DBWn
Database Writer
process
Control
files
CKPT
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.
Transactions
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
• 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
Target
Data files database Image copies
Backup pieces
Archive
log files
Redundant Backup data
archive log
files Fast recovery area
ORACLE SECURE 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
Data file #6
Image copies
(Duplicate data and log files in OS format)
RECOVERY MANAGER (RMAN)
show all;
CONFIGURING BACKUP SETTINGS
Level 0 and level1
SCHEDULING BACKUPS: STRATEGY shell script – crontab
MANAGING BACKUPS
list backup;
list backup summary;
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
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
- Incremental Backup
- Level 0 - FULL Database backup
- Level 1 - Backup changes only from last incremental backup
- 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;
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
• 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”
impdp
client
DATA PUMP UTILITY: INTERFACES AND
MODES
REMAP_TABLE = 'EMPLOYEES':'EMP'
DEMO:
CONN / AS SYSDBA
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';
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
Data Block
insert writes
Table
HWM
Always generates redo entries Generates redo only under specific conditions
Enforces all constraints Enforces only PRIMARY KEY, UNIQUE, and NOT NULL
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
PGA
Server ORACLE_LOADER
process driver
(Text)
ext_table
(Metadata Only)
ORACLE_DATAPUMP
driver
Database (Binary)
EXTERNAL TABLE BENEFITS
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
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
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
identified by "example"
profile default
account unlock
2. Create a Table
SQL> conn example/example@pdb2
Table created.
2 /
Oracle User
Management
Database User Accounts
DBSNMP Same as sys but for the OEM, owns all internal tables in the sysaux tablespace.
create
create user TEST1 identified by TEST1;
Drop:
drop user TEST1 ;
drop user TEST2 cascade;
Creating a Role
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
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';
SQL*Loader
expdp impdp Other clients
(sqlldr)
Data Pump
DBMS_DATAPUMP
Data/Metadata Movement Engine
Oracle Oracle
Loader DataPump Direct Path API Metadata API
• 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”
impdp
client
DATA PUMP UTILITY: INTERFACES AND
MODES
REMAP_TABLE = 'EMPLOYEES':'EMP'
DEMO:
CONN / AS SYSDBA
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';
Primary
Database LGWR
Online
Redo
Log
ARCn
LOG_ARCHIVE_DEST_1
Archived
Redo
Logs
With Data Guard
Production DR
Online Standby
Redo Redo
Log Log
ARCn ARCn
LOG_ARCHIVE_DEST_1
Archived Archived
Redo Redo
Logs Logs
Standby Database
Types
Physical Standby Databases
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
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
Real
Time
Online Standby Apply
Redo Redo
Log Log
ARCn ARCn
LOG_ARCHIVE_DEST_1
Archived Archived
Redo Redo
Logs Logs
DATA GUARD
SWITCHOVER
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
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
Generating and displaying the execution plan for the last SQL statement executed in a session:
$top
vmstat
$free -g
iostat
$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)
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
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
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
Source Target
Data Pump Server
job process
Database Database
Master Dump Dump Master
table file set file set table
“Network mode”
impdp
client
Data Pump Utility: Interfaces and Modes
REMAP_TABLE = 'EMPLOYEES':'EMP'
Migration with Data Pump Legacy Mode
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
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.
Result:
Transaction 1 Transaction 2
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
Undo
segment
Redo log
files
Managing Undo
DBA
Guaranteeing Undo Retention
Retention guarantee:
15 minutes
Undo data in
undo
tablespace
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
Policy: AUDIT_EMPS_SALARY
SELECT name, salary
FROM employees
WHERE
employees
department_id = 10;
Audited DML Statement: Considerations
UPDATE hr.employees
SET salary = 1000
WHERE employee_id = 200;
Oracle Audit Vault
Automatic Automatic
Workload Diagnostic
Repository Efficient Repository
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
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
Working with
Support
Using the Support Workbench
View critical
1 error alerts in
Enterprise Manager.
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