Sie sind auf Seite 1von 83

ORACLE DBA | CASE STUDIES

Oracle Enterprise Linux 5 Installation


1. Boot from the CD or DVD. At the boot screen, press the "Enter" key.

2. Press the "tab" key to move focus to the "Skip" key, then press the "Enter" key to
continue.

3. On the "Welcome" screen, click the "Next" button.

ORACLE DBA | CASE STUDIES

4. Select the appropriate language, then click the "Next" button.

5. Select the relevant keyboard setting, then click the "Next" button.

ORACLE DBA | CASE STUDIES

6. Click the "Yes" button on the disk partitioning warning dialog.

7. Check the "Review and modify partitioning layout" option, then allow the installer
to automatically partition the disk by clicking on the "Next" button

ORACLE DBA | CASE STUDIES

8. Click the "Yes" button on the subsequent warning dialog.

9. The installer will list the default partitioning scheme for your size disk.

ORACLE DBA | CASE STUDIES

The following screen shots show the actions I take for small test installations

10. Edit the "/boot" partition, setting it to "150M" and "Fixed size", then click the "OK"
button

ORACLE DBA | CASE STUDIES

11. The "/root" and "/swap" partitions are part of a volume group.

12. Edit the "/root" partition, setting it to "8000 MB", then click the "OK" button.

ORACLE DBA | CASE STUDIES

13.Edit the "swap" partition, setting it to "2048M", then click the "OK" button.

If you need additional swap space, simply make this partition bigger.
14. The partitions screen should now looks something like the following picture, then
click the "Next" button.

ORACLE DBA | CASE STUDIES

15. Accept the boot loader settings by clicking the "Next" button.

16. Configure the network interface with the apropriate settings. This can be done
automatically using DHCP, or manually.

ORACLE DBA | CASE STUDIES

17. If you are not using DHCP, enter the appropriate IP addess and subnet mask,
then click the "OK" button.

18. If you are not using DHCP, enter the host name, gateway and DNS information,
then click the "Next" button.

ORACLE DBA | CASE STUDIES 10

19. Select the relevant region by clicking on the map.

20. Select the relevant city by clicking on the map. Click on the "Next" button to
proceed.

ORACLE DBA | CASE STUDIES 11

21.Enter a root password for the server, then click the "Next" button to proceed.

22.Select the "Customize now" option and the appropriate installation type and click
the "Next" button.

ORACLE DBA | CASE STUDIES 12

23. The "Package Group Selection" screen allows you to select the required package
groups, and individual packages within the details section. When you've made your
selection, click the "Next" button.

24. On the "About to Install" screen, click the "Next" button.

ORACLE DBA | CASE STUDIES 13

25. Click the "Continue" button on the "Required Install Media" screen.

26. During the installation phase, enter the appropriate CDs as requested.

ORACLE DBA | CASE STUDIES 14

27.Click the "Reboot" button to complete the installation.

28. On the "Welcome" screen, click the "Forward" button.

ORACLE DBA | CASE STUDIES 15

29.Accept the license agreement and click the "Forward" button.

30. On the Firewall screen, choose the "Disabled" option and click the "Forward"
button.

ORACLE DBA | CASE STUDIES 16

31. Click the "Yes" button on the subsequent warning screen.

32. On the SELinux screen, choose the "Disabled" option and click the "Forward"
button.

ORACLE DBA | CASE STUDIES 17

33. Click the "Yes" button on the subsequent warning screen.

34. Accept the default setting on the Kdump screen by clicking the "Forward" button.

ORACLE DBA | CASE STUDIES 18

35. Adjust the Date and Time settings if necessary, and click the "Forward" Button.

36. If you have a Red Hat Network account, you can enter it here and register your
system. Alternatively, you can pick the "No, I prefer to register at a later time" option
and click the "Forward" button to avoid this step.
37. Create an additional system user if required, and click the "Next" button.

ORACLE DBA | CASE STUDIES 19

38. If you chose not to define an additional system user, click the "Continue" button
on the resulting warning dialog.

39. On the sound card screen, click the "Forward" button.

ORACLE DBA | CASE STUDIES 20

40. On the "Additional CDs" screen, click the "Finish" button.

41. Click the "OK" button on the reboot request dialog.

ORACLE DBA | CASE STUDIES 21

42. Once the system has rebooted, you are presented with the login screen.

43. Once logged in, you are ready to use the desktop.

ORACLE DBA | CASE STUDIES 22

Guide to install Oracle 10 on Linux


Checking minimum hardware requirements
At least, your system should meet the following requirements:
1GB RAM
Requirement for swap space in Oracle installation is as follows:
AVAILABLE RAM

SWAP SPACE REQUIRED

Between 1 GB and 2 GB

1.5 times the size of RAM

Between 2 GB and 8 GB

Equal to the size of RAM

More than 8 GB

.75 times the size of RAM

400MB free space in /tmp directory


Depending on type of the installation, 1.5-3.5 GB free space for Oracle Software
1.5GB free space if new Oracle Database is created

ORACLE DBA | CASE STUDIES 23

Getting familiar with requirements mentioned above, we need to get hardware


information of our system. To check the size of RAM, Swap space and tmp directory,
we run these commands:
To check the size of physical memory, execute
grep MemTotal

/proc/meminfo

df h /tmp
Making Directories
To make directories, execute:
su - root
mkdir p /app/oracle/product/10.2.0/ [u01 if needed]
Checking Kernel Parameters
To see all kernel parameters, execute:
su - root
sysctl a
The options for sysctl are as follows:
-a List all the currently available string or integer values. This is
the default, if no parameters are given to sysctl.
Verify that the kernel parameters shown in the following table are set to values
greater than or equal to the recommended value shown. Do not change the value of
any kernel parameter on a system where it is already higher than listed as minimum
requirement.
Parameter

Value

File

semmsl

250

/proc/sys/kernel/sem

semmns

32000

semopm

100

semmni

128

shmall

2097152

/proc/sys/kernel/shmall

shmmax

Half the size of


physical memory (in
bytes)

/proc/sys/kernel/shmmax

ORACLE DBA | CASE STUDIES 24

Parameter

Value

File

shmmni

4096

/proc/sys/kernel/shmmni

file-max

65536

/proc/sys/fs/file-max

ip_local_port_range Minimum:1024

/proc/sys/net/ipv4/ip_local_port_range

Maximum: 65000
rmem_default

1048576

/proc/sys/net/core/rmem_default

rmem_max

1048576

/proc/sys/net/core/rmem_max

wmem_default

262144

/proc/sys/net/core/wmem_default

wmem_max

262144

/proc/sys/net/core/wmem_max

We added the following lines to the /etc/sysctl.conf file which is used during the
boot process:
# Kernel Parameters for Oracle 10.2.0
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 1048576
net.core.rmem_max = 1048576
net.core.wmem_default = 262144
net.core.wmem_max = 262144
Creating Oracle Groups
To create the oracle group(s), execute the following commands:
su root
groupadd <groupname> [For Primary Group]
groupadd <groupname> [For Secondary Group .If Needed]
Creating Oracle User Account
To create the oracle account execute the following commands:
su root
useradd c "Oracle Owner" g oinstall G dba d
/app/oracle/product/10.2.0/
oracle

ORACLE DBA | CASE STUDIES 25

Changing Owner and Mode


To change the user and mode execute
root>chown <username>.<primarygroupname> R /app/
root>chmod 755 R /app/
Setup Environment
Before installing the Oracle software, set the environment. To set an environment
execute
root>su - <username>
user>vi.bash_profile
Modify the .bash_profile according to your requirements
Sample bash_profile
unset TWO_TASK
export
export
export
export
export
export
export

ORACLE_SID=GENTIC
LISTENER_NAME=$ORACLE_SID
ORACLE_BASE=/export/home/oracle
ORACLE_HOME=$ORACLE_BASE/product/10.2.0
ORACLE_DOC=$ORACLE_HOME/doc
LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
TNS_ADMIN=/export/home/oracle/admin/sqlnet

export
export
export
export
export
export

PATH=$ORACLE_HOME/bin:$PATH
NLS_LANG=american_america.al32utf8
ORA_NLS10=$ORACLE_HOME/nls/data
TEMP=/tmp
TMPDIR=/tmp
EDITOR=vi

ulimit -u 16384 -n 63536


Compile the bash_profile by executing
./.bash_profile
Start Installer
The runInstaller will on the path /dump/database. To proceed execute
user>cd /dump/database/

ORACLE DBA | CASE STUDIES 26

./runInstaller
The DBCA screen will appear. Please follow the wizard to install the oracle on your
machine.

Manual creation of Database


In LINUX:
Create folders for Admin log files
$ cd /app/oracle/admin/<db_name>/
( Example db_name = xyz)

$ cd /app/oracle/admin/xyz
$ mkdir adump cdump bdump dpdump pfile udump script
Create/modify init.ora file under pfile
Modify the following parameters in init.ora file according to your need
db_name, background_dump_dest,core_dump_dest,user_dump_dest ,
control_files , db_recovery_file_dest , audit_file_dest, SERVICE
Create folders for physical files ( Datafiles, Redofiles, Controlfiles,etc.,)
$ cd

/app/oracle/oradata/<db_name>

(Example db_name=xyz)
$ mkdir xyz
Create the password for the database
$ cd /app/oracle/product/10.2.0/dbs/
$ export ORACLE_SID=<db_name>
$ orapwd file=oraxyzpw password=xyz

entries=3

force=y

Connect to SQLPLUS
$ sqlplus /nolog
SQL> connect sys as sysdba
Password: xyz
Startup the Instance
SQL> startup pfile=/app/oracle/admin/<db_name>/pfile/init.ora
nomount

ORACLE DBA | CASE STUDIES 27

Create database script(Createdb.sql) under script directory


(/app/oracle/admin/<db_name>/script)
SQL > @/app/oracle/admin/<db_name>/script/dbcreate.sql
Database created.
SQL> select username from dba_users;
SQL> select tablespace_name from dba_tablespaces;
SQL> @/app/oracle/product/10.2.0/rdbms/admin/catalog.sql
SQL> @/app/oracle/product/10.2.0/rdbms/admin/catproc.sql
SQL> select username from dba_users;
SQL> select tablespace_name from dba_tablespaces;

Note: Please ensure that the name given in init.ora file and database creation
script are same

ORACLE DATABASE CLONING


Connect to target system and execute
User>sqlplus /nolog
Sys as sysdba
Password
startup
Then issue
SQL>alter database backup controlfile to trace

Get file from /u01/oracle/admin/oldlsq/udump/xxxx.sql


It will look something like this:
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "OLDLSQ" NORESETLOGS

ORACLE DBA | CASE STUDIES 28

NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 2
MAXDATAFILES 240
MAXINSTANCES 1
MAXLOGHISTORY 113
LOGFILE
GROUP 1 ('/u03/oradata/oldlsq/log1a.dbf',
'/u03/oradata/olslsq/log1b.dbf') SIZE 30M,
GROUP 2 ('/u04/oradata/oldlsq/log2a.dbf',
'/u04/oradata/oldlsq/log2b.dbf') SIZE 30M
DATAFILE
'/u01/oradata/oldlsq/system01.dbf',
'/u01/oradata/oldlsq/mydatabase.dbf'
;
# Recovery is required if any of the datafiles are restored
# backups, or if the last shutdown was not normal or
immediate.
RECOVER DATABASE
# Database can now be opened normally.
ALTER DATABASE OPEN;
Shutdown the target database
Copy all data files into the new directories on the new server.
You may change the file names if you want, but you must edit the controlfile to reflect
the new data files names on the new server.
cp
cp
cp
cp

