You are on page 1of 282

Oracle 10g Database Associate

Student Guide (V2)

Volume 1
This document contains proprietary information. It is provided under a
license agreement containing restrictions on use and disclosure and is
also protected by copyright law.

This material or any portion of it may not be copied in any form or by


any means without the express written permission of Jeremy Russell &
Associates. Any other copying is a violation of copyright law and may
result in civil and/or criminal proceedings.

The information contained in this document is subject to change


without notice. If you find any problems in the documentation, please
report them in writing to Jeremy Russell & Associates Ltd., 1 Tucker
Street, Watford, Herts. WD18 0AU, U.K. Whilst every precaution has
been taken in the preparation of this information, Jeremy Russell &
Associates Ltd. do not warrant that this document is error-free. No
responsibility is assumed by Jeremy Russell & Associates Ltd. for any
errors or omissions or for damages resulting from the use of the
information contained herein.

All products and company names are used for identification purposes
only and may be trademarks or registered trademarks of their
respective owners.
Table of Contents Oracle 10g Database Associate

Lesson I Oracle10g DBA Associate Class Overview 1


Lesson Summary 2
Objectives 3
Course Structure 4
Suggested Class Structure 6
Summary 7

Lesson 1 Installing Oracle 10g 9


Objectives 10
Starting Installation 11
Windows systems 11
Linux/UNIX systems 14
Installation Welcome 15
Select Installation Type 16
Specify Home Details 17
Product-Specific Prerequisite Checks 18
Installation Summary Display 19
Installation In Progress 20
End of Installation 21
Database Storage 22
Summary 23
Practice 1 24

Lesson 2 Oracle 10g Architecture 27


Oracle Server Configuration 29
Database and Instance 30
Disk Structure 34
Parameter File 36
Control File 37
Data files 39
Data Dictionary 40
Redo Log Files 41
Password File 42
Logical and Physical Structures 44
Blocks 45
Extents 46
Segments 47
Memory Structures 48
Shared Pool 49
Buffer Cache 50
Redo Log Buffer 51
Process Structure 52
Database Writer 53
Log Writer 54
System Monitor 55
Process Monitor 56

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page i


Oracle 10g Database Associate Table of Contents

Checkpoint Process 57
Server Process 58
Processing a query 59
Processing an Update 60
Processing a transaction 61
Summary 62

Lesson 3 Creating a Database 69


Starting DBCA 71
DBCA Operations 72
Select Database Template 73
Database Identification 74
Management Options 75
Database Credentials 76
Storage Options 77
Database File Locations 78
Recovery Configuration 79
Database Content 80
Initialisation Parameters 81
Creation Options 86
Confirmation 87
Creating the Database 88
Password Management 89
Configure Database Options 90
Delete a Database 91
Templates 92
Summary 95
Practice 3 96

Lesson 4 Database Interfaces 97


Relational Database Table 99
SQL*Plus 100
iSQL*Plus 101
Connecting to a Database 102
Database Retrieval Examples 103
Database Credentials 104
Accessing Information 105
Logical Table Structures 106
Choosing Columns and Rows 107
Joining Tables 109
Data Manipulation Language 110
Data Control Language 114
Data Definition Statements 116
SQL*Plus Commands 117
SQL*Plus Conventions 119
PL/SQL 120

V2: Page ii Copyright 2007 Jeremy Russell & Associates Ltd.


Table of Contents Oracle 10g Database Associate

Enterprise Manager 122


EM Home Page 123
EM Performance 124
EM Administration 125
EM Maintenance 126
Summary 127
Practice 4 128

Lesson 5 Starting and Stopping Oracle 129


EM Database Control Daemon 131
Starting a Listener 134
Windows Oracle Service 135
Database Control Startup Credentials 136
Status Screen 137
Startup/Shutdown Confirmation 138
Startup Progress 139
Shutdown Options 140
Starting iSQL*Plus 141
Parameter Files 142
Alert Log 144
Summary 147
Practice 5 148

Lesson 6 Tablespaces and Datafiles 149


Tablespaces 151
Datafiles 152
Tablespace Types 154
Installation Tablespaces 155
SYSTEM & SYSAUX 156
TEMP 157
EM & Tablespaces 158
Oracle Managed Files 159
Inside a tablespace 160
Tablespace Management 161
Datafile Management 162
Data Dictionary 163
Segments, Extents and Blocks 166
Segment Space Management 169
Extent Allocation 170
Blocks 171
Data Dictionary 172
Summary 174
Practice 6 175

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page iii
Oracle 10g Database Associate Table of Contents

Lesson 7 Schema Objects 177


Schema 179
Tables 180
Table Operations 181
Creating New Tables 182
Table Storage 188
Managing Tables 189
Table Block Usage 190
Indexes 191
Index Storage 192
Managing Indexes 193
Views 194
Sequences 195
Using Sequences 196
Data Dictionary 197
Summary 202
Practice 7 203

Lesson 8 Undo Management 205


Undo Basics 207
Creating Undo Tablespaces and Datafiles 208
Undo Storage Tablespace Parameters 212
Managing Undo Tablespace 213
Activating Undo Tablespace 214
Undo Space Usage 215
Undo Generation Statistics 216
Manual Sizing 217
Automated Sizing 218
Undo Retention Guarantee 220
Summary 221
Practice 8 222

Lesson 9 Data Administration 225


Moving Data 227
Intra-Database Movement - Insert / Merge 228
DataPump 231
Exporting with DataPump 235
Export/Import Modes 237
Directories 238
Executing an Export 239
Export Output 240
Executing an Import 241
Import Type 243
Selected Schemas 244
Schema Re-Mapping 245
Options 246

V2: Page iv Copyright 2007 Jeremy Russell & Associates Ltd.


Table of Contents Oracle 10g Database Associate

Schedule 247
Review 248
DBMS_DATAPUMP Job 249
Job Execution 250
Job Activity 251
Summary and Log 252
SQL*Loader 253
Data File 256
Control File 257
Executing SQL*Loader 258
Control File Generation 259
Select Control File 260
Select Data File 261
Load Method 262
Load Options 263
Schedule 264
Review 265
Confirmation 266
Completion Report 267
Summary 268
Practice 9 269

Lesson 10 PL/SQL for DBA's 271


PL/SQL Overview 273
Anonymous Block 275
PL/SQL Block Structure 276
PL/SQL Procedures 277
PL/SQL Functions 278
PL/SQL Packages 279
PL/SQL at Runtime 280
PL/SQL Triggers 281
Supplied Packages 282
Supplied Package Examples 283
EM Administration 284
Summary 285
Practice 10 286

Lesson 11 Database Security 287


Defensive Database Security 289
Principle Of Least Privilege 290
Default User Accounts 292
Standard Password Security Features 294
Audit Database Activity 295
Network Security 297
Register For Security Updates 298
Conclusions 300
Summary 301

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page v


Oracle 10g Database Associate Table of Contents

Lesson 12 User Administration 303


User Accounts 305
Profiles 306
Profile Password Limits 308
Profile Kernel Limits 309
Profile Management 310
Authentication Mechanisms 311
Tablespace Settings 313
Privileges 314
Roles 316
Creating a new user 318
User Management 320
Roles and Users 322
Data Dictionary 323
Summary 325
Practice 12 326

Lesson 13 Network Administration 329


Client Server Architecture 331
Client/Server Connection Options 332
Oracle Net Components 333
Name Resolution 334
Net Manager Host Configuration 335
Name Resolution : Local Naming 336
Net Manager Local Configuration 337
Net Manager Service Name Configuration 338
Adding a new service 339
SQLNET.ORA 344
TNSNAMES.ORA 346
LISTENER.ORA 349
Listener Control Utility 351
EM Listener Status 354
EM Edit Listener 355
Logging and Tracing 357
Static Registration 358
Other Services 359
Listener Management 360
Connections 361
TNSPING 364
Logging and Tracing Parameters 366
Listener Audit Trail 372
Network Error Codes 374
Network Problem Diagnosis 375
Trace Assistant 379
Summary 382
Practice 13 383

V2: Page vi Copyright 2007 Jeremy Russell & Associates Ltd.


Table of Contents Oracle 10g Database Associate

Lesson 14 Backup and Recovery Concepts 385


Recovery Structures 387
Recovery Features 388
Recovery Operations 388
Redo Log Buffer 389
LGWR Process 390
Redo Logs 391
Dictionary Tables 393
ARCH Process 394
Control Files 395
CKPT Process 397
Data Files 398
Archiving Setup - Manual 399
Archiving Setup EM 401
Archiving Setup Confirmation 402
Flash Recovery 403
Define Flash Recovery Area 404
Recovery Manager Utility 405
Points of Failure 407
Summary 408
Practice 14 409

Lesson 15 Database Backups 411


Closed Database Backup 413
Open Database Backup 417
Oracle-Suggested Backup 419
Manual Control File Backup 421
Control File Text Backup 422
Image Copies 425
Backup Sets 426
Monitoring Flash Recovery Area 427
Summary 428
Practice 15 429

Lesson 16 Database Recoveries 431


Recover from Cold Backup 433
Recover from Hot Backup 434
Rename Data File 436
Complete Recovery Procedures 438
EM Tablespace Recovery 440
Recover Control File 441
Log File Recovery 442
Incomplete Recovery Overview 443
Summary 445
Practice 16 446

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page vii
Oracle 10g Database Associate Table of Contents

Lesson 17 Lock Management 447


Locking Overview 449
Lock Types 450
Locking Issues 451
Locking Diagnostics 452
EM Blocking Sessions 454
EM Hang Analysis 455
Resolving Locking Issues 456
Deadlocks 457
Dictionary Information 458
Summary 460
Practice 17 461

Lesson 18 Automatic Maintenance 463


Automatic Maintenance Features 465
Automatic Workload Repository 466
How AWR Works 467
Customising the AWR 468
Automatic Database Diagnostic Monitor 469
ADDM Goals 470
ADDM Findings and Recommendations 471
Active Session History 472
Alerts and Thresholds 474
EM Alert Display 476
Thresholds 477
Editing Thresholds 478
Baseline Metrics 479
Automating Maintenance Tasks 480
Summary 481
Practice 18 482
Filling Tablespaces 482
Blocking Sessions 484
Cleanup 488

Lesson 19 Performance Tuning 489


Oracle Tuning Principles 491
Tuning Considerations 492
EM Performance Page 494
ADDM Recommendations 496
Oracle Statistics 497
Oracle Query Optimiser 500
Execution Plans 502
Optimiser Dynamic Sampling 504
Advisor Central 505
Memory Advisor 506

V2: Page viii Copyright 2007 Jeremy Russell & Associates Ltd.
Table of Contents Oracle 10g Database Associate

MTTR Advisor 507


Segment Advisor 508
Segment Advisor Example 509
SQL Access Advisor 510
SQL Tuning Advisor 512
SQL Tuning Advisor Recommendations 513
Undo Advisor 515
Memory Advisor 516
MTTR Advisor 517
Invalid/Unusable Objects 518
Invalid Objects Example 520
Summary 522
Practice 19 523

Lesson 20 Q & A 527


Suggested Reading List 529
Useful Websites 530
Oracle Certification 531
Further training 532
Oracle Certified Professional Training 533
Summary 534

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page ix


Oracle 10g Database Associate Table of Contents

This page intentionally left blank

V2: Page x Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson I Class Overview Oracle 10g Database Associate

0I
Oracle10g DBA Associate V2

Class Overview

ODBA10gDB-OCA--Intro-1 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

LESSON I ORACLE10G DBA ASSOCIATE CLASS OVERVIEW


This is an intensive, hands-on class that provides an introduction to the features of the Oracle 10g
Database for Administrators. After completing this class, delegates will be prepared for the Oracle
Database 10g: Administration 1 certification test (Oracle code 1Z0-042).

For full information regarding this exam, please refer to the latest information on the Oracle
Corporation website1.

1
http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=39

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 1


Oracle 10g Database Associate Lesson I Class Overview

Lesson Summary

Introductions
Class Objectives
Course Structure
Suggested Class Structure

ODBA10gDB-OCA--Intro-2 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Lesson Summary

Introductions
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

Class Objectives
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

Course Structures
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

Suggested Class Structure


________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

V2: Page 2 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson I Class Overview Oracle 10g Database Associate

Objectives

After completing this course, you should be


able to do the following:
List features of the Oracle10g database
Understand the concepts of Oracle 10g
Comprehend the Oracle DBA tasks
Understand Oracle tuning mechanisms
Appreciate Oracle network configuration

ODBA10gDB-OCA--Intro-3 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Objectives

List the features of Oracle10g database


Oracle10g was launched to provide enhancements for grid computing, whilst simultaneously
reducing the administration overhead required to provide a secure and available database
environment. With Oracle10g, Release 2, the product offers improved efficiency, reducing
downtime and enhancing scalability and unique security features.

Understand the concepts of Oracle


Oracle automates time-consuming, error-prone administrative tasks, so DBAs can focus on
strategic business objectives. Studies from the Edison Group prove Oracle Database 10g
offers superior manageability and significant cost savings over comparative products.

Comprehend the Oracle DBA tasks


In the typical organisation, a DBA is responsible for installing, monitoring and tuning
database software, devising and implementing a security (backup and recovery) mechanism
for databases and some network administration for database connections (see below).

Understand Oracle tuning mechanisms


Development DBAs may also work with software teams to ensure that in-house applications
are written using best practices for portability and performance. Production DBAs will be
responsible for overall database tuning.

Appreciate Oracle network configuration


An appreciation of the Oracle networking configuration is useful for larger environments,
where many databases are supported and required for access from a variety of client types.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 3


Oracle 10g Database Associate Lesson I Class Overview

Course Structure 1

Lesson Topic
1 Installing Oracle 10g
2 Oracle 10g Architecture
3 Creating an Oracle Database
4 Database Interfaces
5 Starting and Stopping Oracle
6 Tablespaces and Datafiles
7 Schema Objects
8 Undo Management
9 Data Administration
10 PL/SQL for DBA's

ODBA10gDB-OCA--Intro-4 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Course Structure 1

Lesson Title Description


1 Oracle 10g Architecture Software installation and starter database
2 Installing Oracle 10g Discusses the basic architecture of Oracle
3 Creating an Oracle Database Database creation options
4 Database Interfaces Software for entering SQL commands
5 Starting and Stopping Oracle Running Oracle automatically & manually
6 Tablespaces and Datafiles Administering storage areas
7 Schema Objects Administering tables, indexes and more
8 Undo Management Organising undo disk areas
9 Data Administration Importing and exporting data
10 PL/SQL for DBAs PL/SQL stored code and triggers

This class consists of a mix of lecture and guided lab sessions. Your instructor will advise you of the
locations of demo, lab and any solution files for your class.

V2: Page 4 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson I Class Overview Oracle 10g Database Associate

Course Structure 2

Lesson Topic
11 Database Security
12 User Administration
13 Network Administration
14 Backup and Recovery Concepts
15 Database Backups
16 Database Recoveries
17 Lock Management
18 Automatic Maintenance
19 Performance Tuning
20 Q&A

ODBA10gDB-OCA--Intro-5 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Course Structure 2

Lesson Title Description

11 Database Security Examines security features in Oracle 10g


12 User Administration Creating and administering user accounts,
privileges and related resources
13 Network Administration Setting up and troubleshooting networks
14 Backup and Recovery Concepts Outline of principles for backing up data files
15 Database Backups Procedures for backing up all file types
16 Database Recoveries Procedures for restoring and recovering all file
types
17 Lock Management Investigating and exploring locking issues
18 Automatic Maintenance Automatic tools for maintaining optimal database
features
19 Performance Tuning Built-in performance management and tuning
mechanisms
20 Q&A

This class consists of a mix of lecture and guided lab sessions. Your instructor will advise you of the
locations of demo, lab and any solution files for your class.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 5


Oracle 10g Database Associate Lesson I Class Overview

Suggested Class Structure


Introduction
Introduction to
to
Oracle10g
Oracle10g
(3
(3 days)
days)
Oracle
Oracle 10g
10g DBA
DBA
Associate
Associate
Introduction
Introduction to
to ((55 days
days)) Oracle
Oracle 10g
10g DBA
DBA
Oracle10g
Oracle10g Workshop
Workshop
PL/SQL
PL/SQL (3
(3 days)
days)
(2
(2 days)
days) Oracle
Oracle 10g
10g DBA
DBA
Professional
Professional
(5
(5 days)
days)
Oracle
Oracle 10g
10g
Advanced
Advanced PL/SQL
PL/SQL
(2 Recommended
(2 days)
days)
Optional

ODBA10gDB-OCA--Intro-6 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Suggested Class Structure

V2: Page 6 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson I Class Overview Oracle 10g Database Associate

Summary

In this lesson, you should have learned


about:
The structure of this class
The purpose of the course
The class environment

ODBA10gDB-OCA--Intro-7 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Summary
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 7


Oracle 10g Database Associate Lesson I Class Overview

This page intentionally left blank

V2: Page 8 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 1 Installing Oracle 10g Oracle 10g Database Associate

1
0
Installing Oracle 10g

ODBA10gDB-OCA-01-1 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

LESSON 1 INSTALLING ORACLE 10G


Lesson 1 discusses the installation of Oracle10g Enterprise Edition on Windows and Linux platforms.

During the lesson, you will install Oracle 10g Release 2 Enterprise Edition and create a sample
database using the Oracle Universal Installer (OUI).

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 9


Oracle 10g Database Associate Lesson 1 Installing Oracle 10g

Objectives

After completing this lesson, you should


be able to do the following:
Install Oracle 10g software
Make installation decisions
Configure starter database
Examine installed files

ODBA10gDB-OCA-01-2 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Objectives

This lesson explains the installation of the Oracle10g Enterprise Edition software.

During the installation, you will use the Database Configuration Assistant (DBCA) to create and
configure a sample starter database.

After the installation has completed, the installed software and data files will be explored.

V2: Page 10 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 1 Installing Oracle 10g Oracle 10g Database Associate

Starting Installation

Download Oracle installation archive


Unzip/unpack archive to working directory
Run OUI (Oracle
Universal Installer)
by double-clicking
..\database\setup
or ../runInstaller

ODBA10gDB-OCA-01-3 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Starting Installation
The Oracle software can be downloaded from the following URL:
http://www.oracle.com/technology/software/products/database/oracle10g/index.html
(Note that this URL may change during reorganisations of the Oracle website).
A version appropriate for your operating system should be selected from this page. At the time of
writing, the latest version available for download is Oracle 10g Release 2.
The downloaded file should be unpacked (use WinZIP or PKZip for Windows or gunzip/cpio for
Linux and Unix operating systems). The unpacked file will create a new directory (database)
containing the Oracle Enterprise Edition installation software.

Windows systems
For Windows XP systems, selected system policies must be enabled. To set these policies, carry out
the following procedure:
1) Login as Administrator (or an account with Administrator privileges).
2) Click the Start button and select the Run option.
3) In the command box, enter secpol.msc
4) Expand Local Policies > User Rights Assignment
5) Double-click Log on as a batch job.
6) Add your account to the selected users or groups list.
In addition, a Windows system must be configured with a static IP address. For systems that are
connected to a Dynamic Host Configuration Protocol system, you must install the Windows local
loopback adapter before installing Oracle.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 11


Oracle 10g Database Associate Lesson 1 Installing Oracle 10g

Checking if a Loopback Adapter Is Installed

To check if a loopback adapter is installed on your computer, run the command below:

C:\> ipconfig /all

If there is a loopback adapter installed, you would see a report that includes the network values for the
loopback adapter. e.g:

~
Ethernet adapter Local Area Connection 2:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft Loopback Adapter
Physical Address. . . . . . . . . : 02-00-4C-4F-4F-50
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Autoconfiguration IP Address. . . : 169.254.25.129
Subnet Mask . . . . . . . . . . . : 255.255.0.0
~

Installing a Loopback Adapter on Windows XP


To install a loopback adapter on Windows 2003 or Windows XP:
1. Open the Windows Control Panel.
2. Double-click Add Hardware to start the Add Hardware wizard.
3. In the Welcome window, click Next.
4. In the Is the hardware connected? window, select Yes, I have already connected the
hardware, and click Next.
5. In the The following hardware is already installed on your computer window, in the list of
installed hardware, select Add a new hardware device, and click Next.
6. In the The wizard can help you install other hardware window, select Install the hardware
that I manually select from a list, and click Next.
7. From the list of hardware types, select the type of hardware you are installing window, select
Network adapters, and click Next.
8. In the Select Network Adapter window, make the following selections:
Manufacturer: Select Microsoft.
Network Adapter: Select Microsoft Loopback Adapter.
9. Click Next.
10. In the The wizard is ready to install your hardware window, click Next.
11. In the Completing the Add Hardware Wizard window, click Finish.
12. If you are using Windows 2003, restart your computer.
13. Right-click My Network Places on the desktop and choose Properties. This displays the
Network Connections Control Panel.

V2: Page 12 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 1 Installing Oracle 10g Oracle 10g Database Associate

14. Right-click the connection that was just created. This is usually named "Local Area Connection
2". Choose Properties.
15. On the General tab, select Internet Protocol (TCP/IP), and click Properties.
16. In the Properties dialog box, click Use the following IP address and do the following:
a. IP Address: Enter a non-routable IP for the loopback adapter. Oracle recommends
the following non-routable addresses:
192.168.x.x (x is any value between 0 and 255)
10.10.10.10
b. Subnet mask: Enter 255.255.255.0
c. Record the values you entered, which you will need later in this procedure.
d. Leave all other fields empty.
e. Click OK.
17. Click OK.
18. Close Network Connections.
19. Restart the computer.
20. Add a line to the SYSTEM_DRIVE:\WINDOWS\system32\drivers\etc\hosts
file with the following format, after the localhost line:
IP_address hostname.domainname hostname
where:
IP_address is the non-routable IP address you entered in step 16.
hostname is the name of the computer.
domainname is the name of the domain.
For example:

10.10.10.10 mycomputer.mydomain.com mycomputer

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 13


Oracle 10g Database Associate Lesson 1 Installing Oracle 10g

Linux/UNIX systems
For Linux and Unix systems, it will be necessary to perform several operating system actions to allow
installation to proceed. These details vary between different operating systems and you should
consult the OS specific installation documentation for the latest specific information. Typical actions
include checking for optional OS packages, checking kernel parameters and creating Oracle OS
accounts and group accounts. A general guide to installing Oracle 10g on Linux is at:

http://www.puschitz.com/InstallingOracle10gOnSUSE.shtml#
DownloadingOracle10gSoftwareAndBurningOracle10gCDs

To install this software and optionally configure a default database (for any operating system), run the
Oracle Universal Installer by navigating to the database subdirectory and executing the setup
utility (for Windows) or runInstaller (for Linux/Unix).

For Linux operating system installations, you may need to specify the -ignoreSysPrereqs
command flag to bypass unnecessary prerequisite checks during installation.

V2: Page 14 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 1 Installing Oracle 10g Oracle 10g Database Associate

Installation Welcome

Basic installation requires password only


Advanced requires many selections, for
password, character set and storage type

ODBA10gDB-OCA-01-4 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Installation Welcome
Basic pre-requisites check
If Oracle database software had been installed on the system beforehand, the OUI may display a pre-
requisites check screen. If the pre-requisites are met, the Installer Welcome screen illustrated above is
shown.

Basic installation
The Welcome screen allows simple (almost one-click) installation and optional configuration of a
starter database. To use this option, select the Basic Installation radio button. To create a starter
database, enter the global database name (default value of orcl) which must be unique on the server
being used.
Leave the Installation Type as Enterprise Edition, the version of Oracle that includes all required
options. Alternatives include Standard Edition and Personal Edition.
Enter an initial Database Password, which will be used for all initial Oracle database administration
accounts. Click Next to continue and automatically install Oracle 10g.

Advanced installation
To perform a manual, advanced installation, select the Advanced installation radio button.This
option allows a number of configuration choices to be specified, including :
Separate passwords for DBA accounts
Database character sets and product languages for international use
Automated backup settings
Alternate storage options, including Automatic Storage Management
The remaining pages in this lesson refer mainly to advanced installation options.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 15


Oracle 10g Database Associate Lesson 1 Installing Oracle 10g

Select Installation Type

ODBA10gDB-OCA-01-5 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Select Installation Type


The Oracle 10g database is provided in various versions:

Enterprise Edition (EE) Fully featured, high performance, multi-processor edition. Can
be extended with several options and add-on packs.
Standard Edition (SE) Licenced for a single server or cluster with up to four
processors. Optional Real Application Cluster (RAC)
support.
Standard Edition One (SE1) Limited to a maximum of two processors.
Express Edition (XE) Entry level database; limited to the following maxima:
4GB of data, 1GB of memory, 1 processor.
Free for deployment and development.
Oracle XE is a separate product and is not discussed further in
this class.

During initial installation, the OUI allows selection of the installation type required.

V2: Page 16 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 1 Installing Oracle 10g Oracle 10g Database Associate

Specify Home Details

ODBA10gDB-OCA-01-6 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Specify Home Details

Multiple versions of the Oracle software can be installed concurrently on a single host system.

Each installation requires a separate ORACLE_HOME directory.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 17


Oracle 10g Database Associate Lesson 1 Installing Oracle 10g

Product-Specific Prerequisite Checks

ODBA10gDB-OCA-01-7 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Product-Specific Prerequisite Checks


Sundry pre-requisite checks are carried out by the OUI, to ensure that the system is capable of running
Oracle 10g. These checks include:
Operating system versions and service pack requirements
Installed memory
Networking configuration
Disk space and path requirements

Checking operating system requirements ...


Expected result: One of 4.0,4.1,5.0,5.1,5.2
Actual Result: 5.1
Check complete. The overall result of this check is: Passed_________________
Checking service pack requirements ...
Expected result: 1
Actual Result: 1
Check complete. The overall result of this check is: Passed_________________
Checking physical memory requirements ...
Expected result: 256MB
Actual Result: 1022MB
Check complete. The overall result of this check is: Passed_________________
Checking Network Configuration requirements ...
Check complete. The overall result of this check is: Passed_________________
Checking for Oracle Home incompatibilities ....
Check complete. The overall result of this check is: Passed_________________
Validating ORACLE_BASE location (if set) ...
Check complete. The overall result of this check is: Passed_________________
Checking Oracle Home path for spaces...
Check complete. The overall result of this check is: Passed_________________
Checking Oracle Home path for location ...
Check complete. The overall result of this check is: Passed_________________
Checking for proper system clean-up....
Check complete. The overall result of this check is: Passed_________________

V2: Page 18 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 1 Installing Oracle 10g Oracle 10g Database Associate

Installation Summary Display

ODBA10gDB-OCA-01-8 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Installation Summary Display

Once the required password information has been entered and the installation checks have been
successful, the OUI displays a summary screen containing all installation options.

If this list is incorrect, click the Back button to return to the previous screen and make appropriate
corrections.

If the options shown are correct, click the Install button to begin the installation and configuration
process for the starter database.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 19


Oracle 10g Database Associate Lesson 1 Installing Oracle 10g

Installation In Progress

ODBA10gDB-OCA-01-9 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Installation In Progress
During installation, several screens are displayed to indicate the progress of the software installation.

After the software installation is completed, the Database Configuration Assistant (DBCA) is
invoked to create the starter database. A separate DBCA window opens to display the progress for
the DBCA. During software installation, the DBCA copies a seed database provided on the
installation media to create a starter database.

A log of the installer actions is at created at:

<OracleHome>\Inventory\logs\installActionsYYYY-MM-DD_HH-MI-SSXX.log

A log of the DBCA actions is at created at:

<OracleHome>\db_1\cfgtoollogs\dbca\<SID>

When the database has been created, a confirmation screen is displayed. This confirmation screen
includes a warning regarding default passwords, which should be changed for production database
systems. This will be discussed in Lesson 3 (Database Creation) and Lesson 12 (User
Management). Click the OK button to complete the installation.

V2: Page 20 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 1 Installing Oracle 10g Oracle 10g Database Associate

End of Installation

ODBA10gDB-OCA-01-10 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

End of Installation
A final confirmation screen is displayed showing URLs for managing the newly created starter
database. These tools are discussed in Lesson 4 (Database Interfaces) and used throughout the
remainder of this class.
Note the URLs displayed for the iSQL*Plus program and OEM controls. These default to:
iSQL*Plus http://<hostname>:5560/isqlplus

OEM http://<hostname>:1158/em

The port numbers may vary from the defaults shown if there are other services using these ports on
the installation server.
These URLs should be added to your browser favourite lists for easy reference.

The following J2EE Applications have been deployed and are


accessible at the URLs listed below.

iSQL*Plus URL:
http://localhost:5560/isqlplus

iSQL*Plus DBA URL:


http://localhost:5560/isqlplus/dba

Enterprise Manager 10g Database Control URL:


http://localhost:1158/em

To complete the installation, select the Exit button and respond to the confirmation prompt.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 21


Oracle 10g Database Associate Lesson 1 Installing Oracle 10g

Database Storage

ODBA10gDB-OCA-01-11 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Database Storage
The starter database will create subdirectories for file storage in the following location:

<oracleHome>/product/<version>/<db_home>/dbs
<oracleHome>/admin/<SID>
<oracleHome>/oradata/<SID>

Subdirectories that are created in the admin area include:


bdump Alert logs and server process trace files
cdump Core dumps for failed processes
create Logs for the install and creation processes (can be deleted)
dpdump Data pump logs
pfile Default parameter file location
udump User process trace files

V2: Page 22 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 1 Installing Oracle 10g Oracle 10g Database Associate

Summary

In this lesson, you should have learned


about:
Installing Oracle 10g software
Making installation decisions
Configuring example database
Examining installed files

ODBA10gDB-OCA-01-12 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Summary
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 23


Oracle 10g Database Associate Lesson 1 Installing Oracle 10g

Practice 1

In this practice, you will install the Oracle


software and create a default ORCL
database
You will create a second database in a
later lesson
Your instructor will provide login and
directory information for this class, which
can be noted below for further reference.

ODBA10gDB-OCA-01-13 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Practice 1
Install the Oracle software as provided on your system paths and directory information will
be provided by your instructor. Please ask any questions that are necessary during the
installation procedure since this process takes a significant amount of time, the procedure
will execute more smoothly if you ask before committing to the installation!
Once the software has been installed, you should modify the environment for your account as
described below:

Windows
On your desktop, right-click My Computer and select Properties. Click the Advanced tab, then
the Environment Variables button.
In the Environment Variables dialog, click the User variables New button:

V2: Page 24 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 1 Installing Oracle 10g Oracle 10g Database Associate

In the New User Variable dialog, enter the following information (see lab script file in
C:\Oracle10g\Labs\Ch01EnvVar.txt for an example which you can copy):
Variable name SQLPATH

Variable value .;C:\Oracle10g\Labs;C:\Oracle10g\Scripts

Note that the variable value should begin with a period / full-stop!

