Вы находитесь на странице: 1из 43

This watermark does not appear in the registered version - http://www.clicktoconvert.

com

GnanaSekar. A

TABLE O F CONTENTS

1. ORACLE ARCHITECTURAL COMPONENTS.......................................................................3


Physical Files ................................ ................................ ................................ ................................ ................... 3
Backgroung Processes ................................ ................................ ................................ ................................ .... 3
Memory Area (SGA) ................................ ................................ ................................ ................................ ........ 4
How Oracle processes a query ................................ ................................ ................................ ...................... 4
How Oracle processes a DML statement ................................ ................................ ................................ .... 4
How Oracle processes a COMMIT statement ................................ ................................ ............................ 5
2. STARTUP AND SHUTDOWN A DATABASE .......................................................................5
Parameter File ................................ ................................ ................................ ................................ ................. 5
STARTUP Command ................................ ................................ ................................ ................................ ....... 6
SHUTDOWN Command ................................ ................................ ................................ ................................ . 6
Basic Dynamic Performance View ................................ ................................ ................................ ............... 7
How to terminate a user session ................................ ................................ ................................ ................... 7
3. CREATE A DATABASE ....................................................................................................7
STEP 1 . Set the operating system variables. ................................ ................................ .............................. 7
STEP 2. Prepare the parameter file. ................................ ................................ ................................ ............. 8
STEP 3. Start the instance in NOMOUNT stage. ................................ ................................ ....................... 8
STEP 4. Create the database ................................ ................................ ................................ ......................... 8
STEP 5. Run scripts to generate the data dictionary and accomplish postcreation steps. ................. 8
Troubles Shooting of Create Database ................................ ................................ ................................ ........ 9
What you get after the database is created ................................ ................................ ................................ . 9
4. MAINTAINING THE CONTROL FILE .................................................................................9
Features and Contents of Control File ................................ ................................ ................................ ........ 9
Multiplex the Control File ................................ ................................ ................................ .............................. 9
5. MAINTAINING REDO LOG FILES.....................................................................................9
Features and Contents of Redo Log Files ................................ ................................ ................................ ... 9
Views about Redo Log Files ................................ ................................ ................................ ........................ 11
Maintenance Operations on Redo Log files ................................ ................................ .............................. 11
6. TABLESPACES AND DATA FILES...................................................................................12
Logical and Physical Structure of a database ................................ ................................ .......................... 12
SYSTEM and Non-SYSTEM Tablespaces ................................ ................................ ................................ ..13
Creating Tablespaces ................................ ................................ ................................ ................................ ... 13
Four Methods to increase the size of tablespaces ................................ ................................ .................... 13
READ-ONLY Tablespace ................................ ................................ ................................ ............................. 14
Dropping Tablespaces ................................ ................................ ................................ ................................ ..15
Dictionary Views about tablespaces and data files ................................ ................................ ................. 15
7. STORAGE STRUCTURE AND RELATIONSHIPS ................................................................16
Storage Clause Precedence ................................ ................................ ................................ ......................... 16
Extent Allocation and Deallocation ................................ ................................ ................................ ........... 16
Block Space Utilization Parameters ................................ ................................ ................................ ........... 16
Dictionay Views about storage ................................ ................................ ................................ ................... 17
8. ROLLBACK SEGMENT...................................................................................................18
Purpose of Rollback Segment ................................ ................................ ................................ ...................... 18
How transactions use Rollback Segment ................................ ................................ ................................ ... 18
Creating Rollback Segment ................................ ................................ ................................ ......................... 19
Offline and Drop Rollback Segment ................................ ................................ ................................ ........... 20
Dictionary Views about Rollback Segment ................................ ................................ ............................... 20
9. TEMPORARY S EGMENT ................................................................................................21
Temporary Segments in a Temporary Tablespace ................................ ................................ ................... 21
Views about temporary segments ................................ ................................ ................................ ................ 21

DBA - 1
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

10. MANAGING TABLES ...................................................................................................21


ROWID in Oracle 8 ................................ ................................ ................................ ................................ ....... 21
High Water Mark ................................ ................................ ................................ ................................ ........... 22
ANALYZE TABLE command ................................ ................................ ................................ ........................ 23
DBMS_ROWID Package ................................ ................................ ................................ .............................. 23
11. MANAGING INDEXES..................................................................................................24
B-Tree Index ................................ ................................ ................................ ................................ ................... 24
Reverse Key Index ................................ ................................ ................................ ................................ .......... 24
Bitmap Index ................................ ................................ ................................ ................................ ................... 24
When we need to rebuild indexes? ................................ ................................ ................................ ............. 25
ANALYZE INDEX command ................................ ................................ ................................ ........................ 25
12. MAINTAINING DATA INTEGRITY ................................................................................25
Types of Constraints ................................ ................................ ................................ ................................ ...... 25
Three States of Constraints ................................ ................................ ................................ .......................... 26
Deferred and non-deferred constraints ................................ ................................ ................................ ..... 27
13. CLUSTERS AND INDEX-O RGANIZED TABLES ..............................................................28
Creating Index Cluster ................................ ................................ ................................ ................................ .28
Creating Hash Clusters ................................ ................................ ................................ ................................ 28
Index-Organized Tables ................................ ................................ ................................ ............................... 29
14. SQL*LOADER, IMPORT/EXPORT.........................................................................30
SQL*Loader Features ................................ ................................ ................................ ................................ ... 30
Files Used by SQL*Loader ................................ ................................ ................................ .......................... 30
Comparing Direct and Conventional Path Loads ................................ ................................ ................... 31
Uses of Export and Import ................................ ................................ ................................ ........................... 31
15. MANAGING DATABASE USERS...................................................................................32
Checklist for Creating Users ................................ ................................ ................................ ........................ 32
Examples and Guidelines about users ................................ ................................ ................................ ....... 32
Dictionary Views about Users ................................ ................................ ................................ ..................... 33
16. MANAGING USER PROFILES .......................................................................................33
User Profiles and resource limits ................................ ................................ ................................ ............... 33
How to enforce resource limit using profiles ................................ ................................ ............................ 34
Password Management ................................ ................................ ................................ ................................ 35
Dictionary Views about user profiles ................................ ................................ ................................ ......... 35
17. MANAGING PRIVILEGES .............................................................................................36
SYSTEM Privileges ................................ ................................ ................................ ................................ ........ 36
Examples about system privileges ................................ ................................ ................................ .............. 36
Dictionary Views about system privileges ................................ ................................ ................................ .37
Object Privileges ................................ ................................ ................................ ................................ ............ 38
Examples about object privileges ................................ ................................ ................................ ............... 40
Dictionary Views about object privileges ................................ ................................ ................................ ..40
18. MANAGING ROLES .....................................................................................................40
What is role? ................................ ................................ ................................ ................................ ................... 40
Manapulating Roles ................................ ................................ ................................ ................................ ...... 41
FREQUENTLY ASKED QUESTIONS IN ORACLE 8 DATABASE ADMINISTRATION ................42

DBA - 2
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

1. Oracle Architectural Components

Physical Files

Data files

store the data dictionary, user objects, and before-images of data that are modified by
current transactions. A database has at least one data file.
Redo log
files
contain a record of changes made to the database to ensure reconstruction of the data
in case of failures. A database requires at least two redo log files.
Control files

contain the information needed to maintain and verify database integrity. A database
needs at least one control file.

Backgroung Processes
The background processes in an instance perform common functions that are needed to service the
requests from several concurrent users, without compromising the integrity and performance of the
whole system. Each Oracle instance may use several background processes, depending on the
configuration, but every instance comprises these five background processes by default:

DBWR
The server process records changes to rollback and data blocks in the buffer cache.
The database writer (DBWR) writes the dirty buffers from the database buffer cache
to the data files. It ensures that sufficient number of free buffers—buffers that can be
overwritten when server processes need to read in blocks from the data files—are
available in the database buffer cache. Database performance is improved because
server processes only make changes in the buffer cache, and the DBWR defers
writing to the
data files until one of the following events occur:
· The number of dirty buffers reaches a threshold value
· A process scans a specified number of blocks when scanning for free buffers and
cannot find any
· A timeout occurs
· A DBWR checkpoint can be triggered by various events such as closing
· of the database, (Checkpoint is a means of synchronizing the database buffer
cache with the data file.)
LGWR
The Log Writer (LGWR) is a background process that writes entries from the redo
log buffer into the redo log files. The LGWR performs sequential writes to the redo
log file under the following situations:
· When the redo log buffer is one-third full
· When a timeout occurs (every three seconds)
· Before DBWR writes modified blocks in the database buffer cache to the
· data files
· When a transaction commits

DBA - 3
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

SMON
· Performs automatic instance recovery.
· Reclaims space used by temporary segments no longer in use.
· Merges contiguous areas of free space in the datafiles.
PMON
· Cleans up abnormally terminated connections.
· Rolls back uncommitted transactions.
· Releases locks held by a terminated process.
· Frees SGA resources allocated to the failed process.
CKPT
Checkpoint Process is responsible for updating the database status information
whenever changes in the buffer cache are permanently recorded in the database.

Memory Area (SGA)