/u01/oradata/oldlsq/*
/u01/oradata/oldlsq/*
/u03/oradata/oldlsq/*
/u04/oradata/oldlsq/*

newhost:/u01/oradata/newlsq
newhost:/u01/oradata/newlsq
newhost:/u03/oradata/newlsq
newhost:/u04/oradata/newlsq

Copy and Edit the Control file Using the output syntax from STEP 1, modify
the controlfile creation script by changing the following:
Old:
CREATE CONTROLFILE REUSE DATABASE "OLDLSQ" NORESETLOGS
New:
CREATE CONTROLFILE SET DATABASE "NEWLSQ" RESETLOGS
Remove the recover database and alter database open syntax

ORACLE DBA | CASE STUDIES 29

# Recovery is required if any of the datafiles are restored


# backups, or if the last shutdown was not normal or
immediate.
RECOVER DATABASE
# Database can now be opened normally.
ALTER DATABASE OPEN;
Re-names of the data files names that have changed.
Old:
DATAFILE
'/u01/oradata/oldlsq/system01.dbf',
'/u01/oradata/oldlsq/mydatabase.dbf'
New:
DATAFILE
'/u01/oradata/newlsq/system01.dbf',
'/u01/oradata/newlsq/mydatabase.dbf'
Create the bdump, udump and cdump ,adump,pfile,dpdump directories
Copy-over the old init.ora file
cp $DBA/admin/olslsq/pfile/*.ora
newhost:/u01/oracle/admin/newlsq/pfile
Modify the init.ora with the new locations and db name
Run the modified control file script.
User>sqlplus /nolog
Sys as sysdba
Password
Sql>Startup pfile=loaction of your pfile nomount
Run the modified script to create control file
@db_create_controlfile.sql
SQL>alter database mount
SQL> alter database open resetlogs

Managing Table spaces

ORACLE DBA | CASE STUDIES 30

Note: Here the lmtbsb is used for tablespace name


Creating Tablespaces
SYNTAX:
SQL>CREATE TABLESPACE <TS NAME> DATAFILE 'Path of the
datafiles.dbf' SIZE <Size>M
Eg:
SQL>CREATE TABLESPACE lmtbsb DATAFILE
'/u02/oracle/data/lmtbsb01.dbf' SIZE 50M
Renaming Tablespaces
SYNTAX:
SQL>alter tablespace <OLD TS NAME> rename to <NEW TS NAME>;
Eg:
SQL>ALTER TABLESPACE users RENAME TO usersts;
Altering a Tablespace
SQL>ALTER TABLESPACE <TS NAME>
ADD DATAFILE 'Path of the datafiles.dbf' SIZE <New Size>M
Dropping Tablespaces
DROP TABLESPACE users INCLUDING CONTENTS;
SQL>DROP TABLESPACE users INCLUDING CONTENTS AND DATAFILES;
SQl>

Viewing Tablespace Information


The following data dictionary and dynamic performance views provide useful
information about the tablespaces of a database.
View

Description

V$TABLESPACE

Name and number of all tablespaces from the


control file.

ORACLE DBA | CASE STUDIES 31

View

Description

DBA_TABLESPACES,
USER_TABLESPACES

Descriptions of all (or user accessible)


tablespaces.

DBA_TABLESPACE_GROUPS

Displays the tablespace groups and the


tablespaces that belong to them.

DBA_SEGMENTS,
USER_SEGMENTS

Information about segments within all (or user


accessible) tablespaces.

DBA_EXTENTS, USER_EXTENTS Information about data extents within all (or


user accessible) tablespaces.
DBA_FREE_SPACE,
USER_FREE_SPACE

Information about free extents within all (or user


accessible) tablespaces.

V$DATAFILE

Information about all datafiles, including


tablespace number of owning tablespace.

V$TEMPFILE

Information about all tempfiles, including


tablespace number of owning tablespace.

DBA_DATA_FILES

Shows files (datafiles) belonging to


tablespaces.

DBA_TEMP_FILES

Shows files (tempfiles) belonging to temporary


tablespaces.

V$TEMP_EXTENT_MAP

Information for all extents in all locally managed


temporary tablespaces.

V$TEMP_EXTENT_POOL

For locally managed temporary tablespaces:


the state of temporary space cached and used
for by each instance.

V$TEMP_SPACE_HEADER

Shows space used/free for each tempfile.

DBA_USERS

Default and temporary tablespaces for all users.

DBA_TS_QUOTAS

Lists tablespace quotas for all users.

V$SORT_SEGMENT

Information about every sort segment in a given

ORACLE DBA | CASE STUDIES 32

View

Description
instance. The view is only updated when the
tablespace is of the TEMPORARY type.

V$TEMPSEG_USAGE

Describes temporary (sort) segment usage by


user for temporary or permanent tablespaces.

Creating a Locally Managed Tablespace


SQL>CREATE TABLESPACE lmtbsb DATAFILE
'/u02/oracle/data/lmtbsb01.dbf' SIZE 50M
EXTENT MANAGEMENT LOCAL AUTOALLOCATE;
SQL>CREATE TABLESPACE lmtbsb DATAFILE
'/u02/oracle/data/lmtbsb01.dbf' SIZE 50M
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K;
Specifying Segment Space Management in Locally Managed Tablespaces
SQL>CREATE TABLESPACE lmtbsb DATAFILE
'/u02/oracle/data/lmtbsb01.dbf' SIZE 50M
EXTENT MANAGEMENT LOCAL
SEGMENT SPACE MANAGEMENT AUTO;
Altering a Locally Managed Tablespace
SQL>ALTER TABLESPACE lmtbsb
ADD DATAFILE '/u02/oracle/data/lmtbsb02.dbf' SIZE 1M;
Altering tablespace availability (ONLINE/OFFLINE/READ ONLY/READWITE).
SQL> ALTER TABLESPACE lmtbsb online/offline/read only/read
write
Creating a Bigfile Tablespace
Sql>CREATE BIGFILE TABLESPACE bigtbs
DATAFILE '/u02/oracle/data/bigtbs01.dbf' SIZE 50G
You can specify SIZE in kilobytes (K), megabytes (M), gigabytes (G), or terabytes
(T).
Altering a Bigfile Tablespace
RESIZE:

ORACLE DBA | CASE STUDIES 33

SQL>ALTER TABLESPACE bigtbs RESIZE 80G;


AUTOEXTEND
SQL>ALTER TABLESPACE bigtbs AUTOEXTEND ON NEXT 20G;
Identifying a Bigfile Tablespace
DBA_TABLESPACES
USER_TABLESPACES
V$TABLESPACE
Creating a Tablespace Group
SQL>CREATE TEMPORARY TABLESPACE lmtemp2 TEMPFILE
'/u02/oracle/data/lmtemp201.dbf' SIZE 50M TABLESPACE GROUP
group1;
SQL>ALTER TABLESPACE lmtemp TABLESPACE GROUP group2;
Changing Members of a Tablespace Group
SQL>CREATE TEMPORARY TABLESPACE lmtemp3 TEMPFILE
'/u02/oracle/data/lmtemp301.dbf' SIZE 25M TABLESPACE GROUP
group1;
SQL>ALTER TABLESPACE lmtemp2 TABLESPACE GROUP group2;
SQL.ALTER TABLESPACE lmtemp3 TABLESPACE GROUP '';
Tablespace lmtemp3 no longer belongs to any group. Further, since there are no
longer any members of group1, this results in the implicit deletion of group1.
Assigning a Tablespace Group as the Default Temporary Tablespace
SQL>ALTER DATABASE sample DEFAULT TEMPORARY TABLESPACE group2;
Migrating the SYSTEM Tablespace to a Locally Managed Tablespace
SQL> EXECUTE
DBMS_SPACE_ADMIN.TABLESPACE_MIGRATE_TO_LOCAL('SYSTEM');
Note:

ORACLE DBA | CASE STUDIES 34

After the SYSTEM tablespace is migrated to locally managed, any dictionarymanaged tablespaces in the database cannot be made read/write. If you want to be
able to use the dictionary-managed tablespaces in read/write mode, then Oracle
recommends that you first migrate these tablespaces to locally managed before
migrating the SYSTEM tablespace.
Listing Tablespaces and Default Storage Parameters
SQL>SELECT TABLESPACE_NAME "TABLESPACE",INITIAL_EXTENT
INITIAL_EXT",NEXT_EXTENT "NEXT_EXT",MIN_EXTENTS "MIN_EXT",
MAX_EXTENTS "MAX_EXT",PCT_INCREASE FROM DBA_TABLESPACES;

Listing the Datafiles and Associated Tablespaces of a Database


SQL>SELECT FILE_NAME, BLOCKS, TABLESPACE_NAME FROM
DBA_DATA_FILES;
Displaying Statistics for Free Space (Extents) of Each Tablespace
SQL>SELECT TABLESPACE_NAME "TABLESPACE", FILE_ID,COUNT(*)
"PIECES",MAX(blocks) "MAXIMUM",MIN(blocks) "MINIMUM",
AVG(blocks) "AVERAGE",SUM(blocks) "TOTAL" FROM DBA_FREE_SPACE
GROUP BY TABLESPACE_NAME, FILE_ID;

Temporary Tablespaces
Creating a Locally Managed Temporary Tablespace
SQL>CREATE TEMPORARY TABLESPACE lmtemp TEMPFILE
'/u02/oracle/data/lmtemp01.dbf' SIZE 20M REUSE EXTENT
MANAGEMENT LOCAL UNIFORM SIZE 16M;
Altering a Locally Managed Temporary Tablespace
SQL>ALTER TABLESPACE lmtemp
ADD TEMPFILE '/u02/oracle/data/lmtemp02.dbf' SIZE 18M
REUSE;
SQL>ALTER TABLESPACE lmtemp TEMPFILE OFFLINE;
SQL>ALTER TABLESPACE lmtemp TEMPFILE ONLINE;
SQL>ALTER DATABASE TEMPFILE '/u02/oracle/data/lmtemp02.dbf'
OFFLINE;
SQL>ALTER DATABASE TEMPFILE '/u02/oracle/data/lmtemp02.dbf'
ONLINE;

ORACLE DBA | CASE STUDIES 35

Resizing a Temporary File


SQL>ALTER DATABASE TEMPFILE '/u02/oracle/data/lmtemp02.dbf'
RESIZE 18M;
Delete a Temporary file
SQL>ALTER DATABASE TEMPFILE '/u02/oracle/data/lmtemp02.dbf'
DROP
INCLUDING DATAFILES;
Creating a Tablespace Group
SQL>CREATE TEMPORARY TABLESPACE lmtemp2 TEMPFILE
'/u02/oracle/data/lmtemp201.dbf'SIZE 50M TABLESPACE GROUP
group1;
SQL>ALTER TABLESPACE lmtemp TABLESPACE GROUP group2;
Changing Members of a Tablespace Group
SQL>CREATE TEMPORARY TABLESPACE lmtemp3 TEMPFILE
'/u02/oracle/data/lmtemp301.dbf'SIZE 25M TABLESPACE GROUP
group1;
Adds a Tablespace to an Existing Group
SQL>ALTER TABLESPACE lmtemp2 TABLESPACE GROUP group2;
Remove a Tablespace from a Group
SQL>ALTER TABLESPACE lmtemp3 TABLESPACE GROUP '';
Assigning a Tablespace Group as the Default Temporary Tablespace
SQL>ALTER DATABASE sample DEFAULT TEMPORARY TABLESPACE group2;
Specifying Nonstandard Block Sizes for Tablespaces
SQL>CREATE TABLESPACE lmtbsb DATAFILE
'/u02/oracle/data/lmtbsb01.dbf' SIZE 50M EXTENT MANAGEMENT
LOCAL UNIFORM SIZE 128K BLOCKSIZE 8K;

ORACLE DBA | CASE STUDIES 36

Managing Undo Tablespaces


Creating an Undo Tablespace
Using CREATE DATABASE to Create an Undo Tablespace
CREATE DATABASE rbdb1
CONTROLFILE REUSE
.
.
.
UNDO TABLESPACE undotbs_01 DATAFILE
'/u01/oracle/rbdb1/undo0101.dbf';
If the undo tablespace cannot be created successfully during CREATE DATABASE,
the entire CREATE DATABASE operation fails. You must clean up the database files,
correct the error and retry the CREATE DATABASE operation.
Using the CREATE UNDO TABLESPACE Statement
SQl>CREATE UNDO TABLESPACE undotbs_02
DATAFILE '/u01/oracle/rbdb1/undo0201.dbf' SIZE 2M REUSE
AUTOEXTEND ON;
Note:
You can create more than one undo tablespace, but only one of them can be active
at any one time.
Altering an Undo Tablespace
SQL>ALTER TABLESPACE undotbs_01
ADD DATAFILE '/u01/oracle/rbdb1/undo0102.dbf' AUTOEXTEND ON
NEXT 1M MAXSIZE UNLIMITED;
Dropping an Undo Tablespace
SQl>DROP TABLESPACE undotbs_01;
Note:
An undo tablespace can only be dropped if it is not currently used by any instance.
Switching Undo Tablespaces
SQL>ALTER SYSTEM SET UNDO_TABLESPACE = undotbs_02;

ORACLE DBA | CASE STUDIES 37

Un Assign the current Undo Tablespace


SQl>ALTER SYSTEM SET UNDO_TABLESPACE = '';
Viewing Information About Undo
The following dynamic performance views are useful for obtaining space information
about the undo tablespace:
View

Description

V$UNDOSTAT

Contains statistics for monitoring and tuning undo space.


Use this view to help estimate the amount of undo space
required for the current workload. The database also uses
this information to help tune undo usage in the system.
This view is meaningful only in automatic undo
management mode.

V$ROLLSTAT

For automatic undo management mode, information


reflects behavior of the undo segments in the undo
tablespace

V$TRANSACTION

Contains undo segment information

DBA_UNDO_EXTENTS Shows the status and size of each extent in the undo
tablespace.
DBA_HIST_UNDOSTAT Contains
statistical
information.

snapshots

of

V$UNDOSTAT

The following example shows the results of a query on the V$UNDOSTAT view.
SQL>SELECT TO_CHAR(BEGIN_TIME, 'MM/DD/YYYY HH24:MI:SS')
BEGIN_TIME, TO_CHAR(END_TIME, 'MM/DD/YYYY HH24:MI:SS')
END_TIME,
UNDOTSN, UNDOBLKS, TXNCOUNT, MAXCONCURRENCY AS "MAXCON"
FROM v$UNDOSTAT WHERE rownum <= 144;

Enabling ARCHIVELOG Mode


Lets start by checking the current archive mode.
SQL> SELECT LOG_MODE FROM SYS.V$DATABASE;

ORACLE DBA | CASE STUDIES 38

LOG_MODE
-----------NOARCHIVELOG
In INIT.ora file add the following parameter
############################
# Archive Log Destinations -benr(10/15/04)
############################
log_archive_dest_1='location=/u02/oradata/cuddle/archive'
log_archive_start=TRUE
Note that we're not actually required to specify the location of the log destination, but
if you don't it'll end up in strange places (in my test it went to $ORACLE_HOME/dbs
making a mess). You can specify as many as 10 diffrent archive log destinations by
using the paramters log_archive_dest_1 through log_archive_dest_10. Remember, if
you run out of space in your archive log destination the database will shut down!
Now we can startup the database in mount mode and put it in archivelog mode.
SQL> startup mount
ORACLE instance started.
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
There are several system views that can provide us with information regarding
archives, such as:
V$DATABASE
Identifies whether the database is in ARCHIVELOG or NOARCHIVELOG
mode and whether MANUAL (archiving mode) has been specified.
V$ARCHIVED_LOG
Displays historical archived log information from the control file. If you use a
recovery catalog, the RC_ARCHIVED_LOG view contains similar information.
V$ARCHIVE_DEST
Describes the current instance, all archive destinations, and the current value,
mode, and status of these destinations.
V$ARCHIVE_PROCESSES
Displays information about the state of the various archive processes for an
instance.
V$BACKUP_REDOLOG
Contains information about any backups of archived logs. If you use a
recovery catalog, the RC_BACKUP_REDOLOG contains similar information.
V$LOG
Displays all redo log groups for the database and indicates which need to be
archived.

ORACLE DBA | CASE STUDIES 39

V$LOG_HISTORY
Contains log history information such as which logs have been archived and
the SCN range for each archived log.
Using these tables we can verify that we are infact in ARCHIVELOG mode:
SQL> select log_mode from v$database;
LOG_MODE
-----------ARCHIVELOG
SQL> select DEST_NAME,STATUS,DESTINATION from V$ARCHIVE_DEST;

Creating Control Files


Creating Initial Control Files
The following is an example of a CONTROL_FILES initialization parameter:
CONTROL_FILES = (/u01/oracle/prod/control01.ctl,
/u02/oracle/prod/control02.ctl,
/u03/oracle/prod/control03.ctl)
Creating Additional Copies, Renaming, and Relocating Control Files
To add a multiplexed copy of the current control file or to rename a control file:
Shut down the database.
SQL>Shutdown immediate
Copy an existing control file to a new location, using operating system
commands.
cp oldpath newpath
Edit the CONTROL_FILES parameter in the database initialization parameter
file to add the new control file name, or to change the existing control
filename.
Restart the database.
SQL>startup pfile=<path of pfile>

ORACLE DBA | CASE STUDIES 40

The CREATE CONTROLFILE Statement (It needed only you want to recreate a
control file)
CREATE CONTROLFILE
SET DATABASE <db name>
LOGFILE GROUP 1 ('/u01/oracle/<db name>/redo01_01.log',
'/u01/oracle/<db name>/redo01_02.log'),
GROUP 2 ('/u01/oracle/<db name>/redo02_01.log',
'/u01/oracle/<db name>/redo02_02.log'),
GROUP 3 ('/u01/oracle/<db name>/redo03_01.log',
'/u01/oracle/<db name>/redo03_02.log')
RESETLOGS
DATAFILE '/u01/oracle/<db name>/system01.dbf' SIZE 3M,
'/u01/oracle/<db name>/rbs01.dbs' SIZE 5M,
'/u01/oracle/<db name>/users01.dbs' SIZE 5M,
'/u01/oracle/prod/temp01.dbs' SIZE 5M
MAXLOGFILES 50
MAXLOGMEMBERS 3
MAXLOGHISTORY 400
MAXDATAFILES 200
MAXINSTANCES 6
ARCHIVELOG;

Dropping Control Files


Shut down the database.
SQL>Shutdown immediate
Edit the CONTROL_FILES parameter in the database initialization parameter
file to delete the old control file name.
Restart the database.
SQL>startup pfile=<path of pfile>
Note:
This operation does not physically delete the unwanted control file from the disk. Use
operating system commands to delete the unnecessary file after you have dropped
the control file from the database.
Displaying Control File Information
The following views display information about control files:

ORACLE DBA | CASE STUDIES 41

View

Description

V$DATABASE

Displays database information from the


control file

V$CONTROLFILE

Lists the names of control files

V$CONTROLFILE_RECORD_SECTION Displays information about control file


record sections
V$PARAMETER

Displays the names of control files as


specified
in
the
CONTROL_FILES
initialization parameter

Creating Redo Log Groups and Members


Creating Redo Log Groups
SQL>ALTER DATABASE
ADD LOGFILE ('/oracle/dbs/log1c.rdo',
'/oracle/dbs/log2c.rdo') SIZE 500K;
SQL>ALTER DATABASE
ADD LOGFILE GROUP 10 ('/oracle/dbs/log1c.rdo',
/oracle/dbs/log2c.rdo')
SIZE 500K;
Creating Redo Log Members
SQL>ALTER DATABASE ADD LOGFILE MEMBER '/oracle/dbs/log2b.rdo'
TO GROUP 2;
SQL>ALTER DATABASE ADD LOGFILE MEMBER '/oracle/dbs/log2c.rdo'
TO ('/oracle/dbs/log2a.rdo', '/oracle/dbs/log2b.rdo');
Note:
Fully specify the filenames of new log members to indicate where the operating
system files should be created. Otherwise, the files will be created in either the
default or current directory of the database server, depending upon your operating
system. You may also note that the status of the new log member is shown as
INVALID. This is normal and it will change to active (blank) when it is first used.

ORACLE DBA | CASE STUDIES 42

Relocating and Renaming Redo Log Members


Shut down the database.
SQL>SHUTDOWN Immediate
Copy the redo log files to the new location.
Note:
You can execute an operating system command to copy a file (or perform other
operating system commands) without exiting SQL*Plus by using the HOST
command. Some operating systems allow you to use a character in place of the
word HOST. For example, you can use an exclamation point (!) in UNIX.
The following example uses operating system commands (UNIX) to move the redo
log members to a new location:
mv /diska/logs/log1a.rdo /diskc/logs/log1c.rdo
mv /diska/logs/log2a.rdo /diskc/logs/log2c.rdo
Startup the database, mount, but do not open it.
SQL>CONNECT / as SYSDBA
SQL>STARTUP MOUNT
Rename the redo log members.
SQL>ALTER DATABASE
RENAME FILE '/diska/logs/log1a.rdo', '/diska/logs/log2a.rdo TO
'/diskc/logs/log1c.rdo', '/diskc/logs/log2c.rdo';
Open the database
SQL>ALTER DATABASE OPEN;
Dropping Log Groups
Make sure a redo log group is archived (if archiving is enabled) before dropping it. To
see whether this has happened, use the V$LOG view.
SQL>SELECT GROUP#, ARCHIVED, STATUS FROM V$LOG;
Drop a redo log group
SQL>ALTER DATABASE DROP LOGFILE GROUP 3;
Dropping Redo Log Members

ORACLE DBA | CASE STUDIES 43

SQL>ALTER DATABASE DROP LOGFILE MEMBER


'/oracle/dbs/log3c.rdo';
Forcing Log Switches
SQL>ALTER SYSTEM SWITCH LOGFILE;
Clearing a Redo Log File
SQl>ALTER DATABASE CLEAR LOGFILE GROUP 3;
Viewing Redo Log Information
The following views provide information on redo logs.
View

Description

V$LOG

Displays the redo log file information from the control file

V$LOGFILE

Identifies redo log groups and members and member status

V$LOG_HISTORY

Contains log history information

Managing Oracle Users


Creating Users
SQl>CREATE USER <UserName>
IDENTIFIED BY <Password>
DEFAULT TABLESPACE data_ts
QUOTA 100M ON test_ts
QUOTA 500K ON data_ts
TEMPORARY TABLESPACE temp_ts
PROFILE clerk;
SQL>GRANT create session TO jward;
A newly created user cannot connect to the database until granted the CREATE
SESSION system privilege.
Note:
As administrator, you should create your own roles and assign only those privileges
that are needed. For example, many users formerly granted the CONNECT privilege

ORACLE DBA | CASE STUDIES 44

did not need the additional privileges CONNECT used to provide. Instead, only
CREATE SESSION was actually needed, and in fact that is the only privilege
CONNECT presently retains.
Specifying a Name
Within each database, a user name must be unique with respect to other user
names and roles. A user and role cannot have the same name. Furthermore, each
user has an associated schema. Within a schema, each schema object must have a
unique name.
Assigning a Default Tablespace
Each user should have a default tablespace. When a user creates a schema object
and specifies no tablespace to contain it, Oracle Database stores the object in the
default user tablespace.
Assigning Tablespace Quotas
By default, a user has no quota on any tablespace in the database. If the user has
the privilege to create a schema object, then you must assign a quota to allow the
user to create objects. Minimally, assign users a quota for the default tablespace,
and additional quotas for other tablespaces in which they can create objects.
Assigning a Temporary Tablespace
Each user also should be assigned a temporary tablespace. When a user executes a
SQL statement that requires a temporary segment, Oracle stores the segment in the
user's temporary tablespace. These temporary segments are created by the system
when doing sorts or joins and are owned by SYS, which has resource privileges in all
tablespaces.
Note:
If your SYSTEM tablespace is locally managed, then users must be assigned a
specific default (locally managed) temporary tablespace. They may not be allowed to
default to using the SYSTEM tablespace because temporary objects cannot be
placed in permanent locally managed tablespaces.
Specifying a Profile
You also specify a profile when you create a user. A profile is a set of limits on
database resources and password access to the database. If no profile is specified,
then the user is assigned a default profile.

ORACLE DBA | CASE STUDIES 45

Setting Default Roles


You cannot set default roles for a user in the CREATE USER statement. When you
first create a user, the default role setting for the user is ALL, which causes all roles
subsequently granted to the user to be default roles. Use the ALTER USER
statement to change the default roles for the user.
Altering Users
You can alter user security settings with the ALTER USER statement. Changing user
security settings affects the future user sessions, not current sessions.
The following statement alters the security settings for the user, avyrros:
SQL>ALTER USER avyrros
IDENTIFIED EXTERNALLY
DEFAULT TABLESPACE data_ts
TEMPORARY TABLESPACE temp_ts
QUOTA 100M ON data_ts
QUOTA 0 ON test_ts
PROFILE clerk;
Dropping Users
SQl>DROP USER jones CASCADE;
User and Profile Information in Data Dictionary Views
The following data dictionary views contain information about database users and
profiles:
View

Description

DBA_USERS

Describes all users of the database

ALL_USERS

Lists users visible to the current user, but does not


describe them

USER_USERS

Describes only the current user

DBA_TS_QUOTAS

Describes tablespace quotas for users

USER_TS_QUOTAS
USER_PASSWORD_LIMITS Describes the password profile parameters that are
assigned to the user

ORACLE DBA | CASE STUDIES 46

View

Description

USER_RESOURCE_LIMITS Displays the resource limits for the current user


DBA_PROFILES

Displays all profiles and their limits

RESOURCE_COST

Lists the cost for each resource

V$SESSION

Lists session information for each current session,


includes user name

V$SESSTAT

Lists user session statistics

V$STATNAME

Displays decoded statistic names for the statistics


shown in the V$SESSTAT view

PROXY_USERS

Describes users who can assume the identity of other


users

Listing All Users and Associated Information


SQl>SELECT USERNAME, PROFILE, ACCOUNT_STATUS FROM DBA_USERS;
Listing All Tablespace Quotas
SQl>SELECT * FROM DBA_TS_QUOTAS;
Listing All Profiles and Assigned Limits
SQl>SELECT * FROM DBA_PROFILES
ORDER BY PROFILE;
Viewing Memory Use for Each User Session
SQL>SELECT USERNAME, VALUE || 'bytes' "Current UGA memory"
FROM V$SESSION sess, V$SESSTAT stat, V$STATNAME name
WHERE sess.SID = stat.SID
AND stat.STATISTIC# = name.STATISTIC#
AND name.NAME = 'session uga memory';
Dropping Profiles
SQL>DROP PROFILE clerk CASCADE;

ORACLE DBA | CASE STUDIES 47

Managing User Roles


Creating a Role
SQL>CREATE ROLE clerk IDENTIFIED BY bicentennial;
Later, you can set or change the authorization method for a role using the ALTER
ROLE statement.
SQL>ALTER ROLE clerk IDENTIFIED EXTERNALLY;
To alter the authorization method for a role, you must have the ALTER ANY ROLE
system privilege or have been granted the role with the ADMIN OPTION.
Dropping Roles
SQl>DROP ROLE clerk;
User Privileges and Roles
Granting System Privileges and Roles
SQL>GRANT CREATE SESSION, accts_pay TO jward;
Granting the ADMIN OPTION
SQL>GRANT new_dba TO michael WITH ADMIN OPTION;
Creating a New User with the GRANT Statement
SQL>GRANT CONNECT TO ssmith IDENTIFIED BY p1q2r3;
Granting Object Privileges
SQL>GRANT SELECT, INSERT, DELETE ON emp TO jfee, tsmith;
To grant all object privileges on the salary view to the user jfee, use the ALL keyword
as shown in the following example:
SQL>GRANT ALL ON salary TO jfee;
Note:
A grantee cannot regrant access to objects unless the original grant included the
GRANT OPTION. Thus in the example just given, jfee cannot use the GRANT
statement to grant object privileges to anyone else.
Granting Object Privileges on Behalf of the Object Owner
SQL>GRANT SELECT ON hr.employees TO blake WITH GRANT OPTION;

ORACLE DBA | CASE STUDIES 48

If you examine the DBA_TAB_PRIVS view, then you will see that hr is shown as the
grantor of the privilege:
SQL> SELECT GRANTEE, OWNER, GRANTOR, PRIVILEGE, GRANTABLE
FROM DBA_TAB_PRIVS WHERE TABLE_NAME = 'EMPLOYEES' and OWNER =
'HR';
SQL>GRANT SELECT ON hr.employees TO clark;
Granting Privileges on Columns
SQL>GRANT INSERT (acct_no) ON accounts TO scott;
SQL>GRANT INSERT(ename, job) ON emp TO jfee, tsmith;
Revoking User Privileges and Roles
Revoking System Privileges and Roles
SQL>REVOKE CREATE TABLE, accts_rec FROM tsmith;
Revoking Object Privileges
SQL>REVOKE SELECT, insert ON emp FROM jfee, tsmith;
SQL>REVOKE ALL ON dept FROM human_resources;
Revoking Object Privileges on Behalf of the Object Owner
SQL>REVOKE

SELECT ON hr.employees FROM clark;

Revoking Column-Selective Object Privileges


SQL>REVOKE UPDATE ON dept FROM human_resources;
SQL>GRANT UPDATE (dname) ON dept TO human_resources;
Revoking the REFERENCES Object Privilege
SQL>REVOKE REFERENCES ON dept FROM jward CASCADE CONSTRAINTS;
The SET ROLE Statement
SQL>SET ROLE clerk IDENTIFIED BY bicentennial;
You can disable all roles with the following statement:
SQL>SET ROLE NONE;
Specifying Default Roles

ORACLE DBA | CASE STUDIES 49

SQL>ALTER USER jane DEFAULT ROLE payclerk, pettycash;


Restricting the Number of Roles that a User Can Enable
A user can enable as many roles as specified by the initialization parameter
MAX_ENABLED_ROLES.
Viewing Privilege and Role Information
To access information about grants of privileges and roles, you can query the
following data dictionary views:
View

Description

DBA_COL_PRIVS

DBA view describes all column object grants in the


database. ALL view describes all column object grants
for which the current user or PUBLIC is the object
owner, grantor, or grantee. USER view describes
column object grants for which the current user is the
object owner, grantor, or grantee.

ALL_COL_PRIVS
USER_COL_PRIVS

ALL_COL_PRIVS_MADE

ALL view lists column object grants for which the current
user is object owner or grantor. USER view describes
USER_COL_PRIVS_MADE column object grants for which the current user is the
grantor.
ALL_COL_PRIVS_RECD

ALL view describes column object grants for which the


current user or PUBLIC is the grantee. USER view
USER_COL_PRIVS_RECD describes column object grants for which the current
user is the grantee.
DBA_TAB_PRIVS
ALL_TAB_PRIVS
USER_TAB_PRIVS

DBA view lists all grants on all objects in the database.


ALL view lists the grants on objects where the user or
PUBLIC is the grantee. USER view lists grants on all
objects where the current user is the grantee.

ALL_TAB_PRIVS_MADE

ALL view lists the all object grants made by the current
user or made on the objects owned by the current user.
USER_TAB_PRIVS_MADE USER view lists grants on all objects owned by the
current user.
ALL_TAB_PRIVS_RECD

ALL view lists object grants for which the user or


PUBLIC is the grantee. USER view lists object grants
USER_TAB_PRIVS_RECD for which the current user is the grantee.

ORACLE DBA | CASE STUDIES 50

View

Description

DBA_ROLES

This view lists all roles that exist in the database.

DBA_ROLE_PRIVS

DBA view lists roles granted to users and roles. USER


view lists roles granted to the current user.

USER_ROLE_PRIVS
DBA_SYS_PRIVS
USER_SYS_PRIVS

DBA view lists system privileges granted to users and


roles. USER view lists system privileges granted to the
current user.

ROLE_ROLE_PRIVS

This view describes roles granted to other roles.


Information is provided only about roles to which the
user has access.

ROLE_SYS_PRIVS

This view contains information about system privileges


granted to roles. Information is provided only about
roles to which the user has access.

ROLE_TAB_PRIVS

This view contains information about object privileges


granted to roles. Information is provided only about
roles to which the user has access.

SESSION_PRIVS

This view lists the privileges that are currently enabled


for the user.

SESSION_ROLES

This view lists the roles that are currently enabled to the
user.

Listing All System Privilege Grants


SQL>SELECT * FROM DBA_SYS_PRIVS;
Listing All Role Grants
SQL>SELECT * FROM DBA_ROLE_PRIVS;
Listing Object Privileges Granted to a User
SQL>SELECT TABLE_NAME, PRIVILEGE, GRANTABLE FROM DBA_TAB_PRIVS
WHERE GRANTEE = 'JWARD';
SQL>SELECT GRANTEE, TABLE_NAME, COLUMN_NAME, PRIVILEGE

ORACLE DBA | CASE STUDIES 51

FROM DBA_COL_PRIVS;
Listing the Current Privilege Domain of Your Session
SQL>SELECT * FROM SESSION_ROLES;
SQL>SELECT * FROM SESSION_PRIVS;
Listing Roles of the Database
SQL>SELECT * FROM DBA_ROLES;
Listing Information About the Privilege Domains of Roles
SQL>SELECT GRANTED_ROLE, ADMIN_OPTION
FROM ROLE_ROLE_PRIVS
WHERE ROLE = 'SYSTEM_ADMIN';
SQL>SELECT * FROM ROLE_SYS_PRIVS WHERE ROLE =
'SECURITY_ADMIN';
SQL>SELECT TABLE_NAME, PRIVILEGE FROM ROLE_TAB_PRIVS
WHERE ROLE = 'SECURITY_ADMIN';

Cold Backup
V$datafile Lists all the data files used in the database
SQL>select name from v$datafile;
Backup the control file and perform a trace of the control file using
SQL>alter database backup controlfile to
'/u10/backup/control.ctl';
SQL>alter database backup controlfile to trace;
Init.ora and config.ora Located under $ORACLE_HOME/dbs directory
Shut down the database
SQL>shutdown
Perform a backup
$cp /u01/oracle/users01.dbf /u10/backup
You can perform the backup of the Init.ora and config.ora files as follows:
$cp $ORACLE_HOME/dbs/init.ora /u10/backup

ORACLE DBA | CASE STUDIES 52

$cp $ORACLE_HOME/dbs/config.ora /u10/backup


Start the database
After the backup is complete, you can start the database as follows:
$su oracle
$sqlplus "/ as sysdba"
SQL> startup

Hot Backup
Put the tablespace in the Backup mode and copy the data files.
SQL>alter tablespace USERS begin backup;
SQL>select file_name from dba_data_files
where tablespace_name='USERS';
$cp /u01/oracle/users01.dbf /u10/backup
$cp /u01/oracle/users02.dbf /u10/backup
The following command ends the backup process and puts the tablespace back in
normal mode.
SQL>alter tablespace USERS end backup;
You have to repeat this process for all tablespaces. You can get the list of
tablespaces by using the following SQL statement:
SQL>select tablespace_name from dba_tablespaces;
Back up the control and Init.ora files.
SQL>alter database backup controlfile to
'/u10/backup/control.ctl';
You can copy the Init.ora file to a backup location using
$cp $ORACLE_HOME/dbs/initorcl.ora /u10/backup
Stop archiving.
SQL>alter system switch logfile;
SQL>alter system archive log stop;
The first command switches redo log file and the second command stops the
archiver process.

ORACLE DBA | CASE STUDIES 53

Back up the archive files.


The archive file location is defined by the LOG_ARCHIVE_DEST_n parameter in the
Init.ora file.
SQL>select min(sequence#) from v$log
where archived='NO';
Restart the archive process.
SQL>alter system archive log start;

Export :
Keyword
USERID
BUFFER
FILE
COMPRESS
GRANTS
INDEXES
ROWS
CONSTRAINTS
CONSISTENT
LOG
STATISTICS
DIRECT
FEEDBACK
HELP
MLS
FULL
OWNER
TABLES
RECORDLENGTH
INCTYPE
RECORD
PARFILE

Description (Default)
username/password
size of data buffer
output file (EXPDAT.DMP)
import into one extent (Y)
export grants (Y)
export indexes(Y)
export data rows (Y)
export table constraints (Y)
cross-table consistency (N)
log file of screen output (None)
analyze objects (ESTIMATE)
Bypass the SQLcommand processing layer (N) (new in
Oracle8)
Show a process meter (a dot) every X rows exported (0
Xvalue)
Shows help listing
MLS_LABEL_FORMAT Used with secure Oracle; we
won't cover these.
export entire file (N)
list of owner usernames
list of table names
length of IO record
incremental export type
track incr. export (Y)
parameter file name

ORACLE DBA | CASE STUDIES 54

IMPORT
Keyword
USERID
BUFFER
FILE
SHOW
IGNORE
RECORDLENGTH
GRANTS
INDEXES
ROWS
LOG
INDEXFILE
FULL
FROMUSER
TOUSER
TABLES
FEEDBACK
INCTYPE
COMMIT
PARFILE
DESTROY
CHARSET

Description (Default)
username/password
size of data buffer
Output file (EXPDAT.DMP)
just list file contents (N)
Ignore create errors (N)
length of IOrecord
Import grants (Y)
Import indexes (Y)
Import data rows (Y)
log file of screen output
write table/index info to specified file
Import entire file (N)
list of owner usernames
list of usernames
list of table names
Provide dot status graph (0)
incremental import type
commit array insert (N)
parameter file name
overwrite tablespace data (N)
char. set of export file (NLS_LANG)

EXPORT DP
Example: expdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp
Keyword

Description(Default)

ATTACH

Attach to existing job, e.g. ATTACH [=job


name].

CONTENT

(ALL), DATA_ONLY, and


METADATA_ONLY

DIRECTORY

Directory object to be used for dumpfiles


and logfiles

DUMPFILE

List of destination dump files


(expdat.dmp),

ORACLE DBA | CASE STUDIES 55

ESTIMATE

(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.

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

ORACLE DBA | CASE STUDIES 56

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

(COMPATIBLE), LATEST, or any valid


database version.

IMPORT DP
Example: impdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp
Keyword

Description(Default)

ATTACH

Attach to existing job, e.g. ATTACH [=job


name].

CONTENT

(ALL), DATA_ONLY, and


METADATA_ONLY

DIRECTORY

Directory object to be used for dumpfiles


and logfiles

DUMPFILE

List of destination dump files


(expdat.dmp),

ESTIMATE

(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

ORACLE DBA | CASE STUDIES 57

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.

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

(COMPATIBLE), LATEST, or any valid


database version.

REMAP_DATAFILE

Redefine datafile references in all DDL


statements

REMAP_SCHEMA

Objects from one schema are loaded


into another schema.

ORACLE DBA | CASE STUDIES 58

REMAP_TABLESPACE

Tablespace object are remapped to


another tablespace.

REUSE_DATAFILES

Tablespace will be initialized if it already


exists (N).

SKIP_UNUSABLE_INDEXES

Skip indexes that were set to the Index


Unusable state.

SQLFILE

Write all the SQL DDL to a specified file.

STREAMS_CONFIGURATION

Enable the loading of Streams metadata.

TABLE_EXISTS_ACTION

Valid keywords: (SKIP), APPEND,


REPLACE and TRUNCATE.

TRANSFORM

Metadata transform to apply (Y/N) to


specific objects.

TRANSPORT_DATAFILES

List of datafiles to be imported by


transportable mode.

USER MANAGED RECOVERY


About User-Managed Restore Operations
To restore a file is to replace it with a backup file. Typically, you restore a file when a
media failure or user error has damaged or deleted the original file. The following
files are candidates for restore operations:

Datafiles and control files


Archived redo logs

Server parameter file

In each case, the loss of a primary file and the restore of a backup has the following
implications for media recovery.
If you lose . . .
One
or
datafiles

Then . . .

more You must restore them from a backup and perform media
recovery. Recovery is required whenever the checkpoint SCN in
the datafile header does not match the checkpoint SCN for the
datafile that is recorded in the control file.

All copies of the You must restore a backup control file and then open the

ORACLE DBA | CASE STUDIES 59

If you lose . . .

Then . . .

current control file database with the RESETLOGS option.


If you do not have a backup, then you can attempt to re-create
the control file. If possible, use the script included in the ALTER
DATABASE BACKUP CONTROLFILE TO TRACE output.
Additional work may be required to match the control file
structure with the current database structure.
One copy of a Copy one of the intact multiplexed control files into the location of
multiplexed control the damaged or missing control file and open the database. If
file
you cannot copy the control file to its original location, then edit
the initialization parameter file to reflect a new location or remove
the damaged control file. Then, open the database.
One
or
more You must restore backups of these archived logs for recovery to
archived
logs proceed. You can restore either to the default or nondefault
required for media location. If you do not have backups, then you must performing
recovery
incomplete recovery up to an SCN before the first missing redo
log and open RESETLOGS.
The
server If you have a backup of the server parameter file, then restore it.
parameter file
Alternatively, if you have a backup of the client-side initialization
parameter file, then you can restore a backup of this file, start the
instance, and then re-create the server parameter file.

Note:
Restore and recovery of Oracle-managed files is no different from restore and
recovery of user-named files.
Determining Which Datafiles Require Recovery
Use the following SQL*Plus commands to format the output of the query:
COL DF# FORMAT 999
COL DF_NAME FORMAT A35
COL TBSP_NAME FORMAT A7
COL STATUS FORMAT A7
COL ERROR FORMAT A10
COL CHANGE# FORMAT 99999999
SELECT r.FILE# AS df#, d.NAME AS df_name, t.NAME AS tbsp_name,
d.STATUS, r.ERROR, r.CHANGE#, r.TIME
FROM V$RECOVER_FILE r, V$DATAFILE d, V$TABLESPACE t

ORACLE DBA | CASE STUDIES 60

WHERE t.TS# = d.TS#


AND d.FILE# = r.FILE#
;
The ERROR column identifies the problem for each file requiring recovery.
Restoring Datafiles and Archived Redo Logs
SQL>ALTER TABLESPACE users OFFLINE IMMEDIATE;
Copy backups of the damaged datafiles to their default location using
operating system commands.
% cp /disk2/backup/users01.dbf
$ORACLE_HOME/oradata/trgt/users01.dbf
Recover the affected tablespace.
SQL>RECOVER TABLESPACE users
Bring the recovered tablespace online.
SQL>ALTER TABLESPACE users ONLINE;
Restoring Archived Redo Logs with Operating System Utilities
The database locates the correct log automatically when required during
media recovery.
% cp /disk2/arch/* $ORACLE_HOME/oradata/trgt/arch
If sufficient space is not available at the location indicated by the archiving
destination initialization parameter, restore some or all of the required archived redo
log files to an alternate location. Specify the location before or during media recovery
using the LOGSOURCE parameter of the SET statement in SQL*Plus or the
RECOVER ... FROM parameter of the ALTER DATABASE statement in SQL. For
example, enter:
SET LOGSOURCE /tmp
# set location using SET statement
DATABASE RECOVER FROM '/tmp'; # set location in RECOVER
statement
After an archived log is applied, and after making sure that a copy of each archived
log group still exists in offline storage, delete the restored copy of the archived redo
log file to free disk space. For example:
% rm /tmp/*.dbf

ORACLE DBA | CASE STUDIES 61

Restoring Control Files


Restore Lost Copy of a Multiplexed Control File
Use the following procedures to recover a database if a permanent media failure has
damaged one or more control files of a database and at least one control file has not
been damaged by the media failure.
Copying a Multiplexed Control File to a Default Location
shut down
SQL>SHUTDOWN
Use an intact multiplexed copy of the database's current control file to copy over the
damaged control files. For example, to replace bad_cf.f with good_cf.f, you might
enter:
% cp /oracle/good_cf.f /oracle/dbs/bad_cf.f
Start a new instance and mount and open the database.
SQL>STARTUP
Copying a Multiplexed Control File to a Nondefault Location
shut down
SQL>SHUTDOWN
% cp $ORACLE_HOME/oradata/trgt/control01.dbf
/new_disk/control01.dbf
Edit the parameter file of the database so that the CONTROL_FILES parameter
CONTROL_FILES='/oracle/oradata/trgt/control01.dbf','/bad_disk/
control02.dbf'
Then, you can edit it as follows:
CONTROL_FILES='/oracle/oradata/trgt/control01.dbf','/new_disk/
control02.dbf'
Start a new instance and mount and open the database.
SQL>STARTUP
Restore Control File from Backup After Loss of All Current Control Files

ORACLE DBA | CASE STUDIES 62

Status of
Status of
Online Logs Datafiles

Restore Procedure

Available

Current

If the online logs contain redo necessary for recovery,


then restore a backup control file and apply the logs
during recovery. You must specify the filename of the
online logs containing the changes in order to open the
database. After recovery, open RESETLOGS.

Unavailable

Current

If the online logs contain redo necessary for recovery,


then re-create the control file. Because the online redo
logs are inaccessible, open RESETLOGS (when the
online logs are accessible it is not necessary to OPEN
RESETLOGS after recovery with a created control file).

Available

Backup

Restore a backup control file, perform complete recovery,


and then open RESETLOGS.

Unavailable

Backup

Restore a backup control file, perform incomplete


recovery, and then open RESETLOGS.

Restoring a Backup Control File to the Default Location


shut down
SQL>SHUTDOWN
% cp /backup/control01.dbf
ORACLE_HOME/oradata/trgt/control01.dbf
% cp /backup/control02.dbf
ORACLE_HOME/oradata/trgt/control02.dbf
Start a new instance and mount the database.
SQL>STARTUP MOUNT
SQL>RECOVER DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL
Apply the prompted archived logs. If you then receive another message saying that
the required archived log is missing, it probably means that a necessary redo record
is located in the online redo logs. This situation can occur when unarchived changes
were located in the online logs when the instance crashed.
For example, assume that you see the following:

ORACLE DBA | CASE STUDIES 63

ORA-00279: change 55636 generated at 11/08/2002 16:59:47


needed for thread 1
ORA-00289: suggestion : /oracle/work/arc_dest/arcr_1_111.arc
ORA-00280: change 55636 for thread 1 is in sequence #111
Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
You can specify the name of an online redo log and press Enter (you may have to try
this a few times until you find the correct log):
ORACLE_HOME/oradata/redo01.dbf
Log applied.
Media recovery complete.
If the online logs are inaccessible, then you can cancel recovery without applying
them. If all datafiles are current, and if redo in the online logs is required for recovery,
then you cannot open the database without applying the online logsOpen the
database with the RESETLOGS option after finishing recovery:
SQL>ALTER DATABASE OPEN RESETLOGS;
Restoring a Backup Control File to a Nondefault Location
Edit all locations specified in the CONTROL_FILES initialization parameter to reflect
the new control file locations. For example, if the control file locations listed in the
server parameter file are as follows, and both locations are inaccessible:
CONTROL_FILES='/oracle/oradata/trgt/control01.dbf',
'/oracle/oradata/trgt/control01.dbf'
Then, you can edit the initialization parameter file as follows:
CONTROL_FILES='/good_disk/control01.dbf','/good_disk/control02
.dbf'
Create New Control File After Losing All Current and Backup Control Files

If you . . .

Then . . .

Executed ALTER DATABASE


Use the CREATE CONTROLFILE statement
BACKUP CONTROLFILE TO
from the trace output as-is.
TRACE NORESETLOGS after you
made the last structural change to
the database, and if you have saved
the SQL command trace output
Performed your most recent
execution of ALTER DATABASE

Edit the output of ALTER DATABASE BACKUP


CONTROLFILE TO TRACE to reflect the

ORACLE DBA | CASE STUDIES 64

If you . . .

Then . . .

BACKUP CONTROLFILE TO
TRACE before you made a
structural change to the database

change. For example, if you recently added a


datafile to the database, then add this datafile
to the DATAFILE clause of the CREATE
CONTROLFILE statement.

Backed up the control file with the


ALTER DATABASE BACKUP
CONTROLFILE TO filename
statement (not the TO TRACE
option)

Use the control file copy to obtain SQL output.


Create a temporary database instance, mount
the backup control file, and then run ALTER
DATABASE BACKUP CONTROLFILE TO
TRACE NORESETLOGS. If the control file
copy predated a recent structural change, then
edit the trace to reflect the change.

Do not have a control file backup in


either TO TRACE format or TO
filename format

Execute the CREATE CONTROLFILE


statement manually (refer to Oracle Database
SQL Reference).

Note:
If your character set is not the default US7ASCII, then you must specify the
character set as an argument to the CREATE CONTROLFILE statement. The
database character set is written to the alert log at startup. The character set
information is also recorded in the BACKUP CONTROLFILE TO TRACE output.
To create a new control file:
Start the database in NOMOUNT mode. For example, enter:
SQL>STARTUP NOMOUNT
Create the control file with the CREATE CONTROLFILE statement, specifying the
NORESETLOGS option. The following example assumes that the character set is
the default US7ASCII:
CREATE CONTROLFILE REUSE DATABASE SALES NORESETLOGS ARCHIVELOG
MAXLOGFILES 32
MAXLOGMEMBERS 2
MAXDATAFILES 32
MAXINSTANCES 16
MAXLOGHISTORY 1600
LOGFILE
GROUP 1 (
'/diska/prod/sales/db/log1t1.dbf',

ORACLE DBA | CASE STUDIES 65

'/diskb/prod/sales/db/log1t2.dbf'
) SIZE 100K
GROUP 2 (
'/diska/prod/sales/db/log2t1.dbf',
'/diskb/prod/sales/db/log2t2.dbf'
) SIZE 100K,
DATAFILE
'/diska/prod/sales/db/database1.dbf',
'/diskb/prod/sales/db/filea.dbf';
After creating the control file, the instance mounts the database.
Recover the database as normal (without specifying the USING BACKUP
CONTROLFILE clause):
SQL>RECOVER DATABASE
Open the database after recovery completes (RESETLOGS option not required):
SQL>ALTER DATABASE OPEN;
Immediately back up the control file. The following SQL statement backs up a
database's control file to /backup/control01.dbf:
SQL>ALTER DATABASE BACKUP CONTROLFILE TO
'/backup/control01.dbf' REUSE;

Automating Recovery with SET AUTORECOVERY


Run the SET AUTORECOVERY ON command to enable on automatic recovery.
To automate the recovery using SET AUTORECOVERY:
Restore a backup of the offline datafiles. This example restores an inconsistent
backup of all datafiles with an operating system utility:
% cp /backup/datafiles/*.dbf $ORACLE_HOME/oradata/trgt/
Ensure the database is mounted. For example, if the database is shut down, run:
SQL>STARTUP MOUNT
Enable automatic recovery.
SET AUTORECOVERY ON
Recover the desired datafiles.

ORACLE DBA | CASE STUDIES 66

SQL>RECOVER DATABASE
Open the database.
SQL>ALTER DATABASE OPEN;
Recovering When Archived Logs Are in the Default Location
Recovering when the archived logs are in their default location is the simplest case.
As a log is needed, the database suggests the filename. If you are running
nonautomatic media recovery with SQL*Plus, then the output is displayed in this
format:
ORA-00279: Change #### generated at DD/MM/YY HH:MM:SS needed
for thread#
ORA-00289: Suggestion : logfile
ORA-00280: Change #### for thread # is in sequence #
Specify log: [<RET> for suggested | AUTO | FROM logsource |
CANCEL ]
For example, SQL*Plus displays output similar to the following:
ORA-00279: change 53577 generated at 11/26/02 19:20:58 needed
for thread 1
ORA-00289: suggestion :
/oracle/oradata/trgt/arch/arcr_1_802.arc
ORA-00280: change 53577 for thread 1 is in sequence #802
Specify log: [<RET> for suggested | AUTO | FROM logsource |
CANCEL ]
Similar messages are returned when you use an ALTER DATABASE ... RECOVER
statement. However, no prompt is displayed.
The database constructs suggested archived log filenames by concatenating the
current values of the initialization parameters LOG_ARCHIVE_DEST_n (where n is
the
highest
value
among
all
enabled,
local
destinations)
and
LOG_ARCHIVE_FORMAT and using log history data from the control file. The
following are possible settings:
LOG_ARCHIVE_DEST_1 = 'LOCATION = /oracle/oradata/trgt/arch/'
LOG_ARCHIVE_FORMAT = arcr_%t_%s.arc
SQL>SELECT NAME FROM V$ARCHIVED_LOG;
Thus, if all the required archived log files are mounted at the
LOG_ARCHIVE_DEST_1 destination, and if the value for LOG_ARCHIVE_FORMAT
is never altered, then the database can suggest and apply log files to complete
media recovery automatically.

ORACLE DBA | CASE STUDIES 67

Resetting the Archived Log Destination


You can edit the initialization parameter file or issue ALTER SYSTEM statements to
change the default location of the archived redo logs.
To change the default archived log location before recovery:
Use an operating system utility to restore the archived logs to a nondefault location.
For example, enter:
% cp /backup/arch/* /tmp/
Change the value for the archive log parameter to the nondefault location. You can
issue ALTER SYSTEM statements while the instance is started, or edit the
initialization parameter file and then start the database instance. For example, while
the instance is shut down edit the parameter file as follows:
LOG_ARCHIVE_DEST_1 = 'LOCATION=/tmp/'
LOG_ARCHIVE_FORMAT = arcr_%t_%s.arc
Using SQL*Plus, start a new instance by specifying the edited initialization
parameter file, and then mount the database. For example, enter:
SQL>STARTUP MOUNT
Begin media recovery as usual. For example, enter:
SQL>RECOVER DATABASE
Responding to Unsuccessful Application of Redo Logs

Error

Possible Cause

Solution

ORA-27037:
Entered
wrong Reenter correct filename.
unable to obtain filename.
Restore backup archived redo log.
file status
Log is missing.
ORA-27047:
The log may have If you can locate an uncorrupted or
unable to read been partially written complete log copy, then apply the intact
the header block or become corrupted. copy and continue recovery.
of file
If no copy of the log exists and you know
the time of the last valid redo entry, then
you use incomplete recovery. Restore
backups and restart recovery.

ORACLE DBA | CASE STUDIES 68

Restoring Backups of the Damaged or Missing Files


In this stage, you restore all necessary backups.
To restore the necessary files:
Use the following guidelines when determining where to restore datafile backups.
If . . .

Then . . .

The hardware problem is


Restore the datafiles to their default locations and
repaired and you can restore the begin media recovery.
datafiles to their default locations
The hardware problem persists Restore the datafiles to an alternative storage
and you cannot restore datafiles device. Indicate the new location of these files in
to their original locations
the control file with ALTER DATABASE RENAME
FILE.

Losing Datafiles in ARCHIVELOG Mode


If either a permanent or temporary media failure affects the datafiles of a database
operating in ARCHIVELOG mode, then the following scenarios can occur.
Damaged Datafiles

Database Status Solution

Datafiles
in
the Database
SYSTEM tablespace or down.
datafiles with active
undo segments.
Datafiles not in the
SYSTEM tablespace or
datafiles that do not
contain active rollback
or undo segments.

shuts If the hardware problem is temporary,


then fix it and restart the database.
Usually, crash recovery recovers lost
transactions.

Affected datafiles
are taken offline,
but the database
stays open.

If the unaffected portions of the


database must remain available, then
do not shut down the database. Take
tablespaces
containing
problem
datafiles offline using the temporary
option, then recover them.

Recovering Through an Added Datafile with a Backup Control File:


If database recovery with a backup control file rolls forward through a CREATE
TABLESPACE or an ALTER TABLESPACE ADD DATAFILE operation, then the

ORACLE DBA | CASE STUDIES 69

database stops recovery when applying the redo record for the added files and lets
you confirm the filenames.
For example, suppose the following sequence of events occurs:
You back up the database.You create a new tablespace containing two datafiles:
/oracle/oradata/trgt/test01.dbf and /oracle/oradata/trgt/test02.dbf.
You later restore a backup control file and perform media recovery through the
CREATE TABLESPACE operation.
You may see the following error when applying the CREATE TABLESPACE redo
data:
ORA-00283:
ORA-01244:
recovery
ORA-01110:
ORA-01110:

recovery session canceled due to errors


unnamed datafile(s) added to control file by media
data file 11: '/oracle/oradata/trgt/test02.dbf'
data file 10: '/oracle/oradata/trgt/test01.dbf'

To recover through an ADD DATAFILE operation, use the following procedure:


View the files added by selecting from V$DATAFILE. For example:
SQL>SELECT FILE#,NAME
FROM V$DATAFILE;
If multiple unnamed files exist, then determine which unnamed file corresponds to
which datafile by using one of these methods:
Open the alert_SID.log, which contains messages about the original file location for
each unnamed file.
Derive the original file location of each unnamed file from the error message and
V$DATAFILE: each unnamed file corresponds to the file in the error message with
the same file number.
Issue the ALTER DATABASE RENAME FILE statement to rename the datafiles. For
example, enter:
SQL>ALTER DATABASE RENAME FILE '/db/UNNAMED00001' TO
'/oracle/oradata/trgt/test01.dbf';
SQL>ALTER DATABASE RENAME FILE '/db/UNNAMED00002' TO
'/oracle/oradata/trgt/test02.dbf';
Continue recovery by issuing the previous recovery statement. For example:
RECOVER AUTOMATIC DATABASE USING BACKUP CONTROLFILE UNTIL
CANCEL

ORACLE DBA | CASE STUDIES 70

Re-Creating Datafiles When Backups Are Unavailable


If a datafile is damaged and no backup of the file is available, then you can still
recover the datafile if:
All archived log files written after the creation of the original datafile are
available

The control file contains the name of the damaged file (that is, the control file
is current, or is a backup taken after the damaged datafile was added to the
database)

Note:
You cannot re-create any of the datafiles for the SYSTEM tablespace by using the
CREATE DATAFILE clause of the ALTER DATABASE statement because the
necessary redo is not available.
To re-create a datafile for recovery:
Create a new, empty datafile to replace a damaged datafile that has no
corresponding
backup.
For
example,
assume
that
the
datafile
?/oradata/trgt/users01.dbf has been damaged, and no backup is available. The
following statement re-creates the original datafile (same size) on disk2:
SQL>ALTER DATABASE CREATE DATAFILE
'?/oradata/trgt/users01.dbf' AS /disk2/users01.dbf';
This statement creates an empty file that is the same size as the lost file. The
database looks at information in the control file and the data dictionary to obtain size
information. The old datafile is renamed as the new datafile.
Perform media recovery on the empty datafile. For example, enter:
SQL>RECOVER DATAFILE '/disk2/users01.dbf'
All archived logs written after the original datafile was created must be applied to the
new, empty version of the lost datafile during recovery.
Recovering Through RESETLOGS with Created Control File: Scenario
You can recover backups through an OPEN RESETLOGS so long as:

You have a current, backup, or created control file that knows about the prior
incarnations
You have all available archived redo logs

If you need to re-create the control file, the trace file generated by ALTER
DATABASE BACKUP CONTROLFILE TO TRACE will contain the necessary
commands
to
re-construct
the
complete
incarnation
history.
The

ORACLE DBA | CASE STUDIES 71

V$DATABASE_INCARNATION view displays the RESETLOGS history known to the


control file, while the V$LOG_HISTORY view displays the archived log history.
It is possible for the incarnation history to be incomplete in the in re-created control
file. For example, archived logs necessary for recovery may be missing. In this case,
it is possible to create incarnation records explicitly with the ALTER DATABASE
REGISTER LOGFILE statement.
In the following example, you register four logs that are necessary for recovery but
are not recorded in the re-created control file, and then recover the database:
ALTER DATABASE REGISTER LOGFILE
'?/oradata/trgt/arch/arcr_1_1_42343523.arc';
ALTER DATABASE REGISTER LOGFILE
'?/oradata/trgt/arch/arcr_1_1_34546466.arc';
ALTER DATABASE REGISTER LOGFILE
'?/oradata/trgt/arch/arcr_1_1_23435466.arc';
ALTER DATABASE REGISTER LOGFILE
'?/oradata/trgt/arch/arcr_1_1_12343533.arc';
RECOVER AUTOMATIC DATABASE;
Media Recovery of Transportable Tablespaces
To recover a transportable tablespace, use the following procedure:
If the database is open, then take the transported tablespace offline. For example, if
you want to recover the users tablespace, then issue:
SQL>ALTER TABLESPACE users OFFLINE IMMEDIATE;
Restore a backup of the transported datafiles with an operating system utility. The
backup can be the initial version of the transported datafiles or any backup taken
after the tablespace is transported. For example, enter:
% cp /backup/users.dbf $ORACLE_HOME/oradata/trgt/users01.dbf
Recover the tablespace as normal. For example, enter:
SQL>RECOVER TABLESPACE users
Recovering After the Loss of Online Redo Log Files
If a media failure has affected the online redo logs of a database, then the
appropriate
Status

Description

UNUSED

The online redo log has never been written to.

ORACLE DBA | CASE STUDIES 72

Status

Description

CURRENT

The online redo log is active, that is, needed for instance
recovery, and it is the log to which the database is currently
writing. The redo log can be open or closed.

ACTIVE

The online redo log is active, that is, needed for instance
recovery, but is not the log to which the database is
currently writing.It may be in use for block recovery, and
may or may not be archived.

CLEARING

The log is being re-created as an empty log after an ALTER


DATABASE CLEAR LOGFILE statement. After the log is
cleared, then the status changes to UNUSED.

CLEARING_CURRENT The current log is being cleared of a closed thread. The log
can stay in this status if there is some failure in the switch
such as an I/O error writing the new log header.
INACTIVE

The log is no longer needed for instance recovery. It may be


in use for media recovery, and may or may not be archived.

Recovering After Losing a Member of a Multiplexed Online Redo Log Group


If the online redo log of a database is multiplexed, and if at least one member of
each online redo log group is not affected by the media failure, then the database
continues functioning as normal, but error messages are written to the log writer
trace file and the alert_SID.log of the database.
Solve the problem by taking one of the following actions:

If the hardware problem is temporary, then correct it. The log writer process
accesses the previously unavailable online redo log files as if the problem
never existed.
If the hardware problem is permanent, then drop the damaged member and
add a new member by using the following procedure.
Note:
The newly added member provides no redundancy until the log group is
reused.
Locate the filename of the damaged member in V$LOGFILE. The status is
INVALID if the file is inaccessible:

ORACLE DBA | CASE STUDIES 73

SQL>SELECT GROUP#, STATUS, MEMBER


FROM V$LOGFILE
WHERE STATUS='INVALID';
Drop the damaged member. For example, to drop member redo01.log from
group 2, issue:
SQL>ALTER DATABASE DROP LOGFILE MEMBER
'/oracle/oradata/trgt/redo02.log';
Add a new member to the group. For example, to add redo02.log to group 2,
issue:
SQL>ALTER DATABASE ADD LOGFILE MEMBER
'/oracle/oradata/trgt/redo02b.log'
TO GROUP 2;
If the file you want to add already exists, then it must be the same size as the
other group members, and you must specify REUSE. For example:
SQL>ALTER DATABASE ADD LOGFILE MEMBER
'/oracle/oradata/trgt/redo02b.log'
REUSE TO GROUP 2;
Recovering After the Loss of All Members of an Online Redo Log Group
If a media failure damages all members of an online redo log group, then different
scenarios can occur depending on the type of online redo log group affected by the
failure and the archiving mode of the database.
If the damaged log group is active, then it is needed for crash recovery; otherwise, it
is not.
If
the
group
is . . .
Then . . .

And you should . . .

Inactive

It is not needed for Clear the archived or unarchived group.


crash recovery

Active

It is needed
crash recovery

Current

It is the log that the Attempt to clear the log; if impossible, then you must

for Attempt to issue a checkpoint and clear the log; if


impossible, then you must restore a backup and
perform incomplete recovery up to the most recent
available redo log.

ORACLE DBA | CASE STUDIES 74

If
the
group
is . . .
Then . . .

And you should . . .

database
is restore a backup and perform incomplete recovery
currently writing to up to the most recent available redo log.

Your first task is to determine whether the damaged group is active or inactive.
Locate the filename of the lost redo log in V$LOGFILE and then look for the
group number corresponding to it. For example, enter:
SQL>SELECT GROUP#, STATUS, MEMBER FROM V$LOGFILE;
Determine which groups are active. For example, enter:
SQL>SELECT GROUP#, MEMBERS, STATUS, ARCHIVED
FROM V$LOG;
Losing an Inactive Online Redo Log Group
If all members of an online redo log group with INACTIVE status are damaged, then
the procedure depends on whether you can fix the media problem that damaged the
inactive redo log group.
If the failure
is . . .
Then . . .
Temporary

Fix the problem. LGWR can reuse the redo log group when required.

Permanent

The damaged inactive online redo log group eventually halts normal
database operation. Reinitialize the damaged group manually by
issuing the ALTER DATABASE CLEAR LOGFILE statement as
described in this section.

Clearing Inactive, Archived Redo


You can clear an inactive redo log group when the database is open or closed. The
procedure depends on whether the damaged group has been archived.

ORACLE DBA | CASE STUDIES 75

To clear an inactive, online redo log group that has been archived, use the following
procedure:
If the database is shut down, then start a new instance and mount the
database:
SQL>STARTUP MOUNT
Reinitialize the damaged log group. For example, to clear redo log group 2,
issue the following statement:
SQL>ALTER DATABASE CLEAR LOGFILE GROUP 2;

RMAN
Data Dictionary Objects
DBA_HIST_INSTANCE_RECOVERY
GV_$RECOVERY_STATUS
DBA_RECOVERABLE_SCRIPT
V_$FLASH_RECOVERY_AREA_USAGE
DBA_RECOVERABLE_SCRIPT_BLOCKS
V_$INSTANCE_RECOVERY
DBA_RECOVERABLE_SCRIPT_ERRORS
V_$RECOVER_FILE
DBA_RECOVERABLE_SCRIPT_PARAMS
V_$RECOVERY_FILE_DEST
GV_$INSTANCE_RECOVERY
V_$RECOVERY_FILE_STATUS
GV_$RECOVER_FILE
V_$RECOVERY_LOG
GV_$RECOVERY_FILE_STATUS
V_$RECOVERY_PROGRESS
GV_$RECOVERY_LOG
V_$RECOVERY_STATUS
GV_$RECOVERY_PROGRESS
Format Directives
Format

Description

%a

Current database activation id

%A

Zero-filled activation ID

%c

The copy number of the backup piece within a set of duplexed backup
pieces.bMaximum value is 256

%d

Database name

%D

Current day of the month from the Gregorian calendar in format DD

%e

Archived log sequence number

%f

Absolute file number

ORACLE DBA | CASE STUDIES 76

%F

Combines the DBID, day, month, year, and sequence into a unique and
repeatable generated name

%h

Archived redo log thread number

%I

DBID

%M

Month in the Gregorian calendar in the format MM

%n

Database name, padded on the right with x characters to a total length of


eight characters

%N

Tablespace name. Only valid when backing up datafiles as image copies.

%p

Piece number within the backup set. This value starts at 1 for each backup
set and is incremented by 1 for each backup piece created. If a PROXY is
specified, the %p variable must be included in the FORMAT string either
explicitly or implicitly within %U.

%r

Resetlogs ID

%s

Backup set number. This number is a counter in the control file that is
incremented for each backup set. The counter value starts at 1 and is unique
for the lifetime of the control file. If you restore a backup control file, then
duplicate values can result. CREATE CONTROLFILE initializes the counter
at 1.

%S

Zero-filled sequence number

%t

Backup set time stamp, a 4-byte value derived as the number of seconds
elapsed since a fixed reference time. The combination of %s and %t can be
used to form a unique name for the backup set.

%T

Year, month, and day in the Gregorian calendar in the format: YYYYMMDD

%u

An 8-character name constituted by compressed representations of the


backup set or image copy number and the time the backup set or image
copy was created

%U

A system-generated unique filename (default). %U is different for image


copies and backup pieces. For a backup piece, %U is a shorthand for %u_
%p_%c and guarantees uniqueness in generated backup filenames. For an
image copy of a datafile, %U means the following:
data-D-%d_id-%I_TS-%N_FNO-%f_%u
For an image copy of an archived redo log, %U means the following:
arch-D_%d-id-%I_S-%e_T-%h_A-%a_%u
For an image copy of a control file, %U means the following:
cf-D_%d-id-%I_%u

%Y

Year in this format: YYYY

%%

Percent (%) character. For example, %%Y translates to the string %Y

Create RMAN User

ORACLE DBA | CASE STUDIES 77

$ sqlplus / as sysdba
SQL> CREATE TABLESPACE cat_tbs;
SQL> CREATE USER repoomega
IDENTIFIED BY oracle1
DEFAULT TABLESPACE cat_tbs
TEMPORARY TABLESPACE temp
QUOTA UNLIMITED ON cat_tbs;
RMAN> GRANT create session TO repoomega
RMAN> GRANT recovery_catalog_owner TO repoomega;
RMAN> GRANT execute ON dbms_stats TO repoomega; -- for demos
-- in the operating system shell
$ rman target / catalog repoomega/oracle1@repos
RMAN>SHOW ALL;
Configuring the parameters for RMAN
For Example:
RMAN>
RMAN>
copy;
RMAN>
RMAN>

configure default device type to disk;


configure device type disk parallelism 2 backup type to
configure retention policy to recovery window of 7 days;
configure backup optimization on;

Allocating a Single Backup Channel


RMAN>RUN{
ALLOCATECHANNELd1DEVICETYPEDISK
FORMAT'/u01/backups/%U';
BACKUPDATABASEPLUSARCHIVELOG;
RELEASECHANNEL;
}
Spread the backup across several disk drives. Allocate one DEVICE TYPE DISK
channel for ach disk drive and specify the format string so that the filenames are on
different disks

RUN {
ALLOCATE CHANNEL d1 DEVICE TYPE DISK FORMAT '/u01/backups/
%U';
ALLOCATE CHANNEL d2 DEVICE TYPE DISK FORMAT '/u02/backups/
%U';
BACKUP DATABASE PLUS ARCHIVELOG;

ORACLE DBA | CASE STUDIES 78

RELEASE CHANNEL;
}
Allocate Maintenance Channel
RMAN> ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE DISK;
BACKUP
Back up a database, tablespace, datafile (current or copy), control file (current or
copy), SPFILE, archived log, or backup set.
BACKUP <BackupOperand> CHANNEL '<channel_id>' CHECK LOGICAL
COPIES <integer>
CUMULATIVE DEVICE TYPE <deviceSpecifier> DISKRATIO <integer>
DURATION
<FileNameConversionSpecification> FILERPERSET <integer> FORCE
< AUXILIARY FORMAT <formatSpec, NEW> | FORMAT <formatSpec>
<forRecoveryOfSpec>
FULL
<keep option>
MAXSETSIZE <sizeSpec>
<notBackedUpSpec>
NO CHECKSUM NO EXCLUDE POOL <integer> PROXY [ONLY] REUSE
SECTION SIZE <sizeSpec> <skipSpec>
TAG '<tag_name>' VALIDATE
BACKUP AS BACKUPSET
RMAN>BACKUP AS BACKUPSET DEVICE TYPE <device_identifier>
COPIES <integer>
DATABASE FORMAT '<location_and_format>' ....
RMAN>BACKUP AS BACKUPSET (DATAFILE 3, 4, 5, 6, 7) (DATAFILE 8,
9);
RMAN>BACKUP AS BACKUPSET DATAFILE 3, 4, 5, 6, 7, 8, 9;

BACKUP AS COMPRESSED BACKUPSET


RMAN>BACKUP AS COMPRESSED BACKUPSET DEVICE TYPE DISK COPIES 2
DATABASE FORMAT '/u01/db_%U', '/u02/db_%U';
BACKUP AS COPY
RUN {
ALLOCATE CHANNEL dev1 DEVICE TYPE DISK FORMAT '/u01/%U';
ALLOCATE CHANNEL dev2 DEVICE TYPE DISK FORMAT '/u02/%U';
BACKUP AS COPY TABLESPACE system, tools, users, undotbs;

ORACLE DBA | CASE STUDIES 79

BACKUP AS COPY CURRENT CONTROLFILE;


}
BACKUP CURRENT
RUN {
BACKUP CURRENT CONTROLFILE TO DESTINATION '/u01/backups';
}
BACKUP DATABASE
RUN {
ALLOCATE CHANNEL d1 DEVICE TYPE DISK;
BACKUP DATABASE;
}
BACKUP DATAFILE
RUN {
ALLOCATE CHANNEL d1 DEVICE TYPE DISK;
BACKUP DATAFILE 1 FORMAT '/u01/backups/%U', '/u02/backups/
%U';
BACKUP DATAFILE 6 TO '/u01/backups', '/u02/backups';
}
BACKUP DURATION
Backup will stop if it is not completed in the specified duration
RMAN> BACKUP DURATION 3:30 DATABASE;
BACKUP ... FOR RECOVER OF ...

RMAN > BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG
'incr_upd' DATABASE FORMAT '/oradata/rman/161932/inc_%d_%T_%t_
%s_%p';
RUN {
RECOVER COPY OF DATABASE WITH TAG 'incr_update' UNTIL TIME
'SYSDATE-7';
BACKUP INCREMENTAL LEVEL 1 FOR RECOVER OF COPY WITH TAG
'incr_upd'
DATABASE;
}
BACKUP INCREMENTAL
RMAN>BACKUP INCREMENTAL LEVEL 0 DATABASE;
RMAN>BACKUP INCREMENTAL LEVEL 1 CUMULATIVE DATABASE;
RMAN>BACKUP INCREMENTAL LEVEL 1 DIFFERENTIAL TABLESPACE users;

ORACLE DBA | CASE STUDIES 80

RMAN>BACKUP INCREMENTAL LEVEL 1 CUMULATIVE SKIP INACCESSIBLE


DATABASE;
Complete Closed Database Recovery. System tablespace is missing
In this case complete recovery is performed, only the system tablespace is missing,
so the database can be opened without reseting the redologs.
1. rman target /
2. startup mount;
3. restore database;
4. recover database;
5. alter database open;
Complete Open Database Recovery. Non system tablespace is missing,
database is up
1. rman target /
2. sql 'alter tablespace <tablespace_name> offline immediate';
3. restore datafile 3;
4. recover datafile 3;
5. sql 'alter tablespace <tablespace_name> online';
Complete Open Database Recovery (when the database is initially closed).
Non system tablespace is missing
A user datafile is reported missing when tryin to startup the database. The datafile
can be turned offline and the database started up. Restore and
recovery are performed using Rman. After recovery is performed the datafile can
be turned online again.
1. sqlplus /nolog
2. connect / as sysdba
3. startup mount
4. alter database datafile '<datafile_name>' offline;
5. alter database open;

ORACLE DBA | CASE STUDIES 81

6. exit;
7. rman target /
8. restore datafile '<datafile_name>';
9. recover datafile '<datafile_name>';
10. sql 'alter tablespace <tablespace_name> online';
Recovery of a Datafile that has no backups (database is up).
If a non system datafile that was not backed up since the last backup is missing,
recovery can be performed if all archived logs since the creation of the missing
datafile exist. Since the database is up you can check the tablespace name and put
it offline. The option offline immediate is used to avoid that the update of the datafile
header.
Pre requisites: All relevant archived logs.
1. sqlplus '/ as sysdba'
2. alter tablespace <tablespace_name> offline immediate;
3. alter database create datafile '/user/oradata/u01/dbtst/newdata01.dbf;
4. exit
5. rman target /
6. recover tablespace <tablespace_name>;
7. sql 'alter tablespace <tablespace_name> online';
If the create datafile command needs to be executed to place the datafile on a
location different than the original use:
alter database create datafile '/user/oradata/u01/dbtst/newdata01.dbf' as
'/user/oradata/u02/dbtst/newdata01.dbf'
Restore and Recovery of a Datafile to a different location. Database is up.
If a non system datafile is missing and its original location not available, restore
can be made to a different location and recovery performed. Pre requisites: All
relevant archived logs, complete cold or hot backup.
1. Use OS commands to restore the missing or corrupted datafile to the new
location, ie:

ORACLE DBA | CASE STUDIES 82

cp -p /user/backup/uman/user01.dbf /user/oradata/u02/dbtst/user01.dbf
2. alter tablespace <tablespace_name> offline immediate;
3. alter tablespace <tablespace_name> rename datafile
'/user/oradata/u01/dbtst/user01.dbf' to '/user/oradata/u02/dbtst/user01.dbf';
4. rman target /
5. recover tablespace <tablespace_name>;
6. sql 'alter tablespace <tablespace_name> online';
Control File Recovery
Always multiplex your controlfiles. If you loose only one controlfile you can replace it
with the one you have in place, and startup the Database. If both controlfiles are
missing, the database will crash. Pre requisites: A backup of your controlfile and all
relevant archived logs. When using Rman alway set configuration parameter
autobackup of controlfile to ON. You will need the dbid to restore the controlfile,
get it from the name of the backed up controlfile. It is the number following the 'c-' at
the start of the name.
1. rman target /
2. set dbid <dbid#>
3. startup nomount;
4. restore controlfile from autobackup;
5. alter database mount;
6. recover database;
7. alter database open resetlogs;
8. make a new complete backup, as the database is open in a new incarnation and
previous archived log are not relevant.
Incomplete Recovery, Until Time/Sequence/Cancel
Incomplete recovery may be necessaire when the database crash and needs to be
recovered, and in the recovery process you find that an archived log is missing. In
this case recovery can only be made until the sequence before the one that is
missing.
Another scenario for incomplete recovery occurs when an important object was

ORACLE DBA | CASE STUDIES 83

dropped or incorrect data was committed on it. In this case recovery needs to be
performed until before the object was dropped. Pre requisites: A full closed or open
database backup and archived logs, the time or sequence that the 'until' recovery
needs to be performed.
1. If the database is open, shutdown it to perform full restore.
2. rman target \
3. startup mount;
4. restore database;
5. recover database until sequence 8 thread 1; # you must pass the thread, if a
single instance will always be 1.
6. alter database open resetlogs;
7. make a new complete backup, as the database is open in a new incarnation and
previous archived log are not relevant.
Alternatively you may use instead of until sequence, until time, ie: '2004-1228:01:01:10'.

Das könnte Ihnen auch gefallen