Press the OK button three times, to close all three open dialogs.
On the Windows task bar, click the Start button and select the Run menu option. In
the Run dialog box, type the following command (to execute the provided script file :

C:> sqlplus /nolog @Ch01CreatePrintTable

An MS-DOS window will open and the specified script will be executed, to create a stored procedure
for easily displaying large tables using SQL*Plus. There should not be any error messages displayed
please ask your instructor for advice if there appears to be an error.
When instructed by the script, type exit and hit return to close the window.

UNIX / Linux

Using the vi editor, open the .profile script in your home directory.

Add a new line to the beginning of this file, as below (Ch01Profile.txt):

$ export SQLPATH=.:/Oracle10g/Labs:/Oracle10g/Scripts

Save the file. Log out of your OS account, then log back in, to re-execute your modified profile.

When the shell prompt is displayed, enter the command shown below, to create a stored procedure for
easily displaying large tables using SQL*Plus.

$ sqlplus /nolog @Ch01CreatePrintTable

File Systems
Explore the installed software and data files that have been created by the installation procedure.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 25


Oracle 10g Database Associate Lesson 1 Installing Oracle 10g

This page intentionally left blank

V2: Page 26 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

2
0
Oracle 10g Architecture

ODBA10gDB-OCA-02-1 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

LESSON 2 ORACLE 10G ARCHITECTURE


This lesson describes and demonstrates the Oracle 10g RDBMS database architecture. Further details
are discussed in later lessons.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 27


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Objectives

After completing this lesson, you should


be able to perform the following:
Appreciate the architecture of an Oracle host
Explain the memory structure for Oracle
Describe the disk structure for Oracle
Comprehend how these co-operate to
process SQL queries and updates

ODBA10gDB-OCA-02-2 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Objectives

This lesson describes and demonstrates the structure of an Oracle system.

After completing this lesson, you will understand the architecture of a typical Oracle system (on both
Windows and UNIX systems).

You will appreciate the memory and disk structures for a typical database installation.

You will also be aware of how these memory and disk areas co-operate to process SQL queries on
and updates to the database information.

V2: Page 28 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

Oracle Database Server Configuration

A server hosts your database(s) and instance(s)


using Oracle software, files, memory, processes
and threads
<ORACLE_BASE>
db_n
BIN database Database 2
rdbms network

Server Database 1
ODBA10gDB-OCA-02-3 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Oracle Server Configuration

Software
Oracles RDBMS software is installed into a dedicated directory area
(the ORACLE_BASE directory). This directory will contain many
subdirectories. For Windows, this directory is set by the Oracle
Universal Installer (OUI) to C:\Oracle\product\release.
Typical subdirectories under ORACLE_BASE include
BIN - executable programs
database - default location for data files
rdbms - database setup scripts
sqlplus - interactive SQL tools
network - networking configuration files
For both Windows and UNIX systems, the PATH environment variable
must be set to include the ORACLE_HOME/bin directory

Database
For each database, the OUI creates a separate home directory under ORACLE_BASE. The name of this
directory is type_n, where type is either db for a database or client for a client only
installation and n is an optional sequence number.

Instance
For each database, the OUI creates a separate instance, a set of memory areas and processes for
managing communication between the memory and the database disk files.
On Windows systems, the instance is implemented as a single multi-threaded process. On UNIX
systems, an instance is implemented as multiple co-operating processes.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 29


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Database and Instance

Database : Sundry Instance : Memory +


Oracle file types Processes or Threads

SGA

Database
Processes
Control Data Redo Log Parameter

Instance

ODBA10gDB-OCA-02-4 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Database and Instance

Database
An Oracle database is the set of Oracle files that together make up the permanent storage area for your
user data (and control information used by the Oracle software).
Each database includes several datafiles that are initialised during database creation. Additional
datafiles can be added as required for new application requirements.

Instance
A database is managed by an Oracle instance, a pre-allocated block of memory together with several
processes or threads that manage the memory and data files.
Depending on the configuration of the server hardware, several instances may co-exist on a single
server. Alternatively, with the Oracle Real Application Cluster (RAC) option, a single database
may be managed by multiple instances executing on separate, inter-connected servers. RAC provides
both scalability and fail-safe processing for 24x7 application requirements.
RAC is not discussed in this class.

V2: Page 30 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

Database

Collection of physical files


Control files
Names, locations, +++
Data files
Dictionary, data, indexes
Database Redo Log
Transaction history

Control Parameter Redo Log Data


Parameter
Configuration & Tuning Settings

ODBA10gDB-OCA-02-5 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Database

A database file set consists of multiple file types, including control files, data files, online redo log
files and a parameter file.

Control files - name and status of data and online redo log files
Data files - pre-allocated storage areas for system and user information
Online Redo Log files - transaction log files holding details of recent updates
Parameter files - configuration and tuning information for the instance

An optional password file is held outside the main data files, in order to authentic privileged user
operations.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 31


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Instance

ORACLE_SID
Instance : Memory and processes
Required to be started
for database access SGA
Instance is the only way Shared Buffer Java Pool
to access information Pool Pool Log Buffer

Consists of memory and Large Pool


processes or threads
Identified by Processes
ORACLE_SID
DBWR LGWR SMON
Defaults in Windows
registry or UNIX PMON CKPT SERVER
environment variable
ARCH
Instance

ODBA10gDB-OCA-02-6 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Instance
An instance must be started for each database that is required to be accessed. The instance is the only
permitted means of accessing information stored in the database. An instance consists of preassigned
memory areas and associated processes or threads.
An instance is identified by a unique system identifier, the ORACLE_SID.

On a Windows system, the ORACLE_HOME and ORACLE_SID settings are stored in the Windows
registry. For UNIX systems, the ORACLE_SID value should be set into an environment variable.

V2: Page 32 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

Memory Areas

An instance includes several memory areas, together called the System Global Area (SGA). The SGA
is used to manage data on behalf of multiple users (clients). Both memory allocation and initialisation
of background processes for the instance are performed automatically as the instance starts.

Instance memory areas include:


Buffer cache - holding area for cached data blocks from data files
Shared pool - holding area for SQL statements and data structurs
Log buffer - buffer area for fast logging of data modifications
Java pool - holding area for Java stored procedures
Large pool - optional area for selected operations (e.g. backup)

Processes

Instance processes include:


Database writer (DBWR) - writes updated blocks from buffer cache to data files
Log writer (LGWR) - writes data modification log to online log files
Process monitor (PMON) - monitors and cleans up after failed user sessions
System monitor (SMON) - monitors instance; recovery on startup if needed
Checkpoint (CKPT) - periodically writes modification information to data files
Archiver (ARCn) - optional process to back up online log files

Additional optional processes may be started for other purposes, as discussed in later lessons. These
processes include:
Memory monitor (MMON) - collects statistics for Automatic Workload Repository
Memory manager (MMAN) - SGA memory broker to coordinates memory area resizing
Change tracking (CTWR) - track changed database blocks to speed backup processing
Queue monitor (QMNn) - coordinates the Oracle Advanced Queuing option

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 33


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Initial Disk Structure

Required files for each database include:


Control file (minimum 1, default 3)
Data files (minimum 2, typical 5+)
Redo log files (minimum 2, default 3)
Parameter file (required 1)
Additional files can be added as required

Control Parameter Redo Log System Sysaux Users Undo Example

ODBA10gDB-OCA-02-7 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Initial Disk Structure


An Oracle database, as a minimum, requires the following disk file setup:
One control file, built during database creation the Database Creation Assistant (DBCA)
recommends three mirrored files.
Two data files, built during database creation. The SYSTEM data file holds the data dictionary
(a set of tables describing the user database structures). The SYSAUX data file holds
performance and tuning information for the Oracle 10g automatic management features.
Additional files (an UNDO datafile, a USERS datafile and an optional EXAMPLE datafile) are also
created by the DBCA.
Two redo log files; the DBCA creates three non-mirrored files.
One parameter file, created by copying the sample init file provided by Oracle
Two types of parameter file may exist:
o a static parameter file, held as a text file usually called initSID.ora
o a persistent parameter file, SPFILE, in binary format, usually called spfileSID.ora
An optional password file can also be created before starting the database build process.
Additional files can and usually are created either during database building or afterwards, at any
time, by the DBA.

The structures illustrated above are the absolute minimum required to start a new database and do not
represent a workable production system setup.

V2: Page 34 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

Typical Disk Structure

Parameter System Sysaux Users Undo Example

Users2 Payroll
Control

Redo Log 1 Redo Log 2

ODBA10gDB-OCA-02-8 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Typical Disk Structure


In a typical database, the DBA can make any or all of the following changes

Add additional control files


New control files can be added when the instance has been stopped, by copying existing files
to a further location. The parameter file must be modified to include the newly added file
name.

Add additional log files and log file groups


Redo log files can also be added, moved or deleted. Unlike control files, these actions are
performed whilst the system is running (with some restrictions).

Add new data files/tablespaces


Further tablespaces (collections of datafiles) can be added to the database to support new
applications.

Add additional data files to existing tablespaces


If a data file becomes full, additional data files can be added to existing tablespaces to extend
the storage available for objects residing in the tablespace.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 35


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Parameter File

Parameter file contains settings used on


instance startup to configure Oracle
Settings include
...
control file location(s) processes = 150
resource limits control_files = /disk1/file1.con
log_buffer = 2899546
memory area sizes ...
tracing options
SPFILE (Binary) or PFILE (text) formats
Changes may require instance reboot Control

when using PFILE format

ODBA10gDB-OCA-02-9 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Parameter File
Two formats of parameter files are supported. A binary format (spfile) is the recommended format.
An alternate text file format (pfile) can be used for backwards compatibility with earlier Oracle
releases.

SPFILE
The spfile resides in a fixed location by default, typically the $ORACLE_HOME/dbs directory on a
**IX system. . (For Oracle10g Release 1 and older, and on Windows NT/2000 systems, the location
is %ORACLE_HOME%\database).

When using spfiles, dynamic) parameters can be modified with an ALTER SYSTEM command and are
therefore taken into account immediately. A SCOPE= argument to the ALTER SYSTEM command
accepts values of MEMORY, SPFILE or BOTH to indicate where changes are to be made.

PFILE
A static parameter file is a text file, usually copied from the Oracle sample provided and modified for
specific site requirements. Parameter files are also often called an initsid.ora file, or init file.
The init file is read during instance creation and startup; modifications to the parameters are not
refreshed until the next instance startup occurs.
If used, a PFILE is located in the same directory as the static file.
The default file name is initXXX.ora, where XXX is the system identifier (SID) assigned to the
database. Access to a PFILE is required from a remote system for startup of an instance.
The v$spparameter view contains current settings (Ch02ListParameters.sql).

V2: Page 36 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

Control File

Small binary file


Used at startup time and for operations
Should be mirrored
Damage requires database recovery

Control
File

ODBA10gDB-OCA-02-10 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Control File
A control file is established when a new database is created, to hold the name and status of all other
files (except the parameter file) in the system. The file is a binary format and must be examined using
Oracle SQL statements.
The control file also stores information used by the Recovery Manager (RMAN) utility. This utility
performs (semi)-automated backup and recovery operations and is discussed in Lessons 14 through
16.
The control file is opened when an instance is started and must remain accessible and writeable for the
entire duration of the instance lifespan. Updates to status information are applied regularly to the
control during operational access.
Loss of a control file can mean that a database restore and recovery may be needed typically, this
involves loss of valuable data from the database. To guard against such occurrences, Oracle
recommend that the control file is mirrored. If a single mirrored file fails, the database instance will
shut down immediately but recovery is possible with no data loss, other than currently executing
transactions.
From Oracle 9i onwards, a feature called OMF (Oracle Managed Files) was introduced. The OMF
facility provides default names and locations for Oracle files, simplifying the creation and
management of control, redo log and data files.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 37


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

The OMF name for a data file is ora_%u.ctl, where %u is a value to guarantee uniqueness.
To use OMF, the following optional initialisation parameters must be set:
DB_CREATE_FILE_DEST
DB_CREATE_ONLINE_LOG_DEST_1
DB_CREATE_ONLINE_LOG_DEST_1

OMF is discussed in more detail in Lesson 6.


Control file information is stored in the data dictionary view V$CONTROLFILE
(Ch02ListControlFiles.sql)

V2: Page 38 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

Data Files

Data files contain system or user data,


retaining contents when Oracle is stopped
Data files are grouped into tablespaces
Additional data files can be added
A file can be extended as necessary
Oracle 10g supports bigfiles up to 128TB

System Sysaux Users Undo Example


ODBA10gDB-OCA-02-11 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Data files
During database building, a database file (the SYSTEM file) is created to hold system information
(dictionary, system undo/rollback areas and more). For Oracle10g, a second required database file
(SYSAUX) is created to hold additional critical database information.
Each datafile belongs to a named database object called a tablespace. The tablespace unit is a
logical container for database objects. This structure allows physical files to be moved around the
system without affecting the logical structure of the database.
Other data files can be added to the system to hold different and additional information and logical
information (tables, indexes etc) can be mapped as required into the physical data files and parent
tablespaces.
Each data file has optional characteristics that permit the file to extend automatically when the file
runs out of space. Alternatively, a file can be manually extended by a DBA when required.
Datafiles are generally limited to a maximum size of under 2 GB by operating system restrictions.
There are few performance restrictions by creating maximum sized datafiles; however, administration,
backup and moving files is likely to be easier if the file sizes are limited to less than the maximum
possible size.
The OMF name for a data file is ora_%t_%u.dbf, where %t is the (truncated) tablespace name and
%uis a value to guarantee uniqueness.
Tablespace and file information is available from the dictionary view DBA_DATA_FILES
(V$DATAFILE) and DBA_TABLESPACES (V$TABLESPACE) respectively (Ch02ListDataFiles.sql).

Bigfiles
Oracle 10g provides an alternate storage format called a bigfile. A bigfile tablespace can only contain
a single datafile, that can be up to 128 terabytes in size (4 billion 32k data blocks).

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 39


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Data Dictionary

Tables / views listing database contents


Owned by SYS user, stored in SYSTEM
Public views provide deciphered versions
Table prefixes
DBA : all objects DBA accounts only
ALL : object accessible to the account
USER : objects owned by the account
V$ : privileged users only
Master list in dictionary and v$fixed_table
ODBA10gDB-OCA-02-12 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Data Dictionary
The data dictionary is a group of tables and associated views that contain and track control
information about the database contents. Any required information can be accessed by sufficiently
privileged user accounts from the dictionary.
The underlying (base) tables are owned by the reserved SYS account. The tables reside in the
SYSTEM tablespace.
Public views are provided to decipher the internal information stored in these tables.
A master list of dictionary tables is held in the view DICTIONARY.
The majority of the dictionary information is provided
SQL> DESCRIBE dba_data_files
in three separate forms. Tables with the following Name Null? Type
prefixes contain the stated information: ----------------- -------- -------------
FILE_NAME VARCHAR2(513)
FILE_ID NUMBER
TABLESPACE_NAME VARCHAR2(30)
DBA : all object types these tables are visible BYTES NUMBER
to DBA accounts only BLOCKS NUMBER
STATUS VARCHAR2(9)
RELATIVE_FNO NUMBER
ALL : objects accessible to the logged in account AUTOEXTENSIBLE VARCHAR2(3)
MAXBYTES NUMBER
USER : objects owned by the logged in account MAXBLOCKS NUMBER
INCREMENT_BY NUMBER
USER_BYTES NUMBER
USER_BLOCKS NUMBER
Additional tables are provided for privileged accounts ONLINE_STATUS VARCHAR2(7)

only, with a prefix of V$ - these tables (known as


dynamic performance tables) may reside either in SGA memory or in the control files.
A master list of dynamic performance tables is held in the view V$FIXED_TABLE.

V2: Page 40 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

Redo Log Files

Record of database changes


Maintained automatically by Oracle
Minimum of two files required to start
Files can be mirrored for more security
Optional (recommended) ARCH process
Damage requires database recovery

Log Buffer LGWR ARCH

ODBA10gDB-OCA-02-13 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Redo Log Files


The redo log file is used to automatically store details of changes applied to data blocks in the data
files. A database requires a minimum of two redo log files to open and operate.
The current log file is the file in use at present by the instance. When the current log is filled, the
instance performs a log switch and begins using the next log in the sequence. When all logs are filled,
the instance cycles back to the first log file.
Redo log contents are used for automatic recovery of damaged data files, by restoring a backup of a
data file and reapplying the log contents in sequence.
Additional redo log files can be added to the database, to extend the time period when recovery data is
available online.
Redo logs can be mirrored for additional security.
An optional ARCH process can be started to copy filled logs to one or more offline areas, for permanent
storage. If archiving is enabled, the database can be backed up in HOT mode i.e. whilst in use. The
combination of a hot (fuzzy) backup and the logs maintained since the backup started are used to
recover with no data loss in the event of a media problem.
If archiving is NOT enabled and this is NOT recommended for production systems the database
recovery will involved loss of all updates since the last backup in the event of a media failure.
The OMF name for a redo log file is ora_%g_%u.log, where %g is the redo log group number and %u
is a value to guarantee uniqueness.
The dictionary tables V$LOG and V$LOGFILE store information about log file groups and members
(Ch02ListLogFiles.sql).

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 41


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Password File

Small file used to store privileged users


Used to authenticate initial login
Contents encrypted for added security
Can be recreated with 'orapwd' command
Display via v$pwfile_users

ODBA10gDB-OCA-02-14 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Password File
An Oracle password file is an optional file, held outside the main database structure, and is used to
authenticate privileged users i.e. those that can start and stop the database instance.
A password file is created using the orapwd OS command, to hold a preset maximum number of
users. Default entries are added for the two Oracle standard users (SYS and SYSTEM). Further
entries can be added for additional users as required.
Without a password file, startup and shutdown is managed using operating system authentication i.e.
valid users are recognised by their OS login name. The precise method used varies therefore between
operating systems.
With a password file, startup and shutdown privilege is granted by a special login method discussed
later.

V2: Page 42 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

orapwd command

C:\>orapwd
Usage: orapwd file=<fname> password=<password> entries=<users> force=<y/n>

where
file - name of password file (mand),
password - password for SYS (mand),
entries - maximum number of distinct DBA and
force - whether to overwrite existing file (opt),
OPERs (opt),
There are no spaces around the equal-to (=) character.

C:\>

The V$PWFILE_USERS view shows the contents of the current password file (Ch02PWfile.sql).

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 43


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Logical / Physical Structures

Database

Tablespace Data file

Segment

Extent

Oracle block Data/OS block

ODBA10gDB-OCA-02-15 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Logical and Physical Structures

Each database consists of several physical data files, grouped into logical structures called
tablespaces. Data files and tablespaces are discussed in Lesson 6.

Database objects (tables, indexes) are positioned within a tablespace on creation. These and other
schema objects are discussed in Lesson 7

Space allocated to one object is termed the segment.

The original space allocated is called an extent.

Each extent is a series of contiguous Oracle data blocks allocated to the segment as a unit.

The data block is the unit of I/O for the Oracle instance.

V2: Page 44 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

Blocks

Primary and smallest unit of data storage


Size set initially by the DBA on creation
Multiple blocks allocated automatically
Block space dedicated to an object type
Space is reusable after deletion and can
include spare areas for object growth
Segment Extent 1 Block 1 Extent 2 Block 4
Block 2 Block 5
Block 3 Block 6

ODBA10gDB-OCA-02-16 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Blocks
The size of the Oracle data block is fixed at database creation time and ranges from a minimum of 2k
to an OS dependent maximum (usually 32k or 64k). The default block size is set by the
db_block_size parameter file entry and is used for the SYSTEM, SYSAUX and any temporary
tablespaces.
Careful consideration must be given to the choice of default Oracle data block size, since this is not
possible to be changed without significant downtime after database creation. The data block size
selected may also severely impact ongoing performance of the database.
A data block may be (and usually is) larger than the underlying operating system block size. The data
block is the unit of I/O and is also the unit in which the size of the buffer cache is specified in the
parameter file.
From Oracle 9i onwards, multiple data block sizes can be supported in a single database. Up to four
additional block sizes can be specified for special purposes. Larger block sizes favour data
warehousing systems; smaller block sizes improve performance for OLTP systems.
Each block is dedicated to a particular type of storage (named table, index etc).
For tables, each block can hold multiple rows. If a row is deleted, the space is marked as reusable and
may be repopulated by further insert operations on the same table. The released space is not
automatically reclaimed by Oracle for other purposes.
Blocks can be configured to include spare (unused) space to allow for growth to existing objects.
This is discussed in Lesson 7 Schema Objects.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 45


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Extents

Set of contiguous blocks for an object


INITIAL extent(s) defined on creation
NEXT size can be specified and altered
Can grow by a percentage rate
Excess space can be released

Segment Extent 1 Block 1 Extent 2 Block 4


Block 2 Block 5
Block 3 Block 6

ODBA10gDB-OCA-02-17 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Extents

An extent is a series of contiguous Oracle blocks allocated to a segment as a unit.

Extents are added automatically to a segment when it runs out of space. The DBA can manually add
extents on demand, subject to free tablespace extents being available.

Each object can have default storage parameters that control the growth rate (percentage) and
maximum allowed size of the object, subject to space being available in the containing tablespace.

V2: Page 46 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

Segments

Collection of extents for one object


Defined for an object during creation
Size can be limited by DBA or tablespace
Data segments Temporary segments
Index segments Undo segments

Segment Extent 1 Block 1 Extent 2 Block 4


Block 2 Block 5
Block 3 Block 6

ODBA10gDB-OCA-02-18 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Segments
The disk space used by a single object, including the area allocated on creation (the INITIAL extent)
and any subsequently allocated areas (the NEXT extents) makes up the SEGMENT for the object. A
segment resides within a single tablespace but can have allocated extents in any data file belonging to
the tablespace.
Data Segments
Each table in the database resides within a single segment, contained within one tablespace.
Partitioned tables can be spread across multiple segments, each of which can reside in separate
tablespaces.
Index Segments
Index (parallel structures to tables for fast access and sorting) reside in their own separate segments.
Index segments should be positioned in a separate tablespace to their associated table for maximising
performance and minimising contention. Index segments can also be partitioned if appropriate.
Temporary Segments
Temporary segments may be created for a SQL statement, when the space required for operations
such as sorting cannot fit inside allocated memory. In such cases, temporary segments are assigned in
dedicated areas for the duration of the statement.
Rollback/Undo Segments
Rollback/Undo segments hold images of database blocks prior to updates being applied, for use in the
event that a statement needs to be undone (rolled back). Rollback segments are created automatically
at database creation in the SYSTEM tablespace.
In Oracle 10g, undo segments, an enhanced mechanism, are used for regular transactions. Further
details are discussed in Lesson 8.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 47


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Memory Structures

SGA
Shared Buffer Java Pool
Pool Pool Log Buffer

Large Pool

SGA sized with 'sga_target' parameter


Automatically sized
Shared Pool Buffer Cache
Library Cache Large Pool
Dictionary Cache Buffer Cache
Manually sized
Log Buffer (log_buffer) Fixed SGA
Memory sized in units of granule
ODBA10gDB-OCA-02-19 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Memory Structures
Oracle reserved memory is allocated at instance startup time and released as the instance stops.

The main area is termed the SGA (shared global area) and consists of several distinct sub-areas.

Initial memory allocations are controlled by the SGA_TARGET parameter, which is set to the total
desired size of memory to be used by an instance. This dynamic parameter can be altered whilst an
instance is running. More information is discussed in Lesson 19, regarding the Memory Advisor and
Automatic Shared Memory Management.

The following areas are sized automatically within this target:


Buffer cache (DB_CACHE_SIZE)
Shared pool (SHARED_POOL_SIZE)
Large pool (LARGE_POOL_SIZE)
Java pool (JAVA_POOL_SIZE)

Memory in the SGA is managed in units of a granule. A granule is either 4MB (for total SGA size of
128MB or less), otherwise a granule is 16MB.

V2: Page 48 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

Shared Pool
SGA
Shared Buffer Java Pool
Pool Pool Log Buffer

Large Pool

Shared pool split into


Library cache (SQL and PL/SQL statements)
Dictionary Cache (Dictionary information)
Overflow results in content reload
Sized by shared_pool_size parameter

ODBA10gDB-OCA-02-20 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Shared Pool

The shared pool area is used to hold recently accessed SQL and PL/SQL statements and dictionary
information describing objects referenced by the cached statements.

The library cache holds both original and parsed SQL & PL/SQL statements. The shared area where
they are held includes the statement text, the compiled version of the statement (the parse tree) and the
execution plan (the break down of the steps to execute the statement block).

Statements already resident in memory can be shared under the control of the Oracle optimiser and
this enhances performance by reducing the requirement for re-parsing/re-compiling statements.

The dictionary cache holds the definitions of database objects used in conjunction with cached
statements. If the server cannot find the required information in the cache, the details are (re) loaded
from disk as required.

A single (shared_pool_size) parameter can be used to the size of this area the minimum
permitted value is 2MB and a more common production system value might start from around 50MB
or more.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 49


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Buffer Cache
SGA
Shared Buffer Java Pool
Pool Pool Log Buffer

Large Pool

Reserved space for data blocks


Filled by shadow process
Cleaned by DBWR process
Multiple cache areas can be used
Sized by db_cache_size parameter

ODBA10gDB-OCA-02-21 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Buffer Cache
The database buffer cache is the memory repository for holding database bocks and making them
available to server processes/user processes for presentation.
Server processes will load data blocks until the area is full, after which blocks may be overwritten if
clean. The DBWR process writes amended (dirty) blocks back to the database when space begins to
run out.
A least recently used (LRU) algorithm is used to identify blocks that can be aged out (written back)
when required.
For manual configuration, the size of the buffer cache is controlled by the parameter
DB_BLOCK_BUFFERS,which specifies how many blocks of DB_BLOCK_SIZE are to be used for this
memory area.

Multiple Block Sizes


TO use multiple block sizes within a single database / instance, separate caches must be created using
the DB_nk_CACHE_SIZE parameters (where n is the relevant block size).

Keep/Recycle Caches
Two additional reserved areas can be defined, the KEEP and RECYCLE cache. These areas have
the same block size as the main db_block_size value. Objects (tables and indexes) can then be set
to use these cache areas.

V2: Page 50 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

Redo Log Buffer


SGA
Shared Buffer Java Pool
Pool Pool Log Buffer

Large Pool

Memory area for change details


Written by shadow process
Emptied by LGWR
Smaller size means frequent writes
Sized by log_buffer parameter

ODBA10gDB-OCA-02-22 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Redo Log Buffer

The Redo Log Buffer is a memory area used by DBWR to record details of changes to data blocks by a
transaction.

The block address, the change position and the new value are recorded automatically.

The single log buffer is used by all concurrent transactions, therefore changes by multiple user
processes can be interleaved.

The buffer is emptied at intervals


when the space is 1/3 full
when a 3 second timeout occurs
when a transaction commits

The frequent writing of the contents from the log buffer to the log file by the LGWR helps to ensure
continued integrity of the database contents. If the log buffer becomes full, processing halts for all
users until the log writer frees sufficient space to continue.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 51


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Process Structure

SGA

LGWR
DBWR SMON
CKPT
PMON SERVER
Processes

Multiple processes manage instance SGA


UNIX uses processes, Windows uses threads
User processes may run on different host
Each shadow process has PGA memory
Dedicated servers : private assigned area
Shared servers : assigned from SGA

ODBA10gDB-OCA-02-23 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Process Structure

A running Oracle instance uses several processes to manage the user interaction. The physical
process structure varies by operating system.

Processes may be user or system processes. All system processes are executed on the same processor
as where the database resides any network communication is performed from the server processes to
the shadow process.

Windows (NT/2000) run all Oracle processes as threads within a single Windows process Windows
inter process communication (IPCS) is not ideally suited to the speed requirements of Oracle.

Most UNIX systems spawn separate physical OS processes, which can be uniquely identified using a
ps ef or ps aux OS command.

Each process has an assigned Program Global Area (PGA). This memory is either private or shared,
depending on the selected networking method.

User processes may run on the same or a different host from the database server processes. Further
details of Oracle Networking are discussed in Lesson 13.

V2: Page 52 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

Database Writer - DBWR


SGA

LGWR
DBWR SMON
CKPT
PMON SERVER
Processes

Cleans buffer cache regularly


Writes blocks optimally to data files
Co-operates with LGWR for integrity
Multiple processes can be started

ODBA10gDB-OCA-02-24 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Database Writer
The DBWR process is responsible for cleaning the buffer cache by writing dirty blocks back to the data
files. These blocks may include live data blocks or undo/rollback segment blocks.

DBWR is responsible for keeping a number of free blocks in the buffer cache memory to allow new data
to be read without delay. Server processes making changes in memory rely on space being available
DBWR runs in the background to avoid a performance penalty on the user front-end processes.

One (or more) DBWR processes are configured to batch up changes to the database files and write them
efficiently when one of a number of events occurs:

the number of dirty blocks in memory reaches a tunable limit


a process scans too many blocks before finding a clean block
a three second timeout occurs
a checkpoint occurs an event during which all dirty blocks are requested to be written back

Multiple database writer processes can be started using the db_writer_processes parameter.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 53


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Log Writer - LGWR


SGA

LGWR
DBWR SMON
CKPT
PMON SERVER
Processes

LGWR empties redo log buffer to log files


Critical for performance and integrity
Managed by SMON
Empties buffer at commit, if buffer is 1/3
full or every 3 seconds

ODBA10gDB-OCA-02-25 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Log Writer
LGWR writes from the redo log buffer to the log files on disk:

When a transaction commits


When the log buffer is 1/3 full
When there is 1MB or more of changes pending in the buffer
In synchronisation with DBWR

The actions of the log writer are essential for ensuring transaction integrity in the event of a recovery
becoming necessary.

If redo logs have been multiplexed, and one of the log files cannot be written, LGWR writes to other
members of the group and records an error in the system alert log.

If all online members of a log group are unavailable for writing, LGWR prevents further processing for
the entire instance until the fault is cleared.

V2: Page 54 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

System Monitor - SMON


SGA

LGWR
DBWR SMON
CKPT
PMON SERVER
Processes

SMON controls other processes


Enforces startup with consistent database,
by applying online redo log contents
Coalesces free space in dictionary
managed tablespaces if required

ODBA10gDB-OCA-02-26 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

System Monitor

SMON performs management functions during startup of the database instance, to automatically recover
a system in the event of an improper shutdown. Incomplete transactions are undone (rolled back) and
data in the log files that has not reached the data files is applied. The effect during this FAST
RECOVERY phase is to ensure that all committed transactions and only committed transactions are
recorded in the data files.

The procedure ensures that all data files represent a consistent view of the data and that this consistent
view/status is recorded in the control files.

Different versions of Oracle handle this process with varying degrees of speed to open the database.

After an instance is running, SMON is responsible for managing deallocated disk space by shadow
processes, by coalescing them into more usable space and for policing the other processes by
controlling their timeout intervals.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 55


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Process Monitor - PMON


SGA

LGWR
DBWR SMON
CKPT
PMON SERVER
Processes

PMON monitors other user processes


Cleans up dead memory if process fails
Roll back transaction in progress
Mark buffer cache blocks as reusable
Unlock rows reserved by failed transaction
Remove information from active process list