Shared Pool
· Size defined by SHARED_POOL_SIZE in parameter file
· Library cache contains statement text, parsed code, and an execution plan. Since
the library cache stores this information, if a query is reexecuted before its
execution plan is aged out by other statements, the server process does not need
to parse the statement. Thus the library cache helps improve the performance of
applications.
· Data dictionary cache stores the most recently used data dictionary information,
such as table and column definitions, usernames, passwords, and privileges.
During the parse phase, the server process looks for the information in the
dictionary cache to resolve the object names specified in the SQL statement and
to validate the access privileges. If necessary, the server process initiates the
loading of this information from the data files.
Database Buffer
Cache
· Number of buffers defined by DB_BLOCK_BUFFERS
· Size of a buffer based on DB_BLOCK_SIZE
· Stores the most recently used blocks
Redo Log
Buffer
· Size defined by LOG_BUFFER
· Records changes made through the instance
· Used sequentially
· Circular buffer

How Oracle processes a query


1. Parse: In this stage, the user process sends the query to the server process with a request to parse
or compile the query. The server process checks the validity of the command and uses the area in
the SGA known as the shared pool to compile the statement. At the end of this phase, the server
process returns the status—that is, success or failure of the parse phase—to the user process.
2. Execute: During this phase in the processing of a query, the server process prepares to retrieve the
data.
3. Fetch: The rows that are retrieved by the query are returned by the server to the user during this
phase. Depending on the amount of memory used for the transfer, one or more fetches are required
to transfer the results of a query to the user.

How Oracle processes a DML statement


1. The server process reads the data and rollback blocks from the data files, if they are not already in
the buffer cache.
2. Copies of the blocks that are read are placed in the buffer cache.

DBA - 4
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

3. The server process places locks on the data.


4. The server process records the changes to be made to the rollback (before-image) and to the data
(new value) in the redo log buffer.
5. The server process records the before-image to the rollback block and updates the data block, both
in the database buffer cache. Both the changed blocks in the buffer cache are marked as dirty
buffers —that is, buffers that are not the same as the corresponding blocks on the disk.

How Oracle processes a COMMIT statement


1. The server process places a commit record, along with the SCN, in the redo log buffer.
2. LGWR performs a contiguous write of all the redo log buffer entries up to and including the
commit record to the redo log files. After this point, the Oracle server can guarantee that the
changes will not be lost even in case of failures.
3. The user is informed that the COMMIT is complete.
4. The server process records information to indicate that the transaction is complete and that
resource locks can be released.

2. Startup and Shutdown a Database

Parameter File
The parameter file, commonly referred to as the init<SID>.ora file, is a text file that can be maintained
using a standard operating system editor. By default, it is located in the $ORACLE_HOME/dbs
directory on a UNIX machine and in the %ORACLE_HOME%\database directory on NT. The
parameter file is only read during instance startup. If the file is modified, shut down and restart the
instance to make the new parameter values effective. The uses of parameter file are :
· Size the System Global Area (SGA) components to optimize performance.
· Set database and instance defaults.
· Set database limits.
· Define (on database creation only) various physical attributes of the database, such as the database
block size.
· Specify control files, archived log files, and trace file locations.

Parameter File Example

# Initialization Parameter File: initDB1.ora


db_name = DB1
control_files = (/DISK1/control01.con,
/DISK2/control02.con)
db_block_size = 8192
db_block_buffers = 2000
shared_pool_size = 30000000
log_buffer = 65536
processes = 50
max_dump_file_size = 10240
background_dump_dest =
(/home/disk3/user15/BDUMP)
user_dump_dest =
(/home/disk3/user15/UDUMP)
rollback_segments = (r01,r02,r03,r04)
...

DBA - 5
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

STARTUP Command

Example

SVRMGR> CONNECT / AS SYSDBA


SVRMGR> STARTUP PFILE=/DISK1/initDB1.ora

Startup Stages

Parameter file is read


Instance is started
(Memory/SGA is allocated,
Background Processes started)

------------------------NOMOUNT

Control file is read


Database configuration is loaded into SGA

------------------------MOUNT

Datafiles and redo log files are located


Verify all the datafiles and redo log files can be
opened
Check the consistency of the database

Database opened ------------------------OPEN


Users can access the database

SHUTDOWN Command

Syntax

SHUTDOWN [NORMAL | TRANSACTIONAL | IMMEDIATE | ABORT ]

Shutdown Mode ABORT IMMEDIATE TRANSACTIONAL NORMAL


Allow new connections X X X X
Wait until current sessions end X X X symbol 252
\f
"Wingding
s" \s 10ü}
Wait until current transactions end X X symbol 252 \f symbol 252
"Wingdings" \s 10ü} \f
"Wingding
s" \s 10ü}
Force a checkpoint and close X symbol 252 \f symbol 252 \f symbol 252
files "Wingdings" "Wingdings" \s 10ü} \f
\s 10ü} "Wingding
s" \s 10ü}

DBA - 6
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

Basic Dynamic Performance View

Dynamic Performance View Description


(accessible in the NOMOUNT stage or above)
V$PARAMETER Contains information about the initialization parameter
V$SGA Contains summary information on the SGA
V$OPTION Lists options that are installed with the Oracle server
V$PROCESS Contains information about the currently active process
V$SESSION Lists current session information
V$VERSION Lists the version number and the components
V$INSTANCE Displays the state of the current instance

Dynamic Performance View Description


( accessible in the MOUNT stage or above)
V$THREAD Contains thread information, for example about the
redo log groups
V$CONTROLFILE Lists the names of the control files (Even though
available, this view returns no rows in NOMOUNT
state.)
V$DATABASE Contains database information
V$DATAFILE Contains data file information from the control file
V$LOGFILE Contains information about the online redo log files

How to terminate a user session

Example : To kill scott’s session

SVRMGR> SELECT sid, serial# FROM v$session WHERE


2> username=‘SCOTT’;

SID SERIAL#
------ ---------
7 15

SVRMGR> ALTER SYSTEM KILL SESSION ‘7,15’;

3. Create a Database

STEP 1 . Set the operating system variables.

On UNIX set the following environment variables:

Variable Description
ORACLE_HOME Set to the directory where the Oracle software will be
installed (Example: /u01/app/oracle/product/8.0.3)
ORACLE_SID Specifies the instance name and must be unique for
Oracle instances running on the same machine.
PATH Search path which must include $ORACLE_HOME/bin

On NT Set the variable ORACLE_SID to use SVRMGR30. Create the service and the password
file with ORADIM80.

C:\> ORADIM80 -NEW -SID u16

DBA - 7
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

-INTPWD password -STARTMODE auto


-PFILE ORACLE_HOME\DATABASE\initU16.ora

STEP 2. Prepare the parameter file.

Create parameter file using any editor in the operation system.

# Initialization Parameter File: initDB1.ora


db_name = DB1
control_files = (/DISK1/control01.con,
/DISK2/control02.con)
db_block_size = 8192
db_block_buffers = 2000
shared_pool_size = 30000000
log_buffer = 65536
processes = 50
max_dump_file_size = 10240
background_dump_dest =
(/home/disk3/user15/BDUMP)
user_dump_dest =
(/home/disk3/user15/UDUMP)
rollback_segments = (r01,r02,r03,r04)
...
...

STEP 3. Start the instance in NOMOUNT stage.

SVRMGR> CONNECT / AS SYSDBA


SVRMGR> STARTUP NOMOUNT PFILE=initDB1.ora
ORACLE instance started.

STEP 4. Create the database

Issue the CREATE DATABASE command in server manager

CREATE DATABASE DB1


MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXDATAFILES 100
LOGFILE
GROUP 1 '/DISK3/log1a.rdo' SIZE 1 M,
GROUP 2 ’/DISK3/log2a.rdo' SIZE 1 M
DATAFILE
'/DISK1/system01.dbf' size 50M

STEP 5. Run scripts to generate the data dictionary and accomplish


postcreation steps.
After database creation, the catalog.sql and catproc.sql scripts must be run as the user SYS. They
are located in the $ORACLE_HOME/rdbms/admin directory on UNIX and in the
%ORACLE_HOME%\rdbms80\admin directory on NT.

Script Purpose
catalog.sql Creates commonly used data dictionary views
catproc.sql Runs all scripts required for PL/SQL on the server

DBA - 8
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

Troubles Shooting of Create Database

Creation of the database fails if:

· There are syntax errors in the SQL script


· Files that should be created already exist
· Operating system errors such as file or directory permission or insufficient space errors occur

What you get after the database is created

· Data files which make up the SYSTEM tablespace


· Control files and redo log files
· User SYS/change_on_install
· User SYSTEM/manager
· Rollback segment SYSTEM
· Internal tables (but no data dictionary views) So you need to run catalog.sql

4. Maintaining the Control File

Features and Contents of Control File

· Is a binary file that is necessary for the database to start and operate successfully.
· Every time an instance mounts an Oracle database, it reads the control file to locate the data files
and online redo log files.
· Is updated continuously during database use and must be available whenever the database is
mounted or opened.
· Provides information about database consistency used during recovery.
· If any of the control files currently being used by the database becomes unavailable, then the
database cannot function properly.
· In summary, control file contains the following information
¾ Database name
¾ Data file location
¾ Redo log file location
¾ Tablespace names
¾ Current log sequence number
¾ Checkpoint information
¾ Log history
¾ Backup information

Multiplex the Control File

To add an additional control file to play use the following steps:

1. Shut down the database.


2. Make a copy of the existing control file to a different device using operating system commands.
3. Edit or add the CONTROL_FILES parameter and specify names for all the control files.
4. Start up the database.

5. Maintaining Redo Log Files

Features and Contents of Redo Log Files


· Used to store the ‘transaction history’
· The Oracle server maintains online redo log files to minimize the loss of data in the database. The
redo log files record all changes made to data in the database buffer cache.

DBA - 9
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

· Redo log files are used in a situation such as an instance failure to recover committed data that has
not been written to the data files. The redo log files are only used for recovery.

Group 1 Group 2 Group 3


Disk 1
Member Member Member

Member
Member Member
Disk 2

· A set of identical copies of online redo log files is called an online redo log group .
· The background process LGWR concurrently writes the same information to all online redo log
files in a group.
· The Oracle server needs a minimum of two online redo log file groups for the normal operation of
a database.
· Each online redo log file in a group is called a member .
· Each member in a group has identical log sequence numbers and the same size. The log sequence
number is assigned each time the Oracle server starts writing to a log group to identify each redo
log file uniquely. The current log sequence number is stored in the control file and in the header of
all data files.

DBA - 10
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

Views about Redo Log Files

SVRMGR> SELECT group#,sequence#,bytes,members,status


2> FROM v$log;

GROUP# SEQUENCE# BYTES MEMBERS STATUS


------ --------- ------- ------- ------
--
1 688 1048576 1
CURRENT
2 689 1048576 1
INACTIVE
2 rows selected.

SVRMGR> SELECT *
2> FROM v$logfile;

GROUP# STATUS MEMBER


------ ------ -----------------------
1 /DISK3/log1a.rdo
2 /DISK4/log2a.rdo
2 rows selected.

Maintenance Operations on Redo Log files

Example 1 : Adding Online Redo Log Groups

SVRMGR> ALTER DATABASE ADD LOGFILE


2> (‘/DISK3/log3a.rdo’) size 1M;

Example 2 : Adding Online Redo Log Members

SVRMGR> ALTER DATABASE ADD LOGFILE MEMBER


2> ‘/DISK4/log1b.rdo’ TO GROUP 1,
3> ‘/DISK4/log2b.rdo’ TO GROUP 2;

Example 3 : Dropping Online Redo Log Groups

SVRMGR> ALTER DATABASE DROP LOGFILE GROUP 3;

Example 4 : Dropping Online Redo Log Members

SVRMGR> ALTER DATABASE DROP LOGFILE MEMBER


2> ‘/DISK4/log2b.dbf’;

DBA - 11
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

6. Tablespaces and Data Files

Logical and Physical Structure of a database

Database

Tablespace Data file

Logical Segment Physical

Extent

Oracle
O/S Block
block

Tablespaces
· A tablespace can belong to only one database.
· Each tablespace consists of one or more operating system files.
· Tablespaces can be brought online while the database is running.
· Except for the SYSTEM tablespace or a tablespace with an active rollback segment, tablespaces
can be taken offline, leaving the database running.
· Tablespaces can be switched between read-write and read-only status.
· Controlling space allocation and assigning space quotas to users
· Controlling availability of data by taking individual tablespaces online or offline
· Distributing data storage across devices to improve I/O performance and to reduce I/O contention
against a single disk
· Performing partial backup and partial recovery operations
· Keeping large amounts of static data on read-only devices

Data Files
· Each tablespace in an Oracle database consists of one or more files called data file s. These are
physical structures that conform with the operating system on which the Oracle server is running.
· A data file can belong to only one tablespace.
· An Oracle server creates a data file for a tablespace by allocating the specified amount of disk
space plus a small overhead.
· The database administrator can change the size of a data file after its creation or can specify that a
data file should dynamically grow as objects in the tablespace grow.

Segments
· A segment is the space allocated for a specific type of logical storage structure within a tablespace.
The following are examples of segments:
¾ Table segment
¾ Index segment
¾ Temporary segment
¾ Rollback segment
· A segment such as a data segment may span multiple files that belong to the same tablespace.

Extents
· An extent is a set of contiguous number of blocks.
· Each type of segment is made up of one or more extents.
· An extent may not span a data file, but must exist in one data file.

Data Blocks

DBA - 12
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

· At the finest level of granularity, the data in an Oracle database is stored in data blocks.
· One data block corresponds to one or more physical file blocks allocated from an existing data file.
· Data block size is specified for each Oracle database by the initialization parameter
DB_BLOCK_SIZE when the database is created.
· The smallest unit of input-output.

SYSTEM and Non-SYSTEM Tablespaces

SYSTEM Tablespace
· Automatic created after the database is created
· Required in all databases for database operation
· Contains data dictionary information, definitions of stored procedures, packages, and database
triggers
· Contains the SYSTEM rollback segment
· Should not contain user data although it is allowed

Non-SYSTEM Tablespace
· Enable more flexibility in database administration
· Can store rollback segments, temporary segments, application data, and application indexes

Creating Tablespaces

Example

CREATE TABLESPACE app_data


DATAFILE ‘/DISK4/app01.dbf’ SIZE 100M,
‘/DISK5/app02.dbf’ SIZE 100M
MINIMUM EXTENT 500K
DEFAULT STORAGE ( INITIAL 500K
NEXT 500K
MINEXTENTS 3
MAXEXTENTS 500
PCTINCREASE 50);

· INITIAL defines the size of the first extent. The minimum size of the first extent is two blocks,
that is (2*DB_BLOCK_SIZE). The default size is 5 blocks, that is (5* DB_BLOCK_SIZE).
· NEXT refers to the size of the second extent. The minimum size of the next extent is one block.
The default size is 5 blocks, that is (5* DB_BLOCK_SIZE).
· MINEXTENTS is the number of extents allocated when the segment is created. The minimum
and default is 1.
· PCTINCREASE is the percent by which the extent size grows. The size of an extent is calculated
using the following formula:
· MAXEXTENTS determines the maximum number of extents that a segment can have. The
minimum value is 1. The default maximum value depends on the data block size. The maximum
size can also be specified by the keyword UNLIMITED, which is equivalent to a value of
2147483645.

Four Methods to increase the size of tablespaces

Method 1 : Adding Data Files to a Tablespace

ALTER TABLESPACE app_data ADD DATAFILE


‘/DISK5/app03.dbf’ SIZE 200M;

Method 2 : Enabling Automatic Extension of new created Data Files

ALTER TABLESPACE app_data ADD DATAFILE

DBA - 13
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

‘/DISK6/app04.dbf’ SIZE 200M


AUTOEXTEND ON NEXT 10M MAXSIZE 500M;

Method 3 : Enabling Automatic Extension of existing Data Files

ALTER DATABASE
DATAFILE ‘/DISK5/app03.dbf’
AUTOEXTEND ON NEXT 10M MAXSIZE 500M;

Method 4 : Changing the Size of Data Files Manually

ALTER DATABASE DATAFILE ‘/DISK5/app02.dbf’


RESIZE 200M;

READ-ONLY Tablespace

Making tablespaces read-only prevents further write operations on the data files. The purpose of read-
only tablespaces is to ensure that no changes are made and to eliminate the need to perform backup and
recovery of large, static portions of a database. The Oracle server never updates the files of a read-only
tablespace, and therefore the files can reside on read-only media, such as CD ROMs or WORM drives.

Example : Make tablespace APP_DATA only available for read operations.

ALTER TABLESPACE app_data READ ONLY;

To make a tablespace READ-ONLY

· The tablespace must be online.


· No active transactions are allowed.
· The tablespace must not contain active rollback segments.
· The tablespace must not currently be involved in an online backup

DBA - 14
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

Dropping Tablespaces
· A tablespace that still contains data cannot be dropped without the INCLUDING CONTENTS
option.
· Once a tablespace has been dropped, its data is no longer in the database.
· When a tablespace is dropped, only the file pointers in the control file of the associated database
are dropped. The database files still exist and must be deleted explicitly at the operating system
level.
· Even if a tablespace is switched to read-only it can still be dropped, along with segments within it.
This is possible because the DROP command only updates the data dictionary (which has to be
read-write), but not the physical files that make up the tablespace.
· It is recommended that you take the tablespace offline before dropping it to ensure that no
transactions access any of the segments in the tablespace.

Example : Removes the APP_DATA tablespace and all its contents

DROP TABLESPACE app_data


INCLUDING CONTENTS;

Dictionary Views about tablespaces and data files

SVRMGR> SELECT tablespace_name, contents,status


2 > FROM dba_tablespaces;

TABLESPACE_NAME CONTENTS
STATUS
--------------- ---------- ----
--
SYSTEM PERMANENT
ONLINE
RBS PERMANENT
ONLINE
TEMP TEMPORARY
ONLINE
DATA01 PERMANENT
ONLINE
4 rows selected.

SVRMGR> SELECT tablespace_name, initial_extent, next_extent,


2 > max_extents, pct_increase, min_extlen
3 > FROM dba_tablespaces;

TABLESPACE INITIAL_EX NEXT_EXT MIN_EXTENT MAX_EXTENT PCT_I


---------- ---------- -------- ---------- ---------- ---
--
SYSTEM 10240 10240 1 121 50
RBS 10240 10240 1 121 50
TEMP 262144 262144 1 999 50
DATA01 204800 204800 1 999 50
4 rows selected.

DBA - 15
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

SVRMGR> SELECT file_name, tablespace_name, bytes,


2 > autoextensible, maxbytes, increment_by
3 > FROM dba_data_files;

FILE_NAME TABLESPACE_NAME BYTES AUT MAXBYTES INCR