ODBA10gDB-OCA-02-27 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Process Monitor

The PMON process periodically confirms that all shadow processes are still active.

For dead processes, PMON performs a clean up on their behalf by unlocking updated blocks and rolling
back pending changes.

All effects and changes of a failed transaction are therefore removed from the instance.

V2: Page 56 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

Checkpoint - CKPT
SGA

LGWR
DBWR SMON
CKPT
PMON SERVER
Processes

Checkpoint writes modified data to files


Writes performed by DBWR
Modifies control files and datafile headers
to record checkpoint completion

ODBA10gDB-OCA-02-28 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Checkpoint

The checkpoint process CKPT manages writing of updated information back to data files.

Periodically, a checkpoint event occurs. During the event, CKPT coordinates with the database writer
to write changed data blocks from the buffer cache back to the data files.

This process also writes checkpoint control information to both the control files and individual data
file headers.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 57


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Server Process
SGA

LGWR
DBWR SMON
CKPT
PMON SERVER
Processes

Server processes SQL on behalf of users


Shared pool checked for same statement
Query is compiled into shared pool
Data blocks are read into buffer cache
Applies changes to buffer for updates
ODBA10gDB-OCA-02-29 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Server Process

As a user process connects to an instance, a server process is started and a Program Global Area
(PGA) is assigned.

Queries issued by the user are passed to the server process.

The shared pool is checked for the presence of the same statement. If the query does not exist in the
pool, the text of the statement is compiled into an execution plan and placed into a shared pool area.

The server statement processes the compiled plan and retrieves the required blocks into the buffer
cache.

If the user issues an update statement, the server process will make the required changes to blocks in
the buffer cache.

V2: Page 58 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

Processing a query

Issue statement SGA


Check SQL Shared Buffer Java Pool
Pool Pool
cache
Log Buffer

Large Pool
Locate blocks
Processes
Read into DBWR LGWR SMON
cache
PMON CKPT SERVER
Return copy to ARCH
user Instance

ODBA10gDB-OCA-02-30 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Processing a query
1. The user process issues a SQL statement to retrieve information.

2. The statement is passed to the shadow process, which confirms whether the same statement is
already in the library cache and parses/compiles a new version if required.

3. The shadow process then checks for the required blocks in memory This may also trigger
activity by DBWR to clean sufficient blocks for the new read operation.

4. If the required blocks are not in memory, the server initiates a read from the data file(s) into
the buffer cache.

5. A reference to the blocks is returned to the user process for presentation.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 59


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Processing a update

Read blocks if SGA


required Shared Buffer Java Pool
Pool Pool
Lock rows in
Log Buffer

Large Pool
buffer cache
Processes
Write change
DBWR LGWR SMON
vectors to log
PMON CKPT SERVER
Update undo
ARCH
Instance

ODBA10gDB-OCA-02-31 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Processing an Update
1. If the blocks to be changed are not already in memory, the shadow process initiates a read
(and possibly action by DBWR to clear sufficient space).

2. The shadow process locks the rows to be updated (inserted / deleted).

3. The change vectors are written to the redo log buffer.

4. Before image information is also written by the shadow process to separate rollback segment
blocks.

V2: Page 60 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

Processing a transaction

Server process SGA


writes commit Shared Buffer Java Pool
Pool Pool
LGWR writes
Log Buffer

Large Pool
log buffer to
disk Processes
DBWR LGWR SMON
User advised of
successful PMON CKPT SERVER

commit ARCH
Instance

ODBA10gDB-OCA-02-32 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Processing a transaction
1. When a commit statement is issued by a user process, the shadow process indicates that by
writing a commit flag to the redo log buffer.

2. LGWR empties the log buffer note that this may include information for other active
transactions that have not committed yet i.e. Oracle is performing a write ahead.

3. The user process receives a successful commit message after step 2 completes and
information has been physically written to disk.

4. The server process then releases all locks on updated resources and waits for another SQL
statement from the user process.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 61


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Summary

In this lesson, you should have learned


about:
The disk structure for Oracle
The process structure for Oracle
The memory structure for Oracle
How these co-operate to process SQL
queries, updates and transactions

ODBA10gDB-OCA-02-33 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Summary
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

V2: Page 62 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 63


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Practice 2 - Questions
1. The DB_BUFFER_SIZE parameter controls the size of the Oracle data block cache?
a. False
b. True
2. Extents for an object can reside in any data file assigned to the database.
a. True
b. False
3. Operating system editors can be used to change control files.
a. True
b. False
4. Archive processes are recommended for test systems to speed non-essential operations.
a. False
b. True
5. The buffer cache is a dynamically resizable area without restarting the database.
a. False
b. True
6. A large log buffer is better for system performance.
a. True
b. False
7. Archive destinations are limited to a single destination.
a. False
b. True
8. An update always writes data immediately to the data files.
a. True
b. False
9. The SMON process monitors the system for failed user processes.
a. False
b. True
10. A data file cannot grow once it has been created
a. True
b. False

V2: Page 64 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

This page intentionally left blank

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 65


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

Practice 2 - Answers
1. DB_BUFFER_SIZE parameter controls the size of the Oracle data block cache?
a. False the size is controlled by DB_CACHE_SIZE
a. True
2. Extents for an object can reside in any data file assigned to the database.
b. True although there are some restrictions on certain data file contents.
c. False
3. Operating system editors can be used to change control files.
a. True
b. False control files are in a binary format and must be altered using SQL.
4. Archive processes are recommended for test systems to speed non-essential operations.
a. False however, the ARCH process is recommended for production systems.
b. True
5. The buffer cache is a dynamically resizable area without restarting the database.
a. False
b. True the use of Automatic Shared Memory Management is preferred.
6. A large log buffer is better for system performance.
a. True
b. False a large log buffer will delay writing transaction information to the disk.
7. Archive destinations are limited to a single destination.
a. False up to ten archive destinations can be specified if required.
b. True
8. An update always writes data immediately to the data files.
a. True
b. False writes performed by the DBWR are delayed for an indeterminate period.
9. The SMON process monitors the system for failed user processes.
a. False this is performed by PMON. The SMON process has other purposes.
b. True
10. A data file cannot grow once it has been created
a. True
b. False a data file can be manually or automatically extended, or manually shrunk.

V2: Page 66 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 2 Oracle 10g Architecture Oracle 10g Database Associate

This page intentionally left blank

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 67


Oracle 10g Database Associate Lesson 2 Oracle 10g Architecture

This page intentionally left blank

V2: Page 68 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 3 Creating a Database Oracle 10g Database Associate

3
0
Creating a Database

ODBA10gDB-OCA--03-1 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

LESSON 3 CREATING A DATABASE


Lesson 3 demonstrates the creation of a new database using the Database Configuration Assistant
(DBCA). Additional features provided by the DBCA are also demonstrated.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 69


Oracle 10g Database Associate Lesson 3 Creating a Database

Objectives

After completing this lesson, you should


be able to do the following:
Use the Database Configuration Assistant
Make decisions for new databases
Configure a new database
Alter existing databases
Delete a database
Manage database templates

ODBA10gDB-OCA--03-2 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Objectives
This lesson demonstrates the use of the Database Configuration Assistant for the following tasks:
Creating a new database
Altering an existing database configuration
Deleting a database
Creating and managing database templates

V2: Page 70 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 3 Creating a Database Oracle 10g Database Associate

Starting DBCA

DBCA is a graphical tool for database


management
Use for creating, reconfiguring, deleting
databases and template management

ODBA10gDB-OCA--03-3 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Starting DBCA

The Database Configuration Assistant (DBCA) is started from a command line window using the
command dbca.

Alternatively, select Start > Programs > Oracle Home > Configuration and Migration Tools >
Database Configuration Assistant.

DBCA is used to create new databases, reconfigure a restricted set of database parameters, delete an
existing database and manage (add, modify or delete) templates for creating further new databases.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 71


Oracle 10g Database Associate Lesson 3 Creating a Database

DBCA Operations

ODBA10gDB-OCA--03-4 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

DBCA Operations
After an initial welcome screen, DBCA presents the following options in step 1:
Create a Database This option creates new databases, configures networking
options and starts the new database instance.
Configure Database Options Selected global system parameters can be changed on
existing databases using this options; examples include the
networking option used to connect to the database.
Delete a Database Shut down a running instance and remove all database
files permanently. Additional passwords are required for
this purpose.
Manage Templates Allows the creation, amendment and removal of the
templates upon which new database creation is based.
When multiple similar databases are to be created, the use
of templates provides a faster method for duplicating
database setup.
Templates can also be save for reuse after completing the
database creation process using DBCA.
Configure Automatic Automatic Storage Management (ASM) is an Oracle
Storage Management RAID equivalent mechanism for managing large
databases. ASM is not discussed in detail in this class.
For more information, please refer to the Oracle Database
Administrator class (Part 2).

V2: Page 72 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 3 Creating a Database Oracle 10g Database Associate

Select Database Template

ODBA10gDB-OCA--03-5 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Select Database Template


Step 2 of the database creation process presents a list of the available templates.
A DBCA template consists of a supplied set of XML configuration files and skeleton data files that
are copied and modified to create a new database.
The following standard templates are included on the Oracle installation media:

Custom Database This option offers the most flexibility when creating new
databases. Use this option for creating a new template from
scratch or where there are particular requirements for new
database configuration.
Data Warehouse Creates a new database which will be used for applications that
will need to support complex queries involving many tables
being joined for reporting and forecasting operations.
General Purpose Where the intended use of the database is not known, or if both
online transaction processing (OLTP) and data warehouse
applications are to be supported.
Transaction Processing For environments where 24/7 operations are required and there
will be a large number of short transactions, this option should
be used to configure an appropriate instance.

Once a database has been created, the DBA can fine-tune almost any template-derived parameter for
optimum speed and / or throughput.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 73


Oracle 10g Database Associate Lesson 3 Creating a Database

Database Identification

ODBA10gDB-OCA--03-6 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Database Identification
Step 3 of the DBCA requires the following database identification parameters:

Global Database Name A unique database name, consisting of the database SID appended
with a domain name. If you do not have a specific domain to use, the
default .world can be specified if required.

If this name needs to be changed in the future, a manual change to the


instance parameter file must be made and an ALTER DATABASE
command must be issued.

System Identifier (SID) The SID must be unique on the server upon which the instance resides.
The SID setting is used in the Oracle Networking files (discussed in
Lesson 13) to associate a connection string from a remote client with a
specific instance and set of database files.

V2: Page 74 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 3 Creating a Database Oracle 10g Database Associate

Management Options

ODBA10gDB-OCA--03-7 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Management Options
In Step 4 of the DBCA, the preferred option for managing the database by a DBA is selected. Two
mechanisms are provided by Oracle, Grid Control and Database Control.
Grid Control
Grid Control allows the management of multiple databases, together with other Oracle resources.
Grid Control must be pre-installed (if required) on a middle-tier server before creating a database
with the DBCA the Grid Contol and Grid Control Agent are provided on a separate CD in the
Oracle installation kit. If the DBCA detects an optional Grid Control Agent service running on the
server, the Grid Control option button is enabled and the required Agent Service to be used with
the database can be selected from the drop-down list. Further details of Grid Control are not
covered in this class.
Database Control
The Database Control can be used in a standalone environment without any additional software
installation. Database Control provides similar management features as Grid Control, for a single
database instance. This screen also permits the entry of e-mail information (server and destination
address) for automated status messages. Automatic daily backups to a Flash Recovery Area
(FRA) can also be enabled (discussed on page 79 and in Lessons 14 through 16).
To enable automated backups, you must specify a operating username and password for a member
of the ORA_DBA group or an Administrator/Superuser account.

Both Grid Control and Database Control management options provide a web-based management
mechanism for controlling a database.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 75


Oracle 10g Database Associate Lesson 3 Creating a Database

Database Credentials

ODBA10gDB-OCA--03-8 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Database Credentials
The DBCA wizard, step 5, allows the passwords for the initial administration accounts to be specified.

The following user accounts are created:

SYS Owner of the underlying data dictionary tables.


SYSTEM Owner of views on the data dictionary tables.
DBSNMP Account for use by the Management Agent to obtain statistics and performance
information from a running instance.
SYSMAN Default super-administrator account (SYSTEM or SYS accounts can also be used).

It is important to set secure passwords for all these critical accounts. During step 5 of the wizard, the
option to use the same default password can be selected.

A later step, invoked at the end of the new database creation procedure, can be used to set these and
other account passwords (discussed on page 89).

V2: Page 76 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 3 Creating a Database Oracle 10g Database Associate

Storage Options

ODBA10gDB-OCA--03-9 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Storage Options
Wizard Step 6, Storage Options, can be used to select the storage method to be used for data files,
control files and redo log files. Oracle 10g provides the following choices:
File System In this database, files will be created in the regular file system. Each
file will therefore have a user assigned name and location or, if Oracle
Managed Files (OMF) is used, files will be named and located
according to Oracle specified rules.
More details on the OMF mechanism is discussed on page 78 and in
Lesson 6.
Automatic Storage Automatic Storage Management is the Oracle RAID replacement
Management (ASM) mechanism. ASM is not recommended for Windows environments.
ASM requires a dedicated ASM instance, which is used to manage
large disk areas in which Oracle controls the software RAID
compatibility.
ASM is not discussed in detail in this class. For more information,
please refer to the Oracle Database Administrator class (Part 2).
Raw Devices For Oracle Real Application Cluster (ORAC) installations, where a
cluster file system is not available, raw devices can be used to bypass
the OS file system structure.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 77


Oracle 10g Database Associate Lesson 3 Creating a Database

Database File Locations

ODBA10gDB-OCA--03-10 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Database File Locations


Step 7 in the DBCA Creation Wizard allows a selection of locations for creating files.
Options provided include:

Locations from Template Uses locations specified in the selected template.


Common Location for Uses a single location, selected using the Browse button, for
All Files all files. Not recommended as a long-term production setting.
Oracle Managed Files Using parameter file entries (discussed in Lesson 6), the
database can be configured to automatically create files in
several named locations.
If OMF is selected, the Multiplex button can be selected to
enter alternate locations for the multiplexed copies of online
logs and control files.

The File Location Variables button displays a list of the pre-defined environment variables used by
the DBCA. The current settings of the preset variables cannot be altered at this stage, but additional
variables can be specified to override and extend the available variables if required.
In all cases, a further wizard step allows selective overriding of the options selected here see page
85.

V2: Page 78 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 3 Creating a Database Oracle 10g Database Associate

Recovery Configuration

ODBA10gDB-OCA--03-11 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Recovery Configuration
Wizard Step 8 allows specification of a range of recovery options, for use in the event of catastrophic
database failure.

Flash Recovery Area


The Oracle 10g Flash Recovery Area (FRA) is a dedicated area of disk, preferably on a separate disk
device, for use by the Recovery Manager (RMAN) tool to hold backups of operational files.
Selection of this option is required if automatic backups are enabled in step 4 (see page 75).
To configure this area, specify a file system location for the FRA and a maximum size. The directory
selected should be large enough to hold at least two copies of all data files, as well as having
additional space for incremental backups, control file copies, parameter file copies and archived log
copies.

Archiving
The optional archiving mechanism runs additional processes to copy (archive) the contents of filled
log files during production running. The archived logs are required in the event of a media failure or
user error that necessitates recovery of part of the database content.
Archiving is strongly recommended for use in production database systems. This feature should be
enabled once the initial database has been built and is ready for production use. If the feature is
enabled during database creation, the time and disk space required to create the database will be
extended without good reason.
If archiving is enabled and flash recovery disabled, the Edit Archive Mode Parameters button can be
used to change the default archive log name and location(s).
Archiving is described in detail in Lessons 14 through 16.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 79


Oracle 10g Database Associate Lesson 3 Creating a Database

Database Content

ODBA10gDB-OCA--03-12 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Database Content
The Oracle installation CD contains sample schemas for demonstrating various mechanisms using
SQL and other features in Oracle. These schemas contain the data used in the Oracle manuals and
sundry tutorials.
For production systems, the sample data is not generally required and therefore should not be selected.
If the Sample Schema checkbox is checked, approximately 130MB of additional space is required to
load the sample data.
The Custom Scripts tab can be selected to run additional user-written scripts during database
creation. Browse to the location of the required script and add to the Script Name box if required.

V2: Page 80 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 3 Creating a Database Oracle 10g Database Associate

Initialisation Parameters - Memory

ODBA10gDB-OCA--03-13 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Initialisation Parameters Memory


Key initialisation parameters can be adjusted to fine-tune the database being created. The parameters
that can be changed are split into several separate areas.
On the Memory tab, selection of Typical allows a specification of the percentage of memory to be
assigned to Oracle. This selection provides fully automated memory allocation without DBA
intervention.
The Custom selection allows two sub-modes: Automatic and Manual.
For Custom-Automatic, the total sizes of the Shared Global Area (SGA) and Program Global Area
(PGA) can be specified.
For Custom-Manual, the detail of the SGA size can be specified by setting the Shared Pool, Buffer
Cache, Java Pool, Large Pool and PGA sizes.
For experienced DBAs, all parameters can be refined once the database instance is established and in
production use. This allows the fine-tuning of a system, in conjunction with automated Oracle
Advisors (see Lessons 18 and 19).

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 81


Oracle 10g Database Associate Lesson 3 Creating a Database

Initialisation Parameters - Sizing

ODBA10gDB-OCA--03-14 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Initialisation Parameters Sizing


The Initialisation Parameters, Sizing tab can be used to set two critical parameters.

Block Size
The Block Size value is used for SYSTEM, SYSAUX, UNDO and TEMP tablespaces. The default selected
(8k) is suitable for the majority of Oracle databases. When using any of the predefined templates, this
value cannot be changed.
Additional tablespaces can be created with different (larger) block sizes for special purposes (see
Lesson 6).

Processes
The Processes value specifies the maximum number of Oracle processes that can connect to the
database. Allowances must be made for background processes and parallel execution processes in
addition to regular user processes.
This parameter can be tuned once the database instance is operational.

V2: Page 82 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 3 Creating a Database Oracle 10g Database Associate

Initialisation Parameters Character Sets

ODBA10gDB-OCA--03-15 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Initialisation Parameters Character Sets


Each Oracle database has a number of Globalisation or National Language Setting (NLS) parameters,
to control storage of characters and date formats. Globalisation parameters include:
Database Character Set Used for storing CHAR data in CHAR, VARCHAR2, CLOB and LONG
column types. This character set is also used for database object
names and stored PL/SQL and Java code. The OS related default is
usually appropriate.
National Character Set An alternate character set for storing NCHAR, NVARCHAR2 and NCLOB
column types. Select an appropriate value from the list if required.
Default Language The default language setting determines how the database supports
locale-sensitive information such as the following: Day / month
names and their abbreviations Symbols for equivalent expressions
for A.M., P.M., A.D., and B.C. Default sorting sequence for
character data when the ORDER BY SQL clause is specified Writing
direction (left or right) Affirmative and negative response strings
(for example, YES and NO)
Default Date Format Different conventions for displaying the hour, day, month, and year
can be handled in local formats. For example, in the United
Kingdom, the date is displayed using the DD-MON-YYYY format,
while the USA commonly uses the MM-DD-YYYY format.

For more information on choosing a National Character Set, see the Oracle Database Globalization
Support Guide

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 83


Oracle 10g Database Associate Lesson 3 Creating a Database

Initialisation Parameters Connection Mode

ODBA10gDB-OCA--03-16 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Initialisation Parameters Connection Mode


Oracle offers two basic connection modes between client processes and the database instance.

Dedicated Server Mode Connects using a separate server process for each client; this
mode is appropriate for long running data warehousing
transactions and when the total number of connections is
anticipated to be low.
Shared Server Mode Previously called Multi-threaded server (MTS), this mode
shares server processes between multiple clients. Shared
servers are appropriate for OLTP applications, web-connected
databases and similar systems with a relatively high
connection level.

More details are discussed in Lesson 13 Network Administration.

Initialisation Parameters All


On any of the Initialisation Parameters screen, the All Initialization Parameters button can be used
to display a list of the parameters which can be edited for fine-tuning purposes. The list is split into
Basic and Advanced parameters. More information regarding each value can be displayed using
the Show Description button.
Almost all parameters can be modified once the instance is established. Relevant details are discussed
later in this course.

V2: Page 84 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 3 Creating a Database Oracle 10g Database Associate

Initialisation Parameters Database Storage

ODBA10gDB-OCA--03-17 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Initialisation Parameters Database Storage


Step 11 in the DBCA wizard allows the file locations specified in step 7 (page 78) to be reviewed and
fine-tuned. This option is not enabled for adding data files, control files or undo files if a
preconfigured template was selected initially.
In particular, this screen can be used to select multiplexing locations for both control files and redo
log files.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 85


Oracle 10g Database Associate Lesson 3 Creating a Database

Creation Options

ODBA10gDB-OCA--03-18 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Creation Options
In Step 12 of the DBCA wizard, the following operations are available:

Create Database Use the entered information in the Wizard to create a new
database. The summary dialog illustrated on the next page
shows the options selected.
Save as a Database Template Saves the entered information in the form of a new template,
which will be added to the list of available templates provided
by Oracle.
A new name and description should be entered to identify the
new template.
Generate Database Creation Saves the entered information as a set of new SQL scripts in a
Scripts user-selectable location.
If this option is chosen, the scripts can be executed using
SQL*Plus (see lesson 4). Networking configuration, Oracle
services for Windows NT/2000/XP and ORATAB entries for
Solaris will need to be configured manually following
database creation.

V2: Page 86 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 3 Creating a Database Oracle 10g Database Associate

Confirmation

ODBA10gDB-OCA--03-19 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Confirmation
Prior to new database creation, an summary page as shown on the slide is presented. This information
can be saved in the form of an HTML file, in a user-selectable location. The saved page should be
printed and filed for future reference.
Select the OK button on this confirmation screen to begin the database creation process.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 87


Oracle 10g Database Associate Lesson 3 Creating a Database

Creating the Database

ODBA10gDB-OCA--03-20 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Creating the Database


During database creation, several progress screens are displayed.
An Oracle-provided set of scripts is executed to create the database. Any custom scripts specified in
the DBCA wizard are then executed.
Networking files are also configured according to the entered parameters
At the end of the creation process, the instance is left in a started state and is then usable immediately.
A summary screen that identifies critical URLs and log file locations is displayed. The log files
should be printed and filed for future reference. The storage location is

<ORACLE_BASE>\product\10.2.0\<ORACLE_HOME>\cfgtoollogs\dbca\<SID>

Further information regarding account and password status is also displayed.


The Password Management button can be used to display a list of accounts see next page.

V2: Page 88 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 3 Creating a Database Oracle 10g Database Associate

Password Management

ODBA10gDB-OCA--03-21 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Password Management
Following successful database creation, the Password Management button can be used from the
DBCA summary screen to display a list of user account names.
For each account, the password can be set individually and required accounts can be unlocked to
allow login using the account details.
More information is discussed in later lessons in this class.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 89


Oracle 10g Database Associate Lesson 3 Creating a Database

Configure Database Options

ODBA10gDB-OCA--03-22 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Configure Database Options


For existing and running databases, the Configure Database Options radio button can be used to
display a list of databases. Select the database to be altered from the displayed list and click Next.
Installed features that can be configured by the wizard are displayed. For features that were not
installed in the database on creation, the appropriate option is displayed greyed out.
Oracle OLAP OLAP (Online Analytical Processing) provides tools for developing and
deploying internet-based business intelligence applications
Oracle Spatial Oracle Spatial is primarily used for Geographical Information Systems
(GIS) to implement geo-reference and solve queries such as how is
something related to a specific location.
Oracle Data Mining Enables data mining inside the database for performance and scalability.
Oracle Text Oracle Text adds support that enables Oracle to manage multimedia content,
both for Internet and traditional applications that need access to image,
audio, video, text, and location information.
Oracle Ultra Search Oracle Ultra Search is a text management solution that enables
organizations to access text information sources as quickly and easily as
structured data.
Oracle Label Oracle Label Security is based on labeling concepts used by government
Security and defense organizations to protect sensitive information and provide data
separation.
Sample Schemas Five sample schemas may be installed for testing specific database features
with realistic data.
Enterprise Manager The Enterprise Manager Repository schema is used by Oracle Enterprise
Repository Manager to store management data about your database.
Oracle HTML DB The Oracle HTML DB option enables you to install and configure the
HTML DB for the new database that you have created.

V2: Page 90 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 3 Creating a Database Oracle 10g Database Associate

Delete a Database

ODBA10gDB-OCA--03-23 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Delete a Database
For existing and running databases, the Delete a Database radio button can be used to display a list
of databases. Select the database instance to be deleted and click Next. Respond to the alert dialog
and to any username/password prompts that are displayes.
You must specify a privileged DBA connection in order to delete a database.
Note that this operation is NOT easily reversible.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 91


Oracle 10g Database Associate Lesson 3 Creating a Database

Templates

ODBA10gDB-OCA--03-24 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Templates
Database templates are stored XML scripts that can be used for creating new databases.
DBCA is installed with three pre-defined templates and the ability to create a new custom template
from scratch.
Templates can be created as below:
From an existing Copy and modify an existing template.
template
From an existing Create a template from an existing database but do not copy the content,
database (structure only) just the physical structure. User schemas are not replicated.
From an existing Create a template from an existing database that duplicates (clones) the
database (structure and entire database structure and content.
data)
See page 93 for more details about creating new templates.

Deleting a Template
Unwanted or obsolete templates can be deleted. This includes the Oracle supplied database templates.

V2: Page 92 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 3 Creating a Database Oracle 10g Database Associate

Template Properties

ODBA10gDB-OCA--03-25 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Template Properties
By selecting a template creation option from the Template Management screen, relevant DBCA
wizard pages are displayed to allow the template or database selected as the base for the new template
are displayed.
Any required template property can be modified by entering the required value in the wizard.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 93


Oracle 10g Database Associate Lesson 3 Creating a Database

Template Confirmation

ODBA10gDB-OCA--03-26 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Template Confirmation
Once the required options have been modified, click the Finish button to save the modified template
and generate the starter database files.

V2: Page 94 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 3 Creating a Database Oracle 10g Database Associate

Summary

In this lesson, you should have learned


about:
Use the Database Configuration Assistant
Make decisions for new databases
Configure a new database
Alter existing databases
Delete a database
Manage database templates

ODBA10gDB-OCA--03-27 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Summary
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 95


Oracle 10g Database Associate Lesson 3 Creating a Database

Practice 3

Using Database Configuration Assistant,


create a database called 'DB2'.
Configure the database as general
purpose using file system storage.
Do not use archiving for the new database
The majority of defaults will be acceptable
Your instructor will provide further details
and instructions during the practice.

ODBA10gDB-OCA--03-28 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Practice 3
In this practice, you should create a second database called DB2
Configure the new database for general purpose use and select the File System option for locating
data, control and redo log files.
The majority of other offered defaults will be acceptable.
Your instructor will provide further details and instructions that are appropriate for your training
environment during the practice.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

V2: Page 96 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 4 Database Interfaces Oracle 10g Database Associate

4
0
Database Interfaces

ODBA10gDB-OCA--04-1 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

LESSON 4 DATABASE INTERFACES


Lesson 4 examines database interfaces, including SQL*Plus and iSQL*Plus, which can be used for
issuing SQL and PL/SQL commands interactively.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 97


Oracle 10g Database Associate Lesson 4 Database Interfaces

Objectives

After completing this lesson, you should


be able to :
Understand basic database storage concepts
Use SQL*Plus and iSQL*Plus to access the
database and examine database structures
Use SQL statements to manage and modify
database content and structure
Describe database transactions
Run Database Control Enterprise Manager

ODBA10gDB-OCA--04-2 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Objectives
This lesson examines the interactive SQL interfaces provided with the Oracle 10g database. Concepts
demonstrated include:
Using SQL*Plus and iSQL*Plus to access the database and examine database structures.
Basic SQL statements for retrieving and modifying database content
A brief overview of commands used to manage structures and control transactions.
The highlights of using Oracle Enterprise Manager for DBA tasks is discussed.

V2: Page 98 Copyright 2007 Jeremy Russell & Associates Ltd.


Lesson 4 Database Interfaces Oracle 10g Database Associate

Relational Database Terminology


COLUMN
COLUMN
ATTRIBUTE
ATTRIBUTE

22
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
ROW
ROW
7369 SMITH CLERK 7902 17-DEC-80 800 800 20

11 7499 ALLEN SALESMAN 7698 20-FEB-81 33 1600 300 30


7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 NULL
NULL
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 55 10
7788 SCOTT ANALYST 7566 19-APR-87 5000 20
7839 KING PRESIDENT 17-NOV-81 1500 10
7844 TURNER SALESMAN 7698 08-SEP-81 1100 0 30
7876 ADAMS CLERK 7788 23-MAY-87 950 20
~ ~ ~ ~ ~ ~ ~ ~
44 KEY
KEY

ODBA10gDB-OCA--04-3 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Relational Database Table


Each table within a relational database is a two-dimensional structure as illustrated above, holding
information relating to a single type of object (entity) being stored in the database. The table structure
can be further broken down into sub-components as listed here.
1. ROW
A row within a database table contains information about a single instance of the entity being stored.
Roughly equivalent to a record in a non-relational structure.
2. COLUMN
A column contains one item of data for each of the rows stored in the table. The column is always
identified by name and contains a defined data type; all instances of the column will contain the same
type of data.
3. ATTRIBUTE
The intersection of a row and a column is known as an attribute.
4. KEY COLUMN
One or more columns may be designated as holding identifying information for each row. A primary
key column, such as the row ID, will contain a unique and therefore different value for each of the
stored rows. Secondary identifying columns (e.g. name) are also supported. Note that these are NOT
the same as indexed columns (discussed later).
5. NULL COLUMN
A column may not contain a value, in which case it is said to be NULL. Note that a null valued
column is not the same as a numeric zero or a text column containing spaces.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 99


Oracle 10g Database Associate Lesson 4 Database Interfaces

Interfaces - SQL*Plus

Character and windows versions

ODBA10gDB-OCA--04-4 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Interfaces SQL*Plus
Oracle 10g is delivered with two versions of the SQL*Plus tool

Command Line Version


For all operating systems, a command line version of SQL*Plus is provided.
To execute this tool on Windows, open a command window by clicking the Start button, choosing
Run and entering cmd. When the command window is displayed, enter the command sqlplus
and press Enter.
To execute this tool on UNIX/Linux systems, enter the command sqlplus at a shell prompt.

Windows Version
For Windows operating systems only, a GUI version of SQL*Plus is provided. This can be installed
on Windows systems from a separate Oracle Client CD, to enable remote access to UNIX/Linux
database. The Windows system will need to be configured for network access to the remote database.
This is discussed in a later lesson.

All versions of SQL*Plus accept the same command syntax, both for SQL commands to be executed
against the database and for control commands to modify the runtime environment.

V2: Page 100 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 4 Database Interfaces Oracle 10g Database Associate

Interfaces - iSQL*Plus