------------------- --------------- -------- ---- -------- ---
--
/DISK1/system01.dbf SYSTEM 31457280 NO 0 0
/DISK2/rbs01.dbf RBS 5242880 NO 0 0
/DISK3/temp01.dbf TEMP 5242880 NO 0 0
/DISK4/data01.dbf DATA01 5242880 NO 0 0
/DISK5/data02.dbf DATA01 512000 YES 15728640 512
5 rows selected.

7. Storage Structure and Relationships

Storage Clause Precedence


· Any storage parameter specified at the segment level overrides the corresponding option set at the
tablespace level, except for the MINIMUM EXTENT tablespace parameter.
· When storage parameters are not explicitly set at the segment level, they default to those at the
tablespace level.
· When storage parameters are not explicitly set at the tablespace level, the Oracle server system
defaults apply.
· If storage parameters are altered, the new options apply only to the extents not yet allocated.
· Some parameters cannot be specified at the tablespace level. These parameters need to be specified
at the segment level only.
· If minimum extent size has been specified for the tablespace, this size will apply to all extents that
are subsequently allocated for segments in the tablespace.

Extent Allocation and Deallocation


· Allocated when the segment is
¾ Created
¾ Extended
¾ Altered
· Deallocated when the segment is
¾ Dropped
¾ Altered
¾ Truncated
¾ Automatically resized (rollback segments only)

Block Space Utilization Parameters

INITRANS
Which defaults to 1 for a data segment, and 2 for an indexs segment, guarantees
minimum level of concurrency. For example, if set to 3, INITRANS ensures that at
least three transactions can concurrently make changes to the block. If necessary,
additional transaction slots can be allocated from the free space in the block, to
permit more concurrent transactions to modify rows in the block.

DBA - 16
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

MAXTRAN
S
Which has a default value of 255, sets the limit for the number of concurrent
transactions that can make changes to a data or an index block. When set, this value
restricts use of space for transaction slots and therefore guarantees that there is
sufficient space in the block for use by row or index data.
PCTFREE
For a data segment specifies the percentage of space in each data block reserved for
growth resulting from updates to rows in the block. The default for PCTFREE is 10
percent.
PCTUSED
For a data segment represents the minimum percentage of used space that Oracle
Server tries to maintain for each data block of the table. A block is put back on the
free list when its used space falls below PCTUSED. The free list of a segment is a
list of blocks that are candidates for accommodating future inserts. A segment, by
default, is created with one free list. Segments can be created with a higher number
of free lists by setting the FREELISTS parameter of the storage clause. The default
for PCTUSED is 40 percent.

Dictionay Views about storage

SVRMGR> SELECT segment_name,tablespace_name,extents,blocks


2> FROM dba_segments
3> WHERE owner='SCOTT';

SEGMENT_NAME TABLESPACE_NAME EXTENTS BLOCKS


------------ --------------- ------- -----
--
EMP DATA01 5 55
DEPT DATA01 1 5
BONUS DATA01 1 5
SALGRADE DATA01 1 5
DUMMY DATA01 1 5
5 rows selected.

SVRMGR> SELECT extent_id,file_id,block_id,blocks


2> FROM dba_extents
3> WHERE owner='SCOTT' AND segment_name='EMP';

EXTENT_ID FILE_ID BLOCK_ID BLOCKS


--------- -------- --------- -------
0 4 2 5
1 4 27 5
2 4 32 10
3 4 42 15
4 4 57 20
5 rows selected.

DBA - 17
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

SVRMGR> SELECT tablespace_name, count(*),


2> max(blocks), sum(blocks)
3> FROM dba_free_space
4> GROUP BY tablespace_name;

TABLESPACE_NAME COUNT(*) MAX(BLOCKS SUM(BLOCKS


--------------- -------- ----------- ----------
DATA01 2 1284 1533
RBS 3 2329 2419
SORT 1 1023 1023
SYSTEM 1 5626 5626
TEMP 1 2431 2431
5 rows selected.

8. Rollback Segment

Purpose of Rollback Segment

Transaction Rollback

When a transaction makes changes to a row in a table, the old image is saved in the rollback segment.
If the transaction is rolled back, the value in the rollback segment is written back to the row, restoring
the original value.

Read Consistency

When transactions are in progress, other users in the database should not see any uncommitted changes
made by these transactions. In addition, a statement should not see any changes that were committed
after the statement commences execution. The old values in the rollback segments are also used to
provide the readers a consistent image for a given statement.

Transaction Recovery

If the instance fails when transactions are in progress, Oracle server needs to rollback the uncommitted
changes when the database is opened again. This rollback is known as transaction recovery and is only
possible if changes made to the rollback segment are also protected by the redo log files.

How transactions use Rollback Segment

1 2

Transaction 1 Transaction 2
4 3

1. When a transaction begins, a rollback segment needs to be assigned to this transaction.


2. A transaction may request a specific rollback segment using the following command:
SET TRANSACTION USE ROLLBACK SEGMENT rollback_segment
3. If no such request is made, the Oracle server chooses the rollback segment with the fewest
transactions, and assigns it to the transaction.

DBA - 18
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

4. Transactions use extents of a rollback segment in an ordered circular fashion, moving from one to
the next after the current extent is full. A transaction writes a record to the current location in the
rollback segment and advances the current pointer by the size of the record.

1 2
1 2

5 3
4 3
4
5. The pointer or the head of the rollback segment moves to the next extent when the current extent is
full. When the last extent that is currently available is full, the pointer can only move back to the
beginning of the first extent if that extent is free. The pointer cannot skip over an extent and move
to the second or any other extent. If the first extent is being used, the transaction will allocate an
additional extent for the rollback segment. This is called an exten d. Similarly, if the head tries to
move into an extent and that extent is active, the rollback segment will allocate an additional
extent. A rollback segment may grow in this manner until it reaches the maximum number of
extents specified by the MAXEXTENTS parameter.
6. The OPTIMAL parameter specifies the size in bytes that a rollback segment must shrink to, if
possible. Specifying OPTIMAL minimizes the waste of space in a rollback segment. If the
OPTIMAL parameter is specified, a rollback segment can release space on completion of
transactions that caused the growth.

Creating Rollback Segment

Example :

SVRMGR> CREATE ROLLBACK SEGMENT rbs01


2> TABLESPACE rbs
3> STORAGE ( INITIAL 100K
4> NEXT 100K
5> OPTIMAL 4M
6> MINEXTENTS 20
7> MAXEXTENTS 100);

SVRMGR> ALTER ROLLBACK SEGMENT rbs01 ONLINE;

Specify the following initialization parameter to ensure rollback segments are brought online at
STARTUP:

ROLLBACK_SEGMENTS=(rbs01)

DBA - 19
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

Offline and Drop Rollback Segment

Take a rollback segment offline:

· To prevent new transactions from using a rollback segment


· If the rollback segment needs to be dropped

ALTER ROLLBACK SEGMENT rbs01 OFFLINE;

· A rollback segment may need to be dropped if it is no longer needed or if it needs to be recreated


with different storage settings like INITIAL, NEXT, and MINEXTENTS.
· A rollback segment needs to be offline before it can be dropped.

DROP ROLLBACK SEGMENT rbs01;

Dictionary Views about Rollback Segment

SVRMGR> SELECT segment_name, tablespace_name, owner, status


2> FROM dba_rollback_segs;

SEGMENT_NAME TABLESPACE_NAME OWNER STATUS


------------ ---------------- ----- -------
SYSTEM SYSTEM SYS ONLINE
RBS1 RBS SYS ONLINE
RBS2 RBS SYS ONLINE
RBS3 RBS SYS OFFLINE
4 rows selected.

SVRMGR> SELECT usn, extents, rssize, optsize, hwmsize, xacts, status


2> FROM v$rollstat

USN EXTENTS RSSIZE OPTSIZE HWMSIZE XACTS STATUS


--- -------- ------- -------- -------- ----- ----------------
0 43 2199552 2199552 0 ONLINE
1 20 202752 204800 417792 0 ONLINE
2 4 38912 38912 0 PENDING OFFLINE
3 rows selected.

DBA - 20
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

9. Temporary Segment
· Temporary segments are used when statements such as the following are executed and the Oracle
server cannot perform the sorting needed in memory because it is bigger than SORT_AREA_SIZE
¾ SELECT. . . ORDER BY
¾ CREATE INDEX
¾ SELECT DISTINCT
¾ SELECT. . . GROUP BY
· The amount of memory used by a process for sorting is determined by the SORT_AREA_SIZE
initialization parameter. If the sort volume exceeds this size, several sort runs are needed, and
intermediate results are stored on disk.
· Temporary segments are created and used by the Oracle server in the tablespace that has been
assigned to the user for sorting.

Temporary Segments in a Temporary Tablespace


· Known as sort segments
· Only one segment per tablespace per instance
· Created when the first disk sort occurs in the instance after startup
· Reused by several transactions based on information in the Sort Extent Pool
· Released on instance shutdown

Views about temporary segments


· DBA_SEGMENTS
Query this view to get information on both types of temporary segments.

· V$SORT_SEGMENT
This view gives the status of the sort extent pool used by the instance.

· V$SORT_USAGE
This view only shows currently active sorts for the instance.

10. Managing Tables

ROWID in Oracle 8
ROWID Format
OOOOOO FFF BBBBBB RRR
Data object Relative file Block number Row number
number number

ROWID is a pseudo-column that can be queried along with other columns in


a table. It has the following characteristics:
· ROWID is a unique identifier for each row in the database.
· ROWID is not stored explicitly as a column value.
· Although the ROWID does not directly give the physical address of a row, it can be used to locate
the row.
· ROWID provides the fastest means of accessing a row in a table.
· ROWIDs are stored in indexes to specify rows with a given set of key values.

ROWID needs 10 bytes of storage on disk and is displayed using 18


characters. It consists of the following components:
· Data Object Number is assigned to each data object, such as table or index when it is created, and
it is unique within the database.
· Relative File Number is unique to each file within a tablespace.
· Block Number represents the position of the block, containing the row, within the file.

DBA - 21
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

· Row Number identifies the position of the row directory slot in the block header.

Example :

SVRMGR> SELECT deptno, ROWID


2> FROM scott.dept;
3>
DEPTNO ROWID
------ ------------------
10 AAAArsAADAAAAUaAAA
20 AAAArsAADAAAAUaAAB
30 AAAArsAADAAAAUaAAC
40 AAAArsAADAAAAUaAAD
4 rows selected.

In this example:
· AAAArs is the data object number.
· AAD is the relative file number.
· AAAAUa is the block number.
· AAA is the row number for the department with DEPTNO=10.

High Water Mark


Extent ID 0 1 2 3 4

· The high water mark for a table indicates the last block that was ever used for the table.
· As data is inserted into the table, the high water mark is moved to mark the last block used.
· The high water mark is not reset when rows are deleted from the table.
· The high water mark is stored in the segment header of the table.
· When the Oracle server performs full table scans, it reads all the blocks up to the high water mark.
· If large extents have been allocated to a table, but have not been used fully, it is possible to
manually deallocate space from the table by the following command. The space thus released is
available for use by other segments in the tablespace.

ALTER TABLE scott.employees


DEALLOCATE UNUSED;

DBA - 22
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

ANALYZE TABLE command

Example 1 : To verify the integrity of each data block of scott’s employees table.

ANALYZE TABLE scott.employees VALIDATE


STRUCTURE;

Example 2 : Gather statistics on scott’s employees table

ANALYZE TABLE scott.employees COMPUTE


STATISTICS;

· The statistics generated by the ANALYZE command will be stored in the data dictionary. E.g.
dba_tables.
· The COMPUTE STATISTICS option will generate statistics based on a full table scan, while the
ESTIMATE STATISTICS will generate statistics based on a sample.
· When statistics are generated, the CHAIN_CNT column of the data dictionary view
DBA_TABLES is updated with the number of rows that are chained or migrated. If a large number
of rows are migrated, then the table needs to be reorganized to eliminate migration.

DBMS_ROWID Package

Function Name Description


ROWID_CREATE Creates a ROWID from individual components
ROWID_OBJECT Returns the object identifier for a ROWID
ROWID_RELATIVE_FNO Returns the relative file number for a ROWID
ROWID_BLOCK_NUMBER Returns the block number for a ROWID
ROWID_ROW_NUMBER Returns the row number for a ROWID
ROWID_TO_ABSOLUTE_FNO Returns the absolute file number for a ROWID
ROWID_TO_EXTENDED Converts a ROWID from restricted to extended
ROWID_TO_RESTRICTED Converts a ROWID from extended to restricted

Example : To obtain the physical location of the rows in a table.

SVRMGR> SELECT deptno, ROWID,


2> DBMS_ROWID.ROWID_OBJECT(ROWID) AS OBJECT,
3> DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) AS "RELATIVE FILE",
4> DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) AS BLOCK
5> FROM scott.departments;

DEPTNO ROWID OBJECT RELATIVE F BLOCK


------ ------------------- ------ ----------- ----
--
10 AAAArsAADAAAAUaAAA 2796 3 1306
20 AAAArsAADAAAAUaAAB 2796 3 1306
30 AAAArsAADAAAAUaAAC 2796 3 1306
40 AAAArsAADAAAAUaAAD 2796 3 1306
4 rows selected.

DBA - 23
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

11. Managing Indexes

B-Tree Index
Index entry

Root

Branch

Index entry header


Leaf Key column length
Key column value
ROWID

· At the top of the index is the root, which contains entries that point to the next level in the index.
· At the next level are branch blocks, which in turn point to blocks at the next level in the index.
· At the lowest level are the leaf nodes, which contain the index entries that point to rows in the
table. The leaf blocks are doubly linked to facilitate scanning the index in an ascending as well as
descending order of key values.

Example : Create a normal B-Tree index on the last_name column of scott’s employees table

CREATE INDEX scott.emp_lname_idx


ON scott.employees(last_name)
PCTFREE 30
STORAGE(INITIAL 200K NEXT 200K
PCTINCREASE 0 MAXEXTENTS 50)
TABLESPACE indx01;

Reverse Key Index


· A reverse key index reverses the bytes of each column indexed (except the ROWID) while
keeping the column order. When inserting records on an ascending key, such as a system-
generated employee number, I/O bottlenecks can occur on the index because all index updates
occur at the same place in the index tree. Reverse key indexes spread the distribution of index
updates across the index tree by reversing the data value of the index key.
· For example, on insert of employee number 7698 in the table, a key value of 8967 is stored in the
index. As the next employee number 7782 is entered, an index entry is made for 2877, thereby
spreading the work load across multiple index blocks.
· Reverse key indexes are useful only for queries that contain equality predicates. Because lexically
adjacent keys are not stored next to each other in a reverse key index, range searches cannot be
performed using such an index.

Example : Create a reverse key index on the ord_no column of scott’s ord table
CREATE UNIQUE INDEX scott.ord_ord_no_idx
ON scott.ord(ord_no) REVERSE
PCTFREE 30
STORAGE(INITIAL 200K NEXT 200K
PCTINCREASE 0 MAXEXTENTS 50)
TABLESPACE indx01;

Bitmap Index
A bitmap index is also organized as a B-tree, but the leaf node stores a bitmap for each key value
instead of a list of ROWIDS. Each bit in the bitmap corresponds to a possible ROWID, and if the bit is
set, it means that the row with the corresponding ROWID contains the key value.

Example : Create a bitmap index on the region_id column of scott’s ord table

DBA - 24
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

CREATE BITMAP INDEX scott.ord_region_id_idx


ON scott.ord(region_id)
PCTFREE 30
STORAGE(INITIAL 200K NEXT 200K
PCTINCREASE 0 MAXEXTENTS 50)
TABLESPACE indx01;

Comparing B-Tree and Bitmap Indexes

B-tree Bitmap
Suitable for high-cardinality columns Suitable for low-cardinality columns
Updates on keys relatively inexpensive Updates to key columns very expensive
Inefficient for queries using OR predicates Efficient for queries using OR predicates
Useful for OLTP Useful for DSS

When we need to rebuild indexes?


· Move an index to a different tablespace
· Improve space utilization by removing deleted entries
· When the index becomes unbalanced/skewed
· Change a reverse key index to a normal B-tree index and vice versa

ALTER INDEX scott.ord_region_id_idx REBUILD


TABLESPACE indx02;

Index rebuilds have the following characteristics:


· A new index is built using an existing index as the data source.
· Sorts are not needed when an index is built using an existing index, resulting in better
performance.
· The old index is deleted after the new index is built. During the rebuild, sufficient space is needed
to accommodate both the old and the new index in their respective tablespaces.
· The resulting index does not contain any deleted entries. Therefore this index uses space more
efficiently.
· Queries can continue to use the existing index while the new index is being built.

ANALYZE INDEX command

Analyze the index to perform the following:

· Check all the index blocks for block corruption. Note that this command does not verify whether
index entries correspond to data in the table.
· Populate the INDEX_STATS view with information about the index.

ANALYZE INDEX scott.ord_region_id_idx


VALIDATE STRUCTURE;

12. Maintaining Data Integrity

Types of Constraints

Constraint Description
NOT NULL Specifies that a column cannot contain null values
UNIQUE Designates a column or combination of columns as unique
PRIMARY KEY Designates a column or combination of columns as the table’s primary key
FOREIGN KEY Designates a column or combination of columns as the foreign key in a referential
integrity constraint

DBA - 25
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

CHECK Specifies a condition that each row of the table must satisfy

Three States of Constraints

Disabled Constraints

A constraint that is disabled is not checked, even though the constraint definition is still stored in the
data dictionary. Data in the table as well as new data that is entered or updated may not conform to the
rules defined by the constraint.

ALTER TABLE scott.departments


DISABLE CONSTRAINT dept_pk CASCADE;

· Disable before bulk load, especially self-referencing foreign keys.


· Disable referencing foreign keys before disabling parent keys.
· Unique indexes are dropped, but nonunique indexes are retained.

Enabled Novalidate Constraints

If a constraint is enabled novalidate, new data that violates the constraint cannot be entered. However,
the table may contain data that is invalid—that is, data that violates the constraint. This is usually an
intermediate stage that ensures that all new data is checked before being accepted into the table.

ALTER TABLE scott.departments


ENABLE NOVALIDATE CONSTRAINT
dept_pk;

· No locks on table
· Primary/unique keys must use nonunique indexes

DBA - 26
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

Enabled Constraints

If a constraint is in this state, then all data in the table is guaranteed to adhere to the constraint. In
addition, this state prevents any invalid data from being entered. This is the normal state of operation of
a constraint for online transaction processing.