iSQL*Plus runs within your browser

ODBA10gDB-OCA--04-5 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Interfaces iSQL*Plus
Oracle 10g is also delivered with a browser based version of SQL*Plus, called iSQL*Plus.
To execute iSQL*Plus, open a browser and enter the URL provided during database creation into the
browser address bar. The default address is:

http://localhost:5560/isqlplus/

Note that the port number (5560 as above) may vary depending upon other databases and TCP/IP
services running on the database server.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 101
Oracle 10g Database Associate Lesson 4 Database Interfaces

Connecting to a Database

Username
Password
Connect Identifier

ODBA10gDB-OCA--04-6 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Connecting to a Database
Several items of information are required to connect to a database:

User name A valid account that has been created in the database, with sufficient
permission to log in to the system.

Password The password associated with the account name.

Host String / Identification string used to locate the database server and instance.
Connect Identifier For remote access, this string needs to be entered into an Oracle
Networking configuration file, as discussed later in this class.

For connecting to an Oracle instance using a command line tool, the account name, password and host
string are specified as illustrated below:

user/password@host_string

scott/tiger@orcl

For the GUI tools, enter the required information on the displayed screen dialog. Click the OK or
Login button to continue.

V2: Page 102 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 4 Database Interfaces Oracle 10g Database Associate

Database Retrieval Examples

The SELECT statement


SELECT
SELECT **
FROM
FROM emp;
emp;

SELECT
SELECT empno,
empno, ename,
ename, job
job
FROM
FROM emp;
emp;

SELECT
SELECT ** FROM
FROM emp
emp
WHERE
WHERE job
job == 'SALESMAN';
'SALESMAN';

SELECT
SELECT ** FROM
FROM members
members
WHERE
WHERE job
job == 'SALESMAN'
'SALESMAN' AND
AND hiredate
hiredate >> '01-JAN-85'
'01-JAN-85'
ORDER
ORDER BY
BY hiredate
hiredate DESC;
DESC;

ODBA10gDB-OCA--04-7 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Database Retrieval Examples


A SELECT statement retrieves information from the database. Each statement requires a column list
and at least one table to be referenced. All lists, including the column list, are separated by commas.
A special reference used in the column list clause, the * character, indicates that all columns from
the referenced table are to be retrieved. For example

SQL> SELECT * FROM scott.emp;

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO


----- ---------- --------- ------- --------- ------- ------- ----------
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10

14 rows selected.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 103
Oracle 10g Database Associate Lesson 4 Database Interfaces

SELECT statement

The SELECT statement syntax


SELECT
SELECT <columnList
<columnList || *>
*>
FROM
FROM <tableList>
<tableList>
[WHERE
[WHERE <searchCondition>]
<searchCondition>]
[GROUP
[GROUP BY
BY <groupColumns>]
<groupColumns>]
[HAVING
[HAVING <groupCondition>]
<groupCondition>]
[ORDER
[ORDER BY
BY <sortColumnList>]
<sortColumnList>]

Example statement
SELECT
SELECT empno,
empno, ename,
ename, job
job
FROM
FROM emp
emp
ORDER
ORDER BY
BY ename
ename

ODBA10gDB-OCA--04-8 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Database Credentials
SELECT <columnList | *> Required
lists one or more columns to be retrieved.
FROM <tableList> Required
where the information is to be retrieved from
(SQL isnt *that* smart!)
[WHERE <searchCondition>] Optional
controls which rows are retrieved. If the clause is omitted,
then all rows from the named table are returned.
[GROUP BY <groupColumns>] Optional
request that SQL summarises all rows having the same
information in the grouped columns.
[HAVING <groupCondition>] Optional
restricts the groups to be displayed.
[ORDER BY <sortColumnList>] Optional
requests a list of results in a specified order. If omitted, results
are presented in no particular sequence. The same statement
may produce different sequences if executed a second time; the
sequence depends on external factors.
.

V2: Page 104 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 4 Database Interfaces Oracle 10g Database Associate

Accessing Information

Columns and tables are referenced by name

Presentation is controlled by the program


issuing the SQL statement

ODBA10gDB-OCA--04-9 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Accessing Information
When a SELECT statement is processed, the database server will retrieve the required rows and
columns and return these to the interface process for presentation.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 105
Oracle 10g Database Associate Lesson 4 Database Interfaces

Logical Table Structures

SQL*Plus and iSQL*Plus DESCribe


command shows table structure
Accessible table names are shown in
data dictionary
Dictionary is created and maintained
automatically for all databases
SELECT
SELECT owner,
owner, table_name
table_name
FROM
FROM all_tables
all_tables

ODBA10gDB-OCA--04-10 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Logical Table Structures

In common with other relational database products, the Oracle Server creates and manages a data
dictionary, consisting of a number of read-only tables that describe the content and structure of the
database.

The dictionary can be read using standard SQL SELECT statements.

Tables that are accessible to the current user can be further examined using the SQL*Plus DESCRIBE
statement. As with other SQL*Plus commands, this keyword can be abbreviated to the short version
DESC.

SQL> DESCRIBE scott.emp


Name Null? Type
------------------------- -------- ----------------------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)

V2: Page 106 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 4 Database Interfaces Oracle 10g Database Associate

Choosing Columns

The PROJECT operation


EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO

7369 SMITH CLERK 7902 17-DEC-80 800 800 20


7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
~ ~ ~ ~ ~ ~ ~ ~

SELECT
SELECT empno,
empno, ename,
ename, job
job
FROM
FROM emp;
emp;

EMPNO ENAME JOB


7369 SMITH CLERK
7499 ALLEN SALESMAN
7521 WARD SALESMAN
~ ~ ~

ODBA10gDB-OCA--04-11 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Choosing Columns

In the SELECT clause, you may include a list of the column names you want to retrieve, separated by
comma's.

An entire set of columns from the table can be retrieved by using the syntax '*' in place of the column
list.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 107
Oracle 10g Database Associate Lesson 4 Database Interfaces

Choosing Rows

The SELECT operation


EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
~ ~ ~ ~ ~ ~ ~ ~

SELECT
SELECT ** FROM
FROM emp
emp
WHERE
WHERE job
job == 'SALESMAN';
'SALESMAN';

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO


7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
~ ~ ~ ~ ~ ~ ~ ~

ODBA10gDB-OCA--04-12 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Choosing Rows
In the optional WHERE clause, you may specify a list of conditions that each row in the listed table.
WHERE clause conditions can use a variety of relational operators, as well as LIKE (for wildcards),
BETWEEN (for range searchs) and IN (for list searches).

An entire set of rows from the table can be retrieved simply by omitting the WHERE clause.

V2: Page 108 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 4 Database Interfaces Oracle 10g Database Associate

Joining tables

The JOIN operation


EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO DEPTNO DNAME
7369 SMITH CLERK 7902 17-DEC-80 800 800 20 10 ACCOUNTING
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 20 RESEARCH
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 30 SALES
~ ~ ~ ~ ~ ~ ~ ~ ~ ~

SELECT
SELECT ename,
ename, dname
dname
FROM
FROM emp,
emp, dept
dept
WHERE
WHERE emp.deptno
emp.deptno == dept.deptno;
dept.deptno;

ENAME DNAME
SMITH RESEARCH
ALLEN SALES
WARD SALES
~ ~

ODBA10gDB-OCA--04-13 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Joining Tables
Tables in the database can be joined - linked together to retrieve information from more than one table
simultaneously.
A database designer will create tables to conform with the 'golden rules' of database design,
normalisation, according to the original design goals of the RDBMS technology.
The rule of 1NF (First Normal Form) encourages the database designer to remove repeated (multiple)
values to a second table. This provides more effective storage with an additional cost to retrieve the
original information.
The trade off between reduced storage needs and additional processing power to retrieve the
information is acceptable.
The entire set of columns and rows from the joined tables can be retrieved simply by omitting the
WHERE clause that links thetables together. Typically, this is neither logical nor desirable. A JOIN
CONDITION should be added to the WHERE clause to specify how the tables actually relate (join).
Oracle 10g supports other join options that conform to the ANSI SQL:99 standard. For more details,
please refer to the Oracle documentation.
.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 109
Oracle 10g Database Associate Lesson 4 Database Interfaces

Data Manipulation Language

Data Manipulation (DML) statements


allow data to be entered, modified and
removed in the database
DML statements run inside transactions,
which are saved or cancelled as a unit
Transactions are critical in managing
concurrent updates and data integrity

ODBA10gDB-OCA--04-14 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Data Manipulation Language


DML statements allow database information to be entered (INSERT statement), modified (UPDATE
statement) and removed (DELETE statement).
Unlike retrieval (SELECT) statements, DML statements that modify information in the database are
automatically wrapped inside a transaction. Modified rows are locked against viewing or further
modification by other users for the duration of the transaction.
Each transaction must be confirmed or cancelled by the operator (or implicitly) before the modified
data is available to other users.

V2: Page 110 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 4 Database Interfaces Oracle 10g Database Associate

DML Statements - Insert

INSERT (new rows into table)


Simple insert
INSERT
INSERT INTO
INTO dept
dept VALUES
VALUES (50,
(50, 'ISD',
'ISD', 'OXFORD')
'OXFORD')

Insert Select
INSERT
INSERT INTO
INTO research_employees
research_employees
SELECT
SELECT ** FROM
FROM emp
emp WHERE
WHERE deptno
deptno == 20
20

Multi-table insert
INSERT
INSERT ALL
ALL
WHEN
WHEN job
job == 'MANAGER'
'MANAGER' THEN
THEN
INTO empman
INTO empman
WHEN
WHEN job
job == 'SALESMAN'
'SALESMAN' THEN
THEN
INTO
INTO empsales
empsales VALUES
VALUES (empno,
(empno, ename,
ename, sal
sal ++ comm)
comm)

ODBA10gDB-OCA--04-15 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

DML Statements Insert


To insert a new row into a table, the INSERT command is used.
Two common formats of the simple INSERT can be used:

INSERT INTO [schema.]tablename VALUES (value1, value2 ...)

INSERT INTO [schema.]tablename (column1, column2, ...)


VALUES (value1, value2, ...)

Rows can be duplicated using the format below:

INSERT INTO [schema.]newtable SELECT ...

A multi-table insert can be carried out using the INSERT ALL statement. Rows from a base table can
be inserted into several tables conditionally.
Several other variations of this command are possible these include an unconditional INSERT, a
conditional FIRST INSERT and a pivoting INSERT.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 111
Oracle 10g Database Associate Lesson 4 Database Interfaces

DML Statements - Update

UPDATE (existing rows in table)


Simple update
UPDATE
UPDATE emp
emp
SET
SET sal
sal == sal
sal ** 1.1
1.1 WHERE
WHERE job
job <>
<> 'PRESIDENT'
'PRESIDENT'

Update merge
MERGE
MERGE INTO
INTO job_history
job_history JJ
USING
USING emp_history
emp_history EE ON
ON (( J.empno
J.empno == E.empno)
E.empno)
WHEN
WHEN MATCHED
MATCHED THEN
THEN
UPDATE
UPDATE SET
SET avsal
avsal == avsal
avsal ++ e.sal,
e.sal, cnt
cnt == cnt
cnt ++ 11
WHEN
WHEN NOT
NOT MATCHED
MATCHED
INSERT
INSERT VALUES
VALUES (empno,
(empno, avsal,
avsal, 1)
1)

ODBA10gDB-OCA--04-16 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

DML Statements Update


For existing rows, data can be changed using the UPDATE statement.
The basic syntax is illustrated below:

UPDATE [schema.]table
SET columnName = value [, columnName = value, ...]
[WHERE condition]

Multiple columns can be updated in a single statement.


If the WHERE clause is omitted, every row in the table is updated.

The Oracle MERGE statement can also be used as shown below. This command can either insert rows
(where no matching row exists in the target table) or update existing rows (where a match is found).

MERGE INTO job_history J


USING emp_history E ON ( J.empno = E.empno)
WHEN MATCHED THEN
UPDATE SET avsal = avsal + e.sal, cnt = cnt + 1
WHEN NOT MATCHED
INSERT VALUES (empno, avsal, 1)

Further details on the MERGE statement are described in Lesson 9 Data Management.

V2: Page 112 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 4 Database Interfaces Oracle 10g Database Associate

DML Statements - Delete

DELETE (rows from table)


DELETE
DELETE FROM
FROM dept
dept
WHERE
WHERE deptno
deptno NOT
NOT IN
IN (SELECT
(SELECT deptno
deptno FROM
FROM emp)
emp)

TRUNCATE TABLE
Single statement transaction
TRUNCATE
TRUNCATE TABLE
TABLE job_history
job_history REUSE
REUSE STORAGE
STORAGE

ODBA10gDB-OCA--04-17 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

DML Statements - Delete


To remove rows from a table, the DELETE command can be used to selectively delete the information.
The basic syntax is illustrated below:

DELETE [FROM] [schema.]table_name


[WHERE condition]

.
If the WHERE clause is omitted, every row in the table is deleted.

DML Statements - Truncate


The TRUNCATE command can be used to unselectively delete every row in a table. This command is
NOT run inside a transaction and is therefore difficult to undo if a mistake is made.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 113
Oracle 10g Database Associate Lesson 4 Database Interfaces

Data Control Language

DCL statements manage transactions


A transaction is a set of DML statements
All statements form one logical work unit
All statements must complete or cancel
Inserted / modified information is locked
and private until transaction completes
Changes confirmed with COMMIT or
cancelled with ROLLBACK

ODBA10gDB-OCA--04-18 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Data Control Language


The Data Control Language (DCL) statements are used to manage database transactions.

A transaction is equivalent to a business unit of work all statements within a transaction must
complete together or be cancelled as a unit.

Oracle client processes are always operating within a transaction context. A new transaction is started
as a client process is run. Terminating a transaction automatically begins a new transaction.

Within a transaction, any modified rows are private to the transaction until it ends successfully.

DDL (CREATE, ALTER, DROP and TRUNCATE) statements implicitly commit any in-progress
transactions.

V2: Page 114 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 4 Database Interfaces Oracle 10g Database Associate

DCL Statements COMMIT/ROLLBACK

COMMIT statement ends a transaction &


starts another
ROLLBACK statement cancels transaction
Executing a tool implicitly begins a new
transaction
Exiting a tool implicitly commits transaction
If tool aborts, transactions are implicitly
cancelled (rolled back)

ODBA10gDB-OCA--04-19 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

DCL Statements COMMIT/ROLLBACK

Transactions are confirmed with the COMMIT statement and cancelled with the ROLLBACK
statement.

If the transaction is cancelled, any changes made within the transaction are reversed.

Modified rows cannot be viewed or further modified by other concurrent transactions until the
modifying transaction completes.

If a client process aborts, the default behaviour of Oracle initiates a ROLLBACK.

If a client process ends normally without an explicit COMMIT, an implicit COMMIT is issued to make the
modifications performed by the transaction permanent.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 115
Oracle 10g Database Associate Lesson 4 Database Interfaces

Data Definition Statements

Data structures are built with CREATE


CREATE
CREATE TABLE
TABLE newdept
newdept ((
deptno
deptno NUMBER(2),
NUMBER(2), dname
dname VARCHAR2(14))
VARCHAR2(14))

Modifications with ALTER


ALTER
ALTER TABLE
TABLE newdept
newdept ADD
ADD ((
loc
loc VARCHAR(12),
VARCHAR(12), manager
manager NUMBER(4))
NUMBER(4))

Removal with DROP


DROP
DROP TABLE
TABLE newdept
newdept

Discussed in later lesson


ODBA10gDB-OCA--04-20 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Data Definition Statements

Three DDL (Data Definition Language) statements are supported by Oracle.

The CREATE statement is used to build new structures.

An alternative form of this statement, CREATE TABLE AS SELECT ... (CTAS) can be used to
duplicate an existing table structure and content. A WHERE clause can be used with this form of the
SELECT statement to limit the rows added into the new table.

The ALTER statement can be used to add, modify or remove the structure of one or more columns in
an existing table. Restrictions are in place to avoid the opportunity for data loss by executing this
statement.

The DROP statement can be used to unconditionally remove a table content and structure.

Further information regarding these statements is discussed in Lesson 7.

V2: Page 116 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 4 Database Interfaces Oracle 10g Database Associate

SQL*Plus Commands

Change column display style COL


COL
COL empno
empno FORMAT
FORMAT 9999
9999 HEADING
HEADING 'Employee|Number'
'Employee|Number'

Set page dimensions


SET
SET LINESIZE
LINESIZE 132
132 PAGESIZE
PAGESIZE 72
72

Control SQL*Plus environment


SET
SET FEEDBACK
FEEDBACK OFF
OFF PAUSE
PAUSE ON
ON PAUSE
PAUSE 'Hit
'Hit return'
return'
SET
SET SQLPROMPT
SQLPROMPT 'Live>
'Live> ''

ODBA10gDB-OCA--04-21 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

SQL*Plus Commands

For all versions of SQL*Plus, management commands can be used to customise the presentation and
environment in which commands are run.

Examples illustrated include changing the display format of a column (the COLUMN command) and
customising the environment for the current session (the SET command).

The SHOW command is used to display the current setting for a SQL*Plus environment variable.

The SHOW ALL command can be used to list all modifiable values, together with their current setting.

Unlike SQL commands, the SQL*Plus command keywords can be abbreviated. For example, a
COLUMN command can be used as the keyword COL.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 117
Oracle 10g Database Associate Lesson 4 Database Interfaces

SQL Functions

Central 'functions' provided in server


All functions work in all interfaces
Functions are grouped into sets
Conversion Grouping
Date System
Character Numeric

ODBA10gDB-OCA--04-22 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

SQL Functions

Oracle provides a wide range of built-in functions that can be used to alter data presentation, convert
between data types and provide access to system level features. For a full list of functions, please
refer to the Oracle SQL Language Reference Manual (Part Number B14200-02).

The general syntax is

function_name [ ( { value | column | expression } [, ...] ) ]

Examples include:

to_number (character_field) to_number ('1234')

to_date (date_field, [format]); to_date (hiredate, 'month yyyy')

months_between (date1, date2) months_between (hiredate, sysdate)

initcap(character_field) initcap(ename)

round (number_field, [, n]) round (sal, -2)

V2: Page 118 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 4 Database Interfaces Oracle 10g Database Associate

SQL*Plus Conventions

Statements terminated with semi-colon


Last statement is buffered for reuse
Can be edited in line or full screen mode
Single statements can be saved or loaded

ODBA10gDB-OCA--04-23 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

SQL*Plus Conventions

SQL statements are multi-line and must be terminated with a semi-colon (or a single / in column 1).

The most recent statement is saved in an internal buffer for editing, saving or reuse.

This statement can be re-executed by entering a / or the r command.

Statements can be edited in either line mode (tricky!) or by typing the EDIT command to invoke a
full screen editor. Saved files are automatically retrieved into the SQL*Plus buffer after editing.

The SAVE and GET commands can be used to write and reload commands to and from disk.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 119
Oracle 10g Database Associate Lesson 4 Database Interfaces

Procedural Language

PL/SQL Procedural Language/SQL


Procedural extensions to SQL
Proprietary to Oracle
Used for creating batch processing tasks
Can be stored in the database
Provides major performance enhancements
Block structured language with embedded
SQL statements for database processing

ODBA10gDB-OCA--04-24 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

PL/SQL

The PL/SQL language is an Oracle proprietary extension to SQL, used to provide batch processing
and stored code capabilities.

PL/SQL blocks can be created as "anonymous blocks", entered and executed through any of the
interactive SQL tools.

DECLARE
v_balance NUMBER(10,2);
BEGIN
SELECT amount_due INTO v_balance
FROM customer WHERE id = 20;

UPDATE customer SET amount_due = v_balance * 1.10


WHERE id = 20;
EXCEPTION
WHEN no_data_found THEN ROLLBACK;
END;
/

A PL/SQL block can contain a mix of procedural statements to control loops and make decisions,
together with SQL statements for database access.

V2: Page 120 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 4 Database Interfaces Oracle 10g Database Associate

Stored Code

Stored PL/SQL Stored


Code
User
Data
CREATE
CREATE PROCEDURE
PROCEDURE update_all
update_all
AS
AS
CURSOR
CURSOR all IS SELECT ** FROM
all IS SELECT FROM emp;
emp;
BEGIN
BEGIN
OPEN all;
OPEN all;
FOREACH
FOREACH emprec
emprec IN
IN all;
all;
UPDATE
UPDATE emp
emp Server
SET
SET sal = sal * 1.10
sal = sal * 1.10
WHERE
WHERE CURRENT
CURRENT OF
OF all;
all;
END FOREACH; Loaded on demand
END FOREACH;
END;
END;

SQLPLUS>
SQLPLUS> execute
execute update_all;
update_all;

Executed
SQLPLUS>
SQLPLUS> execute
execute update_all;
update_all;
SGA
ODBA10gDB-OCA--04-25 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Stored Code
Code can be stored within the database, as procedures, functions, packages (groupings of procedures
and functions) or triggers (automatically executed code routines invoked in response to a table or
database event).
A CREATE [ PROCEDURE | FUNCTION | PACKAGE | TRIGGER ] command is used to store and
compile the code.

CREATE PROCEDURE update_all


AS
CURSOR all IS SELECT * FROM scott.emp;
BEGIN
OPEN all;
FOREACH emprec IN all;
UPDATE emp
SET sal = sal * 1.10
WHERE CURRENT OF all;
END FOREACH;
END;
/

For all stored code, except the automatically invoked triggers, execution can be requested by using the
EXECUTE command as below. User-defined functions can be used in the same way as system
provided functions discussed previously.

SQL> execute update_all

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 121
Oracle 10g Database Associate Lesson 4 Database Interfaces

Enterprise Manager

Oracle EM is the 10g Graphical DBA tool


Runs inside a browser window

ODBA10gDB-OCA--04-26 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Enterprise Manager

The graphical Enterprise Manager(EM) tool is the main feature of Oracle 10g for DBA tasks to
manage databases.

EM runs inside a browser and is invoked at the browser location displayed after creating the database.
The default location (for the database control) is :

http://<hostname>:1158/em

A DBCONSOLE service or daemon must be running against the database before EM can be used.

In order to connect to the database, a suitable login and password must be supplied. For executing
privileged DBA commands, a SYSDBA or SYSOPER account must be specified.

V2: Page 122 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 4 Database Interfaces Oracle 10g Database Associate

EM Home Page

ODBA10gDB-OCA--04-27 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

EM Home Page
The EM Home Page provides a summary of the selected database status.
Information provided includes the following categories:
General Database status, version, host informationm listener status
Host CPU Load status, paging statistics
Active Session Wait status, user I/O and CPU statistics for Oracle processes
SQL Statistics If statistics are available, shows SQL details (Lesson 19)
Diagnostic Info Automated Database Diagnostic Monitor (ADDM) information
Disk Space Summary Database sizing information and problem information
High Availability Info Statistics for automated failure recovery
Alerts Critical and warning alert information for DBA attention
Job Overview Information on scheduled jobs
Related Links Links to additional pages containing more DBA statistics

The majority of graphical displays and textual information are live links, that can be clicked to drill
down for further information.
Most pages refresh automatically, according to the refresh schedule at the top right of the page.
Details are discussed throughout this class in relevant lessons.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 123
Oracle 10g Database Associate Lesson 4 Database Interfaces

EM Performance

ODBA10gDB-OCA--04-28 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

EM Performance
The EM Performance page shows the following statistics for the past hour
Host CPU Utilisation percentage
Average active sessions Wait statistics that may indicated potential database slowdowns
Instance Disk I/O Database read/write request rates
Instance Throughput Indicates potential contention issues in the database.,

V2: Page 124 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 4 Database Interfaces Oracle 10g Database Associate

EM Administration

ODBA10gDB-OCA--04-29 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

EM Administration
The EM Administration page allows sundry management tasks to be carried out, including

Database Administration
Storage File and tablespace management
Database Configuration Initialisation file management
Database Scheduler Jobs, schedules, programs and windows
Statistics Management AWR and optimiser statistics
Change Database Automatic Storage Management and tablespace migration

Schema Administration
Database Objects Management for tables, indexes, view & other schema objects
Programs Management for stored PL/SQL and Java code objects
Users and Privileges Users, roles and privilege management
Materialized Views Materialized view management and diagnostics

EM Administration
Administrators Define privileged EM administrators
Notification Schedule Manage automatic notification schedules
Blackouts Suspend database monitoring for database maintenance ops.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 125
Oracle 10g Database Associate Lesson 4 Database Interfaces

EM Maintenance

ODBA10gDB-OCA--04-30 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

EM Maintenance
The EM Maintenance page provides access to functions affecting the entire Oracle database.

High Availability
Backup/Recovery Schedule and perform backup and recovery operations

Backup/Recovery Settings Change settings for RMAN backup and recovery

Data Movement
Move Row Data Export, import and data load operations

Move Database Files Duplicate (clone) database; transport files to other database

Streams Quickly replicate schema across databases

Software Deployment
Installed Software Check for all installed Oracle products

Software Patching Check current level of installed software via Metalink

V2: Page 126 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 4 Database Interfaces Oracle 10g Database Associate

Summary

In this lesson, you have learnt about :


Using SQL*Plus and iSQL*Plus to access the
database and examine database structures
Using SQL statements to manage and
modify database content and structure
Definition of database transactions
Running Enterprise Manager

ODBA10gDB-OCA--04-31 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Summary
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 127
Oracle 10g Database Associate Lesson 4 Database Interfaces

Practice 4

Connect to your database using both


interfaces, as user SCOTT
Examine structures of accessible tables
Copy the EMP table to a NEWEMP table
Delete all employees in department 20
Add a new employee for department 10
Update all salaries for employees in
department 30 by 10%

ODBA10gDB-OCA--04-32 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Practice 4
In this practice, you will utilise several of the supplied SQL interfaces.

________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

V2: Page 128 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 5 Starting and Stopping Oracle Oracle 10g Database Associate

5
0
Starting and Stopping Oracle

ODBA10gDB-OCA-05-1 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

LESSON 5 STARTING AND STOPPING ORACLE


This lesson demonstrates the commands required to start and stop a database instance.
Associated processes are also examined, including the database control daemon, the database listener
and the iSQLPlus control daemon.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 129
Oracle 10g Database Associate Lesson 5 Starting and Stopping Oracle

Objectives

After completing this lesson, you should


be able to start and stop:
EM Database Control
Oracle 10g Database Instances
iSQL*Plus
Additionally, you will be able to
Locate and modify parameter files
Locate and interpret alert logs

ODBA10gDB-OCA-05-2 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Objectives
This lesson examines the commands and processes required to start up and shutdown an Oracle
database instance, including:
Enterprise Manager Database Control
The Oracle instance
The iSQL*Plus background process
Additional topics explored include the use of parameter files for instance tuning and alert logs for
monitoring significant database events.

V2: Page 130 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 5 Starting and Stopping Oracle Oracle 10g Database Associate

EM Database Control

EM Database Control is used for most


DBA management tasks
The 'emctl' utility manages the 'dbconsole'
daemon / background process

ODBA10gDB-OCA-05-3 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

EM Database Control

The EM Database Control, introduced in Lesson 4, can be used for most database administration
tasks. The interface is displayed in a browser as already demonstrated.

Before the EM can be displayed, the dbconsole process (for UNIX) or service (for Windows) must
be started. The process is automatically created and started up during database creation.

Alternatively, the SQL*Plus interface can be used to start and stop the instance. No pre-started
program is required to administer the database if SQL*Plus is used.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 131
Oracle 10g Database Associate Lesson 5 Starting and Stopping Oracle

Starting EMCTL daemon

To run the daemon, 'emctl start dbconsole'


Server process OracleDBConsole<sid> is
started

ODBA10gDB-OCA-05-4 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Starting EMCTL daemon


The operating system ORACLE_SID environment variable must be set to the name of the instance for
whom a console daemon is to be started.

Use the following command (in a UNIX/Linux shell or Windows cmd session):

C:\> SET ORACLE_SID=orcl # Windows

$ export ORACLE_SID=orcl # UNIX/Linux

To start the dbconsole process after a system reboot, ensure that the ORACLE_HOME/bin directory is
on your path, then issue the command:

OS> emctl start dbconsole

In Windows, the process can also be started as a service. Click Start, Control Panel, Administrative
Tools, Services to display the services page.
Scroll down to the entry labelled OracleDBConsole<SID>, where <SID> is the database system
identifier. Right click the process and select Start from the context menu.
The dbconsole service maintains log files in:

<Oracle_Home>/<host>_<SID>/sysman/log

V2: Page 132 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 5 Starting and Stopping Oracle Oracle 10g Database Associate

The emctl command can also be used for other purposes. See the help screen below:

OS>emctl
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation. All rights reserved.
Invalid arguments

Unknown command option


Usage::
Oracle Enterprise Manager 10g Database Control commands:
emctl start| stop| status| setpasswd dbconsole
emctl secure <options>

emctl set ssl test|off|on em


emctl set ldap <host> <port> <user dn> <user pwd> <context dn>
emctl blackout options can be listed by typing "emctl blackout"
emctl config options can be listed by typing "emctl config"
emctl secure options can be listed by typing "emctl secure"
emctl ilint options can be listed by typing "emctl ilint"
emctl deploy options can be listed by typing "emctl deploy"

EM Agent
Part of the function of the EM database control is delegated to a separate agent process. The agent
logs in to the database and passes control information to the EM database control for graphical
presentation of performance and status.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 133
Oracle 10g Database Associate Lesson 5 Starting and Stopping Oracle

Starting a Listener

Listener enables database connections


Invoked with 'lsnrctl start' command
Discussed further in Lesson 13

ODBA10gDB-OCA-05-5 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Starting a Listener
A listener process is required to provide a connection mechanism between client processes and the
database server. The listener performs the following tasks:

receives client connection requests,


validates the request,
resolves the requested database connection string to an instance
spawns a server process to handle SQL requests from the client.

To start a listener following a system restart, use the Listener Control utility as below:

$ lsnrctl start # Unix/Linux

C:\> lsnrctl start # Windows

The service OracleOracleHomeTNSListener is started.

This single listener process can support multiple database instances.

Further details are discussed in Lesson 13 Networking.

V2: Page 134 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 5 Starting and Stopping Oracle Oracle 10g Database Associate

Windows Oracle Service

Windows uses OracleService<sid> to


contain all instance processes
Service must be started to run database

ODBA10gDB-OCA-05-6 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Windows Oracle Service

For Microsoft Windows only, an additional service must be started to be able to use the database.

One process is required for each database instance in use.

The instance runs all server processes as threads within a single OS process.

To start the process, click Start, Control Panel, Administrative Tools, Services to display the services
page.

Scroll down to the entry labelled OracleService<SID>, where <SID> is the database system
identifier. Right click the process and select Start from the context menu.

Alternatively, open a command window and enter the command below to start the service:

C:> net start oracleservice<SID>

The service can also be set to automatically start the associated database instance, using the
Windows control panel.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 135
Oracle 10g Database Associate Lesson 5 Starting and Stopping Oracle