ALTER TABLE scott.employees


ENABLE VALIDATE CONSTRAINT
emp_dept_fk;

· Locks table
· Can use unique or nonunique indexes
· Needs valid table data

How to use the EXCEPTIONS table

The EXCEPTIONS clause helps to identify any row that violates a


constraint that is being enabled.

1. Create EXCEPTIONS table (utlexcpt.sql ).


2. Execute ALTER TABLE with EXCEPTIONS clause.
3. Use subquery on EXCEPTIONS to locate rows with invalid data.
4. Rectify the errors.
5. Reexecute ALTER TABLE to enable the constraint.

Deferred and non-deferred constraints

Nondeferred or Immediate Constraints

Nondeferred constraints, also known as immediate constraints, are enforced


at the end of every DML statement. A constraint violation causes the
statement to be rolled back.

Deferred Constraints

Deferred constraints are constraints that are checked only when a transaction
commits. If any constraint violations are detected at commit time, the entire
transaction is rolled back. These constraints are most useful when both the
parent and child rows in a foreign key relationship are entered at the same
time, as in the case of an order entry system, where the order and the items
in the order are entered at the same time.

DBA - 27
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

13. Clusters and Index-Organized tables


For example, there are two tables, ORD and ITEM. If they were stored as regular tables, ORD and
ITEM are placed in different segments. This means that the tables use their own set of blocks—a block
that is used to store a row from the ORD table does not contain data from the ITEM table, and vice
versa.
If the tables ORD and ITEM are stored in a cluster, they share the same cluster segment. A block in
this segment can store rows from both tables. If a table is stored in a cluster, the cluster becomes the
physical unit of storage and the table is a logical entity—that is, part of the cluster.

Clusters have the following characteristics:


· Clusters have a cluster key, which is used to identify the rows that need to be stored together.
· The cluster key may consist of one or more columns.
· Tables in a cluster have columns that correspond to the cluster key.
· Clustering is a mechanism that is transparent to the applications using the tables. Data in a
clustered table can be manipulated as though it were stored in a regular table.
· Updating one of the columns in the cluster key may entail physically relocating the row.
· The cluster key is independent of the primary key. The tables in a cluster can have a primary key,
which may be the cluster key or a different set of columns.
· Clusters are usually created to improve performance. Random access to clustered data may be
faster, but full table scans on clustered tables are generally slower.

Creating Index Cluster


1. Create a cluster

CREATE CLUSTER scott.ord_clu


(ord_no NUMBER(3))
SIZE 200 TABLESPACE DATA01
STORAGE(INITIAL 5M NEXT 5M PCTINCREASE
0);

2. Create a cluster index

CREATE INDEX scott.ord_clu_idx


ON CLUSTER scott.ord_clu
TABLESPACE INDX01
STORAGE(INITIAL 1M NEXT 1M PCTINCREASE
0);

3. Create tables in the cluster

CREATE TABLE scott.ord


(ord_no NUMBER(3)
CONSTRAINT ord_pk PRIMARY KEY,
ord_dt DATE, cust_cd VARCHAR2(3))
CLUSTER scott.ord_clu(ord_no);

CREATE TABLE scott.item


(ord_no NUMBER(3) CONSTRAINT item_ord_fk REFERENCES scott.ord,
prod VARCHAR2(5), qty NUMBER(3),
CONSTRAINT item_pk PRIMARY KEY(ord_no,prod))
CLUSTER scott.ord_clu(ord_no);

Creating Hash Clusters

1. Create a cluster

DBA - 28
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

CREATE CLUSTER scott.off_clu


(country VARCHAR2(2),postcode VARCHAR2(8))
SIZE 500 HASHKEYS 1000
TABLESPACE DATA01
STORAGE(INITIAL 5M NEXT 5M PCTINCREASE 0);

2. Create tables in a cluster

CREATE TABLE scott.office(


office_cd NUMBER(3), cost_ctr NUMBER(3), country
VARCHAR2(2), postcode VARCHAR2(8))
CLUSTER scott.off_clu(country,postcode);

Index-Organized Tables

Accessing index- Storage Structure


organized table An index-organized table keeps all data for a table within a B-tree
structure. The B-tree index, which is based on the primary key of the
table, is organized like an index. The leaf blocks in this structure
contain the nonkey columns, instead of the ROWID, as the second
element of the index leaf entry. Therefore, the use of an index-
organized table eliminates the need to have two separate segments, the
table and the index.

Accessing an Index-Organized Table


Index access to a regular table requires that one or more index blocks
are read to retrieve the ROWID and the I/O on the table based on the
ROWID. In contrast, reading an index-organized table requires only
Non-key columns index block reads because the whole row is available in the leaf node.
An index-organized table can be accessed using either the primary key
Key column
or a combination of columns that constitute the leading part of the
Row header primary key. Changes to the table data, such as adding new rows,
updating rows, or deleting rows, result only in updating the index.

Index-Organized Tables Compared with Regular Tables

Regular Table Index-Organized Table


Unique identifier–ROWID Identified by primary key
ROWID implicit No ROWID
Supports several indexes No secondary indexes
FTS returns rows in no specific order Full index scans return rows in PK order
Unique constraints allowed No support for unique constraints
Distribution, replication, and partitioning Distribution, replication, and partitioning not
supported supported

DBA - 29
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

Example

CREATE TABLE scott.sales


( office_cd NUMBER(3),
qtr_end DATE,
revenue NUMBER(10,2),
review VARCHAR2(1000),
CONSTRAINT sales_pk
PRIMARY KEY(office_code, qtr_end))
ORGANIZATION INDEX TABLESPACE data01
PCTTHRESHOLD 20
OVERFLOW TABLESPACE data02;

where

ORGANIZATION INDEX : specifies that it is an index-organized table


PCTTHRESHOLD : specifies the percentage of space reserved in the index block for an index-
organized table row (If a row exceeds the size calculated based on this
value, all columns after the column named in the INCLUDING clause are
moved to the overflow segment. If OVERFLOW is not specified, then rows
exceeding the threshold are rejected. PCTTHRESHOLD defaults to 50 and
must be a value from 0 to 50.)
INCLUDING column : specifies a column at which to divide an index-organized table row into
index and overflow portions (All columns that follow column are stored in
the overflow data segment. If this is not specified and a row size exceeds
PCTTHRESHOLD, all columns except the primary key columns will be
moved to the overflow area. The column is either the name of the last
primary key column or any nonprimary key column.)
OVERFLOW : specifies that index-organized table data rows exceeding the specified
threshold are placed in the data segment defined by
segment_attributes_clause, which specifies the tablespace, storage, and
block utilization parameters

14. SQL*Loader, IMPORT/EXPORT

SQL*Loader loads data from external files into tables


in an Oracle database.

SQL*Loader Features
· One or more input files can be used.
· Several input records can be combined into one logical record for loading.
· Input fields can be fixed or variable length.
· Input data can be in any format—character, binary, packed decimal, date, and zoned decimal.
· Data can be loaded from different types of media such as disk, tape, or named pipes.
· Data can be loaded into several tables in one run.
· Options are available to either replace or to append to existing data in the tables.
· SQL functions can be applied on the input data before the row is stored in the database.
· Column values can be autogenerated based on rules. For example, a sequential key value can be
generated and stored in a column.
· Data can be loaded directly into the table, bypassing the database buffer cache.

Files Used by SQL*Loader


· Control file: specifies the input format, output tables, and optional conditions that may be used to
load only part of the records found in the input data files
· Data files: contain the data in the format defined in the control file
· Parameter file: is an optional file that can be used to define the command line parameters for the
load

DBA - 30
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

· Bad file: is used by the utility to write the records that are rejected during the load (This can occur
during input record validation by the utility or during record insertion by the Oracle server.)
· Log file: is created by SQL*Loader and contains a record of the load
· Discard file: is a file that can be created, if necessary, to store all records
· that did not satisfy the selection criteria

Comparing Direct and Conventional Path Loads

Conventional Load Direct Path Load


Uses COMMITs to make changes permanent Uses data saves
Redo log entries always generated Generates redo only under specific conditions
Enforces all constraints Enforces only primary key, unique, and NOT NULL
INSERT triggers fire INSERT triggers do not fire
Can load into clustered tables Cannot load into clustered tables
Other users can make changes to tables Other users cannot make changes to tables

Example :

$sqlldr scott/tiger control=ulcase6.ctl \


> log=ulcase6.log direct=true

Uses of Export and Import


· Reorganize tables
· Move data owned by one user to another user
· Move data between databases:
· Development to production
· OLTP system to a data warehouse
· Migrate to a different platform or release of Oracle
· Repeat test runs during development or upgrade
· Perform a logical backup

Example 1 : Export scott’s EMP and DEPT tables with direct path export.
Name the exported file as emp.dmp and the log file as exp.log.

$exp scott/tiger tables=(dept,emp) \


> file=emp.dmp log=exp.log direct=y

Example 2 : Import the data from example 1 back to the database

$imp scott/tiger tables=(dept,emp) \


> file=emp.dmp log=imp.log

DBA - 31
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

Import Behavior

· Order of Import
Table symbol 224 \f "Wingdings" \s 10à} Data symbol 224 \f "Wingdings" \s 10à}B-tree Indexes
symbol 224 \f "Wingdings" \s 10à}Constraints, Triggers, Bitmap indexes
· Tablespace used for the object
Same tablespace as in the source database, if possible
User’s default tablespace

15. Managing Database Users

Checklist for Creating Users


1. Choose a username and authentication mechanism. (E.g. login and password)
2. Identify tablespaces in which the user needs to store objects. (Don’t assign SYSTEM tablespace)
3. Decide on quotas for each tablespace.
4. Assign default tablespace and temporary tablespace.
5. Create a user. (Using the CREATE USER command)
6. Grant privileges and roles to the user.

Examples and Guidelines about users

Example 1 : Create a new user called PETER and assign tablespace quota to him.

CREATE USER peter


IDENTIFIED BY my1stson
DEFAULT TABLESPACE data01
TEMPORARY TABLESPACE temp
QUOTA 15m ON data01
QUOTA 20M on data02
QUOTA 10M on INDX01
PASSWORD EXPIRE;

Guidelines

· Choose a standard password initially


· Use the EXPIRE keyword to force users to reset their passwords during their first login.
· Always assign temporary tablespace.
· Restrict quotas to few users use QUOTA UNLIMITED with caution.
· Educate users:
¾ To connect
¾ To change password

Example 2 : Revoke PETER’s quota on tablespace data01

ALTER USER peter QUOTA 0 ON data01;

Once a quota of 0 is assigned, the objects owned by the user remain in the revoked tablespace but they
cannot be allocated any new space. For example, if a table that is 10 MB exists in tablespace data01,
and the tablespace data01 quota is altered to 0, no more new extents can be allocated for that table.

DBA - 32
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

Example 3 : Drop the database user PETER

DROP USER peter;

or

DROP USER peter CASCADE;

Guidelines

· When the user is dropped, all his objects(all tables, indexes, views.......) are dropped
· The CASCADE option drops all objects in the schema before dropping the user. This must be
specified if the schema contains any objects.
· A user who is currently connected to the Oracle server cannot be dropped.

Dictionary Views about Users

DBA_USERS DBA_TS_QUOTAS
USERNAME USERNAME
USER_ID TABLESPACE_NAME
CREATED BYTES
ACCOUNT_STATUS MAX_BYTES
LOCK_DATE BLOCKS
EXPIRY_DATE MAX_BLOCKS
DEFAULT_TABLESPACE
TEMPORARY_TABLESPACE

SVRMGR> SELECT tablespace_name, blocks, max_blocks,bytes, max_bytes


2> FROM dba_ts_quotas
3> WHERE username = 'SCOTT';

TABLESPACE_NAME BLOCKS MAX_BLOCKS BYTES MAX_BYTES


--------------- ------ ----------- ------ ---------
DATA01 10 -1 20480 -1
1 row selected.

A value of -1 in MAX_BLOCKS or MAX_BYTES column indicates that the user has unlimited quota
on a tablespace.

SVRMGR> SELECT username, account_status, temporary_tablespace


2> FROM dba_users;

USERNAME DEFAULT_TABLESPACE TEMPORARY_TABLESPACE


ACCOUNT_STATUS
-------- ------------------- --------------------- ------------
--
SYS SYSTEM TEMP OPEN
SYSTEM DATA01 TEMP OPEN
DBSNMP DATA01 TEMP OPEN
SCOTT DATA02 TEMP LOCKED
4 rows selected.

16. Managing User Profiles

User Profiles and resource limits


· Are named sets of resource and password limits

DBA - 33
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

· Are assigned to users by the CREATE/ALTER USER command


· Can be enabled or disabled
· Can relate to the DEFAULT profile
· Can limit system resources on session or call level

Resource Limits at Session Level

Resource Description
CPU_PER_SESSION Total CPU time measured in hundredths of seconds
SESSIONS_PER_USER Number of concurrent sessions allowed for each username
CONNECT_TIME Elapsed connect time measured in minutes
IDLE_TIME Periods of inactive time measured in minutes
LOGICAL_READS_PER _SESSION Number of data blocks (physical and logical reads)
PRIVATE_SGA Private space in the SGA measured in bytes (for MTS only)

Resources Limits at Call Level

Resource Description
CPU_PER_CALL CPU time per call in hundredths of seconds
LOGICAL_READS_PER _CALL Number of data blocks

How to enforce resource limit using profiles

STEP 1 : Create profiles

CREATE PROFILE developer_prof LIMIT


SESSIONS_PER_USER 2
CPU_PER_SESSION 10000
IDLE_TIME 60
CONNECT_TIME 480;

STEP 2 : Assign profiles to the user.

For new user :

CREATE USER user3 IDENTIFIED BY user3


DEFAULT TABLESPACE data01
TEMPORARY TABLESPACE temp
QUOTA unlimited ON data01
PROFILE developer_prof;

For existing user :

ALTER USER scott


PROFILE developer_prof;

STEP 3 : Enabling Resource Limits

Set the initialization parameter RESOURCE_LIMIT to TRUE in the parameter file. Then restart the
databse.

or

Enforce the resource limits by enabling the parameter with the ALTER SYSTEM command so that you
do not need to restart the database

ALTER SYSTEM SET RESOURCE_LIMIT=TRUE;

DBA - 34
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

Password Management

Parameter Description
FAILED_LOGIN_ATTEMPTS Number of failed login attempts before lockout of the
account
PASSWORD_LOCK_TIME Number of days for which the account remains locked
upon password expiration
PASSWORD_LIFE_TIME Lifetime of the password in days after which the
password expires
PASSWORD_GRACE_TIME Grace period in days for changing the password after the
first successful login after the password has expired
PASSWORD_REUSE_TIME Number of days before a password can be reused
PASSWORD_REUSE_MAX Maximum number of times a password can be reused
PASSWORD_VERIFY_FUNCTION PL/SQL function that makes a password complexity
check before a password is assigned

Example :

CREATE PROFILE grace_5 LIMIT


FAILED_LOGIN_ATTEMPTS 3
PASSWORD_LIFE_TIME 30
PASSWORD_REUSE_TIME 30
PASSWORD_VERIFY_FUNCTION verify_function
PASSWORD_GRACE_TIME 5;

Dictionary Views about user profiles

SVRMGR> SELECT username, password, account_status,


2> lock_date, expiry_date
3> FROM dba_users;
USERNAME ACCOUNT_STATUS LOCK_DATE
EXPIRY_DATE
-------- --------------- ---------- ---------
--
SYS OPEN 19-DEC-97
SYSTEM OPEN 19-DEC-97
SCOTT OPEN 19-DEC-97
DBSNMP OPEN 19-DEC-97
4 rows selected.

SVRMGR> SELECT p.profile, p.resource_name, p.limit


2> FROM dba_users u, dba_profiles p
3> WHERE p.profile=u.profile AND username=’SCOTT’ AND
p.resource_type=’KERNEL’;

PROFILE RESOURCE_NAME LIMIT


-------------- -------------------------- --------
DEVELOPER_PROF COMPOSITE_LIMIT DEFAULT
DEVELOPER_PROF SESSIONS_PER_USER 2
DEVELOPER_PROF CPU_PER_SESSION 10000
DEVELOPER_PROF CPU_PER_CALL DEFAULT
DEVELOPER_PROF LOGICAL_READS_PER_SESSION DEFAULT
DEVELOPER_PROF LOGICAL_READS_PER_CALL DEFAULT
DEVELOPER_PROF IDLE_TIME 60
DEVELOPER_PROF CONNECT_TIME 480
DEVELOPER_PROF PRIVATE_SGA DEFAULT
9 rows selected.

DBA - 35
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

SVRMGR> SELECT * FROM dba_profiles


2> WHERE resource_type='PASSWORD' and profile=’DEVELOPER_PROF’

PROFILE RESOURCE_NAME LIMIT


-------------- -------------------------- -------
DEVELOPER_PROF FAILED_LOGIN_ATTEMPTS DEFAULT
DEVELOPER_PROF PASSWORD_LIFE_TIME DEFAULT
DEVELOPER_PROF PASSWORD_REUSE_IME DEFAULT
DEVELOPER_PROF PASSWORD_REUSE_MAX DEFAULT
DEVELOPER_PROF PASSWORD_VERIFY_FUNCTION DEFAULT
DEVELOPER_PROF PASSWORD_LOCK_TIME DEFAULT
DEVELOPER_PROF PASSWORD_GRACE_TIME DEFAULT
7 rows selected.

17. Managing Privileges

SYSTEM Privileges
· System privileges enable users to perform particular actions in the database
· There are about 80 system privileges.
· The ANY-keyword in the privileges signifies that users have the privilege in every schema.
· The GRANT command adds a privilege to a user or a group of users.
· The REVOKE command deletes the privileges.

Examples of system privileges

Category Examples
INDEX CREATE ANY INDEX
ALTER ANY INDEX
DROP ANY INDEX
TABLE CREATE TABLE
CREATE ANY TABLE
ALTER ANY TABLE
DROP ANY TABLE
SELECT ANY TABLE
UPDATE ANY TABLE
DELETE ANY TABLE
SESSION CREATE SESSION
ALTER SESSION
RESTRICTED SESSION
TABLESPACE CREATE TABLESPACE
ALTER TABLESPACE
DROP TABLESPACE
UNLIMITED TABLESPACE

Examples about system privileges

Example 1 : Allow user1 to connect to the database and create his own tables

GRANT CREATE SESSION, CREATE TABLE TO user1;

Example 2 : Allow scott to connect to the database and to further grant the privilege to
other users or roles