Database Control Startup Credentials

ODBA10gDB-OCA-05-7 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Database Control Startup Credentials


Once the dbconsole service is running, the database instance can be started using the EM Database
Control.

The following parameters are required to connect to and start the database:

Host credentials
Username Enter OS account name for Oracle owner e.g. oracle or
administrator
Password Enter OS account password for the selected host username

Target Database Credentials


Username Enter a database username e.g. SYSTEM or SYSMAN (which
must have SYSDBA or SYSOPER privilege)
Password Enter associated password for database username
Connect As Select SYSDBA or SYSOPER to change the database status.

Save as Preferred Credential Check to save this information for future logins (applies to
both host and target credentials).

V2: Page 136 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 5 Starting and Stopping Oracle Oracle 10g Database Associate

Status Screen

ODBA10gDB-OCA-05-8 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Status Screen

If the database is down, the status screen displays a corresponding message.

The listener status and agent status is also reported by this screen.

To start the database, click the Startup button at the top right hand corner of the screen.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 137
Oracle 10g Database Associate Lesson 5 Starting and Stopping Oracle

Startup/Shutdown Confirmation

ODBA10gDB-OCA-05-9 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Startup/Shutdown Confirmation

After clicking the startup button on the status screen, a confirmation screen is displayed.

To confirm this operation, click the Yes button.

The Show SQL button can be used to display the SQL command that will be issued by EM to
perform the operation. Many other EM screens also include the same button.

SQL commands can also be issued via SQL*Plus to perform the same operation this applies
throughout the EM product.

V2: Page 138 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 5 Starting and Stopping Oracle Oracle 10g Database Associate

Startup Progress

ODBA10gDB-OCA-05-10 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Startup Progress
A startup progress screen will be displayed whilst the database instance is started.
The database instance will transition through the following stages during startup:

Stage Actions
NOMOUNT Parameter file is opened from default (or other) location
SGA is initialised according to parameter specifications
Background processes are initialised
MOUNT Parameter file CONTROL_FILES entry is used to locate and open all
control files
OPEN Data files are located from V$DATAFILES dictionary table.
Status (SCN) is checked between control file and datafile header
If all files agree, database is opened for normal use
If files are out of sync, database recovery may be required (see later
lessons)

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 139
Oracle 10g Database Associate Lesson 5 Starting and Stopping Oracle

Shutdown Options

ODBA10gDB-OCA-05-11 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Shutdown Options
Under normal circumstances, a started database instance can (and should) be left running 24/7.
Unattended jobs can be scheduled to execute in off-peak periods. Oracle is installed with several
automatic jobs that will not be run if the instance is down.
Maintenance operations, including backups of selected
tablespaces and datafiles, can also be performed
automatically without requiring a database shutdown.
If the database instance does need to be shut down, for
maintenance on the hardware, the EM Home, General
Tab can be used to initiate the operation.
Clicking the Shutdown button displays a shutdown
confirmation screen.
On this screen, the Advanced Options button
displays a further list of shutdown modes that can be
used. A Browse Sessions button can also be used to
display a full list of currently connected processes. These include both user processes and
background daemon processes.
The following shutdown options can be selected from the advanced screen.
Mode Usage
Normal Waits for all users to disconnect before shutting down
Transactional Waits for user to commit (or rollback) before disconnecting the session
Immediate Disconnects users, rolling back work in progress, then shuts down
Abort Shuts down immediately, without writing pending work to disk.

V2: Page 140 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 5 Starting and Stopping Oracle Oracle 10g Database Associate

Starting iSQL*Plus

Requires iSQLPlus Service for Windows


Manage with isqlplusctl

ODBA10gDB-OCA-05-12 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Starting iSQL*Plus

For open databases, an isqlplus application server process is required in order to accept
connection requests.

To manage this process, the isqlplusctl command can be used.

To start the application server process, use the following command from an OS shell:

isqplusctl start

To shutdown the application server processes, use the following command from an OS shell:

isqplusctl stop

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 141
Oracle 10g Database Associate Lesson 5 Starting and Stopping Oracle

Parameter Files

EM>Administration>Database Configuration
>All Initialization Parameters > SPFile tab
Server Parameter File resides at
<OracleHome>/dbs/SPFILE<SID>.ORA
Can be exported to text file using
CREATE PFILE FROM SPFILE
Text PFILE resides at
<OracleHome>/database/init<SID>.ora

ODBA10gDB-OCA-05-13 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Parameter Files

To start an instance, a parameter file is required which is used to store memory configuration and
other tuning parameters. A starter file is generated as a database is created during software
installation or subsequently.

Two options for parameter files are provided:


SPFILE A server side parameter file, stored on the database host; binary format
PFILE A client side parameter file, held in text format

The SPFILE format is preferred, since parameter changes can be made dynamically during instance
running. In some cases, these are made and stored automatically by Oracle.

In contrast, a PFILE is only read during instance startup. Subsequent parameter file changes require
that Oracle is shutdown and restarted in order to recognise the parameter changes.

V2: Page 142 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 5 Starting and Stopping Oracle Oracle 10g Database Associate

Parameter File Contents

*.audit_file_dest='C:\oracle/admin/v10g/adump'
*.background_dump_dest='C:\oracle/admin/v10g/bdump'
*.compatible='10.2.0.1.0'
*.control_files='C:\oracle\oradata\v10g\control01.ctl',...
*.core_dump_dest='C:\oracle/admin/v10g/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='v10g'
*.db_recovery_file_dest='C:\oracle/flash_recovery_area'
*.db_recovery_file_dest_size=2147483648
*.dispatchers='(PROTOCOL=TCP) (SERVICE=v10gXDB)'
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=96468992
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=289406976
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS1'
*.user_dump_dest='C:\oracle/admin/v10g/udump'

ODBA10gDB-OCA-05-14 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Parameter File Contents


Parameter settings can be examined via EM.

Select the Administration tab and select the All Initialization Parameters link.

This screen displays parameters in groups of 50 values the drop down list and Next/Previous links
above the table of parameters allows pagination through the list. The Show All button can be used
to display all parameters.

The Name box and other control at the top left of the screen allow wildcard selection on the
parameter name column, limiting the parameters displayed.

To save the current parameter set to a PFILE format, select the Save to File button. This invokes a
browser file save sequence, during which you can select the name and location of the file to be saved
(depending on the browser in use).

If changes are made to the value of any parameter, check the Apply changes in current running
instance(s) checkbox in order to apply the changes immediately.

If the system running the EM browser is online, the icon can be clicked to display help from the
Oracle TechNet website on the selected parameter.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 143
Oracle 10g Database Associate Lesson 5 Starting and Stopping Oracle

Alert Log

Rolling log of all significant database


events
Resides in directory identified by
'background_dump_dest' parameter
Contents accessible from EM via Related
Links > Alert Log Content

ODBA10gDB-OCA-05-15 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Alert Log

An alert log in text format is maintained automatically by the Oracle server, in the directory identified
by the background_dump_dest parameter.

This file records significant events in the life of the database, including
startup and shutdown operations,
creation, alteration and deletion of disk area
changes to system wide parameters
errors in client and server processes

The log file can be examined using EM. From the main pages, scroll to the Related Links section at
the bottom of the page; select Alert Log Content list.

V2: Page 144 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 5 Starting and Stopping Oracle Oracle 10g Database Associate

Alert Log Contents

ODBA10gDB-OCA-05-16 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Alert Log Examples


The extract below has been reformatted for printing purposes

Starting ORACLE instance (normal)


LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
Picked latch-free SCN scheme 2
Using LOG_ARCHIVE_DEST_10 parameter default value as USE_DB_RECOVERY_FILE_DEST
Autotune of undo retention is turned on.
IMODE=BR
ILAT =18
LICENSE_MAX_USERS = 0
SYS auditing is disabled
Wed May 09 17:17:55 2007
ksdpec: called for event 13740 prior to event group initialization
Starting up ORACLE RDBMS Version: 10.2.0.1.0.
System parameters with non-default values:
processes = 150
__shared_pool_size = 83886080
__large_pool_size = 4194304
__java_pool_size = 4194304
__streams_pool_size = 0
spfile = C:\ORACLE\PRODUCT\10.2.0\DB_1\DBS\SPFILEV10G.ORA
sga_target = 289406976
control_files = C:\ORACLE\PRODUCT\10.2.0\ORADATA\V10G\CONTROL01.CTL,
C:\ORACLE\PRODUCT\10.2.0\ORADATA\V10G\CONTROL02.CTL,
C:\ORACLE\PRODUCT\10.2.0\ORADATA\V10G\CONTROL03.CTL
db_block_size = 8192
__db_cache_size = 192937984
compatible = 10.2.0.1.0
db_file_multiblock_read_count= 16
db_recovery_file_dest = C:\oracle\product\10.2.0/flash_recovery_area
db_recovery_file_dest_size= 2147483648

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 145
Oracle 10g Database Associate Lesson 5 Starting and Stopping Oracle

undo_management = AUTO
undo_tablespace = UNDOTBS1
remote_login_passwordfile= EXCLUSIVE
db_domain =
dispatchers = (PROTOCOL=TCP) (SERVICE=v10gXDB)
job_queue_processes = 10
audit_file_dest = C:\ORACLE\PRODUCT\10.2.0\ADMIN\V10G\ADUMP
background_dump_dest = C:\ORACLE\PRODUCT\10.2.0\ADMIN\V10G\BDUMP
user_dump_dest = C:\ORACLE\PRODUCT\10.2.0\ADMIN\V10G\UDUMP
core_dump_dest = C:\ORACLE\PRODUCT\10.2.0\ADMIN\V10G\CDUMP
db_name = v10g
open_cursors = 300
pga_aggregate_target = 96468992
PSP0 started with pid=3, OS id=576
MMAN started with pid=4, OS id=1276
PMON started with pid=2, OS id=1064
DBW0 started with pid=5, OS id=1432
LGWR started with pid=6, OS id=1440
CKPT started with pid=7, OS id=1420
SMON started with pid=8, OS id=1408
RECO started with pid=9, OS id=1404
CJQ0 started with pid=10, OS id=1396
MMON started with pid=11, OS id=1484
MMNL started with pid=12, OS id=1488
Wed May 09 17:17:57 2007
starting up 1 dispatcher(s) for network address
'(ADDRESS=(PARTIAL=YES)(PROTOCOL=TCP))'...
starting up 1 shared server(s) ...
Wed May 09 17:18:00 2007
alter database mount exclusive
Wed May 09 17:18:05 2007
Setting recovery target incarnation to 2
Wed May 09 17:18:05 2007
Successful mount of redo thread 1, with mount id 2703632776
Wed May 09 17:18:05 2007
Database mounted in Exclusive Mode
Completed: alter database mount exclusive
Wed May 09 17:18:06 2007
alter database open
Wed May 09 17:18:08 2007
Thread 1 opened at log sequence 5
Current log# 1 seq# 5 mem# 0: C:\ORACLE\PRODUCT\10.2.0\ORADATA\V10G\REDO01.LOG
Successful open of redo thread 1
Wed May 09 17:18:16 2007
MTTR advisory is disabled because FAST_START_MTTR_TARGET is not set
Wed May 09 17:18:16 2007
SMON: enabling cache recovery
Wed May 09 17:18:26 2007
Successfully onlined Undo Tablespace 1.
Wed May 09 17:18:26 2007
SMON: enabling tx recovery
Wed May 09 17:18:27 2007
Database Characterset is WE8MSWIN1252
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
QMNC started with pid=16, OS id=480
Wed May 09 17:19:03 2007
Completed: alter database open
Wed May 09 17:19:13 2007
...

V2: Page 146 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 5 Starting and Stopping Oracle Oracle 10g Database Associate

Summary

In this lesson, you have learnt about


starting and using:
EM Database Control
Oracle 10g Database Instances
iSQL*Plus
and locating
Parameter files
Alert logs

ODBA10gDB-OCA-05-17 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Summary
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 147
Oracle 10g Database Associate Lesson 5 Starting and Stopping Oracle

Practice 5

Using EM, shut down your database.


Try to connect using any of the available
interactive SQL*Plus interfaces make
notes of the error messages displayed
Ensure that all required server processes
are running
Restart the database and confirm that you
can connect now via SQL*Plus
Examine the alert log after the restart
ODBA10gDB-OCA--05-18 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Practice 5
In this practice, you will shutdown and restart your database.
________________________________________________________________________

Using EM, shut down your database (Ch05Shutdown.sql)


________________________________________________________________________
________________________________________________________________________

Try to connect using any of the available interactive SQL*Plus interfaces make notes of the error
messages displayed
________________________________________________________________________
________________________________________________________________________

Ensure that all required server processes are running


________________________________________________________________________
________________________________________________________________________

Restart the database (Ch05Startup.sql) and confirm that you can connect now via SQL*Plus
________________________________________________________________________
________________________________________________________________________

Examine the alert log after the restart.


________________________________________________________________________

V2: Page 148 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 6 Tablespaces and Datafiles Oracle 10g Database Associate

6
0
Tablespaces and Datafiles

ODBA10gDB-OCA-06-1 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

LESSON 6 TABLESPACES AND DATAFILES


Lesson 6 examines the use of tablespaces and datafiles.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 149
Oracle 10g Database Associate Lesson 6 Tablespaces and Datafiles

Objectives

After completing this lesson, you will


understand
Purpose & use of tablespaces and datafiles
Create, manage and drop tablespaces
Associated dictionary information and how to
use the EM tool to retrieve status details
The default and required tablespaces for all
Oracle instances

ODBA10gDB-OCA-06-2 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Objectives
Lesson 6 examines the use of tablespaces and datafiles for storing system and user information.
Topics include:
The purpose and use of tablespaces and datafiles
EM and SQL commands for managing tablespaces and datafiles
Data dictionary information held by Oracle
Default and required tablespaces used by Oracle

V2: Page 150 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 6 Tablespaces and Datafiles Oracle 10g Database Associate

Tablespaces

Database owns at least two tablespaces


Tablespace is a logical group of datafiles
Tablespace properties -
"own" one or more data files
may have default storage settings
locally managed or dictionary managed
may be offlined (except for SYSTEM / UNDO)
may be extended with more data files
can be read only (except for SYSTEM / SYSAUX / UNDO)

ODBA10gDB-OCA-06-3 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Tablespaces
All Oracle 10g databases require at least two tablespaces to operate in a practical environment these
are SYSTEM and SYSAUX. Other tablespaces e.g. UNDO and TEMP are strongly recommended and
production systems will typically include many more tablespaces.

A tablespace is the unit to which logical structures (tables, indexes ) are allocated. A tablespace is
composed of one or more operating system files (data files).

Newly created databases built with the DBCA will have several tablespaces (see page 155 and Lesson
2 Typical Disk Structure). A manually created database will require a similar setup.

The tablespace definition may include default storage parameters, that reserve space for objects that
do not override the tablespace storage clause in the object creation statement. These storage criteria
apply only to tablespaces where segment management is manual (see page 169).

Except for critical tablespaces including SYSTEM and UNDO, a tablespace may be taken offline for
repair or moving the files.

A tablespace can be managed by adding data files to increase the space available for contained
objects.

Tablespaces (except for critical tablespaces) can be made readonly.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 151
Oracle 10g Database Associate Lesson 6 Tablespaces and Datafiles

Datafiles

Tablespace owns one or more data files


Oracle server processes create data files
DBA can change the size of a data file
Datafile properties
Created with an initial size
Can be extended (auto or manual) or shrunk
Maximum size and growth increment can be
set for each datafile

ODBA10gDB-OCA-06-4 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Datafiles
Each tablespace owns one or more datafiles, which can be spread across as many different disks and
disk units as required.

Datafiles are created and extended by the CREATE/ALTER TABLESPACE statements.

The DBA can manually extend or move a datafile to balance the I/O load on demand.

A datafile includes an AUTOEXTEND property that allows it to grow by a set increment, optionally
until it reaches a maximum size.

V2: Page 152 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 6 Tablespaces and Datafiles Oracle 10g Database Associate

Tablespaces & Datafiles

Objects positioned in
one tablespace Database
Multiple data files
Tablespace Data file
belong to tablespace
Segment
Tablespace size is
sum of data files Extent

Oracle block Data/OS block

ODBA10gDB-OCA-06-5 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Tablespaces & Datafiles


A database will consist of several physical data files, grouped into logical structures called
tablespaces.

Database objects (tables, indexes) are positioned within a tablespace on creation.

A tablespace consists of one or more data files. Each data file can only belong to a single tablespace.

The tablespace size is the sum of all data files that belong to the tablespace.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 153
Oracle 10g Database Associate Lesson 6 Tablespaces and Datafiles

Tablespace Types

Extent Management
Locally Managed
Dictionary Managed
File Types
Smallfile
Bigfile
Segment Management
Auto
Manual
ODBA10gDB-OCA-06-6 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Tablespace Types

Extent Management
Locally managed tablespaces (LMTs) are the default and preferred option for Oracle 10g. A locally
managed tablespace reserves some header blocks for a bitmap of the free and used space within a
tablespace. Using locally managed tablespaces offloads a major source of possible contention in the
SYSTEM tablespace.

Dictionary managed tablespaces (DMT) use the DBA_FREE_SPACE view in the SYSTEM tablespace for
managing free space areas. Oracle do not recommend creating dictionary managed tablespaces in
Oracle 10g. This feature is scheduled for future de-support.
More information is discussed shortly.

File Types
A smallfile tablespace is the default Oracle tablespace type, which can contain 1022 datafiles or
tempfiles, each of which can contain up to 222 or 4M blocks.
A bigfile tablespace contains only one datafile (or tempfile). The file can contain up to 232 or 4G
blocks. The maximum size of the single datafile or tempfile is 128 terabytes (TB) for a tablespace
with 32K blocks and 32TB for a tablespace with 8K blocks.

Segment Space Management


Relevant for permanent, locally managed tablespaces only, this clause should be specified as
SEGMENT SPACE MANAGEMENT AUTO for new tablespaces. The alternate setting, MANUAL is not
recommended for new tablespaces and is only supported for backwards compatibility in upgraded
databases.

V2: Page 154 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 6 Tablespaces and Datafiles Oracle 10g Database Associate

Installation Tablespaces

SYSTEM : dictionary information


SYSAUX : automatic workload
TEMP : overflow from memory
UNDOTBS : undo information
USERS : default user data (optional)
EXAMPLE : sample data (optional)

ODBA10gDB-OCA-06-7 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Installation Tablespaces
The following tablespaces are created for new DBCA created databases:

SYSTEM Stores the main data dictionary and a default SYSTEM rollback segment
For more information, see page 156

SYSAUX Companion to SYSTEM; contains secondary system information.


Contents can be listed by EM > Administration > Tablespaces > SYSAUX

TEMP Used for overflow information from PGA during SQL operations
For more information, see page 157

UNDOTBS Holds recovery and redo information for database/tablespace repair


Discussed in Lesson 8

USERS Default tablespace assigned to new users for schema objects

EXAMPLE Optional tablespace used for holding example data for databases created from
supplied templates.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 155
Oracle 10g Database Associate Lesson 6 Tablespaces and Datafiles

SYSTEM & SYSAUX

SYSTEM
Created by CREATE DATABASE command
Contains main data dictionary tables
Contains SYSTEM rollback segment

SYSAUX
Auxiliary storage not required for startup
Automatic Workload Repository

ODBA10gDB-OCA-06-8 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

SYSTEM & SYSAUX


The SYSTEM tablespace is created during the CREATE DATABASE operation. This tablespace contains
the main dictionary tables and a SYSTEM rollback segment.

If the SYSTEM tablespace is locally managed, then all other tablespaces must also be locally managed
i.e. not dictionary managed.

The SYSAUX tablespace is an extension tablespace for the SYSTEM tablespace. Many required and
optional database components use the SYSAUX tablespace as their default location to store data. The
SYSAUX tablespace is therefor always created during database creation or database upgrade.

During normal database operation, the SYSTEM and SYSAUX tablespaces cannot be dropped or renamed.

If the SYSAUX tablespace is unavailable due to a media failure, an instance can still continued to be
used but some database features might not be available or may fail.

V2: Page 156 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 6 Tablespaces and Datafiles Oracle 10g Database Associate

TEMP

Used for overflow from PGA


Unindexed queries, index creation, groups
System wide default setting allowed
Temporary tablespace groups
Sets of temporary files
One group can be selected as default

ODBA10gDB-OCA-06-9 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

TEMP
Temporary tablespaces store information generated and used during SQL statements, where the space
required exceeds the assigned PGA memory.

The operations that require temporary storage space include sort space for unindexed queries, index
creation statements, grouped queries and more.

For (upgraded) databases with locally managed SYSTEM tablespaces, at least one default temporary
tablespace must be available. A locally managed SYSTEM tablespace cannot be used for default
temporary storage.

A default temporary tablespace for all users can be set using the Database Instance: v10g >
Tablespaces > Edit Tablespace screen; check the Set as default temporary tablespace
checkbox.

Temporary tablespace groups enable the use of temporary space from multiple tablespaces. Using a
tablespace group rather than a single temporary tablespace reduces problems caused when one
tablespace is insufficient to hold the results of a sort.

A temporary tablespace group name can be assigned as a default temporary tablespace for the
database or as a temporary tablespace for an individual user (discussed in a later lesson).

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 157
Oracle 10g Database Associate Lesson 6 Tablespaces and Datafiles

EM & Tablespaces

ODBA10gDB-OCA-06-10 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

EM & Tablespaces
To display the tablespace usage within Enterprise Manager, select Administration > Tablespaces

Each tablespace is listed, with details including the tablespace size, usage (MB and %), free space,
status, datafiles, extent management and segment management.

More information can be displayed by selecting the associated radio button and clicking View. A
variety of actions can be carried out by selecting the required option from the Actions drop-down
list.

Individual data-file information can be displayed by clicking on


the relevant file name.

Sundry metrics can be displayed by clicking the Used % value.


Metrics are discussed in lessons 18 and 19.

V2: Page 158 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 6 Tablespaces and Datafiles Oracle 10g Database Associate

Oracle Managed Files

DBA specifies storage locations


Oracle determines file names
Initialisation parameters:
db_create_file_dest
db_create_online_log_dest_[1-5]
Files are created and deleted by Oracle

ODBA10gDB-OCA-06-11 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Oracle Managed Files


Oracle Managed Files (OMF) allow Oracle to manage names and locations of data files (as well as
control and redo log files).

To enable the OMF mechanism, set the following initialisation parameters:


db_create_file_ dest Directory for creating all data files
db_create_online_log_dest_n Directory for creating online redo log and control files

If these parameters are set, new tablespaces can be created via SQL*Plus using the following
command:

SQL> CREATE TABLESPACE newTablespaceName;

No file name or size is required; the new file is created with an Oracle generated name in the default
location and with a standard size of 100 megabytes.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 159
Oracle 10g Database Associate Lesson 6 Tablespaces and Datafiles

Inside a tablespace

t1 t2 t1 t2 free t2

Empty
Six extents blocks
Different sizes
Free space embedded in extents
Free space can be within tablespace

ODBA10gDB-OCA-06-12 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Inside a tablespace
Space inside a tablespace is assigned to permanent objects as contiguous sets of disk blocks; each set
of blocks is termed an extent.

Depending on the tablespace type, the size of the extent may be Oracle- or user-specified.

The total of all extents assigned to a single object is called a segment.

Each extent is dedicated to a specified type of object. When information is added to the object, the
assigned space is consumed. Further space can be added to the object automatically. As information
is deleted from the object, the space is retained by the object and subsequently reused when further
information is added.

V2: Page 160 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 6 Tablespaces and Datafiles Oracle 10g Database Associate

Tablespace Management

CREATE [UNDO|TEMPORARY] TABLESPACE


tablespace_name [DATAFILE|TEMPFILE]
'file_name' SIZE size[K|M|G|T]
[AUTOEXTEND [ON|OFF]
[MAXSIZE [maxsize|UNLIMITED]

ALTER TABLESPACE t1
[OFFLINE|ONLINE|READ ONLY|READ WRITE]

DROP TABLESPACE t1
[INCLUDING CONTENTS [AND DATAFILES]
[CASCADE CONSTRAINTS]]

ODBA10gDB-OCA-06-13 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Tablespace Management
The following commands can be used to manage a tablespace via any of the SQL interfaces:

CREATE TABLESPACE
The CREATE TABLESPACE statement builds new tablespaces and adds one or more data-files to the
tablespace.

ALTER TABLESPACE
The ALTER TABLESPACE statement can add or drop datafiles from a tablespace and change the
ONLINE / OFFLINE or READ ONLY / READ WRITE status of the tablespace.

DROP TABLESPACE
The DROP TABLESPACE statement can be used to drop a tablespace (including both contents and
datafiles if required). Note that dropping a tablespace with contents may require a recovery operation
for the entire database in order to restore the information contained in the tablespace.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 161
Oracle 10g Database Associate Lesson 6 Tablespaces and Datafiles

Datafile Management

ALTER DATABASE
DATAFILE 'file_name'
RESIZE size[K|M|G|T];
ALTER DATABASE
RENAME FILE
'old_file_name' TO
'new_file_name';

ODBA10gDB-OCA-06-14 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Datafile Management
Datafiles can be resized manually, in order to provide more space for objects contained in the parent
tablespace.

Oracle also provides an option for each datafile to allow additional space to be added automatically
(auto-increment) until the file reaches a specified size.

Files can be moved to new locations on disk, and the ALTER DATABASE RENAME FILE statement can
then be used to update the Oracle dictionary and control files to recognise the new location. This may
take the contents of the file offline for the duration of the move operation.

File renaming is not possible via Enterprise Manager and therefore must be performed using
command line SQL*Plus.

V2: Page 162 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 6 Tablespaces and Datafiles Oracle 10g Database Associate

Data Dictionary Tablespaces & Datafiles

DBA_TABLESPACES
V$TABLESPACE

DBA_DATA_FILES
V$DATAFILE

DBA_TEMP_FILES
V$TEMPFILE

ODBA10gDB-OCA-06-15 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Data Dictionary

DBA_TABLESPACES
Name Null? Type
----------------------------------------- -------- ----------------------------
TABLESPACE_NAME NOT NULL VARCHAR2(30)
BLOCK_SIZE NOT NULL NUMBER
INITIAL_EXTENT NUMBER
NEXT_EXTENT NUMBER
MIN_EXTENTS NOT NULL NUMBER
MAX_EXTENTS NUMBER
PCT_INCREASE NUMBER
MIN_EXTLEN NUMBER
STATUS VARCHAR2(9)
CONTENTS VARCHAR2(9)
LOGGING VARCHAR2(9)
FORCE_LOGGING VARCHAR2(3)
EXTENT_MANAGEMENT VARCHAR2(10)
ALLOCATION_TYPE VARCHAR2(9)
PLUGGED_IN VARCHAR2(3)
SEGMENT_SPACE_MANAGEMENT VARCHAR2(6)
DEF_TAB_COMPRESSION VARCHAR2(8)
RETENTION VARCHAR2(11)
BIGFILE VARCHAR2(3)

V$TABLESPACE
Name Null? Type
----------------------------------------- -------- ----------------------------
TS# NUMBER
NAME VARCHAR2(30)
INCLUDED_IN_DATABASE_BACKUP VARCHAR2(3)
BIGFILE VARCHAR2(3)
FLASHBACK_ON VARCHAR2(3)
ENCRYPT_IN_BACKUP VARCHAR2(3)

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 163
Oracle 10g Database Associate Lesson 6 Tablespaces and Datafiles

DBA_DATA_FILES
Name Null? Type
----------------------------------------- -------- ----------------------------
FILE_NAME VARCHAR2(513)
FILE_ID NUMBER
TABLESPACE_NAME VARCHAR2(30)
BYTES NUMBER
BLOCKS NUMBER
STATUS VARCHAR2(9)
RELATIVE_FNO NUMBER
AUTOEXTENSIBLE VARCHAR2(3)
MAXBYTES NUMBER
MAXBLOCKS NUMBER
INCREMENT_BY NUMBER
USER_BYTES NUMBER
USER_BLOCKS NUMBER
ONLINE_STATUS VARCHAR2(7)

V$DATAFILE
Name Null? Type
----------------------------------------- -------- ----------------------------
FILE# NUMBER
CREATION_CHANGE# NUMBER
CREATION_TIME DATE
TS# NUMBER
RFILE# NUMBER
STATUS VARCHAR2(7)
ENABLED VARCHAR2(10)
CHECKPOINT_CHANGE# NUMBER
CHECKPOINT_TIME DATE
UNRECOVERABLE_CHANGE# NUMBER
UNRECOVERABLE_TIME DATE
LAST_CHANGE# NUMBER
LAST_TIME DATE
OFFLINE_CHANGE# NUMBER
ONLINE_CHANGE# NUMBER
ONLINE_TIME DATE
BYTES NUMBER
BLOCKS NUMBER
CREATE_BYTES NUMBER
BLOCK_SIZE NUMBER
NAME VARCHAR2(513)
PLUGGED_IN NUMBER
BLOCK1_OFFSET NUMBER
AUX_NAME VARCHAR2(513)
FIRST_NONLOGGED_SCN NUMBER
FIRST_NONLOGGED_TIME DATE

V2: Page 164 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 6 Tablespaces and Datafiles Oracle 10g Database Associate

DBA_TEMP_FILES
Name Null? Type
----------------------------------------- -------- ----------------------------
FILE_NAME VARCHAR2(513)
FILE_ID NUMBER
TABLESPACE_NAME NOT NULL VARCHAR2(30)
BYTES NUMBER
BLOCKS NUMBER
STATUS CHAR(9)
RELATIVE_FNO NUMBER
AUTOEXTENSIBLE VARCHAR2(3)
MAXBYTES NUMBER
MAXBLOCKS NUMBER
INCREMENT_BY NUMBER
USER_BYTES NUMBER
USER_BLOCKS NUMBER

V$TEMPFILE
Name Null? Type
----------------------------------------- -------- ----------------------------
FILE# NUMBER
CREATION_CHANGE# NUMBER
CREATION_TIME DATE
TS# NUMBER
RFILE# NUMBER
STATUS VARCHAR2(7)
ENABLED VARCHAR2(10)
BYTES NUMBER
BLOCKS NUMBER
CREATE_BYTES NUMBER
BLOCK_SIZE NUMBER
NAME VARCHAR2(513)

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 165
Oracle 10g Database Associate Lesson 6 Tablespaces and Datafiles

Segments, Extents & Blocks

One objects space


is a segment Database
Group of contiguous
Tablespace Data file
blocks is an extent
Segment
Data block size is set
for the database on Extent
creation Oracle block Data/OS block
Data block is I/O unit

ODBA10gDB-OCA-06-16 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Segments, Extents and Blocks


Space allocated to one object is termed the segment.

The original space allocated is called an extent.

Each extent is a series of contiguous Oracle data blocks allocated to the segment as a unit.

A data block is the unit of I/O.

V2: Page 166 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 6 Tablespaces and Datafiles Oracle 10g Database Associate

Segments

A segment is the total disk space


allocated to an object
Segments are contained within a single
tablespace
Each segment can grow by adding more
extents

ODBA10gDB-OCA-06-17 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Segments
A segment is a set of extents allocated for a single logical structure (table, index and more).
The following table describes the different types of segments.
Segment Type Description

Data Each table has a data segment. All table data is stored in the extents of the
data segment..
Index An index has an index segment that stores all of its data (key values and
ROWID / disk addresses of associated data rows)
Temporary Temporary segments are created by Oracle when a SQL statement needs a
temporary database area to operate. Extents in the temporary segment are
returned to the system for future use when the statement finishes
execution.
Rollback/ If the database is in automatic undo management mode, then the database
Undo server manages undo space using dedicated tablespaces. Oracle
recommends that you use automatic undo management. These segments
are discussed in a separate lesson.
Oracle releases before 10g used rollback segments to store undo
information, for use during database recovery and for rolling back
uncommitted transactions for users.
Oracle 10g still uses a SYSTEM rollback segment for performing system
transactions, which is created automatically at CREATE DATABASE time.
No maintenance or management is required for the SYSTEM rollback
segment.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 167
Oracle 10g Database Associate Lesson 6 Tablespaces and Datafiles

Extents

Extents are dedicated disk areas


assigned to a segment
A segment has at least one extent and
can have an unlimited number
Extents can be of different sizes
Extents are contained within a single data
file

ODBA10gDB-OCA-06-18 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Extents

An extent is a set of contiguous blocks assigned as a unit to a segment.

An initial extent is assigned when an object is created. Further next extents can be assigned
throughout the lifespan of an object.

Extents can be of different sizes although this can create issues for reuse of the space if an object is
dropped.

Extents are contained within a single data file, although the extents for an object can spread across
several data files belonging to a tablespace.

V2: Page 168 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 6 Tablespaces and Datafiles Oracle 10g Database Associate

Segment Space Management

Free space in segments can be managed


using freelists of blocks within a segment
Blocks considered full when space used
exceeds segment setting for PCTUSED
With LMTs, alternative ASSM is available
In-segment free space is tracked using
bitmaps in each segment
Provides more efficient way of working

ODBA10gDB-OCA-06-19 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Segment Space Management


Within a block, the free space inside each block is managed using two methods:

Manual
Manual free space management uses a setting for each segment called PCTFREE, which sets a
percentage of free space to be maintained in each block. Once this level has been reached, the
block is no longer used for further inserts. The block is removed from a freelist until sufficient
rows have been deleted from the block to reduce the space usage to a lower level, called
PCTUSED. This manual space free management is less efficient than the alternative.

Automatic
Oracle 10g also supports Automatic Segment Space Management (ASSM). With this mechanism,
a bitmap is held at the beginning of each extent, which records the level of fullness of each block
in a series of bands (< 25%, 25%-50%, 50%-75%, 75%+). When searching for a block to
perform an insert, the DBWR can select a block with an appropriate amount of free space, thus
packing rows more tightly into the segment.
In addition, whereas freelist or manual space management typically has a single chain of free
blocks within a segment, ASSM distributes the free status information for blocks across multiple
header blocks. Because each block in the freelist bitmap can be accessed and updated separately,
the use of ASSM causes less contention for the DBWR. The performance of multiple concurrent
updates to a single segment is therefore dramatically improved.
ASSM is the default space management method for Oracle 10g. Manual space management is
supported only for backwards compatibility for databases that have been upgraded from prior releases
of Oracle.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 169
Oracle 10g Database Associate Lesson 6 Tablespaces and Datafiles

Extent Allocation

LMTs can use two extent allocation


strategies:
UNIFORM all extents are the same size
Extent size is set on tablespace creation
Use for tablespaces with small objects and UNDO
AUTOALLOCATE
Oracle allocates space automatically
64k allocated initially; then 1M, then 8M
Use for all purposes except as above

ODBA10gDB-OCA-06-20 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Extent Allocation
For locally managed tablespaces, two extent allocation strategies are provided. The required strategy
can be specified as below:

CREATE TABLESPACE tablespace_name file_specification


EXTENT MANAGEMENT LOCAL
AUTOALLOCATE | UNIFORM SIZE size [K|M|G]]

UNIFORM
The required extent size is specified when the tablespace is first created. Multiple extents are
allocated if a larger storage area is required on object creation.
Uniform space allocation is recommended for use with tablespaces containing many small objects, as
well as for UNDO tablespaces.

AUTOALLOCATE
Oracle assigns extents automatically, using an algorithm developed by Oracle engineers. This
mechanism cannot be overridden for individual tablespaces.
Initially, 8 block / 64K extents are assigned. When sixteen extents have been assigned (i.e. the object
reaches 1 MB in size, the extent size allocated grows to 128 blocks / 1MB. When a further 64 of
these extents have been allocated, the extent size allocated grows again to 1024 blocks / 8MB.
In essence, objects will grow at an exponential rate. This recommended mechanism reduces the load
on the DBA when planning disk usage, by removing the need to micro-manage disk space.

V2: Page 170 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 6 Tablespaces and Datafiles Oracle 10g Database Associate

Blocks

An Oracle data block is the smallest unit


of manageable storage
One block may contain many rows or
many index entries
Blocks in traditional tablespaces may
have spare space allocated for growth

ODBA10gDB-OCA-06-21 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Blocks

An Oracle block is the basic unit of storage belonging to an object.

A default block size is set for the entire database on creation, and can range from 2k to 32k (or 64k on
some OS versions). A standard block size of 8k is used for all databases created from the supplied
DBCA templates.

If the appropriate system parameters are set up to provide multiple buffer caches, additional
tablespaces can be created with different block sizes for special purposes.

Multiple rows and index entries can be contained within a block conversely, a data row can spread
across multiple blocks (chaining).

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 171
Oracle 10g Database Associate Lesson 6 Tablespaces and Datafiles

Data Dictionary Segments and Extents

DBA_SEGMENTS

DBA_EXTENTS

ODBA10gDB-OCA-06-22 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Data Dictionary

DBA_SEGMENTS
Name Null? Type
----------------------------------------- -------- ----------------------------

OWNER VARCHAR2(30)
SEGMENT_NAME VARCHAR2(81)
PARTITION_NAME VARCHAR2(30)
SEGMENT_TYPE VARCHAR2(18)
TABLESPACE_NAME VARCHAR2(30)
HEADER_FILE NUMBER
HEADER_BLOCK NUMBER
BYTES NUMBER
BLOCKS NUMBER
EXTENTS NUMBER
INITIAL_EXTENT NUMBER
NEXT_EXTENT NUMBER
MIN_EXTENTS NUMBER
MAX_EXTENTS NUMBER
PCT_INCREASE NUMBER
FREELISTS NUMBER
FREELIST_GROUPS NUMBER
RELATIVE_FNO NUMBER
BUFFER_POOL VARCHAR2(7)

V2: Page 172 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 6 Tablespaces and Datafiles Oracle 10g Database Associate

DBA_EXTENTS
Name Null? Type
----------------------------------------- -------- ----------------------------

OWNER VARCHAR2(30)
SEGMENT_NAME VARCHAR2(81)
PARTITION_NAME VARCHAR2(30)
SEGMENT_TYPE VARCHAR2(18)
TABLESPACE_NAME VARCHAR2(30)
EXTENT_ID NUMBER
FILE_ID NUMBER
BLOCK_ID NUMBER
BYTES NUMBER
BLOCKS NUMBER
RELATIVE_FNO NUMBER

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 173
Oracle 10g Database Associate Lesson 6 Tablespaces and Datafiles

Summary

In this lesson, you learnt about:


Concepts of tablespaces and datafiles
How to create, manage and drop
tablespaces and datafiles
Data dictionary information and how to use
the EM tool to retrieve status details
Default and required tablespaces for all
Oracle instances

ODBA10gDB-OCA-06-23 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Summary
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

V2: Page 174 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 6 Tablespaces and Datafiles Oracle 10g Database Associate

Practice 6

Use EM to examine tablespace structure


Create a new tablespace called 'TEST',
with a single 50MB file
Using EM, add a new file to TEST
Take the new tablespace offline and
move the file to a new location
Bring the tablespace online again
Experiment with other options in EM as
suggested by your instructor

ODBA10gDB-OCA-06-24 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Practice 6
In this practice, you will work with tablespaces.

Use EM to examine the existing tablespace structure in your database (Ch06Tablespaces.sql).


________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

Create a new tablespace called TEST with a single 50 megabyte file


(Ch06CreateTablespace.sql).
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

Using Enterprise Manager, add a second file to the TEST tablespace (Ch06AddDatafile.sql).
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 175
Oracle 10g Database Associate Lesson 6 Tablespaces and Datafiles

Take the tablespace offline and move the datafiles to a new disk location (use a TEMP area on your
disk either C:\Temp for Windows or /tmp for Linux/Unix) (Ch06

V2: Page 176 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 7 Schema Objects Oracle 10g Database Associate

7
0
Schema Objects

ODBA10gDB-OCA-07-1 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

LESSON 7 SCHEMA OBJECTS


This lesson discusses and demonstrates important schema objects, including tables, indexes,
constraints, views and sequences.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 177
Oracle 10g Database Associate Lesson 7 Schema Objects

Objectives

After completing this lesson, you will


understand
Create and modify tables
Select appropriate data types
Define constraints
View the attributes and contents of tables
Create indexes and views
Create and use sequences

ODBA10gDB-OCA-07-2 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Objectives
Lesson 7 discusses and demonstrates sundry schema objects, including tables, indexes, constraints,
views and sequences. Topics include:
Creating and modifying tables
Understanding available data types
Defining constraints (business rules)
Viewing the attributes and contents of tables
Creating indexes and views on tables
Creating and using sequences

V2: Page 178 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 7 Schema Objects Oracle 10g Database Associate

Schema

A schema is a collection of objects owned


by a named user
Schema objects include:
tables basic unit of data storage
indexes optional performance structures
views stored queries on base tables
synonyms alias for other schema objects
sequences reference number generators

ODBA10gDB-OCA-07-3 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Schema
A database schema is a collection of objects, owned by a named user and sharing the name of the
user account. On logging in to Oracle with an account/user name, the objects owned by the schema
name used to connect are automatically available to the session. Other objects may be accessible,
depending on explicit permissions that may have been granted to the account concerned.

Schema objects include:


Tables Basic unit of data storage, holding rows (records) and columns (fields)
Indexes Parallel structures on tables, for enhancing sorting and searching
Views Stored queries used to simplify future queries
Synonyms Aliases for other schema objects
Sequences Sequence number generators for primary key columns

Other schema objects that can be owned by an account include


Database links Reference to objects in other database instance schemas
Directories Reference to OS directories used for loading and saving external data
Stored code PL/SQL procedures, function, packages, triggers and Java code objects.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 179
Oracle 10g Database Associate Lesson 7 Schema Objects

Tables

A table is the basic unit of data storage


Tables contain rows, consisting of many
columns
Administration > Schema > DB Objects >
Tables
Enter or select schema name
Select object and required action from
drop-down list

ODBA10gDB-OCA-07-4 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Tables
A database table is the basic storage structure, consisting of rows (records) and columns (fields) in a
named object. Simple relational tables (also known as heap tables), are used to stored unordered
rows in the order in which the rows were added to the table.

Each table will have one or more columns, with a datatype and an optional size.

To create a new (or alter an existing) table, select the EM Administration page. Click the Schema >
Database Objects > Table link. Enter the name of the schema to be used (or select the searchlight
icon ) to select from a list of available schemas.

Press the GO button to display the tables within the specified schema.

Click the Create button to begin creating a new table.

V2: Page 180 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 7 Schema Objects Oracle 10g Database Associate

Table Operations

For a selected table, operations


can be selected from the EM
drop-down list
Operations that create new
objects default to the current schema

ODBA10gDB-OCA-07-5 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Table Operations
To operate on an existing table, refer to the displayed list of tables in the selected schema. Select the
radio button corresponding to the object to be operated on and choose an operation from the drop
down action list.

When creating new objects, the currently logged in schema is the default owner of any new objects.

Object Names
All Oracle schema objects must adhere to the following naming rules
Names must begin with an alphabetic character or underscore
Remaining characters can be alphanumeric, underscore, dollar or hash (#) symbols
Maximum length is thirty characters
Name selected must be unique within the namespace (schema)

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 181
Oracle 10g Database Associate Lesson 7 Schema Objects

Creating New Tables - Columns

Select schema and click 'Create' button


Choose table type (heap, temp or IOT)
Enter table name, schema, tablespace
For each column:
Choose column type
Enter size, scale if required
Enter defaults
Select primary key column(s)

ODBA10gDB-OCA-07-6 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Creating New Tables


To create a new table using EM, navigate to Administration > Schema > Database Objects Tables.
Click the Create button.

Select a table type to be created :


Standard A standard (heap) table is the normal Oracle table type, used for
permanent storage of information
Standard [Temp] Temporary tables are stored in a separate area and hold their information for
the duration of a transaction or session only i.e. the contents are not retained
permanently. Temporary tables are used for scratch / working storage only.
Index Organized IOTs are an alternative table organisation structure that is appropriate for
information with long identification (keys) and short data values.

Enter a tablename and enter (or select) a tablespace name.

Enter details of the columns to be created. For each column, specify a name and a data type.

V2: Page 182 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 7 Schema Objects Oracle 10g Database Associate

Oracle supports the following data types:


[N]VARCHAR2 Variable length char, 1 to 4000 bytes. Can use BYTE or CHAR, [National]
chars.
NUMBER Number with precision p (138)and scale s (-84127). FLOAT is
equivalent to NUMBER with no specified size. INTEGER is equivalent to
NUMBER(38)

DATE Date from 1st January, 4712BC to 31st December, 9999


[N]CHARacter Fixed length, space padded [national] characters
LONG [RAW] Variable length character [binary] data, up to 2GB in size. Limit of one per
row.
RAW Variable length binary data, up to 2000 bytes in size.
UROWID Base 64 encoded string representing a logical row address.
BLOB/CLOB Binary/character large object (raw) maximum size is (4GB 1)*block
size.
NCLOB Unicode large object (raw) maximum size is (4GB 1)*block size.
BFILE Pointer to external binary file stored in an Oracle directory.
TIMESTAMP YMDHMS, fractions, [WITH [LOCAL] TIME ZONE].
INTERVAL YEAR TO MONTH or DAY TO SECOND

BINARY_DOUBLE 64 bit floating point number


BINARY_FLOAT 32 bit floating point number

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 183
Oracle 10g Database Associate Lesson 7 Schema Objects

Creating New Tables - Constraints

Constraints select from displayed


types click add
Enter names and choose columns
Select constraint attributes
Disabled
Deferrable
Validate
Rely

ODBA10gDB-OCA-07-7 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Creating New Tables Constraints


Constraints are named business rules on tables or columns.
Constraints are one of the following types:
NOT NULL Set as a column property, not a specific constraint. Requires a value to be
present for every row in the table.
PRIMARY KEY Defines one (or more) columns where the values are mandatory (implied
NOT NULL) and not duplicated (implied UNIQUE). Managed by an
index with the same name as the constraint rule.
UNIQUE Defines one (or more) columns where the values are not duplicated in any
other row in the same table.
CHECK Defines a checking rule to which the relevant column value must conform.
Check examples include BETWEEN 0 and 1000, IN (A, E, I,
O, U) similar syntax to SQL WHERE clause.
FOREIGN KEY Defines a cross reference to the PRIMARY KEY of another table; values in
the FOREIGN KEY column must already exist in the referenced table.
Example: a DEPARTMENT CODE in an EMPLOYEE table must
already exist (as a primary key) in a DEPARTMENT table.
Constraint attributes can also be entered as below:
DISABLED Constraint is not checked for new or existing data
DEFERRABLE Constraint is enabled but not checked until COMMIT
[NO]VALIDATE Constraint is [not] checked for existing rows
[NO]RELY Constraint is disabled but is valid for existing data relevant for
materialized views (not discussed in this class)

V2: Page 184 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 7 Schema Objects Oracle 10g Database Associate

Creating New Tables - Storage

Tablespace
logging parameters
Extents
initial size
Space Usage
percentage free/used
Free Lists
for dictionary tablespaces
Transactions
reserved space requirements
Buffer Pool
keep, recycle, default

ODBA10gDB-OCA-07-8 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Creating New Tables Storage

Tablespace Logging Parameters


This option specifies whether the creation of the table (and associated constraint indices) are logged
for recovery purposes by the Redo Logging mechanism. NOLOGGING operations are not recoverable,
therefore backups may be required to secure the contents of the relevant tables and indices.

Extent Parameters
Overrides the storage clause, initial extent size for the (dictionary managed) tablespaces.

Space Usage
Sets the spare space to be left in each block for growth to existing rows in blocks (see page 190). This
applies for objects in tablespaces with SEGMENT SPACE MANAGEMENT MANUAL only.

Transactions Parameters
Sets the number of concurrent updates that can be applied to a single block. Leave as default unless
using multi-cpu systems.

Buffer Pool
Select one of KEEP, RECYCLE or DEFAULT to assign blocks in the buffer cache to an appropriate
sub-pool. Requires appropriate memory configuration (discussed later).

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 185
Oracle 10g Database Associate Lesson 7 Schema Objects

Create New Tables - Options

Row Movement
allows silent optimisation of row placement
Parallelism
permits multiple processes for large tables
Cache
positions rows in optimum SGA buffer on scan

ODBA10gDB-OCA-07-9 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Creating New Tables Options

Row Movement
Determines whether Oracle can reposition rows, changing the inherent disk address (rowid). This
may occur during table compression of regular (heap) tables (discussed in Lesson 19) and in other
operations on partitioned tables (not discussed in this course).

Parallelism
Determines whether table creation, queries and subsequent DML operations can be parallelised. Only
appropriate for multi-cpu systems. Values include PARALLEL, NOPARALLEL and PARALLEL n.

Cache
The inclusion of this keyword ensures that retrieved rows are placed at the most recently used end of
the buffer list within the SGA buffer cache on a full table scan. If the (default) NOCACHE clause is
specified, rows retrieved during a full table scan are usually placed at the least recently used end of
the buffer cache list.

V2: Page 186 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 7 Schema Objects Oracle 10g Database Associate

Creating New Tables - SQL

CREATE TABLE tablename (


columnName dataType,
columnName dataType, ...

CREATE TABLE dept (


code NUMBER(4),
name VARCHAR2(15)
);

ODBA10gDB-OCA-07-10 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Creating New Tables SQL


All EM statements that operate on tables can be executed using any of the SQL interfaces.
For further details, generate the required statement using EM screen, then select the Show SQL button
.
Sample statements are illustrated below:

CREATE TABLE tableName (


columnName dataType [, columnName dataType ]...)
[ TABLESPACE tablespace ]
[ PCTFREE integer ]
[ PCTUSED integer ]
[ STORAGE storage-clause ];

Note this is not the complete syntax for the statement.

CREATE TABLE emp (


code NUMBER(4),
ename VARCHAR2(14),
dob DATE,
deptno NUMBER(2),
sal NUMBER(7,2))
TABLESPACE data1
PCTFREE 20
STORAGE (initial 10k next 10k pctincrease 0);

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 187
Oracle 10g Database Associate Lesson 7 Schema Objects

Table Storage

PCTFREE n
PCTUSED n Header
STORAGE ( Spare
INITIAL nk
NEXT nK
MINEXTENTS n
Data rows
MAXEXTENTS n
PCTINCREASE n
)

ODBA10gDB-OCA-07-11 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Table Storage
For dictionary managed tablespaces, the following options can be specified:

PCTFREE Percentage of space to leave free fill each block up to 100 PCTFREE

PCTUSED Percentage of free space to begin reinserting rows.

STORAGE INITIAL Size of first extent in blocks

NEXT Size of next extent in blocks

PCTINCREASE Percentage increase after initial and next extents

MINEXTENTS Minimum number of extents for table

MAXEXTENTS Maximum number of extents for table

V2: Page 188 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 7 Schema Objects Oracle 10g Database Associate

Managing Tables

ALTER TABLE t
Table storage and column structure can be
altered in place
DROP TABLE t [PURGE]
Dropped tables are placed into a
RECYCLEBIN, unless PURGE is specified
MOVE
ALTER can move table to new tablespace

ODBA10gDB-OCA-07-12 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Managing Tables
Some sample statements are illustrated below:

ALTER TABLE
ALTER TABLE t STORAGE (storage-clause);

ALTER TABLE t PCTFREE integer;

ALTER TABLE t ALLOCATE EXTENT (SIZE integer DATAFILE d);

ALTER TABLE t ADD (new column);

ALTER TABLE t MODIFY (column);

ALTER TABLE t DROP COLUMN ;

ALTER TABLE t SET UNUSED COLUMN c;

ALTER TABLE t DROP UNUSED COLUMNS;

DROP TABLE
DROP TABLE t;

DROP TABLE t PURGE;

MOVE TABLE
ALTER TABLE t MOVE TABLESPACE t;

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 189
Oracle 10g Database Associate Lesson 7 Schema Objects

Table Block Usage

Header used for row


locks and control data Header

Spare space reserved Spare


for growth of existing
rows
Data rows stored as Data rows
"row pieces" with varying
sizes for efficiency

ODBA10gDB-OCA-07-13 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Table Block Usage

A data block for a table is split into three sections:

Header holds control and locking information for rows in the block

Spare reserved space, controlled by the tables PCTFREE clause (for tablespaces
specified with SEGMENT SPACE MANAGEMENT MANUAL). The reserved
space is maintained for updates to existing rows in the block.

Data rows the table data, split into row pieces, that are reassembled into a complete
row for query purposes and returned to the requesting user process.

V2: Page 190 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 7 Schema Objects Oracle 10g Database Associate

Indexes

Logical index types


Single column v Multi column
Unique or Duplicate
Physical index types
Non-partitioned v Partitioned
B-Tree
Normal v Reverse
Bitmap Header Value
Len Rowid

ODBA10gDB-OCA-07-14 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Indexes
For any column or combination of columns in a table, a corresponding index structure can be defined
to hold the indexed column values for fast searching and sorting. When a suitable index exists, the
Oracle optimiser will use the index to devise the execution plan for the query.
Indexes require additional disk space and processing for updates; the additional cost of maintaining
the index may be offset by the improved response times on queries.
Indexes can be categorised as below:
Logical Single Column Index declared on a single column.
Multiple Composite index declared on multiple columns;
Column Leading edge of the index must be specified in a query
Unique The index does not allow multiple identical values (primary key)
Duplicate The index permits multiple identical values
Physical Non-partitioned Normal index, contained in a single tablespace
Partitioned Split index; can reside across multiple tablespaces
B-tree Normal / Index is held in forward order (for exact match and
Reverse range searches) or reverse order (for exact match
searches only).
Bitmap Index type that favours data warehousing style queries on large
amounts of data with a limited range of data values (low
cardinality).

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 191
Oracle 10g Database Associate Lesson 7 Schema Objects

Index Storage

PCTFREE n
PCTUSED n Header
STORAGE ( Spare
INITIAL nk
NEXT nK
MINEXTENTS n
Index
MAXEXTENTS n
PCTINCREASE n entries
)

ODBA10gDB-OCA-07-15 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Index Storage

The storage clauses are similar to the TABLE storage clause.

PCTFREE indicates the percentage block space to be reserved for newly inserted rows within the
current range of keys in the block. A table where inserts are performed in key sequence can use a
low PCTFREE value. Where keys are inserted out of sequence, efficiency may be improved by
specifying a higher PCTFREE value.

PCTUSED does not apply to index segments / blocks.

V2: Page 192 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 7 Schema Objects Oracle 10g Database Associate

Managing Indexes

CREATE
ALTER
REBUILD
MOVE
DROP

ODBA10gDB-OCA-07-16 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Managing Indexes
Some sample statements are illustrated below:

Create Index
CREATE INDEX i ON t(c);

CREATE UNIQUE INDEX I_Empno ON emp(empno)


TABLESPACE indx STORAGE (INITIAL 10K NEXT 10K PCTINCREASE 0);

CREATE INDEX i_ename ON emp(lastname, firstname);

Alter Index
ALTER INDEX i_empno PCTFREE 20;

ALTER INDEX i_ename REBUILD TABLESPACE index2;

ALTER INDEX i_ename REBUILD ONLINE;

Drop Index
DROP INDEX i_ename;

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 193
Oracle 10g Database Associate Lesson 7 Schema Objects

Views

Stored query on base table


Parameters include
View Name
Replace if exists
Query text
Options
Force
Read-only
With check option
ODBA10gDB-OCA-07-17 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Views

Database views are stored SQL statements that can be used in queries (and in restricted DML
statements) in place of base tables.

Parameters required to create views include:

View Name Standard Oracle naming rules apply (as already discussed)

Replace if Exists If checked, create view unconditionally. If not checked, and view
exists, reports an error

Query Text SQL query to be used as the source of the view

Options Force Create view even if base objects do not exist

Options ReadOnly Mark view as non-updatable

Options With Check For updateable views, create associated constraint to prevent DML
operations removing rows from the view

V2: Page 194 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 7 Schema Objects Oracle 10g Database Associate

Sequences

Number generators for primary keys


Arguments include
Maximum
Minimum
Interval
Initial
Cycle
Order
Cache
ODBA10gDB-OCA-07-18 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Sequences
A database sequence is an independent object used to generate integer numbers in sequence to be used
as primary keys for tables.
Sequences are immune to transaction rollback operations, therefore once a sequence number has been
reserved, the same number will not be reused unless the sequence recycles back to the start.
Sequence numbers can also be cached in memory for speed; however, if the instance aborts, cached
sequence numbers will be lost.
Sequence creation arguments include:
Maximum Must be greater than initial and minimum values
Minimum Must be less than or equal to initial value and less than maximum value
Interval Specifies the Increment By value; negative values generate reversing values
Initial Specifies the Start With value
Cycle Boolean setting to indicate whether the sequence cycles back after reaching the
maximum value
Order Boolean value to ensure that sequence numbers are generated in order of request; only
applicable for Real Application Cluster (RAC) systems
Cache Specifies count of sequences to cache in memory

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 195
Oracle 10g Database Associate Lesson 7 Schema Objects

Using Sequences

To use a new sequence number


INSERT INTO emp VALUES (
emp_seq.nextval, ...)

To reuse the same sequence number


within a single transaction
INSERT INTO empsal VALUES (
emp_seq.currval, ...)

ODBA10gDB-OCA-07-19 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Using Sequences

A created sequence has two properties that can be referenced, either in SQL statements or inside
PL/SQL code blocks.

The NEXTVAL property retrieves a new sequence number and automatically advances the sequence
counter to the next available value.

The CURRVAL property retrieves the previous value (within the same transaction) to allow reuse of
the same value for different tables.

V2: Page 196 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 7 Schema Objects Oracle 10g Database Associate

Data Dictionary

DBA_TABLES
DBA_TAB_COLUMNS
DBA_INDEXES
DBA_IND_COLUMNS
DBA_VIEWS
DBA_SEQUENCES

ODBA10gDB-OCA-07-20 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Data Dictionary

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 197
Oracle 10g Database Associate Lesson 7 Schema Objects

DBA_TABLES

Name Null? Type


----------------------------------------- -------- ----------------------------
OWNER NOT NULL VARCHAR2(30)
TABLE_NAME NOT NULL VARCHAR2(30)
TABLESPACE_NAME VARCHAR2(30)
CLUSTER_NAME VARCHAR2(30)
IOT_NAME VARCHAR2(30)
STATUS VARCHAR2(8)
PCT_FREE NUMBER
PCT_USED NUMBER
INI_TRANS NUMBER
MAX_TRANS NUMBER
INITIAL_EXTENT NUMBER
NEXT_EXTENT NUMBER
MIN_EXTENTS NUMBER
MAX_EXTENTS NUMBER
PCT_INCREASE NUMBER
FREELISTS NUMBER
FREELIST_GROUPS NUMBER
LOGGING VARCHAR2(3)
BACKED_UP VARCHAR2(1)
NUM_ROWS NUMBER
BLOCKS NUMBER
EMPTY_BLOCKS NUMBER
AVG_SPACE NUMBER
CHAIN_CNT NUMBER
AVG_ROW_LEN NUMBER
AVG_SPACE_FREELIST_BLOCKS NUMBER
NUM_FREELIST_BLOCKS NUMBER
DEGREE VARCHAR2(10)
INSTANCES VARCHAR2(10)
CACHE VARCHAR2(5)
TABLE_LOCK VARCHAR2(8)
SAMPLE_SIZE NUMBER
LAST_ANALYZED DATE
PARTITIONED VARCHAR2(3)
IOT_TYPE VARCHAR2(12)
TEMPORARY VARCHAR2(1)
SECONDARY VARCHAR2(1)
NESTED VARCHAR2(3)
BUFFER_POOL VARCHAR2(7)
ROW_MOVEMENT VARCHAR2(8)
GLOBAL_STATS VARCHAR2(3)
USER_STATS VARCHAR2(3)
DURATION VARCHAR2(15)
SKIP_CORRUPT VARCHAR2(8)
MONITORING VARCHAR2(3)
CLUSTER_OWNER VARCHAR2(30)
DEPENDENCIES VARCHAR2(8)
COMPRESSION VARCHAR2(8)
DROPPED VARCHAR2(3)

V2: Page 198 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 7 Schema Objects Oracle 10g Database Associate

DBA_TAB_COLUMNS

Name Null? Type


----------------------------------------- -------- ----------------------------
OWNER NOT NULL VARCHAR2(30)
TABLE_NAME NOT NULL VARCHAR2(30)
COLUMN_NAME NOT NULL VARCHAR2(30)
DATA_TYPE VARCHAR2(106)
DATA_TYPE_MOD VARCHAR2(3)
DATA_TYPE_OWNER VARCHAR2(30)
DATA_LENGTH NOT NULL NUMBER
DATA_PRECISION NUMBER
DATA_SCALE NUMBER
NULLABLE VARCHAR2(1)
COLUMN_ID NUMBER
DEFAULT_LENGTH NUMBER
DATA_DEFAULT LONG
NUM_DISTINCT NUMBER
LOW_VALUE RAW(32)
HIGH_VALUE RAW(32)
DENSITY NUMBER
NUM_NULLS NUMBER
NUM_BUCKETS NUMBER
LAST_ANALYZED DATE
SAMPLE_SIZE NUMBER
CHARACTER_SET_NAME VARCHAR2(44)
CHAR_COL_DECL_LENGTH NUMBER
GLOBAL_STATS VARCHAR2(3)
USER_STATS VARCHAR2(3)
AVG_COL_LEN NUMBER
CHAR_LENGTH NUMBER
CHAR_USED VARCHAR2(1)
V80_FMT_IMAGE VARCHAR2(3)
DATA_UPGRADED VARCHAR2(3)
HISTOGRAM VARCHAR2(15)

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 199
Oracle 10g Database Associate Lesson 7 Schema Objects

DBA_INDEXES
Name Null? Type
----------------------------------------- -------- ----------------------------

OWNER NOT NULL VARCHAR2(30)


INDEX_NAME NOT NULL VARCHAR2(30)
INDEX_TYPE VARCHAR2(27)
TABLE_OWNER NOT NULL VARCHAR2(30)
TABLE_NAME NOT NULL VARCHAR2(30)
TABLE_TYPE VARCHAR2(11)
UNIQUENESS VARCHAR2(9)
COMPRESSION VARCHAR2(8)
PREFIX_LENGTH NUMBER
TABLESPACE_NAME VARCHAR2(30)
INI_TRANS NUMBER
MAX_TRANS NUMBER
INITIAL_EXTENT NUMBER
NEXT_EXTENT NUMBER
MIN_EXTENTS NUMBER
MAX_EXTENTS NUMBER
PCT_INCREASE NUMBER
PCT_THRESHOLD NUMBER
INCLUDE_COLUMN NUMBER
FREELISTS NUMBER
FREELIST_GROUPS NUMBER
PCT_FREE NUMBER
LOGGING VARCHAR2(3)
BLEVEL NUMBER
LEAF_BLOCKS NUMBER
DISTINCT_KEYS NUMBER
AVG_LEAF_BLOCKS_PER_KEY NUMBER
AVG_DATA_BLOCKS_PER_KEY NUMBER
CLUSTERING_FACTOR NUMBER
STATUS VARCHAR2(8)
NUM_ROWS NUMBER
SAMPLE_SIZE NUMBER
LAST_ANALYZED DATE
DEGREE VARCHAR2(40)
INSTANCES VARCHAR2(40)
PARTITIONED VARCHAR2(3)
TEMPORARY VARCHAR2(1)
GENERATED VARCHAR2(1)
SECONDARY VARCHAR2(1)
BUFFER_POOL VARCHAR2(7)
USER_STATS VARCHAR2(3)
DURATION VARCHAR2(15)
PCT_DIRECT_ACCESS NUMBER
ITYP_OWNER VARCHAR2(30)
ITYP_NAME VARCHAR2(30)
PARAMETERS VARCHAR2(1000)
GLOBAL_STATS VARCHAR2(3)
DOMIDX_STATUS VARCHAR2(12)
DOMIDX_OPSTATUS VARCHAR2(6)
FUNCIDX_STATUS VARCHAR2(8)
JOIN_INDEX VARCHAR2(3)
IOT_REDUNDANT_PKEY_ELIM VARCHAR2(3)
DROPPED VARCHAR2(3)

V2: Page 200 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 7 Schema Objects Oracle 10g Database Associate

DBA_IND_COLUMNS

Name Null? Type


----------------------------------------- -------- ----------------------------
INDEX_OWNER NOT NULL VARCHAR2(30)
INDEX_NAME NOT NULL VARCHAR2(30)
TABLE_OWNER NOT NULL VARCHAR2(30)
TABLE_NAME NOT NULL VARCHAR2(30)
COLUMN_NAME VARCHAR2(4000)
COLUMN_POSITION NOT NULL NUMBER
COLUMN_LENGTH NOT NULL NUMBER
CHAR_LENGTH NUMBER
DESCEND VARCHAR2(4)

DBA_VIEWS

Name Null? Type


----------------------------------------- -------- ----------------------------
OWNER NOT NULL VARCHAR2(30)
VIEW_NAME NOT NULL VARCHAR2(30)
TEXT_LENGTH NUMBER
TEXT LONG
TYPE_TEXT_LENGTH NUMBER
TYPE_TEXT VARCHAR2(4000)
OID_TEXT_LENGTH NUMBER
OID_TEXT VARCHAR2(4000)
VIEW_TYPE_OWNER VARCHAR2(30)
VIEW_TYPE VARCHAR2(30)
SUPERVIEW_NAME VARCHAR2(30)

DBA_SEQUENCES

Name Null? Type


----------------------------------------- -------- ----------------------------
SEQUENCE_OWNER NOT NULL VARCHAR2(30)
SEQUENCE_NAME NOT NULL VARCHAR2(30)
MIN_VALUE NUMBER
MAX_VALUE NUMBER
INCREMENT_BY NOT NULL NUMBER
CYCLE_FLAG VARCHAR2(1)
ORDER_FLAG VARCHAR2(1)
CACHE_SIZE NOT NULL NUMBER
LAST_NUMBER NOT NULL NUMBER

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 201
Oracle 10g Database Associate Lesson 7 Schema Objects

Summary

In this lesson, you learnt about:


Creating and modifying tables
Selecting appropriate data types
Defining constraints
Viewing the attributes and contents of tables
Creating indexes and views
Creating and use sequences

ODBA10gDB-OCA-07-21 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Summary
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

V2: Page 202 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 7 Schema Objects Oracle 10g Database Associate

Practice 7

Create a copy of SCOTT's EMP table, in


the SYSTEM schema, called NEWEMP
Create a new duplicate index on the
NEWEMP ENAME column
Create a new sequence in SYSTEM
Insert three rows into the NEWEMP table,
using the sequence as a primary key
Create a view called EMPMGR on
SCOTT.EMP to show managers only
ODBA10gDB-OCA--07-22 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Practice 7
In this practice, you will work with tables, indexes, sequences and views.

Use EM to create a copy of the SCOTT.EMP table in the SYSTEM schema, called NEWEMP.
(Ch07CreateNewEmp.sql)
________________________________________________________________________
________________________________________________________________________

Copy the data into the new table, using the following SQL command: (Ch07CopyEmpData.sql)
INSERT INTO NEWEMP SELECT * FROM SCOTT.EMP
________________________________________________________________________
________________________________________________________________________

After loading the new table, create a new duplicate index on the new tables ENAME column.
(Ch07CreateIndex.sql)
________________________________________________________________________
________________________________________________________________________

Create a new sequence called EMPSEQ in the SYSTEM schema specify the start value as 100
(Ch07CreateSequence.sql).
________________________________________________________________________
________________________________________________________________________

Insert three new rows into the NEWEMP table, using the sequence as the primary key
(Ch07InsertEmployees.sql).
________________________________________________________________________

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 203
Oracle 10g Database Associate Lesson 7 Schema Objects

________________________________________________________________________

Create a new view, EMPMGR, using the clause WHERE JOB = 'MANAGER'
(Ch07CreateView.sql)
________________________________________________________________________
________________________________________________________________________

Confirm that the view is working as you expected.


________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

V2: Page 204 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 8 Undo Management Oracle 10g Database Associate

8
0
Undo Management

ODBA10gDB-OCA-08-1 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

LESSON 8 UNDO MANAGEMENT


Lesson 8 describes the usage, configuration and administration of undo areas.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 205
Oracle 10g Database Associate Lesson 8 Undo Management

Objectives

After completing this lesson, you should be


able to do the following:
Comprehend the purpose of Undo space
Monitor and administer undo
Use the Undo Advisor
Understand undo use by transactions
Size an undo tablespace
Guarantee undo retention

ODBA10gDB-OCA-08-2 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Objectives
Lesson 8 describes the usage, configuration and administration of undo areas. Topics include:
Understanding the purpose of Undo space
Create, monitor and configure Undo space
Use the Undo Advisor for automated advice
Understand the use of undo space by transactions
Size an undo tablespace appropriately
Know how to set guaranteed retention periods and understand the implications

V2: Page 206 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 8 Undo Management Oracle 10g Database Associate

Undo Basics

Standard feature to hold pending changes


Information used for several purposes
to roll back transactions on request
to reconstruct old images of rows
assist in database recovery
support Flashback operations
Every database requires undo tablespace
Can be 'Fire and Forget' after creation

ODBA10gDB-OCA-08-3 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Undo Basics

Oracle has a mechanism for storing sufficient information to be able to reverse the effect of a
transaction. Information is written to a reserved area (the Undo tablespace) by update statements.

This undo information may additionally be used for:


Reversing a transaction in response to a ROLLBACK statement.
Recovering part or all of the database contents following a media or power failure.
Providing read consistent (unupdated) views of data in the process of being altered.
Return historical data and recovering from logical corruptions using Oracle Flashback.

Pre-10g versions of Oracle called this facility ROLLBACK. Oracle 10g still uses a single rollback
segment in the SYSTEM tablespace for selected system operations.

Every database should have a dedicated Undo tablespace for normal user transactional updates.

Once an Undo tablespace has been created and sized correctly, management can be automatic unless a
major change to the system configuration or application load occurs.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 207
Oracle 10g Database Associate Lesson 8 Undo Management

Creating Undo Tablespace - SQL

Default created at database creation time


Further undo tablespaces can be added

Undo tablespace extent management


must be 'local autoallocate'
Autoextend recommended for future use

ODBA10gDB-OCA-08-4 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Creating Undo Tablespace SQL

When a new database is created during installation or subsequently using the DBCA, an Undo
tablespace is automatically created.

New undo tablespaces can be created as required, to distribute I/O loads across multiple disk units.

On instance startup, if multiple undo tablespaces are found, the first available undo tablespace is
selected for activation. If no undo tablespaces are located, undo information is written to the
SYSTEM tablespace; this is not recommended for long-term production use.

To activate a specific undo tablespace, the initialisation parameter UNDO_TABLESPACE =


tableSpaceName canbe set. This dynamic parameter can be changed whilst an instance is running.

V2: Page 208 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 8 Undo Management Oracle 10g Database Associate

The CREATE UNDO TABLESPACE command can be used to build additional tablespaces manually
(Ch08CreateUndoSpace.sql).

SQL> CREATE UNDO TABLESPACE undotbs2


2 DATAFILE 'undotbs2.dbf' SIZE 25M
3 REUSE AUTOEXTEND ON;

Datafiles for undo tablespaces must use local for extent management and auto[allocate]
for segment space management. These defaults allows Oracle to create, manage and optimise undo
segments automatically within the undo tablespace, without further DBA intervention.

To prevent running out of disk space for undo information, Oracle recommend that the
autoextend property is specified for all datafiles belonging to undo tablespaces.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 209
Oracle 10g Database Associate Lesson 8 Undo Management

Creating Undo Tablespace with EM

ODBA10gDB-OCA-08-5 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Creating Undo Tablespace with EM

To create an undo tablespace using Enterprise Manager, select Administration > Tablespaces. From
the list of tablespaces, select the Create button.

Enter a name for the tablespace.

Select the type of the new tablespace as UNDO. Leave Extent Management as Locally
Managed and Status as Read Write.

Click the Add button to specify a datafile name, location and size.

V2: Page 210 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 8 Undo Management Oracle 10g Database Associate

Creating Undo Datafile with EM

ODBA10gDB-OCA-08-6 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Creating Undo Datafile with EM


On the Add Datafile screen, enter a file name for the new datafile.

Change the default directory location if appropriate.

Check and change the size of the file to be created if required.

As already recommended, it is advised to check the Automatically extend checkbox


and enter an increment (and maximum file size if required) to allow the new file to grow if necessary.

Click Continue to return to the previous screen.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 211
Oracle 10g Database Associate Lesson 8 Undo Management

Undo Storage Tablespace Parameters

ODBA10gDB-OCA-08-7 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Undo Storage Tablespace Parameters

During undo tablespace creation, these parameters can be displayed after file names are added to the
creation command.

For existing undo tablespaces, these parameters can be displayed by selecting the Storage tab in the
Create Tablespace screen.

The parameters displayed are for information only and should not generally be changed by the DBA.

V2: Page 212 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 8 Undo Management Oracle 10g Database Associate

Managing Undo Tablespace

Only one undo tablespace can be active


Undo tablespace switch at any time
Inactive undo tablespace can be dropped
Initialisation parameters:
UNDO_MANAGEMENT = AUTO | MANUAL
UNDO_TABLESPACE = tableSpaceName
UNDO_RETENTION = 900 [seconds]

ODBA10gDB-OCA-08-8 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Managing Undo Tablespace


A database instance can use any one of the available undo tablespaces on startup.

The UNDO_TABLESPACE dynamic parameter can be changed at any time to use another available undo
tablespace. The old tablespace can be dropped, once any active space within the tablespace has been
released by all potential transactions that may require the information.

The default value of the initialisation parameter UNDO_MANAGEMENT = AUTO should be


retained. The MANUAL setting is for backwards compatibility with releases prior to 10g and should
not generally be used.

The UNDO_RETENTION = seconds parameter is also not required for most databases. Oracle will
automatically tune the use of undo to achieve the maximum possible undo retention period within the
bounds of assigned and available disk space.

This parameter should only be set in the following circumstances:


If the undo tablespace datafiles are set to AUTOEXTEND
Undo retention is set for LOB data types
A guaranteed retention period is required (see page 220)

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 213
Oracle 10g Database Associate Lesson 8 Undo Management

Activating Undo Tablespace

ODBA10gDB-OCA-08-9 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Activating Undo Tablespace

To activate a different undo tablespace using Enterprise Manager, select Administration > Database
Configuration > Undo Management.

Use the Change tablespace


button to select another
tablespace to activate for the
current instance.

V2: Page 214 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 8 Undo Management Oracle 10g Database Associate

Undo Space Usage

Undo data in undo tablespace is :


active : required for read consistency
expired : may still be needed for flashback
unused : not used by this instance
Minimum size to hold active transactions

ODBA10gDB-OCA-08-10 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Undo Space Usage


Within the current undo tablespace, disk areas are classified in one of the following categories:

Active Space containing information that is still required by active transactions for future read
consistency.

Expired Space containing information for completed transactions that may still be required for
future flashback operations.

Unused Space that can be released from the undo tablespace datafiles if the file is resized to be
smaller than at present (wasted space!).

A minimum sized undo tablespace will only retain active space and can reuse expired space as
required. Assigning more space gives more likelihood that other, unrelated transactions will succeed
and not report Snapshot too old errors.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 215
Oracle 10g Database Associate Lesson 8 Undo Management

Undo Generation Statistics

ODBA10gDB-OCA-08-11 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Undo Generation Statistics


In order to determine a useful undo tablespace and datafile size, Enterprise Manager provides a
variety of statistics to explain the use of assigned undo space. Basic statistics are displayed on the
Administration > Undo Management page:

Query time in minutes, together with average and maximum undo generation rates (KB/minute) are
shown automatically.

The Show Graph link on this page shows three additional graphs,
illustrating the following information for the monitored period. This
value can be changed with the Analysis Time Period drop down list:

Undo tablespace usage green areas indicate possible oversized undo tablespaces
Undo retention auto tuning shows longest running query and maximum flashback duration
Undo generation rate in KB/second

V2: Page 216 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 8 Undo Management Oracle 10g Database Associate

Manual Sizing

Measure undo space use at peak periods


Insufficient space results in 'Snapshot too
old' error messages
Monitor using V$UNDOSTAT

ODBA10gDB-OCA-08-12 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Manual Sizing
For manually sizing undo space, measurements should be taken at peak periods.

If insufficient space is available i.e. the undo tablespace is sized too small, other transactions may fail
with intermittent Snapshot too old errors.

The dynamic performance table V$UNDOSTAT holds statistics gathered every 10 minutes to show the
undo block consumption and any transactions failing because of undo space unavailability
(Ch08UndoStats.sql):

SQL> SELECT to_char(end_time, 'DD-MM-YYYY HH24:MI') end_time,


2* undoblks, ssolderrcnt FROM v$undostat;

END_TIME UNDOBLKS SSOLDERRCNT


---------------- ---------- -----------
21-09-2005 17:02 82 0
21-09-2005 16:57 18 0
21-09-2005 16:47 15 0
21-09-2005 16:37 5 0
21-09-2005 16:27 22 0
21-09-2005 16:17 13 0
21-09-2005 16:07 71 0
21-09-2005 15:57 19 0
21-09-2005 15:47 24 0
21-09-2005 15:37 6 0
21-09-2005 15:27 13 0
... ... ...

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 217
Oracle 10g Database Associate Lesson 8 Undo Management

Automatic Sizing with Undo Advisor

ODBA10gDB-OCA-08-13 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Automated Sizing with Undo Advisor

From the Undo Management page, the Undo Advisor button invokes an automated advisor showing
statistics that calculate a recommended size for the undo tablespace based on the recent transaction
load. If the undo_retention parameter is set (see page 213), the guaranteed retention period
is also taken into account in the calculation.

V2: Page 218 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 8 Undo Management Oracle 10g Database Associate

Sizing Undo Tablespace

Use Undo
Advisor graph
Click point on
graph
New size &
period will be
computed

ODBA10gDB-OCA-08-14 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Sizing Undo Tablespace

The graph below the advisor statistics shows the maximum undo retention period plotted against the
amount of disk space required.

Click any point on the


graph to change the value
in the statistics section of
the display for New Undo
Retention.

To apply the change, click


the OK button.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 219
Oracle 10g Database Associate Lesson 8 Undo Management

Undo Retention Guarantee

Optional guarantee of undo retention


Disabled by default for new databases
DML operations may fail if option enabled
Used to ensure successful Flashback
operations

ODBA10gDB-OCA-08-15 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Undo Retention Guarantee


Oracle 10g attempts to maintain information in the undo tablespace for as long as possible. The main
control that should be applied by the DBA is in setting the size and autoextend parameters for the
undo tablespace and datafiles belonging to the tablespace.

For more control, an undo tablespace can have a RETENTION GUARANTEE set. Use the following SQL
commands to set this value (Ch08RetentionGuarantee.sql):

SQL> ALTER TABLESPACE undoTableSpace RETENTION GUARANTEE;

Setting this value ensure that the minimum undo_retention period is used to retain undo information
for at least this length of time (in seconds), even if inactive but unexpired data space is required by
other transactions. This may mean that some transactions may fail due to a lack of space in the undo
tablespace.
The retention guarantee can be cleared for a tablespace with the following command:

SQL> ALTER TABLESPACE undoTableSpace RETENTION NOGUARANTEE;

If retention guarantee is disabled, Oracle may overwrite unexpired undo when space is low. This
reduces the effective undo retention period for the database. Some queries may therefore fail with a
Snapshot too old error message. This option is disabled by default in new databases.

V2: Page 220 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 8 Undo Management Oracle 10g Database Associate

Summary

By completing this lesson, you should be


able to do the following:
Monitor and administer undo
Configure undo retention
Use the Undo Advisor
Describe the relationship between undo and
transactions
Size the undo tablespace
Guarantee undo retention

ODBA10gDB-OCA-08-16 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Summary
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 221
Oracle 10g Database Associate Lesson 8 Undo Management

Practice 8

Examine the Undo Management setup for


your database
Configure a new undo tablespace using
Enterprise Manager
Check undo space recommendations
using both the EM Undo Advisor and the
V$UNDOSTAT dynamic performance view
Your instructor will provide further
commands to exercise the undo system
ODBA10gDB-OCA-08-17 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Practice 8
In this practice, you will configure and manage undo tablespaces

Use EM to examine the undo management setup for your database (Ch08UndoInfo.sql).
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

Configure a new undo tablespace using Enterprise Manager. Recheck your current setup to ensure
that the new undo tablespace is being used. (Ch08CreateUndoSpace.sql):
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

Check the space recommendations from both the EM Undo Advisor and the dynamic performance
table V$UNDOSTAT in the SGA (Ch08UndoInfo.sql).
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

V2: Page 222 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 8 Undo Management Oracle 10g Database Associate

Your instructor will provide you with additional examples of SQL statements to exercise the undo
setup (Ch08Exercise.sql).
________________________________________________________________________
________________________________________________________________________

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 223
Oracle 10g Database Associate Lesson 8 Undo Management

This page intentionally left blank

V2: Page 224 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

9
0
Data Administration

ODBA10gDB-OCA-09-1 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

LESSON 9 DATA ADMINISTRATION


Lesson 9 discusses the SQL commands and external utilities used to move data inside and across
Oracle databases.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 225
Oracle 10g Database Associate Lesson 9 Data Administration

Objectives

After completing this lesson, you should be


able to manage data movement using:
SQL DML Statements (INSERT, MERGE)
Data Pump to export and import database
structure and contents
SQL-Loader to import from external
sources
Oracle directories for locating data

ODBA10gDB-OCA-09-2 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Objectives
Lesson 9 describes discusses the SQL commands and external utilities used to move data inside and
across Oracle databases. Topics include:
The SQL INSERT and MERGE statements
The DataPump technology in the database server
The expdp and impdp command line utilities for accessing DataPump
The SQL*Loader utility for importing external files
The use of Oracle directory objects in conjunction with other utilities

V2: Page 226 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

Moving Data

Why does data need to move?


Intra-database
Reorganising disk locations
Redefining data structures
Inter-database
OLTP to Data Warehousing
Extra-database
From external & legacy systems

ODBA10gDB-OCA-09-3 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Moving Data

Data rows that have already been loaded into Oracle tables may need to be moved for several reasons.

Within a single database, rows might be moved for technical reasons to another tablespace or
datafile or for business reasons, perhaps to preserve a copy of all or part of a table for further
analysis.

More frequently, data is moved between OLTP and Data Warehousing databases, as part of an ETL
(Extract, Transform, Load) sequence of operations.

There is also the option of loading data into Oracle from external or legacy sources.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 227
Oracle 10g Database Associate Lesson 9 Data Administration

Intra-Database Movement - Insert

Data can be moved using SQL statements


INSERT SELECT copies rows between
tables
INSERT
INSERT INTO
INTO research_employees
research_employees
SELECT
SELECT ** FROM
FROM emp
emp WHERE
WHERE deptno
deptno == 20
20

INSERT ALL/FIRST inserts/updates rows


INSERT
INSERT ALL
ALL
WHEN
WHEN job
job == 'MANAGER'
'MANAGER' THEN
THEN
INTO
INTO empman
empman
WHEN
WHEN job
job == 'SALESMAN'
'SALESMAN' THEN
THEN
INTO
INTO empsales
empsales VALUES
VALUES (empno,
(empno, ename,
ename, sal
sal ++ comm)
comm)

ODBA10gDB-OCA-09-4 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Intra-Database Movement - Insert


The INSERT INTO table SELECT ... statement is used to select all columns, selected columns
or aggregated values from base (source) tables and insert the relevant rows into an existing (target)
table.

The SELECT statement can use any required clause that is permitted for this statement
(Ch09InsertSelect.sql).

SQL> INSERT INTO newemp SELECT * FROM scott.emp ORDER BY ename;

To insert only certain columns into the target table, the colums must be specified after the tablename
as illustrated below(Ch09InsertPartSelect.sql):

SQL> INSERT INTO newemp(empno, ename, sal)


2 SELECT empno, ename, sal from scott.emp ORDER BY ename;

V2: Page 228 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

The INSERT ALL/FIRST statement is used to pivot the rows from a source table into multiple target
tables (Ch09SplitTableQuery.sql).

SQL> CREATE TABLE emp10 AS SELECT * FROM scott.emp WHERE 1=0;

SQL> CREATE TABLE emp20 AS SELECT * FROM scott.emp WHERE 1=0;

SQL> CREATE TABLE emp30 AS SELECT * FROM scott.emp WHERE 1=0;

SQL> CREATE TABLE empothers AS


2 SELECT * FROM scott.emp WHERE 1=0;

SQL> INSERT ALL


2 WHEN deptno = 10 THEN INTO emp10
3 WHEN deptno = 20 THEN INTO emp20
4 WHEN deptno = 30 THEN INTO emp30
5 ELSE INTO empothers
6 SELECT * FROM scott.emp;

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 229
Oracle 10g Database Associate Lesson 9 Data Administration

Intra-Database Movement - Merge

The Oracle 'MERGE' statement updates


or inserts rows in tables
Summarises data for further analysis
MERGE
MERGE INTO
INTO emp_new
emp_new e_n
e_n USING
USING
(( SELECT
SELECT ** FROM
FROM emp_old
emp_old )) e_o
e_o ON
ON (( e_n.empno
e_n.empno == e_o.empno
e_o.empno ))
WHEN
WHEN MATCHED
MATCHED THEN
THEN UPDATE
UPDATE SET
SET
e_n.ename
e_n.ename == e_o.ename,
e_o.ename, e_n.sal
e_n.sal == e_o.sal,
e_o.sal,
e_n.mgr
e_n.mgr == e_o.mgr,
e_o.mgr, e_n.deptno
e_n.deptno == e_o.deptno
e_o.deptno
WHEN
WHEN NOT
NOT MATCHED
MATCHED THEN
THEN
INSERT
INSERT (( e_n.empno,
e_n.empno, e_n.ename,
e_n.ename,
e_n.sal,
e_n.sal, e_n.mgr,
e_n.mgr, e_n.deptno
e_n.deptno ))
VALUES
VALUES (( e_o.empno,
e_o.empno, e_o.ename,
e_o.ename,
e_o.sal,
e_o.sal, e_o.mgr,
e_o.mgr, e_o.deptno
e_o.deptno ); );

ODBA10gDB-OCA-09-5 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Intra-Database Movement - Merge


The MERGE statement can be used to either insert new or update existing rows in a designated target
table.
The example below reads the emp_old table and matches rows with the emp_new table. Where a
row already exists in the emp_new table, it is updated with the information from the emp_old table.
For new rows, the relevant values are inserted into emp_new (Ch09Merge.sql).

SQL> CREATE TABLE emp_old AS SELECT * FROM scott.emp;

SQL> CREATE TABLE emp_new AS SELECT * FROM scott.emp WHERE empno <= 7788;

SQL> SELECT count(*) FROM emp_new;


COUNT(*)
----------
8

SQL> MERGE INTO emp_new e_n


2 USING ( SELECT * FROM emp_old ) e_o ON ( e_n.empno = e_o.empno )
3 WHEN MATCHED THEN UPDATE SET
4 e_n.ename = e_o.ename, e_n.sal = e_o.sal,
5 e_n.mgr = e_o.mgr, e_n.deptno = e_o.deptno
6 WHEN NOT MATCHED THEN
7 INSERT ( e_n.empno, e_n.ename, e_n.sal, e_n.mgr, e_n.deptno )
8 VALUES ( e_o.empno, e_o.ename, e_o.sal, e_o.mgr, e_o.deptno );

SQL> SELECT count(*) FROM emp_new;


COUNT(*)
----------
14

V2: Page 230 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

Data Pump Overview

Moves data across / inside databases


Implemented within database kernel
Accessed via command line utilities or
PL/SQL package (DBMS_DATAPUMP)
expdp
expdp impdp
impdp Others
Others

SERVER
DBMS_DATAPUMP
DBMS_DATAPUMP Data/Metadata
Data/Metadata Engine
Engine

Metadata
Metadata Direct
Direct External
External
API
API Path
Path API
API Table
Table API
API

ODBA10gDB-OCA-09-6 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

DataPump Overview

The DataPump facility is a feature within the database server for transferring data and structural
information (metadata) between databases as well as internally within a single database.

Access to the facility is provided via command line programs for exporting and importing information
from and to an Oracle database.

In addition, a stored procedure package (DBMS_DATAPUMP) can be utilised to invoke DataPump


functionality from user written programs.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 231
Oracle 10g Database Associate Lesson 9 Data Administration

expdp
expdp client
client Data Pump Architecture

Source Target

DataPump
DataPump Server
Server
Job
Job Process
Process

Master Dump Dump Master


table file set file set table

Server
Server DataPump
DataPump
Process
Process Job
Job

impdp
impdp client
client

ODBA10gDB-OCA-09-7 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Data Pump Architecture


When a DataPump request is made, an Oracle job is created and queued for execution i.e. the job does
not require continuous access to a workstation. The general job mechanism within Oracle is
discussed in a later lesson in this course.

DataPump export jobs create a Dump File Set in an Oracle directory (see page 238) residing on the
server.

Each DataPump job creates a Master Table in the schema of the user executing the job. This table
controls all aspects of the DataPump job, including the sequence of objects that were exported. The
Master Table is read first during an import and used to sequence the objects being imported. The
table can be used to restarted failed DataPump jobs and is automatically removed once the job has
completed successfully.

The master table is created with a name matching the specified or system-generated job name.

V2: Page 232 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

Master Table

SQL> DESC sys_export_schema_01


Name Null? Type
----------------------------------------- -------- --------------------------

PROCESS_ORDER NUMBER
DUPLICATE NUMBER
DUMP_FILEID NUMBER
DUMP_POSITION NUMBER
DUMP_LENGTH NUMBER
DUMP_ALLOCATION NUMBER
COMPLETED_ROWS NUMBER
ERROR_COUNT NUMBER
ELAPSED_TIME NUMBER
OBJECT_TYPE_PATH VARCHAR2(200)
OBJECT_PATH_SEQNO NUMBER
OBJECT_TYPE VARCHAR2(30)
IN_PROGRESS CHAR(1)
OBJECT_NAME VARCHAR2(500)
OBJECT_LONG_NAME VARCHAR2(4000)
OBJECT_SCHEMA VARCHAR2(30)
ORIGINAL_OBJECT_SCHEMA VARCHAR2(30)
PARTITION_NAME VARCHAR2(30)
SUBPARTITION_NAME VARCHAR2(30)
FLAGS NUMBER
PROPERTY NUMBER
COMPLETION_TIME DATE
OBJECT_TABLESPACE VARCHAR2(30)
SIZE_ESTIMATE NUMBER
OBJECT_ROW NUMBER
PROCESSING_STATE CHAR(1)
PROCESSING_STATUS CHAR(1)
BASE_PROCESS_ORDER NUMBER
BASE_OBJECT_TYPE VARCHAR2(30)
BASE_OBJECT_NAME VARCHAR2(30)
BASE_OBJECT_SCHEMA VARCHAR2(30)
ANCESTOR_PROCESS_ORDER NUMBER
DOMAIN_PROCESS_ORDER NUMBER
PARALLELIZATION NUMBER
UNLOAD_METHOD NUMBER
GRANULES NUMBER
SCN NUMBER
GRANTOR VARCHAR2(30)
XML_CLOB CLOB
NAME VARCHAR2(30)
VALUE_T VARCHAR2(4000)
VALUE_N NUMBER
IS_DEFAULT NUMBER
FILE_TYPE NUMBER
USER_DIRECTORY VARCHAR2(4000)
USER_FILE_NAME VARCHAR2(4000)
FILE_NAME VARCHAR2(4000)
EXTEND_SIZE NUMBER
FILE_MAX_SIZE NUMBER

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 233
Oracle 10g Database Associate Lesson 9 Data Administration

PROCESS_NAME VARCHAR2(30)
LAST_UPDATE DATE
WORK_ITEM VARCHAR2(30)
OBJECT_NUMBER NUMBER
COMPLETED_BYTES NUMBER
TOTAL_BYTES NUMBER
METADATA_IO NUMBER
DATA_IO NUMBER
CUMULATIVE_TIME NUMBER
PACKET_NUMBER NUMBER
OLD_VALUE VARCHAR2(4000)
SEED NUMBER
LAST_FILE NUMBER
USER_NAME VARCHAR2(30)
OPERATION VARCHAR2(30)
JOB_MODE VARCHAR2(30)
CONTROL_QUEUE VARCHAR2(30)
STATUS_QUEUE VARCHAR2(30)
REMOTE_LINK VARCHAR2(4000)
VERSION NUMBER
DB_VERSION VARCHAR2(30)
TIMEZONE VARCHAR2(64)
STATE VARCHAR2(30)
PHASE NUMBER
GUID RAW(16)
START_TIME DATE
BLOCK_SIZE NUMBER
METADATA_BUFFER_SIZE NUMBER
DATA_BUFFER_SIZE NUMBER
DEGREE NUMBER
PLATFORM VARCHAR2(101)
ABORT_STEP NUMBER
INSTANCE VARCHAR2(60)

V2: Page 234 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

Exporting with DataPump

Command Line: 'expdp' utility


EM: Maintenance > Data Movement > Export

ODBA10gDB-OCA-09-8 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Exporting with DataPump


DataPump exports can be started with the command line expdp utility.

This command line tool runs in several modes:


interactive mode,
with options specified on the command line or
options inside an parameter file, named on the command line using the
parfile=parameterFile.par keyword parameter.

Alternatively, the export can be started (and scheduled) using the Enterprise Manager. Select the
Maintenance tab > Data Movement > Export to Export Files links.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 235
Oracle 10g Database Associate Lesson 9 Data Administration

expdp options

C:\Exports>expdp help=y

Export: Release 10.2.0.1.0 - Production on Tuesday, 27 September, 2005 13:14:30

Copyright (c) 2003, 2005, Oracle. All rights reserved.

The Data Pump export utility provides a mechanism for transferring data objects
between Oracle databases. The utility is invoked with the following command:

Example: expdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp

You can control how Export runs by entering the 'expdp' command followed
by various parameters. To specify parameters, you use keywords:

Format: expdp KEYWORD=value or KEYWORD=(value1,value2,...,valueN)


Example: expdp scott/tiger DUMPFILE=scott.dmp DIRECTORY=dmpdir SCHEMAS=scott
or TABLES=(T1:P1,T1:P2), if T1 is partitioned table

USERID must be the first parameter on the command line.

Keyword Description (Default)


------------------------------------------------------------------------------
ATTACH Attach to existing job, e.g. ATTACH [=job name].
COMPRESSION Reduce size of dumpfile contents where valid
keyword values are: (METADATA_ONLY) and NONE.
CONTENT Specifies data to unload where the valid keywords are:
(ALL), DATA_ONLY, and METADATA_ONLY.
DIRECTORY Directory object to be used for dumpfiles and logfiles.
DUMPFILE List of destination dump files (expdat.dmp),
e.g. DUMPFILE=scott1.dmp, scott2.dmp, dmpdir:scott3.dmp.
ENCRYPTION_PASSWORD Password key for creating encrypted column data.
ESTIMATE Calculate job estimates where the valid keywords are:
(BLOCKS) and STATISTICS.
ESTIMATE_ONLY Calculate job estimates without performing the export.
EXCLUDE Exclude specific object types, e.g. EXCLUDE=TABLE:EMP.
FILESIZE Specify the size of each dumpfile in units of bytes.
FLASHBACK_SCN SCN used to set session snapshot back to.
FLASHBACK_TIME Time used to get the SCN closest to the specified time.
FULL Export entire database (N).
HELP Display Help messages (N).
INCLUDE Include specific object types, e.g. INCLUDE=TABLE_DATA.
JOB_NAME Name of export job to create.
LOGFILE Log file name (export.log).
NETWORK_LINK Name of remote database link to the source system.
NOLOGFILE Do not write logfile (N).
PARALLEL Change the number of active workers for current job.
PARFILE Specify parameter file.
QUERY Predicate clause used to export a subset of a table.
SAMPLE Percentage of data to be exported;
SCHEMAS List of schemas to export (login schema).
STATUS Frequency (secs) job status is to be monitored where
the default (0) will show new status when available.
TABLES Identifies a list of tables to export - one schema only.
TABLESPACES Identifies a list of tablespaces to export.
TRANSPORT_FULL_CHECK Verify storage segments of all tables (N).
TRANSPORT_TABLESPACES List of tablespaces from which metadata will be unloaded.
VERSION Version of objects to export where valid keywords are:
(COMPATIBLE), LATEST, or any valid database version.

V2: Page 236 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

Export/Import Modes

Full
entire database (except dictionary)
Schema
one (or more) schemas all objects in schema
Table
one (or more) tables
Tablespace
all objects within one (or more) tablespaces
Transportable Tablespace
metadata for tablespace contents

ODBA10gDB-OCA-09-9 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Export/Import Modes
The following modes are supported by both export and import operations.

Full Copies the entire database contents, except for dictionary information owned by
the SYS schema and other instance specific information.

Schema Copies all objects owned by one or more schemas, including tables, indexes,
views and other objects.

Table Copies one or more tables owned by one or more schemas.

Tablespace Copies all objects contained within one or more tablespaces.

Transportable Creates a dump file containing metadata only for objects residing in one or more
Tablespace tablespaces. The physical datafiles for the named tablespaces can then be
copied to the target server and plugged in to the instance.

To perform a full database export, or to export information owned by other schemas, the
EXP_FULL_DATABASE permission must be granted to the exporting user.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 237
Oracle 10g Database Associate Lesson 9 Data Administration

Directories

Alias for OS file server directory


Must also create physical directory in OS
Oracle grants READ/WRITE on alias
Directory permissions should match alias
Used as destination for export operations
CREATE
CREATE DIRECTORY
DIRECTORY alias
alias AS
AS 'fullPathName';
'fullPathName';

CREATE
CREATE DIRECTORY
DIRECTORY exports
exports AS
AS '/home/myExports';
'/home/myExports';

ODBA10gDB-OCA-09-10 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Directories
For data administration features that require access to named files, Oracle requires the creation of a
database DIRECTORY, a named object that is an alias for a physical OS directory.

The DBA must also create the directory in the operating system and ensure that the permissions on the
physical directory match the relevant permissions on the Oracle directory object.

The creating user is granted READ and WRITE privilege on the Oracle directory object
automatically. Other users of the same directory will require specific privilege to be granted
individually.

CREATE DIRECTORY alias AS 'fullPathName';

CREATE DIRECTORY exports AS '/home/myExports';

V2: Page 238 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

Executing an Export

ODBA10gDB-OCA-09-11 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Executing an Export

To execute an export from the command line, use the following command example:

expdp system/oracle schemas = scott directory = exports dumpfile = export.dmp

Sample output from an export run is shown on the next page.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 239
Oracle 10g Database Associate Lesson 9 Data Administration

Export Output

Export: Release 10.2.0.1.0 - Production on Monday, 4 June, 2007 13:00:00

Copyright (c) 2003, 2005, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0


With the Partitioning, OLAP and Data Mining options

Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/********


schemas = scott directory = exports dumpfile = export.dmp

Estimate in progress using BLOCKS method...


Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 448 KB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
. . exported "SCOTT"."DEPT" 5.656 KB 4 rows
. . exported "SCOTT"."EMP" 7.820 KB 14 rows
. . exported "SCOTT"."EMP10" 7.375 KB 3 rows
. . exported "SCOTT"."EMP20" 7.453 KB 5 rows
. . exported "SCOTT"."EMP30" 7.507 KB 6 rows
. . exported "SCOTT"."NEWEMP" 7.531 KB 14 rows
. . exported "SCOTT"."SALGRADE" 5.585 KB 5 rows
. . exported "SCOTT"."BONUS" 0 KB 0 rows
. . exported "SCOTT"."EMPOTHERS" 0 KB 0 rows
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
C:\EXPORTS\EXPORT.DMP
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at 13:00:30

V2: Page 240 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

Executing an Import

'impdp' command line utility


EM > Maintenance > Data Movement >
Move Row Data > Import from Export Files
Can also import from
other running database
Jobs are scheduled for
unattended execution

ODBA10gDB-OCA-09-12 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Executing an Import
DataPump imports can be started with the command line impdp utility.

This command line tool runs in several modes:


interactive mode,
with options specified on the command line or
options inside an parameter file, named on the command line using the
parfile=parameterFile.par keyword parameter.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 241
Oracle 10g Database Associate Lesson 9 Data Administration

impdp options
C:\>impdp help=y

The Data Pump Import utility provides a mechanism for transferring data objects
between Oracle databases. The utility is invoked with the following command:
Example: impdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp
You can control how Import runs by entering the 'impdp' command followed
by various parameters. To specify parameters, you use keywords:

Format: impdp KEYWORD=value or KEYWORD=(value1,value2,...,valueN)


Example: impdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp

USERID must be the first parameter on the command line.

Keyword Description (Default)


------------------------------------------------------------------------------
ATTACH Attach to existing job, e.g. ATTACH [=job name].
CONTENT Specifies data to load where the valid keywords are:
(ALL), DATA_ONLY, and METADATA_ONLY.
DIRECTORY Directory object to be used for dump, log, and sql files.
DUMPFILE List of dumpfiles to import from (expdat.dmp),
e.g. DUMPFILE=scott1.dmp, scott2.dmp, dmpdir:scott3.dmp.
ENCRYPTION_PASSWORD Password key for accessing encrypted column data.
This parameter is not valid for network import jobs.
ESTIMATE Calculate job estimates where the valid keywords are:
(BLOCKS) and STATISTICS.
EXCLUDE Exclude specific object types, e.g. EXCLUDE=TABLE:EMP.
FLASHBACK_SCN SCN used to set session snapshot back to.
FLASHBACK_TIME Time used to get the SCN closest to the specified time.
FULL Import everything from source (Y).
HELP Display help messages (N).
INCLUDE Include specific object types, e.g. INCLUDE=TABLE_DATA.
JOB_NAME Name of import job to create.
LOGFILE Log file name (import.log).
NETWORK_LINK Name of remote database link to the source system.
NOLOGFILE Do not write logfile.
PARALLEL Change the number of active workers for current job.
PARFILE Specify parameter file.
QUERY Predicate clause used to import a subset of a table.
REMAP_DATAFILE Redefine datafile references in all DDL statements.
REMAP_SCHEMA Objects from one schema are loaded into another schema.
REMAP_TABLESPACE Tablespace object are remapped to another tablespace.
REUSE_DATAFILES Tablespace will be initialized if it already exists (N).
SCHEMAS List of schemas to import.
SKIP_UNUSABLE_INDEXES Skip indexes that were set to the Index Unusable state.
SQLFILE Write all the SQL DDL to a specified file.
STATUS Frequency (secs) job status is to be monitored where
the default (0) will show new status when available.
STREAMS_CONFIGURATION Enable the loading of Streams metadata
TABLE_EXISTS_ACTION Action to take if imported object already exists.
Valid keywords: (SKIP), APPEND, REPLACE and TRUNCATE.
TABLES Identifies a list of tables to import.
TABLESPACES Identifies a list of tablespaces to import.
TRANSFORM Metadata transform to apply to applicable objects.
Valid transform keywords: SEGMENT_ATTRIBUTES, STORAGE
OID, and PCTSPACE.
TRANSPORT_DATAFILES List of datafiles to be imported by transportable mode.
TRANSPORT_FULL_CHECK Verify storage segments of all tables (N).
TRANSPORT_TABLESPACES List of tablespaces from which metadata will be loaded.
Only valid in NETWORK_LINK mode import operations.
VERSION Version of objects to export where valid keywords are:
(COMPATIBLE), LATEST, or any valid database version.
Only valid for NETWORK_LINK and SQLFILE.

V2: Page 242 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

Import Type

ODBA10gDB-OCA-09-13 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Import Type
To begin an import using EM, select Maintenance > Import from Export Files.

This screen requires the selection (or creation) of an Oracle Directory Object and the specification of
the name for the output dump file.

This screen also allows the selection of an Import Type (see page 237).

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 243
Oracle 10g Database Associate Lesson 9 Data Administration

Selected Schemas

ODBA10gDB-OCA-09-14 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Selected Schemas
For a SCHEMA import as selected on the previous slide, the named export file is read to check the
information in the file. The following is displayed during this process:

Once the file has been read, the Add button allows selection of one or more of the schemas found in
the dump file.

V2: Page 244 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

Schema Re-Mapping

ODBA10gDB-OCA-09-15 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Schema Re-Mapping
During the import process, tables can be transferred to other accounts, a process known as schema
remapping

Click the Add Another Row button below the schema list, then select both the source schema to be
remapped and the destination schema to receive the imported objects.

Multiple schemas (and tablespaces) can be remapped in a single operation.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 245
Oracle 10g Database Associate Lesson 9 Data Administration

Import: Options

ODBA10gDB-OCA-09-16 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Options
Step 3 in this process allows specification of a variety of options for the import. Options include:
Number of threads for faster parallel import.
Whether a log file is required, together with a directory and file name if necessary.

Advanced options include


Import of data, metadata or both
Include or exclude objects by wildcard
Actions to take for existing objects
Index options for unusable indexes

V2: Page 246 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

Import: Schedule

ODBA10gDB-OCA-09-17 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Schedule

Step 4 allows entry of an optional job name and schedule information, to provide for later and
unattended execution of the import job.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 247
Oracle 10g Database Associate Lesson 9 Data Administration

Import: Review

ODBA10gDB-OCA-09-18 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Review
Before executing the import, the Review screen displays a summary of the job and options.
The Show PL/SQL button can be used to display the PL/SQL commands that will be used to invoke
the job via the DBMS_DATAPUMP package as illustrated on the next page.

V2: Page 248 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

DBMS_DATAPUMP Job
declare
h1 NUMBER;
begin
begin
h1 := dbms_datapump.open (operation => 'IMPORT', job_mode => 'SCHEMA',
job_name => 'IMPORT000161', version => 'COMPATIBLE');
end;
begin
dbms_datapump.set_parallel(handle => h1, degree => 1);
end;
begin
dbms_datapump.set_parameter(handle => h1, name => 'KEEP_MASTER', value => 0);
end;
begin
dbms_datapump.add_file(handle => h1, filename => 'EXPORT.DMP',
directory => 'EXPORTS', filetype => 1);
end;
begin
dbms_datapump.metadata_remap(handle => h1, name => 'REMAP_SCHEMA',
old_value => 'SCOTT', value => 'ANONYMOUS');
end;
begin
dbms_datapump.metadata_filter(handle => h1, name => 'SCHEMA_EXPR',
value => 'IN(''SCOTT'')');
end;
begin
dbms_datapump.set_parameter(handle => h1, name => 'DATA_ACCESS_METHOD',
value => 'AUTOMATIC');
end;
begin
dbms_datapump.set_parameter(handle => h1, name => 'INCLUDE_METADATA',
value => 1);
end;
begin
dbms_datapump.set_parameter(handle => h1, name => 'SKIP_UNUSABLE_INDEXES',
value => 0);
end;
begin
dbms_datapump.start_job(handle => h1, skip_current => 0, abort_step => 0);
end;
begin
dbms_datapump.detach(handle => h1);
end;
end;
/

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 249
Oracle 10g Database Associate Lesson 9 Data Administration

Import : Job Execution

ODBA10gDB-OCA-09-19 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Job Execution
Whilst a job is executing, the screen display on the slide is shown for jobs submitted with immediate
execution.

Delayed jobs are added to a Jobs Queue. The current queue can be
displayed from any EM page, Related Links > Jobs.

Selecting this link displays a list of completed and pending jobs. A job
in the queue can be deleted, suspended, restarted, stopped, deleted or
cloned for rerunning.

V2: Page 250 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

Import: Job Activity

ODBA10gDB-OCA-09-20 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Job Activity
Jobs submitted for immediate execution display the confirmation screen above once the job has been
submitted Note that the status is shown as Running.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 251
Oracle 10g Database Associate Lesson 9 Data Administration

Import: Summary and Log

ODBA10gDB-OCA-09-21 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Summary and Log


Once a job is over, a log file can be displayed if it was requested at submission time.
A sample log file is illustrated below:

Job IMPORT000061 has been reopened at Monday, 4 June, 2007 14:50


Restarting "SYSTEM"."IMPORT000061":
Processing object type SCHEMA_EXPORT/USER
ORA-31684: Object type USER:"JEREMY" already exists
Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
Processing object type SCHEMA_EXPORT/ROLE_GRANT
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "JEREMY"."DEPT" 5.656 KB 4 rows
. . imported "JEREMY"."EMP" 7.820 KB 14 rows
. . imported "JEREMY"."NEWEMP" 7.820 KB 14 rows
. . imported "JEREMY"."SALGRADE" 5.585 KB 5 rows
. . imported "JEREMY"."BONUS" 0 KB 0 rows
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/VIEW/VIEW
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
Job "SYSTEM"."IMPORT000061" completed with 1 error(s) at 14:51:08
Execution errors encountered.

Job state: COMPLETED


.

Note that some errors may be acceptable for the submitted job, yet the job will still show as failed in
the status screens.

V2: Page 252 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

SQL*Loader Overview

Imports from external files


Input
Input
File Control
File File

Log
Bad
File SQL*Loader File

Data Discard
base File

ODBA10gDB-OCA-09-22 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

SQL*Loader Overview
The SQL*Loader utility provides for imports from externally generated files.

These files may have been exported from other database products or purchased from commercial list
vendors.

SQL*Loader requires a control file to define the format of one or more input files containing the
data to be imported.

Data files can be fixed length format or separated with field delimiters and separators.

Optionally, selected rows can be ignored (and written to a discard file). Records that are not in the
required format can be written to a bad file for further (re)processing.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 253
Oracle 10g Database Associate Lesson 9 Data Administration

SQL*Loader Command Line

ODBA10gDB-OCA-09-23 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

SQL*Loader Command Line


SQL*Loader can be run from an OS command line. The options shown on the next page are
provided.

V2: Page 254 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

SQL*Loader Options
C:\>sqlldr

SQL*Loader: Release 10.2.0.1.0 - Production on Mon Jun 4 15:26:35 2007

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

Usage: SQLLDR keyword=value [,keyword=value,...]

Valid Keywords:

userid --
ORACLE username/password
control --
control file name
log --
log file name
bad --
bad file name
data --
data file name
discard --
discard file name
discardmax --
number of discards to allow (Default all)
skip --
number of logical records to skip (Default 0)
load --
number of logical records to load (Default all)
errors --
number of errors to allow (Default 50)
rows --
number of rows in conventional path bind array or between
direct path data saves
(Default: Conventional path 64, Direct path all)
bindsize -- size of conventional path bind array in bytes (Default 256000)
silent -- suppress messages during run (header,feedback,errors,discards,
partitions)
direct -- use direct path (Default FALSE)
parfile -- parameter file: name of file that contains parameter
specifications
parallel -- do parallel load (Default FALSE)
file -- file to allocate extents from
skip_unusable_indexes -- disallow/allow unusable indexes or index partitions
(Default FALSE)
skip_index_maintenance -- do not maintain indexes, mark affected indexes as
unusable (Default FALSE)
commit_discontinued -- commit loaded rows when load is discontinued
(Default FALSE)
readsize -- size of read buffer (Default 1048576)
external_table -- use external table for load; NOT_USED, GENERATE_ONLY, EXECUTE
(Default NOT_USED)
columnarrayrows -- number of rows for direct path column array (Default 5000)
streamsize -- size of direct path stream buffer in bytes (Default 256000)
multithreading -- use multithreading in direct path
resumable -- enable or disable resumable for current session (Default FALSE)
resumable_name -- text string to help identify resumable statement
resumable_timeout -- wait time (in seconds) for RESUMABLE (Default 7200)
date_cache -- size (in entries) of date conversion cache (Default 1000)

PLEASE NOTE: Command-line parameters may be specified either by


position or by keywords. An example of the former case is 'sqlldr
scott/tiger foo'; an example of the latter is 'sqlldr control=foo
userid=scott/tiger'. One may specify parameters by position before
but not after parameters specified by keywords. For example,
'sqlldr scott/tiger control=foo logfile=log' is allowed, but
'sqlldr scott/tiger control=foo log' is not, even though the
position of the parameter 'log' is correct.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 255
Oracle 10g Database Associate Lesson 9 Data Administration

SQL*Loader Data File

7000|Geoffrey|Manager|6001|15-JAN-03|10000.0|0.0|10|
7000|Geoffrey|Manager|6001|15-JAN-03|10000.0|0.0|10|
7001|Chris|Developer|6001|15-JAN-03|9000.0|0.0|20|
7001|Chris|Developer|6001|15-JAN-03|9000.0|0.0|20|
7002|Barbara|Programmer|6001|15-JAN-03|9500.0|0.0|10|
7002|Barbara|Programmer|6001|15-JAN-03|9500.0|0.0|10|
7003|Sion|Developer|6001|15-JAN-03|10000.0|0.0|20|
7003|Sion|Developer|6001|15-JAN-03|10000.0|0.0|20|
7004|Willie|Chairman|6001|15-JAN-03|8000.0|6000.0|10|
7004|Willie|Chairman|6001|15-JAN-03|8000.0|6000.0|10|
7005|John|Developer|6001|15-JAN-03|10000.0|0.0|20|
7005|John|Developer|6001|15-JAN-03|10000.0|0.0|20|
7006|Matthew|Support|6001|15-JAN-03|10000.0|0.0|10|
7006|Matthew|Support|6001|15-JAN-03|10000.0|0.0|10|
7007|Michelle|Administrator|6001|15-JAN-03|7500.0|0.0|20|
7007|Michelle|Administrator|6001|15-JAN-03|7500.0|0.0|20|
7008|Jaye|Manager|6001|15-JAN-03|8500.0|4000.0|20|
7008|Jaye|Manager|6001|15-JAN-03|8500.0|4000.0|20|
7009|Jeremy|Instructor|6001|15-JAN-03|11000.0|0.0|10|
7009|Jeremy|Instructor|6001|15-JAN-03|11000.0|0.0|10|
...
...

ODBA10gDB-OCA-09-24 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Data File
SQL*Loader data files can be read in a variety of formats. One example of a delimited file is
illustrated on the slide (Ch09Employees.txt); other examples are illustrated below:

7782 CLARK MANAGER 7839 2572.50 10


7839 KING PRESIDENT 5500.00 10
7934 MILLER CLERK 7782 920.00 10
7566 JONES MANAGER 7839 3123.75 20
7499 ALLEN SALESMAN 7698 1600.00 300.00 30
7654 MARTIN SALESMAN 7698 1312.50 1400.00 30
7658 CHAN ANALYST 7566 3450.00 20

Sample fixed length format data file

Today's Newly Hired Employees

Dept Job Manager MgrNo Emp Name EmpNo Salary/Commission


---- -------- -------- ----- -------- ----- -----------------
20 Salesman Blake 7698 Shepard 8061 $1,600.00 (3%)
Falstaff 8066 $1,250.00 (5%)
Major 8064 $1,250.00 (14%)

30 Clerk Scott 7788 Conrad 8062 $1,100.00


Ford 7369 DeSilva 8063 $800.00
Manager King 7839 Provo 8065 $2,975.00

Sample report layout data file

V2: Page 256 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

SQL*Loader Control File

LOAD
LOAD DATA
DATA
APPEND
APPEND
INTO
INTO TABLE
TABLE SCOTT.NEWEMP
SCOTT.NEWEMP
FIELDS
FIELDS TERMINATED
TERMINATED BY
BY '|'
'|' OPTIONALLY
OPTIONALLY ENCLOSED
ENCLOSED BY
BY ''
''
((
EMPNO
EMPNO INTEGER
INTEGER EXTERNAL,
EXTERNAL,
ENAME
ENAME CHAR,
CHAR,
JOB
JOB CHAR,
CHAR,
MGR
MGR INTEGER
INTEGER EXTERNAL,
EXTERNAL,
HIREDATE
HIREDATE DATE,
DATE,
SAL
SAL INTEGER
INTEGER EXTERNAL,
EXTERNAL,
COMM
COMM INTEGER
INTEGER EXTERNAL,
EXTERNAL,
DEPTNO
DEPTNO INTEGER
INTEGER EXTERNAL
EXTERNAL
))

ODBA10gDB-OCA-09-25 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Control File
A SQL*Loader control file is used to define the structure and actions to be taken with the data file
identified. The sample on the slide above corresponds to the data file on the previous slide.
The following examples also correspond to the examples on the previous page.
LOAD DATA INFILE 'ulcase2.dat' INTO TABLE EMP
( EMPNO POSITION(01:04) INTEGER EXTERNAL,
ENAME POSITION(06:15) CHAR,
JOB POSITION(17:25) CHAR,
MGR POSITION(27:30) INTEGER EXTERNAL,
SAL POSITION(32:39) DECIMAL EXTERNAL,
COMM POSITION(41:48) DECIMAL EXTERNAL,
DEPTNO POSITION(50:51) INTEGER EXTERNAL)
Sample fixed length format control file

LOAD DATA INFILE 'ulcase7.dat' DISCARDFILE 'ulcase7.dis'


APPEND INTO TABLE emp
WHEN (57)='.'
TRAILING NULLCOLS
(hiredate SYSDATE,
deptno POSITION(1:2) INTEGER EXTERNAL(3) NULLIF deptno=BLANKS,
job POSITION(7:14) CHAR TERMINATED BY WHITESPACE
NULLIF job=BLANKS "UPPER(:job)",
mgr POSITION(28:31) INTEGER EXTERNAL TERMINATED BY WHITESPACE
NULLIF mgr=BLANKS,
ename POSITION (34:41) CHAR TERMINATED BY WHITESPACE "UPPER(:ename)",
empno INTEGER EXTERNAL TERMINATED BY WHITESPACE,
sal POSITION(51) CHAR TERMINATED BY WHITESPACE
"TO_NUMBER(:sal,'$99,999.99')",
comm INTEGER EXTERNAL ENCLOSED BY '(' AND '%'
":comm * 100"
)
Sample report layout control file

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 257
Oracle 10g Database Associate Lesson 9 Data Administration

Executing SQL*Loader

'sqlldr' command line utility


EM > Maintenance > Data Movement >
Move Row Data>Load Data From User Files
EM wizard can create all
required files
Jobs are scheduled for
unattended execution

ODBA10gDB-OCA-09-26 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Executing SQL*Loader

SQL*Loader can be executed via the OS command line, using the sqlldr command as described on
page 255.

To perform an external load using Enterprise Manager, select Maintenance > Data Movement > Move
Row Data > Load Data from User Files.

This invokes the EM wizard, which can create all necessary control and log files.

As with import and export commands, SQL*Loader jobs can be scheduled for later,
unattended execution.

V2: Page 258 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

SQLLDR: Control File

ODBA10gDB-OCA-09-27 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Control File Generation


Via the EM wizard, an existing control file can be selected or the Wizard can be instructed to generate
a new control file based on the selected data file.

The first step in the Load Data wizard requests a choice of one of these options.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 259
Oracle 10g Database Associate Lesson 9 Data Administration

SQL*Loader: Select Control File

ODBA10gDB-OCA-09-28 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Select Control File


If the option to select a control file is chosen, a directory can be selected for display of the file names
in the directory, then one of the files can be selected.

V2: Page 260 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

SQL*Loader: Select Data File

ODBA10gDB-OCA-09-29 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Select Data File


Choose a data file source, either from the control file or from an external OS file in any directory.
Note that Oracle directory objects are not used by SQL*Loader for this purpose.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 261
Oracle 10g Database Associate Lesson 9 Data Administration

SQL*Loader: Load Method

ODBA10gDB-OCA-09-30 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Load Method
SQL*Loader (in common with the import/export utilities) allows for several loading
methods to be used. These include:

Conventional Load Populates existing blocks in the segment. Slower but economical on disk
space

Direct Load Populates blocks above the segment high water mark; faster but may
require more space for the object

Parallel Direct Load As Direct Load but uses multiple processes; fastest loading method

V2: Page 262 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

SQL*Loader: Load Options

ODBA10gDB-OCA-09-31 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Load Options
Sundry load options can be specified for each load job.

Number of Rows to Load A sample of rows can be loaded by setting this option

Skip Initial rows If a sample had been loaded, skip already loaded rows

Maximum Errors Abort the run if this many errors are found

Maximum Discards Abort the run if this many rows are discarded

Allow Unusable Indexes Load data even if indexes on table are invalid / unusable

Bad File Location and name of optional file for bad (unloaded) rows

Discard File Location and name of optional file for discarded rows

Log File Location and name of optional log file

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 263
Oracle 10g Database Associate Lesson 9 Data Administration

SQL*Loader: Schedule

ODBA10gDB-OCA-09-32 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Schedule
As with import/export jobs, a SQL*Loader job can be run immediately or scheduled for later
execution. An optional job name and description can be entered for future reference to the job on the
job queue.

V2: Page 264 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

SQL*Loader: Review

ODBA10gDB-OCA-09-33 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Review
Before executing the load, the Review screen displays a summary of the job and options.
The Show Parameters button can be used to display the SQL*Loader options that will be used to
invoke the job.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 265
Oracle 10g Database Associate Lesson 9 Data Administration

SQL*Loader: Confirmation

ODBA10gDB-OCA-09-34 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Confirmation
The final confirmation screen displays the queueing status for the SQL*Loader job.

V2: Page 266 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

SQL*Loader: Completion Report

ODBA10gDB-OCA-09-35 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Completion Report
After a SQL*Loader job has executed, whether immediately or queued, a completion report screen is
displayed.

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 267
Oracle 10g Database Associate Lesson 9 Data Administration

Summary

By completing this lesson, you should be


able to use the following:
SQL DML Statements (INSERT, MERGE)
Data Pump to export and import
database structure and contents
SQL-Loader to import from external
sources
Oracle directory objects

ODBA10gDB-OCA-09-36 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Summary
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________

V2: Page 268 Copyright 2007 Jeremy Russell & Associates Ltd.
Lesson 9 Data Administration Oracle 10g Database Associate

Practice 9

Create a copy of SCOTT.EMP owned by


SYSTEM; don't copy the original data
Create a directory called 'MyExport'
Using either EM or expdb, export the
contents of SCOTT.EMP to a dump file
Using either EM or sqlldr, import the
contents of 'employees.txt' into the newly
created SYSTEM.EMP table

ODBA10gDB-OCA-09-37 Copyright Jeremy Russell & Associates, 2007. All rights reserved.

Practice 9
In this practice, you will execute miscellaneous data management tasks.

Create a copy of SCOTT.EMP owned by SYSTEM; dont copy the original data. Use the command below
to create the copy (Ch09CreateNewemp.sql):

SQL> CONNECT system/password

SQL> CREATE TABLE newemp AS SELECT FROM scott.emp WHERE 1 = 0;

________________________________________________________________________
________________________________________________________________________

Create a directory called MyExport. Use EM to create the directory object and open an OS
command window to create a physical directory with an appropriate name. Remember that OS
directory (and file) names are case sensitive on Unix or Linux systems.
________________________________________________________________________
________________________________________________________________________

Using either EM or expdb, export the contents of SCOTT.EMP to a dump file


________________________________________________________________________
________________________________________________________________________
Using either EM or sqlldr, import the contents of 'employees.txt' into the newly created
SYSTEM.NEWEMP table

________________________________________________________________________

Copyright 2007 Jeremy Russell & Associates Ltd. V2: Page 269
Oracle 10g Database Associate Lesson 9 Data Administration

This page intentionally left blank

V2: Page 270 Copyright 2007 Jeremy Russell & Associates Ltd.

You might also like