GRANT CREATE SESSION TO scott


WITH ADMIN OPTION;

DBA - 36
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

Example 3 : Do not allow user1 to create table

REVOKE CREATE TABLE FROM user1;

Interesting example about WITH ADMIN OPTION

1. The DBA grants the CREATE TABLE system privilege to USER 1 with the ADMIN OPTION.
2. USER 1 creates a table.
3. USER 1 grants the CREATE TABLE system privilege to SCOTT.
4. SCOTT creates a table.
5. The database administrator revokes the CREATE TABLE system privilege from USER 1.

The result:
1. The table of USER 1 still exists but the user cannot create any new tables.
2. SCOTT still has the table and the CREATE TABLE system privilege.

Dictionary Views about system privileges


Query the DBA_SYS_PRIVS to list system privileges granted to users and roles:

DBA - 37
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

SVRMGR>SELECT * FROM DBA_SYS_PRIVS;

GRANTEE PRIVILEGE ADM


------- ------------------- ---
-
...
SCOTT SELECT ANY TABLE NO
SYS DELETE ANY TABLE NO
SYS EXECUTE ANY TYPE NO
SYS INSERT ANY TABLE NO
SYS SELECT ANY SEQUENCE NO
SYS SELECT ANY TABLE YES
SYS UPDATE ANY TABLE NO
SYSTEM UNLIMITED TABLESPAC YES
...

The view SESSION_PRIVS lists the privileges that are available for the current session to a
user—in our example, for the user SCOTT.

SVRMGR> SELECT * FROM session_privs;

PRIVILEGE
-----------------------
--
CREATE SESSION
ALTER SESSION
CREATE TABLE
SELECT ANY TABLE
CREATE CLUSTER
CREATE SYNONYM
CREATE VIEW
CREATE SEQUENCE
CREATE PROCEDURE
9 rows selected.

Object Privileges
· Object privileges enables users to access and manipulate a specific object
· Each object privilege that is granted authorizes the grantee to perform someoperation on the
object.
· The table below summarizes the object privileges that can be granted on each type of object.

Object priv. Table View Sequence Procedure


ALTER symbo symbol
l 252 252 \f
\f "Wingding
"Wing s" \s 10ü}
dings"
\s
10ü}
DELETE symbo symb
l 252 ol 252
\f \f
"Wing "Win
dings" gding
\s s" \s
10ü} 10ü}
EXECUTE symbol
252 \f

DBA - 38
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

"Wingding
s" \s 10ü}
INDEX symbo symb
l 252 ol 252
\f \f
"Wing "Win
dings" gding
\s s" \s
10ü} 10ü}
INSERT symbo
l 252
\f
"Wing
dings"
\s
10ü}
REFERENCES symbo
l 252
\f
"Wing
dings"
\s
10ü}
SELECT symbo symb symbol
l 252 ol 252 252 \f
\f \f "Wingding
"Wing "Win s" \s 10ü}
dings" gding
\s s" \s
10ü} 10ü}
UPDATE symbo symb
l 252 ol 252
\f \f
"Wing "Win
dings" gding
\s s" \s
10ü} 10ü}

DBA - 39
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

Examples about object privileges

Example 1 : Allow all users to execute the package dbms_pipe

GRANT EXECUTE ON dbms_pipe TO public;

Example 2 : Allow user1 to update ename and sal columns of the emp table and also allow
user1 to grant the object privileges to other users or roles

GRANT UPDATE(ename,sal) ON emp TO user1


WITH GRANT OPTION;

Example 3 : Do not allow scott to use the package dbms_pipe

REVOKE execute ON dbms_pipe FROM scott;

Interesting example about WITH GRANT OPTION

1. USER 1 is granted the SELECT object privilege with the GRANT OPTION.
2. USER 1 grants the SELECT privilege on EMP to USER 2.

The result:
3. Later, the SELECT privilege is revoked from USER 1. This revoke is cascaded to USER 2 as well.

Dictionary Views about object privileges

Query DBA_TAB_PRIVS to return all object privileges granted to the specified user.

svrmgr> SELECT * FROM dba_tab_privs


2> WHERE GRANTEE=’SCOTT’

GRANTEE OWNER TABLE_NAME GRANTOR PRIVILEGE GRANTABLE


------- ----- ---------- ------- --------- ---------
SCOTT SYS RESUMES SYS READ NO
1 row selected.

Query DBA_COL_PRIVS to list all the column specific privileges that have been granted use the
following query:

svrmgr> SELECT * FROM dba_col_privs;

GRANTEE OWNER TABLE_NAME COLUMN_NAME GRANTOR PRIVILEGE


GRANTABLE
------- ----- ---------- ----------- ------- --------- ------
---
SYSTEM SCOTT EMP EMPNO SCOTT INSERT NO
SYSTEM SCOTT EMP SAL SCOTT UPDATE NO
2 rows selected.

18. Managing Roles

What is role?
Roles are named groups of related privileges that are granted to users or other roles. They are designed
to ease the administration of privileges in the database.

DBA - 40
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

Role Characteristics
· Granted to and revoked from users with the same commands used to grant and revoke system
privileges
· May be granted to any user or role, except to itself (even indirectly)
· Can consist of both system and object privileges
· May be enabled or disabled for each user granted the role
· Can require a password to enable
· Each role name must be unique among existing usernames and role names
· Are not owned by anyone; are not in any schema
· Have their descriptions stored in the data dictionary

Benefits of Roles
· Reduced granting of privileges
· Dynamic privilege management
· Selective availability of privileges
· Granted through the OS
· No cascading revokes
· Improved performance

Manapulating Roles

Example 1 : Creat a role without password

CREATE ROLE sales_clerk;

Example 2 : Create a role with password

CREATE ROLE hr_clerk


IDENTIFIED BY bonus;

Example 3 : Grant privileges to the role

Grant create session, create table, select on


emp to sales_clerk;

Example 4 : Assigning Roles to users

GRANT sales_clerk TO scott, peter;

Example 5 : Grant a role to another role

GRANT hr_clerk TO hr_manager;

Example 6 : Grant the role to scott and enable him to grant the role to other users

GRANT hr_manager TO scott


WITH ADMIN OPTION;

DBA - 41
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

Frequently Asked Questions in Oracle 8 Database Administration

Q1. How can I coalesce free space?

SMON coalesces free space (extents) into larger, contiguous extents


every 2 hours and even then only for a short period of time.

SMON will not coalesce free space if a tablespace's default storage


parameter "pctincrease" is set to 0. One can manually coalesce a
tablespace using the ALTER TABLESPACE ... COALESCE; command.

Q2 . How can I prevent tablespace fragmentation?

Always set PCTINCREASE to 0 or 100.

Bizarre values for PCTINCREASE will contribute to fragmentation. For


example if you set PCTINCREASE to 1 you will see that your extents
are going to have weird and wacky sizes: 100K, 100K, 101K, 102K, etc.
Such extents of bizarre size are rarely re-used in their entirety.
PCTINCREASE of 0 or 100 gives you nice round extent sizes that can
easily be reused. Eg. 100K, 100K, 200K, 400K, etc.

Q3. Can one rename a tablespace's name?

No

Workaround:
Export all of the objects from the tablespace
Drop the tablespace including contents
Recreate the tablespace
Import the objects back in

Q4. Can one rename a database user (schema)?

No

Workaround:
Do a user-level export of user A
create new user B
import system/manager fromuser=A touser=B
drop user A

Q5. What database block size should I use?

Oracle recommends that your database block size match, or be


multiples of your operating system block size. One can go smaller,
but the performance cost is significant. Your choice should depend on
the type of application you are running. If you have lots of small
transaction like with OLTP, use a small block size. With fewer but
larger transactions, like with a DSS application, use a large block
size.

Q6. Can one resize tablespaces and data files?

DBA - 42
This watermark does not appear in the registered version - http://www.clicktoconvert.com

GnanaSekar. A

You can manually increase the size of a datafile

ALTER DATABASE DATAFILE 'filename2' RESIZE 100M;

Because you can change the sizes of datafiles, you can add more space
to your database without adding more datafiles. This is beneficial if
you are concerned about reaching the maximum number of datafiles
allowed in your database.
Manually reducing the sizes of datafiles allows you to reclaim unused
space in the database. This is useful for correcting errors in
estimates of space requirements.
Also, datafiles can be allowed to automatically extend if more space
is required. Look at the following command:

CREATE TABLESPACE pcs_data_ts


DATAFILE 'c:\ora_apps\pcs\pcsdata1.dbf' SIZE 3M
AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED
DEFAULT STORAGE ( INITIAL 10240
NEXT 10240
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0)
ONLINE
PERMANENT;

Q7. Can one improve the performance of SQL*Loader?

1. A very simple but easily overlooked hint, do not have any indexes
and/or constraints (primary key) on your load tables during the
load process. This will significantly slowdown load times.
2. Add the following option in the command line: DIRECT=TRUE. This
will effectively bypass most of the RDBMS processing.
3. Turn off database logging by specifying the NOLOGGING option. This
option can only be used with direct data loads.
4. Run multiple load jobs concurrently.

Q8. Common Import/ Export problems

ORA-01555: Snapshot too old - Ask you users to STOP working while you
are exporting or use CONSISTENT=NO
ORA-01562: Failed to extend rollback segment - Set COMMIT=Y while
importing

DBA - 43

Вам также может понравиться