You are on page 1of 67

http://www.jlcomp.demon.co.uk/faq/ind_faq.

html
How can you find out how many users are currently logged into
the database? How can you find their operating system id?
Answer: There are several ways. One is to look at the v$session or
v$process views. Another way is to check the current_logins
parameter in the v$sysstat view. Another if you are on UNIX is to do a
"ps -ef|grep oracle|wc -l? command, but this only works against a
single instance installation.
How can you tell if a tablespace has excessive fragmentation?
If a select against the dba_free_space table shows that the count of a tablespaces extents
is greater than the count of its data files, then it is fragmented.

Q: When to create control files ?


A. Create controlfiles when
1. You have lost all your control files.
2. When you want to rename a database name (db_name)
Q. How to create control files.
You need a create controlfile script for recreating control files.
SQL*Plus: Release 9.2.0.2.0 - Production on Fri Feb 28 17:04:00 2003
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Enter user-name: sys as sysdba
Enter password:
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.2.1 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.2.0 - Production
SQL> alter database backup controlfile to trace;
Database altered.
SQL>

This will create a trace file in the udump directory.


Im my case it was
E:\oracle\admin\ORCL\udump\orcl_ora_2052.trc
Edit the file to point the path of the datafiles and redologfiles.
CREATE CONTROLFILE REUSE DATABASE "ORCL" RESETLOGS
ARCHIVELOG
MAXLOGFILES 5
MAXLOGMEMBERS 3
MAXDATAFILES 14
MAXINSTANCES 1
MAXLOGHISTORY 226
LOGFILE
GROUP 1 'E:\ORACLE\ORADATA\ORCL\REDO01.LOG' SIZE 100M,
GROUP 2 'E:\ORACLE\ORADATA\ORCL\REDO02.LOG' SIZE 100M,
GROUP 3 'E:\ORACLE\ORADATA\ORCL\REDO03.LOG' SIZE 100M
DATAFILE
'E:\ORACLE\ORADATA\ORCL\SYSTEM01.DBF',
'E:\ORACLE\ORADATA\ORCL\UNDOTBS01.DBF',
'E:\ORACLE\ORADATA\ORCL\EXAMPLE01.DBF',
'E:\ORACLE\ORADATA\ORCL\INDX01.DBF',
'E:\ORACLE\ORADATA\ORCL\TOOLS01.DBF',
'E:\ORACLE\ORADATA\ORCL\USERS01.DBF',
'E:\ORACLE\ORADATA\ORCL\OEM_REPOSITORY.DBF',
'E:\ORACLE\ORADATA\ORCL\CWMLITE01.DBF',
'E:\ORACLE\ORADATA\ORCL\DRSYS01.DBF',
'E:\ORACLE\ORADATA\ORCL\ODM01.DBF',
'E:\ORACLE\ORADATA\ORCL\XDB01.DBF',
'E:\ORACLE\ORADATA\ORCL\USERS02.DBF',
'E:\ORACLE\ORADATA\ORCL\USERS03.DBF',
'E:\ORACLE\ORADATA\ORCL\USERS04.DBF'
CHARACTER SET WE8MSWIN1252
;
ALTER DATABASE OPEN RESETLOGS;
and rename it to ctl.sql
Then startup the database in nomount mode and run the ctl.sql file as sys as sysdba user

SQL*Plus: Release 9.2.0.2.0 - Production on Fri Feb 28 17:25:14 2003


Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Enter user-name: sys as sysdba
Enter password:
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 80812648 bytes
Fixed Size 453224 bytes
Variable Size 54525952 bytes
Database Buffers 25165824 bytes
Redo Buffers 667648 bytes
SQL> @E:\oracle\admin\ORCL\udump\ctl.sql
Control file created.
Database altered.
SQL> select status from v$instance;
STATUS
-----------------------------------OPEN
SQL> select name from v$controlfile;
NAME
-------------------------------------------------------E:\ORACLE\ORADATA\ORCL\CONTROL01.CTL
E:\ORACLE\ORADATA\ORCL\CONTROL02.CTL
E:\ORACLE\ORADATA\ORCL\CONTROL03.CTL

To rename the database change reuse to set in the create control file script as shown
below
CREATE CONTROLFILE SET DATABASE "ORCL" RESETLOGS ARCHIVELOG
MAXLOGFILES 5
MAXLOGMEMBERS 3

MAXDATAFILES 14
MAXINSTANCES 1
MAXLOGHISTORY 226
LOGFILE
GROUP 1 'E:\ORACLE\ORADATA\ORCL\REDO01.LOG' SIZE 100M,
GROUP 2 'E:\ORACLE\ORADATA\ORCL\REDO02.LOG' SIZE 100M,
GROUP 3 'E:\ORACLE\ORADATA\ORCL\REDO03.LOG' SIZE 100M
DATAFILE
'E:\ORACLE\ORADATA\ORCL\SYSTEM01.DBF',
'E:\ORACLE\ORADATA\ORCL\UNDOTBS01.DBF',
'E:\ORACLE\ORADATA\ORCL\EXAMPLE01.DBF',
'E:\ORACLE\ORADATA\ORCL\INDX01.DBF',
'E:\ORACLE\ORADATA\ORCL\TOOLS01.DBF',
'E:\ORACLE\ORADATA\ORCL\USERS01.DBF',
'E:\ORACLE\ORADATA\ORCL\OEM_REPOSITORY.DBF',
'E:\ORACLE\ORADATA\ORCL\CWMLITE01.DBF',
'E:\ORACLE\ORADATA\ORCL\DRSYS01.DBF',
'E:\ORACLE\ORADATA\ORCL\ODM01.DBF',
'E:\ORACLE\ORADATA\ORCL\XDB01.DBF',
'E:\ORACLE\ORADATA\ORCL\USERS02.DBF',
'E:\ORACLE\ORADATA\ORCL\USERS03.DBF',
'E:\ORACLE\ORADATA\ORCL\USERS04.DBF'
CHARACTER SET WE8MSWIN1252
;
ALTER DATABASE OPEN RESETLOGS;

What is tablespace fragmentation and should I worry about it ?


In an ideal world every Oracle object would be sized such that it fit into one and only one extent
and would never grow beyond that initial extent. But the world is not ideal and the eventual size for
many objects is often not known. As such objects are expected and allowed to take extents. If the
tablespace is built without specifying default storage parameters and the objects are built using the
Oracle default tablespace parameters as many canned (purchased) software packages are then the
objects start with only 5 Oracle data blocks and ask for each new extent after the first additional
extent to be 50% larger than the prior allocation. If some of these objects are work tables/indexes
that get truncated, the objects are later dropped, or the objects are relocated to different
tablespaces for some reason, then the tablespace ends up with multiple free extents of varying sizes
existing scattered throughout the tablespace. Many of these free extents can be sizes that no object
in the tablespace has as its calculated next extent size so that they are unusable for all practical
purposes. Eventually a request is made for an extent allocation that cannot be found in one free
contiguous extent even though the total free space in the tablespace may be significantly larger
than the requested size. This is a free space fragmentation problem, and normally the term
tablespace fragmentation is referring to free space fragmentation within a tablespace.
How much of a problem free space fragmentation is depends on your tablespace extent
management policies. From the first paragraph it should be obvious that sizing the object extents

based on reasonable expectations or history and setting the pctincrease for all objects to zero from
the default of 50% would help reduce fragmentation, as would the use of the same next extent size
for all objects in a tablespace. With Oracle 8.1 the rdbms introduced new tablespace creation
parameters that enforce uniform extent sizing within a tablespace overriding any object storage
clause specified at creation to pretty much enforce the ideas I just described.

Ver. 8.1
create tablespace x
datafile '/dev/vx/rdsk/filename' size 1024M
extent management local uniform size 512K;

There are several variations of the options available to manage a tablespace. This FAQ is not going
to attempt to cover any of these features in depth, but basically you can now create a tablespace to
be dictionary managed, which is the pre-8.1 method or to be locally managed. Locally managed
tablespaces contain a bitmap used to control extent allocation within the tablespace and eliminate
the need to acquire the single database wide ST lock to allocate or deallocate extents within the
locally managed tablespace. Locally managed tablespaces should be declared to use uniform extent
management; otherwise, they default to type autoallocate, which forbids users from specifying
extent size information. With uniform extents if a user submits an object create with an initial size
of 750K in the tablespace above the Oracle rdbms would allocate two 512k extents to hold the
object overriding the storage request but would otherwise accept the statement.
One of the nice effects of using uniform extents is that it makes predicting growth and determining
when another file needs to be added to a tablespace fairly straightforward. Just divide the total
free space in the tablespace by the extent size and round down to the integer value as there are no
unusable free extents cluttering up the tablespace. There will usually be some wasted space at the
end of the file as the extent size will rarely divide perfectly into the file size minus the header block
minus the bitmap remaining useable size, but barring using a very small uniform extent size with
humongous objects requiring the creation of multiple bitmaps this will be less than one extent.
When measured over time you can get a pretty good idea of extents per time period worth of usage.
If you are working with a pre-8.1 version of Oracle or have inherited a system upgraded from earlier
versions that use permanent tablespaces created using traditional dictionary managed space then
you can still manage by extents, but you will have to work to get the tablespace objects sized
appropriately.

Pre 8.1
Create tablespace x
Datafile '/dev/vx/rdsk/filename' size 1024M
Default storage (initial 512k next 512k pctincrease 0)

The second create statement appears to pretty much define the tablespace the same as the uniform
extent example, but if a user submits an object create with a storage clause initial extent request
of 750K then Oracle will give them the 750K request overriding the tablespace defaults. Starting
with version 7.3 Oracle provided the minimum extent clause, which required that every extent in
the tablespace be at least integer value in size or a multiple of this size. In a way this was the

forerunner of the new uniform extent option. This parameter should not be confused with the
minextents object storage clause parameter.
Here is SQL that works for version 7.3+ (due to inline view) to determine the number of next extent
allocations that can be taken within a tablespace based on the largest next extent allocation
request size for any object allocated to the tablespace:

COLUMN tablespace_name
COLUMN extents

FORMAT a20 heading 'Tablespace Name'

FORMAT 99999 heading 'Available|Extents'

select f.tablespace_name
,sum(floor(nvl(f.bytes,0)/(s.MEXT))) extents
from

sys.dba_free_space f
,( select tablespace_name, max(next_extent) as MEXT
from

sys.dba_segments

group by tablespace_name
)s
where

f.tablespace_name = s.tablespace_name(+)

group by f.tablespace_name
/

Available
Tablespace Name

Extents

==================== =========
LGDATA01

LGDATA02

LGIDX01

16

LGIDX02

32

..........

The packaged procedure


DBMS_SPACE_ADMIN.TABLESPACE_MIGRATE_TO_LOCAL can be used to
migrate an existing tablespace to being locally managed; however, there is no way to
automatically migrate the existing objects extents into a uniform extent size. A note on
Metalink advised that the Oracle release level should be 8.1.6.3 before using the routine
due to several small bugs (Ref: Oracle, Helen Schoone 23 Aug-01 18:37 Re : Locally
managed tablespace question). My personal opinion is that you should build new locally
managed tablespaces using uniform extents and migrate your objects over time if at all
possible rather than use the package. I believe this because there should not be an ST lock
contention problem on systems that have configured a true temporary tablespace to
handle sort requests, and this is how sort space should be allocated with 8.1.7+

Further reading: The Concepts manual has an introduction to tablespace management,


and the SQL manual documents the create tablespace command. The FAQ: How do I
find out who is currently using the space in the temporary tablespace ? has material
on the use of temporary vs. permanent tablespaces to support sort operations.
Reference also Oracle Metalink notes:
109630.1: How and Where Bitmaps are Allocated for Locally Managed
Tablespaces,
120061.1: Next Extent Size After Migrating Tablespace from Dictionary
to Locally Managed

How does one coalesce free space ? (for DBA)

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. With Oracle 7.3 one can
manually coalesce a tablespace using the ALTER TABLESPACE ... COALESCE;
command, until then use:
ALTER TABLESPACE <tablespace_name> COALESCE

SQL> alter session set events 'immediate trace name coalesce level ';
Where 'n' is the tablespace number you get from SELECT TS#, NAME FROM SYS.TS$;
You can get status information about this process by selecting from the
SYS.DBA_FREE_SPACE_COALESCED dictionary view.

How does one prevent tablespace fragmentation? (for DBA)


Tablespaces that record extent allocation in the dictionary, are called dictionary managed
tablespaces, and tablespaces that record extent allocation in the tablespace header, are
called locally managed tablespaces
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 reused in their entirety. PCTINCREASE of 0 or 100 gives you nice round extent sizes that

can easily be reused. E.g.. 100K, 100K, 200K, 400K, etc.


Use the same extent size for all the segments in a given tablespace. Locally Managed
tablespaces (available from 8i onwards) with uniform extent sizes virtually eliminates
any tablespace fragmentation. Note that the number of extents per segment does not
cause any performance issue anymore, unless they run into thousands and thousands
where additional I/O may be required to fetch the additional blocks where extent maps of
the segment are stored.
Where can one find the high water mark for a table? (for DBA)

There is no single system table, which contains the high water mark (HWM) for a table.
A table's HWM can be calculated using the results from the following SQL statements:
SELECT BLOCKS
FROM DBA_SEGMENTS
WHERE OWNER=UPPER(owner) AND SEGMENT_NAME = UPPER(table);
ANALYZE TABLE owner.table ESTIMATE STATISTICS;
SELECT EMPTY_BLOCKS
FROM DBA_TABLES
WHERE OWNER=UPPER(owner) AND SEGMENT_NAME = UPPER(table);
Thus, the tables' HWM = (query result 1) - (query result 2) - 1
NOTE: You can also use the DBMS_SPACE package and calculate the
HWM = TOTAL_BLOCKS - UNUSED_BLOCKS - 1.
E.G
selectBLOCKSfromdba_segments
whereowner='APPLSYS'ANDSEGMENT_NAME=
UPPER('fnd_concurrent_requests')
ANALYZETABLEAPPLSYS.FND_CONCURRENT_REQUESTSESTIMATESTATISTICS;
SELECTEMPTY_BLOCKS
FROMDBA_TABLES
WHEREOWNER=UPPER('APPLSYS')ANDTABLE_NAME=
UPPER('fnd_concurrent_requests')

How are extents allocated to a segment? (for DBA)

Starting with Oracle 9i, DBAs can now create locally managed tablespaces.
A Locally Managed TBS manages its own list of free extents in a bitmap block placed inside the
header of the first data file of the tablespace. Inside the bitmap block, each bit maps to a free
block in the tablespace. When creating a locally managed tablespace, you can specify the extent
allocation method to be used.
AUTOALLOCATE - means that the extent sizes are managed by Oracle.
Oracle will choose the optimal next size for the extents starting with 64KB. As the segments grow
and more extents are needed, Oracle will start allocating larger and larger sizes ranging from 1Mb
to eventually 64Mb extents. This might help conserve space but will lead to fragmentation. This is
usually recommended for small tables or in low managed systems.
UNIFORM - specifies that the extent allocation in the tablespace is in a fixed uniform size. The
extent size can be specified in M or K. The default size for UNIFORM extent allocation is 1M. Using
uniform extents usually minimizes fragmentation and leads to better overall performance.
SQL>CREATE TABLESPACE test_tablespcae DATAFILE '/emc/oradata/test_tablespace1.dbf'
SIZE 50M
EXTENT MANAGEMENT LOCAL AUTOALLOCATE;
SQL>CREATE TABLESPACE test_tablespcae DATAFILE '/emc/oradata/test_tablespace1.dbf'
SIZE 50M
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 512K;
I usually prefer to keep large production-grade tables in UNIFORM sized tablespaces and smaller
tables or tables in unmanaged environments in AUTOALLOCATE tablespaces.
Also note: if you specify, LOCAL, you cannot specify DEFAULT STORAGE, MINIMUM EXTENT or
TEMPORARY.
Advantages of Locally Managed Tablespaces:

o
o
o
o

Eliminates the need for recursive SQL operations against the data dictionary (UET$ and FET$
tables)
Reduce contention on data dictionary tables (single ST enqueue)
Locally managed tablespaces eliminate the need to periodically coalesce free space
(automatically tracks adjacent free space)

Changes to the extent bitmaps do not generate rollback information.

Can one rename a database user (schema)? (for DBA)

No, this is listed as Enhancement Request 158508. Workaround:


Do a user-level export of user A
create new user B
Import system/manager fromuser=A touser=B
Drop user A
What is the use of ANALYZE command ?

To perform one of these function on an index, table, or cluster:


- To collect statistics about object used by the optimizer and store them in the data dictionary.
- To delete statistics about the object used by object from the data dictionary.
- To validate the structure of the object.
- To identify migrated and chained rows of the table or cluster.
What is default tablespace ?
The Tablespace to contain schema objects created without specifying a tablespace name.

Import/Export
exp and imp are the executables that allow to make exports and imports of data objects (such as
tables). Therefore, logical backups can be made with exp. exp/imp allow to transfer the data
accross databases that reside on different hardware plattforms and/or on different Oracle versions.
If the data is exported on a system with a different Oracle version then on that on which it is
imported, imp must be the newer version. That means, if something needs to be exported from 10g
into 9i, it must be exported with 9i's exp. imp doesn't re-create an already existing table. It either
errors out or ignores the errors. In order to use exp and imp, the catexp.sql script must be run.
catexp.sql basically creates the exp_full_database and imp_full_database roles. It is found under
$ORACLE_HOME/rdbms/admin:
SQL> @?/rdbms/admin/catexp
catexp is called by catalog.sql.
Import export modes
exp/imp can be used in four modes:
Full Export
The EXP_FULL_DATABASE and IMP_FULL_DATABASE, respectively, are needed to perform a full
export. Use the full export parameter for a full export.
Tablespace
Use the tablespaces export parameter for a tablespace export.
User
This mode can be used to export and import all objects that belong to a user. Use the owner export
parameter and the from user import parameter for a user (owner) export-import.
Table

Specific tables (and partitions) can be exported/imported with table export mode. Use the tables
export parameter for a table export.
exp
Objects owned by SYS cannot be exported.
Prerequisites
One must have the create session privilege for being able to use exp. If objects of another user's
schema need to be exported, the EXP_FULL_DATABASE role is required.
direct
Used for a direct path export.
feedback=n
Prints a dot after each nth exported row.
flashback_scn
The exported data is consistent with the specified SCN.
flashback_time
The exported data is consistent with a SCN that approximately matches that of the specified time.
consistent
object_consistent
query
Restricts the exported rows by means of a where clause. The query parameter can only be used for
table export mode. For obvious reasons, it must be appliable to all exported tables.
parfile
Specifies a parfile.
NLS_LANG settings
As exp and imp are client utilities they use the NLS_LANG settings. See also nls_language.
imp
If the parameter touser is used and (?) the export was made with FULL=YES, the users must already
be created in the target database.
Parameters

show
This parameter only shows the contents of an export file; it does not perform an import.
fromuser
This parameter is used when an import in 'user export/import mode is made.
Using imp/exp accross different Oracle versions
If exp and imp are used to export data from an Oracle database with a different version than the
database in which is imported, then the following rules apply:
exp must be of the lower version
imp must match the target version.
Transportable tablespaces
The parfile
A parfile (=parameter file) contains a list of export parameters

What is import/export and why does one need it?


Submitted by admin on Sat, 2004-08-07 11:43.

Oracle's export (exp) and import (imp) utilities are used to perform logical database backup and
recovery. When exporting, database objects are dumped to a binary file which can then be imported
into another Oracle database.
These utilities can be used to move data between different machines, databases or schema.
However, as they use a proprietary binary file format, they can only be used between Oracle
databases. One cannot export data and expect to import it into a non-Oracle database.
Various parameters are available to control what objects are exported or imported. To get a list of
available parameters, run the exp or imp utilities with the help=yes parameter.
The export/import utilities are commonly used to perform the following tasks:

o
o
o
o
o
o
o

Backup and recovery (small databases only)


Move data between Oracle databases on different platforms (for example from Solaris to
Windows).
Reorganization of data/ Eliminate database fragmentation (export, drop and re-import
tables)
Upgrade databases from extremely old versions of Oracle (when in-place upgrades are not
supported by the Database Upgrade Assistant anymore)
Detect database corruption. Ensure that all the data can be read.
Transporting tablespaces between databases
Etc.

From Oracle 10g, users can choose between using the old imp/exp utilities, or the newly introduced
Data Pump utilities, called expdp and impdp. These new utilities introduce much needed
performance improvements, network based exports and imports, etc.
NOTE: It is generally advised not to use exports as the only means of backing-up a database. Physical
backup methods (for example when you use RMAN) are normally much quicker and supports point in
time based recovery (apply archivelogs after recovering a database). Also, exp/imp is not practical
for large database environments.

How does one use the import/export utilities?


Submitted by admin on Sat, 2004-08-07 11:43.

Look for the "imp" and "exp" executables in your $ORACLE_HOME/bin directory. One can run them
interactively, using command line parameters, or using parameter files. Look at the imp/exp
parameters before starting. These parameters can be listed by executing the following commands:
"exp help=yes" or "imp help=yes".
The following examples demonstrate how the imp/exp utilities can be used:

exp scott/tiger file=emp.dmp log=emp.log tables=emp rows=yes indexes=no


exp scott/tiger file=emp.dmp tables=(emp,dept)
imp scott/tiger file=emp.dmp full=yes
imp scott/tiger file=emp.dmp fromuser=scott touser=scott tables=dept

Using a parameter file:

exp userid=scott/tiger@orcl parfile=export.txt


... where export.txt contains:

BUFFER=100000
FILE=account.dmp
FULL=n
OWNER=scott
GRANTS=y
COMPRESS=y

NOTE: If you do not like command line utilities, you can import and export data with the "Schema
Manager" GUI that ships with Oracle Enterprise Manager (OEM).

Can one export a subset of a table?


Submitted by admin on Sat, 2004-08-07 11:43.

From Oracle8i one can use the QUERY= export parameter to selectively unload a subset of the data
from a table. Look at this example:

exp scott/tiger tables=emp query="where deptno=10"

Can one monitor how fast a table is imported?


Submitted by admin on Sat, 2004-08-07 11:43.

If you need to monitor how fast rows are imported from a running import job, try one of the
following methods:
Method 1:

select substr(sql_text,instr(sql_text,'INTO "'),30) table_name,


rows_processed,
round((sysdate-to_date(first_load_time,'yyyy-mm-dd hh24:mi:ss'))*24*60,1) minutes,
trunc(rows_processed/((sysdate-to_date(first_load_time,'yyyy-mm-dd hh24:mi:ss'))*24*60))
rows_per_min
from

sys.v_$sqlarea

where

sql_text like 'INSERT %INTO "%'

and

command_type = 2

and

open_versions > 0;

For this to work one needs to be on Oracle 7.3 or higher (7.2 might also be OK). If the import has
more than one table, this statement will only show information about the current table being
imported.
Method 2:
Use the FEEDBACK=n import parameter. This command will tell IMP to display a dot for every N rows
imported

Can one import tables to a different tablespace?


Submitted by admin on Sat, 2004-08-07 11:43.

Oracle offers no parameter to specify a different tablespace to import data into. Objects will be recreated in the tablespace they were originally exported from. One can alter this behaviour by
following one of these procedures:

Pre-create the table(s) in the correct tablespace:


o
o
o
o

Import the dump file using the INDEXFILE= option


the indexfile. Remove remarks and specify the correct tablespaces.
Run this indexfile against your database, this will create the required tables in the
appropriate tablespaces
Import the table(s) with the IGNORE=Y option.

Change the default tablespace for the user:


o

Revoke the "UNLIMITED TABLESPACE" privilege from the user

o
o
o

Revoke the user's quota from the tablespace from where the object was exported. This
forces the import utility to create tables in the user's default tablespace.
Make the tablespace to which you want to import the default tablespace for the user
Import the table

Does one need to drop/ truncate objects before


importing?
Submitted by admin on Sat, 2004-08-07 11:43.

Before one import rows into already populated tables, one needs to truncate or drop these tables to
get rid of the old data. If not, the new data will be appended to the existing tables. One must
always DROP existing Sequences before re-importing. If the sequences are not dropped, they will
generate numbers inconsistent with the rest of the database.
Note: It is also advisable to drop indexes before importing to speed up the import process. Indexes
can easily be recreated after the data was successfully imported

Can one import/export between different


versions of Oracle?
Submitted by admin on Sat, 2004-08-07 11:43.

Different versions of the import utility is upwards compatible. This means that one can take an
export file created from an old export version, and import it using a later version of the import
utility. This is quite an effective way of upgrading a database from one release of Oracle to the
next.
Oracle also ships some previous catexpX.sql scripts that can be executed as user SYS enabling older
imp/exp versions to work (for backwards compatibility). For example, one can run
$ORACLE_HOME/rdbms/admin/catexp7.sql on an Oracle 8 database to allow the Oracle 7.3 exp/imp
utilities to run against an Oracle 8 database.

Can one export to multiple files?/ Can one beat


the Unix 2 Gig limit?
Submitted by admin on Sat, 2004-08-07 11:43.

From Oracle8i, the export utility supports multiple output files. This feature enables large exports
to be divided into files whose sizes will not exceed any operating system limits (FILESIZE=
parameter). When importing from multi-file export you must provide the same filenames in the
same sequence in the FILE= parameter. Look at this example:

exp SCOTT/TIGER FILE=D:F1.dmp,E:F2.dmp FILESIZE=10m LOG=scott.log


Use the following technique if you use an Oracle version prior to 8i:
Create a compressed export on the fly. Depending on the type of data, you probably can export up
to 10 gigabytes to a single file. This example uses gzip. It offers the best compression I know of, but
you can also substitute it with zip, compress or whatever.

# create a named pipe


mknod exp.pipe p

# read the pipe - output to zip file in the background


gzip < exp.pipe > scott.exp.gz &

# feed the pipe


exp userid=scott/tiger file=exp.pipe ...

How can one improve Import/ Export


performance?
Submitted by admin on Sat, 2004-08-07 11:43.

EXPORT:

o
o
o
o
o

Set the BUFFER parameter to a high value (e.g. 2M)


Set the RECORDLENGTH parameter to a high value (e.g. 64K)
Stop unnecessary applications to free-up resources for your job.
If you run multiple export sessions, ensure they write to different physical disks.
DO NOT export to an NFS mounted filesystem. It will take forever.

IMPORT:

o
o
o
o
o
o
o
o

Create an indexfile so that you can create indexes AFTER you have imported data. Do this
by setting INDEXFILE to a filename and then import. No data will be imported but a file
containing index definitions will be created. You must this file afterwards and supply the
passwords for the schemas on all CONNECT statements.
Place the file to be imported on a separate physical disk from the oracle data files
Increase DB_CACHE_SIZE (DB_BLOCK_BUFFERS prior to 9i) considerably in the init$SID.ora
file
Set the LOG_BUFFER to a big value and restart oracle.
Stop redo log archiving if it is running (ALTER DATABASE NOARCHIVELOG;)
Create a BIG tablespace with a BIG rollback segment inside. Set all other rollback segments
offline (except the SYSTEM rollback segment of course). The rollback segment must be as
big as your biggest table (I think?)
Use COMMIT=N in the import parameter file if you can afford it
Use ANALYZE=N in the import parameter file to avoid time consuming ANALYZE statements
Remember to run the indexfile previously created

What are the common Import/ Export problems?


Submitted by admin on Sat, 2004-08-07 11:43.

o
o

ORA-00001: Unique constraint (...) violated You are importing duplicate rows. Use
IGNORE=NO to skip tables that already exist (imp will give an error if the object is recreated).
ORA-01555: Snapshot too old Ask your users to STOP working while you are exporting or
use parameter CONSISTENT=YES

o
o

ORA-01562: Failed to extend rollback segment Create bigger rollback segments or set
parameter COMMIT=Y while importing
IMP-00015: Statement failed ... object already exists... Use the IGNORE=Y import
parameter to ignore these errors, but be careful as you might end up with duplicate rows.

SQL*Loader
How does one use the SQL*Loader utility?
Submitted by admin on Sat, 2004-08-07 06:10.

One can load data into an Oracle database by using the sqlldr (sqlload on some platforms) utility.
Invoke the utility without arguments to get a list of available parameters. Look at the following
example:

sqlldr scott/tiger control=loader.ctl


This sample control file (loader.ctl) will load an external data file containing delimited data:

load data
infile 'c:\datamydata.csv'
into table emp
fields terminated by "," optionally enclosed by '"'
( empno, empname, sal, deptno )

The mydata.csv file may look like this:

10001,"Scott Tiger", 1000, 40


10002,"Frank Naude", 500, 20

Another Sample control file with in-line data formatted as fix length records. The trick is to specify
"*" as the name of the data file, and use BEGINDATA to start the data section in the control file.

load data
infile *
replace
into table departments
(

dept

position (02:05) char(4),

deptname position (08:27) char(20)


)
begindata

COSC

COMPUTER SCIENCE

ENGL

ENGLISH LITERATURE

MATH

MATHEMATICS

POLY

POLITICAL SCIENCE

What is SQL*Loader and what is it used for?


Submitted by admin on Fri, 2004-08-06 05:50.

SQL*Loader is a bulk loader utility used for moving data from external files into the Oracle database.
Its syntax is similar to that of the DB2 Load utility, but comes with more options. SQL*Loader
supports various load formats, selective loading, and multi-table loads.

How does one load MS-Excel data into Oracle?


Submitted by admin on Thu, 2006-01-26 11:04.

Open the MS-Excel spreadsheet and save it as a CSV (Comma Separated Values) file. This file can
now be copied to the Oracle machine and loaded using the SQL*Loader utility.
Possible problems and workarounds:
The spreadsheet may contain cells with newline characters (ALT+ENTER). SQL*Loader expects the
entire record to be on a single line. Run the following macro to remove newline characters (Tools ->
Macro -> Visual Basic or):

' Removing tabs and carriage returns from worksheet cells

Sub CleanUp()
Dim TheCell As Range
On Error Resume Next

For Each TheCell In ActiveSheet.UsedRange


With TheCell
If .HasFormula = False Then
.Value = Application.WorksheetFunction.Clean(.Value)
End If
End With
Next TheCell
End Sub

Is there a SQL*Unloader to download data to a flat


file?
Submitted by admin on Sat, 2004-08-07 06:11.

Oracle does not supply any data unload utilities. Here are some workarounds:

Using SQL*Plus
You can use SQL*Plus to select and format your data and then spool it to a file. This example spools
out a CSV (comman separated values) file that can be imported into MS-Excel:

set echo off newpage 0 space 0 pagesize 0 feed off head off trimspool on
spool oradata.txt
select col1 || ',' || col2 || ',' || col3
from
where

tab1
col2 = 'XYZ';

spool off

You can also use the "set colsep ," command if you don't want to put the commas in by hand. This
saves a lot of typing:

set colsep ,
set echo off newpage 0 space 0 pagesize 0 feed off head off trimspool on
spool oradata.txt
select col1, col2, col3
from
where

tab1
col2 = 'XYZ';

spool off

Using PL/SQL
PL/SQL's UTL_FILE package can also be used to unload data:

rem Remember to update initSID.ora, utl_file_dir='c:\oradata' parameter


declare
fp utl_file.file_type;
begin
fp := utl_file.fopen('c:\oradata','tab1.txt','w');
utl_file.putf(fp, '%s, %sn', 'TextField', 55);
utl_file.fclose(fp);
end;

Third-party programs
You might also want to investigate third party tools to help you unload data from Oracle. Here are
some examples:

o
o
o

SQLWays from Ispirer Systems


TOAD from Quest
ManageIT Fast Unloader from CA

Can one load variable and fix length data records?


Submitted by admin on Sat, 2004-08-07 06:13.

Loading delimited (variable length) data


In the first example we will show how delimited (variable length) data can be loaded into Oracle:

LOAD DATA
INFILE *
INTO TABLE load_delimited_data
FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(

data1,
data2

)
BEGINDATA
11111,AAAAAAAAAA
22222,"A,B,C,D,"

NOTE: The default data type in SQL*Loader is CHAR(255). To load character fields longer than 255
characters, code the type and length in your control file. By doing this, Oracle will allocate a big
enough buffer to hold the entire column, thus eliminating potential "Field in data file exceeds
maximum length" errors. Example:

...
resume char(4000),
...

Loading positional (fixed length) data


If you need to load positional data (fixed length), look at the following control file example:

LOAD DATA
INFILE *

INTO TABLE load_positional_data


(

data1 POSITION(1:5),
data2 POSITION(6:15)

)
BEGINDATA
11111AAAAAAAAAA
22222BBBBBBBBBB

Can one skip header records while loading?


Submitted by admin on Fri, 2004-08-06 05:50.

One can skip header records or continue an interrupted load (for example if you run out of space) by
specifying the "SKIP n" keyword. "n" specifies the number of logical rows to skip. Look at this
example:

OPTIONS (SKIP 5)
LOAD DATA
INFILE *
INTO TABLE load_positional_data
(

data1 POSITION(1:5),
data2 POSITION(6:15)

)
BEGINDATA
11111AAAAAAAAAA
22222BBBBBBBBBB
...

If you are continuing a multiple table direct path load, you may need to use the CONTINUE_LOAD
clause instead of the SKIP parameter. CONTINUE_LOAD allows you to specify a different number of
rows to skip for each of the tables you are loading.

Can one modify and add data as the database gets


loaded?
Submitted by admin on Sat, 2004-08-07 06:14.

Data can be modified as it loads into the Oracle Database. One can also populate columns with
static or derived values. However, this only applies for the conventional load path (and not for
direct path loads). Here are some examples:

LOAD DATA
INFILE *
INTO TABLE modified_data
(

rec_no

"my_db_sequence.nextval",

region

CONSTANT '31'</FONT>,

time_loaded

[b]"to_char(SYSDATE, 'HH24:MI')",

data1

POSITION(1:5)

":data1/100",

data2

POSITION(6:15) "upper(:data2)",

data3

POSITION(16:22)"to_date(:data3, 'YYMMDD')"

)
BEGINDATA
11111AAAAAAAAAA991201
22222BBBBBBBBBB990112
LOAD DATA
INFILE 'mail_orders.txt'
BADFILE 'bad_orders.txt'
APPEND
INTO TABLE mailing_list
FIELDS TERMINATED BY ","
(

addr,
city,
state,
zipcode,
mailing_addr

"decode(:mailing_addr, null, :addr, :mailing_addr)",

mailing_city

"decode(:mailing_city, null, :city, :mailing_city)",

mailing_state
)

Can one load data from multiple files/ into


multiple tables at once?
Submitted by admin on Fri, 2004-08-06 05:50.

Loading from multiple input files


One can load from multiple input files provided they use the same record format by repeating the
INFILE clause. Here is an example:

LOAD DATA
INFILE file1.dat
INFILE file2.dat
INFILE file3.dat
APPEND
INTO TABLE emp
( empno
ename

POSITION(1:4)

INTEGER EXTERNAL,

POSITION(6:15)

CHAR,

deptno POSITION(17:18) CHAR,


mgr

POSITION(20:23) INTEGER EXTERNAL

Loading into multiple tables


One can also specify multiple "INTO TABLE" clauses in the SQL*Loader control file to load into
multiple tables. Look at the following example:

LOAD DATA
INFILE *
INTO TABLE tab1 WHEN tab = 'tab1'
( tab

FILLER CHAR(4),

col1 INTEGER
)
INTO TABLE tab2 WHEN tab = 'tab2'
( tab

FILLER POSITION(1:4),

col1 INTEGER
)
BEGINDATA
tab1|1
tab1|2
tab2|2
tab3|3

The "tab" field is marked as a FILLER as we don't want to load it.


Note the use of "POSITION" on the second routing value (tab = 'tab2'). By default field scanning
doesn't start over from the beginning of the record for new INTO TABLE clauses. Instead, scanning
continues where it left off. POSITION is needed to reset the pointer to the beginning of the record
again.
Another example:

LOAD DATA
INFILE 'mydata.dat'
REPLACE
INTO TABLE emp
WHEN empno != ' '
( empno
ename

POSITION(1:4)

INTEGER EXTERNAL,

POSITION(6:15)

CHAR,

deptno POSITION(17:18) CHAR,


mgr

POSITION(20:23) INTEGER EXTERNAL

)
INTO TABLE proj
WHEN projno != ' '
(

projno POSITION(25:27) INTEGER EXTERNAL,


empno

POSITION(1:4)

INTEGER EXTERNAL

Can one selectively load only the records that one


need?
Submitted by admin on Sat, 2004-08-07 06:17.

Look at this example, (01) is the first character, (30:37) are characters 30 to 37:

LOAD DATA
INFILE

'mydata.dat' BADFILE

'mydata.bad' DISCARDFILE 'mydata.dis'

APPEND
INTO TABLE my_selective_table
WHEN (01) <> 'H' and (01) <> 'T' and (30:37) = '20031217'
(
region

CONSTANT '31',

service_key

POSITION(01:11)

INTEGER EXTERNAL,

call_b_no

POSITION(12:29)

CHAR

NOTE: SQL*Loader does not allow the use of OR in the WHEN clause. You can only use AND as in the
example above! To workaround this problem, code multiple "INTO TABLE ... WHEN" clauses. Here is
an example:

LOAD DATA
INFILE

'mydata.dat' BADFILE

'mydata.bad' DISCARDFILE 'mydata.dis'

APPEND
INTO TABLE my_selective_table
WHEN (01) <> 'H' and (01) <> 'T'
(
region

CONSTANT '31',

service_key

POSITION(01:11)

INTEGER EXTERNAL,

call_b_no

POSITION(12:29)

CHAR

)
INTO TABLE my_selective_table
WHEN (30:37) = '20031217'
(
region

CONSTANT '31',

service_key

POSITION(01:11)

INTEGER EXTERNAL,

call_b_no

POSITION(12:29)

CHAR

Can one skip certain columns while loading data?


Submitted by admin on Sat, 2004-08-07 06:20.

One cannot use POSTION(x:y) with delimited data. Luckily, from Oracle 8i one can specify FILLER
columns. FILLER columns are used to skip columns/fields in the load file, ignoring fields that one
does not want. Look at this example:

LOAD DATA
TRUNCATE INTO TABLE T1
FIELDS TERMINATED BY ','
( field1,
field2 FILLER,
field3
)

How does one load multi-line records?


Submitted by admin on Sat, 2004-08-07 06:21.

One can create one logical record from multiple physical records using one of the following two
clauses:

o
o

CONCATENATE: - use when SQL*Loader should combine the same number of physical
recordstogether to form one logical record.
CONTINUEIF - use if a condition indicates that multiple records should be treated as one.
Eg. by having a '#' character in column 1.

How can one get SQL*Loader to COMMIT only at


the end of the load file?
Submitted by admin on Fri, 2004-08-06 05:50.

One cannot, but by setting the ROWS= parameter to a large value, committing can be reduced. Make
sure you have big rollback segments ready when you use a high value for ROWS=.

Can one improve the performance of


SQL*Loader?
Submitted by admin on Sat, 2004-08-07 06:23.

o
o
o
o

A very simple but easily overlooked hint is not to have any indexes and/or constraints
(primary key) on your load tables during the load process. This will significantly slow down
load times even with ROWS= set to a high value.
Add the following option in the command line: DIRECT=TRUE. This will effectively bypass
most of the RDBMS processing. However, there are cases when you can't use direct load.
Refer to chapter 8 on Oracle server Utilities manual.
Turn off database logging by specifying the UNRECOVERABLE option. This option can only be
used with direct data loads.
Run multiple load jobs concurrently.

What is the difference between the conventional


and direct path loader?
Submitted by admin on Fri, 2004-08-06 05:50.

The conventional path loader essentially loads the data by using standard INSERT statements. The
direct path loader (DIRECT=TRUE) bypasses much of the logic involved with that, and loads directly
into the Oracle data files. More information about the restrictions of direct path loading can be
obtained from the Utilities Users

How does one use SQL*Loader to load images,


sound clips and documents?
Submitted by admin on Sat, 2004-08-07 06:23.

SQL*Loader can load data from a "primary data file", SDF (Secondary Data file - for loading nested
tables and VARRAYs) or LOBFILE. The LOBFILE method provides an easy way to load documents,
photos, images and audio clips into BLOB and CLOB columns. Look at this example:
Given the following table:

CREATE TABLE image_table (


image_id

NUMBER(5),

file_name

VARCHAR2(30),

image_data BLOB);

Control File:

LOAD DATA
INFILE *
INTO TABLE image_table
REPLACE
FIELDS TERMINATED BY ','
(
image_id

INTEGER(5),

file_name

CHAR(30),

image_data LOBFILE (file_name) TERMINATED BY EOF


)
BEGINDATA
001,image1.gif
002,image2.jpg
003,image3.jpg

How does one load EBCDIC data?


Submitted by George Lewycky on Sun, 2006-01-08 11:36.

Specify the Characterset WE8EBCDIC500 for the EBCDIC data. The following example shows the
SQL*Loader Controlfile to load a fixed length EBCDIC record into the Oracle Database:

LOAD DATA
CHARACTERSET WE8EBCDIC500
INFILE data.ebc "fix 86 buffers 1024"
BADFILE data.bad'
DISCARDFILE data.dsc'
REPLACE
INTO TABLE temp_data
(
field1

POSITION (1:4)

INTEGER EXTERNAL,

field2

POSITION (5:6)

INTEGER EXTERNAL,

field3

POSITION (7:12)

INTEGER EXTERNAL,

field4

POSITION (13:42)

CHAR,

field5

POSITION (43:72)

CHAR,

field6

POSITION (73:73)

INTEGER EXTERNAL,

field7

POSITION (74:74)

INTEGER EXTERNAL,

field8

POSITION (75:75)

INTEGER EXTERNAL,

field9

POSITION (76:86)

INTEGER EXTERNAL

Managing Oracle Tablespaces and Data Files


What Is an Oracle Tablespace ?
An Oracle tablespace is a big unit of logical storage in an Oracle database. It is managed and used by
the Oracle server to store structures data objects, like tables and indexes.
What Is an Oracle Data File?
An Oracle data file is a big unit of physical storage in the OS file system. One or many Oracle data
files are organized together to provide physical storage to a single Oracle tablespace.

How a Tablespace Is Related to Data Files?


Each tablespace in an Oracle database consists of one or more files called datafiles, which are
physical structures that conform to the operating system in which Oracle is running.
How a Database Is Related to Tablespaces?
A database's data is collectively stored in the datafiles that constitute each tablespace of the
database. For example, the simplest Oracle database would have one tablespace and one datafile.
Another database can have three tablespaces, each consisting of two datafiles (for a total of six
datafiles).
How To View the Tablespaces in the Current Database?
If you want to get a list of all tablespaces used in the current database instance, you can use the
DBA_TABLESPACES view as shown in the following SQL script example:
SQL> connect SYSTEM/fyicenter
Connected.

SQL> SELECT TABLESPACE_NAME, STATUS, CONTENTS


2 FROM USER_TABLESPACES;
TABLESPACE_NAME

STATUS

CONTENTS

------------------------------ --------- --------SYSTEM

ONLINE

PERMANENT

UNDO

ONLINE

UNDO

SYSAUX

ONLINE

PERMANENT

TEMP

ONLINE

TEMPORARY

USERS

ONLINE

PERMANENT

What Are the Predefined Tablespaces in a Database?


When you create a new database, Oracle server will create 4 required tablespaces for the new
database:
SYSTEM Tablespace - Every Oracle database contains a tablespace named SYSTEM, which Oracle
creates automatically when the database is created. The SYSTEM tablespace is always online when
the database is open.
SYSAUX Tablespace - The SYSAUX tablespace was installed as an auxiliary tablespace to the SYSTEM
tablespace when you created your database. Some database components that formerly created and
used separate tablespaces now occupy the SYSAUX tablespace.
UNDO Tablespace - UNDO tablespaces are special tablespaces used solely for storing undo
information. You cannot create any other segment types (for example, tables or indexes) in undo
tablespaces. Each database contains zero or more undo tablespaces. In automatic undo management
mode, each Oracle instance is assigned one (and only one) undo tablespace. Undo data is managed
within an undo tablespace using undo segments that are automatically created and maintained by
Oracle.
TEMP Tablespace - When the SYSTEM tablespace is locally managed, you must define at least one
default temporary tablespace when creating a database. A locally managed SYSTEM tablespace
cannot be used for default temporary storage.
How To View the Data Files in the Current Database?
If you want to get a list of all data files used in the current database instance, you can use the
DBA_DATA_FILES view as shown in the following SQL script example:
SQL> connect SYSTEM/fyicenter
Connected.
SQL> col tablespace_name format a16;

SQL> col file_name format a36;


SQL> SELECT TABLESPACE_NAME, FILE_NAME, BYTES
2 FROM DBA_DATA_FILES;
TABLESPACE_NAME FILE_NAME

BYTES

--------------- ------------------------------- --------USERS

\ORACLEXE\ORADATA\XE\USERS.DBF 104857600

SYSAUX

\ORACLEXE\ORADATA\XE\SYSAUX.DBF 461373440

UNDO

\ORACLEXE\ORADATA\XE\UNDO.DBF

SYSTEM

\ORACLEXE\ORADATA\XE\SYSTEM.DBF 356515840

94371840

How To Create a new Oracle Data File?


There is no dedicated statement to create a data file. Data files are created as part of statements
that manages other data structures, like tablespace and database.
How To Create a New Tablespace?
If you want a new dataspace, you can use the CREATE TABLESPACE ... DATAFILE statement as shown
in the following script:
SQL> CREATE TABLESPACE my_space
2 DATAFILE '/temp/my_space.dbf' SIZE 10M;
Tablespace created.
SQL> SELECT TABLESPACE_NAME, STATUS, CONTENTS
2 FROM USER_TABLESPACES;
TABLESPACE_NAME STATUS

CONTENTS

---------------- --------------- --------SYSTEM

ONLINE

PERMANENT

UNDO

ONLINE

UNDO

SYSAUX

ONLINE

PERMANENT

TEMP

ONLINE

TEMPORARY

USERS

ONLINE

PERMANENT

MY_SPACE

ONLINE

PERMANENT

SQL> SELECT TABLESPACE_NAME, FILE_NAME, BYTES


2 FROM DBA_DATA_FILES;
TABLESPACE_NAME FILE_NAME

BYTES

--------------- -------------------------------- --------USERS

\ORACLEXE\ORADATA\XE\USERS.DBF 104857600

SYSAUX

\ORACLEXE\ORADATA\XE\SYSAUX.DBF 461373440

UNDO

\ORACLEXE\ORADATA\XE\UNDO.DBF

SYSTEM

\ORACLEXE\ORADATA\XE\SYSTEM.DBF 356515840

MY_SPACE

\TEMP\MY_SPACE.DBF

94371840

10485760

So one statement created two structures: a tablespace and a data file. If you check your file system
with Windows file explorer, you will see the data file is located in the \temp directory of. The data
file size is about 10MB. Its contents should be blank and full of \x00 at this time.
How To Rename a Tablespace?
You can easily rename a tablespace by using the ALTER TABLESPACE ... RENAME TO statement as
shown in the example below:
SQL> CREATE TABLESPACE my_space
2 DATAFILE '/temp/my_space.dbf' SIZE 10M;
Tablespace created.
SQL> ALTER TABLESPACE my_space RENAME TO your_space;
Tablespace created.
SQL> SELECT TABLESPACE_NAME, STATUS, CONTENTS
2 FROM USER_TABLESPACES;
TABLESPACE_NAME STATUS

CONTENTS

---------------- --------------- --------SYSTEM

ONLINE

PERMANENT

UNDO

ONLINE

UNDO

SYSAUX

ONLINE

PERMANENT

TEMP

ONLINE

TEMPORARY

USERS

ONLINE

PERMANENT

YOUR_SPACE

ONLINE

PERMANENT

How To Drop a Tablespace?


If you have an existing tablespace and you don't want it anymore. You can delete a tablespace by
using the DROP TABLESPACE statement as shown in the example below:
SQL> CREATE TABLESPACE my_space
2 DATAFILE '/temp/my_space.dbf' SIZE 10M;
Tablespace created.
SQL> DROP TABLESPACE my_space;
Tablespace dropped.
What Happens to the Data Files If a Tablespace Is Dropped?
If a tablespace is dropped, what happens to its data files? By default, data files will remain in OS file
system, even if the tablespace they are mapped is dropped. Of course, you delete the data files
using OS commands, if they are no longer needed.
Another way of deleting data files is to use the INCLUDING clause in the DROP TABLESPACE
statement. Here is a SQL sample script:
SQL> CREATE TABLESPACE my_space
2 DATAFILE '/temp/my_space.dbf' SIZE 10M;
Tablespace created.
SQL> DROP TABLESPACE my_space INCLUDING CONTENTS
2 AND DATAFILES;
Tablespace dropped.
With the INCLUDING CONTENTS AND DATAFILES clause, all contents and mapped data files are also
deleted.
How To Create a Table in a Specific Tablespace?

After you have created a new tablespace, you can give it to your users for them to create tables in
the new tablespace. To create a table in a specific tablespace, you need to use the TABLESPACE
clause in the CREATE TABLE statement. Here is a sample script:
SQL> connect SYSTEM/fyicenter
Connected.

SQL> CREATE TABLESPACE my_space


2 DATAFILE '/temp/my_space.dbf' SIZE 10M;
Tablespace created.

SQL> connect HR/fyicenter


Connected.

SQL> CREATE TABLE my_team TABLESPACE my_space


2 AS SELECT * FROM employees;
Table created.

SQL> SELECT table_name, tablespace_name, num_rows


2 FROM USER_TABLES
3 WHERE tablespace_name in ('USERS', 'MY_SPACE');

TABLE_NAME

TABLESPACE_NAME

------------------------------ ---------------- ---------MY_TEAM

MY_SPACE

EMPLOYEES

USERS

107

...
How To See Free Space of Each Tablespace?

NUM_ROWS

One of the important DBA tasks is to watch the storage usage of all the tablespaces to make sure
there are enough free space in each tablespace for database applications to function properly. Free
space information can be monitored through the USER_FREE_SPACE view. Each record in
USER_FREE_SPACE represents an extent, a contiguous area of space, of free space in a data file of a
tablespace.
Here is SQL script example on how to see free space of a tablespace:
SQL> connect HR/fyicenter
Connected.

SQL> SELECT TABLESPACE_NAME, FILE_ID, BYTES


2 FROM USER_FREE_SPACE
3 WHERE TABLESPAE_NAME IN ('USERS', 'MY_SPACE');
TABLESPACE_NAME

FILE_ID

BYTES

------------------------------ ---------- ---------MY_SPACE

5 10354688

USERS

4 101974016

USERS

65536

USERS

65536

USERS

65536

USERS

65536

USERS

65536

USERS

65536

USERS

65536

USERS

65536

USERS

65536

USERS

65536

USERS

65536

USERS

65536

This tells us that:


MY_SPACE has a single free extent of 10MB.
USERS has one big free extent of 100MB, and many small free extents of 64KB.
How To Bring a Tablespace Offline?
If you want to stop users using a tablespace, you can bring it offline using the ALTER TABLESPACE ...
OFFLINE statement as shown in the following script:
SQL> connect HR/fyicenter
Connected.

SQL> CREATE TABLESPACE my_space


2 DATAFILE '/temp/my_space.dbf' SIZE 10M;
Tablespace created.

SQL> ALTER TABLESPACE my_space OFFLINE NORMAL;


Tablespace altered.
After bringing a tablespace offline, you can backup or rename the data file safely.
How To Bring a Tablespace Online?
If you have brought a tablespace offline, now you want to make it available to users again, you can
use the ALTER TABLESPACE ... ONLINE statement as shown in the following script:
SQL> connect HR/fyicenter
SQL> CREATE TABLESPACE my_space
2 DATAFILE '/temp/my_space.dbf' SIZE 10M;
Tablespace created.
SQL> ALTER TABLESPACE my_space OFFLINE NORMAL;
Tablespace altered.
SQL> ALTER TABLESPACE my_space ONLINE;
Tablespace altered.

How To Add Another Datafile to a Tablespace?


If you created a tablespace with a data file a month ago, now 80% of the data file is used, you
should add another data file to the tablespace. This can be done by using the ALTER TABLESPACE ...
ADD DATAFILE statement. See the following sample script:
SQL> connect HR/fyicenter
SQL> CREATE TABLESPACE my_space
2 DATAFILE '/temp/my_space.dbf' SIZE 10M;
Tablespace created.
SQL> ALTER TABLESPACE my_space
2 ADD DATAFILE '/temp/my_space_2.dbf' SIZE 5M;
Tablespace altered.
SQL> SELECT TABLESPACE_NAME, FILE_NAME, BYTES
2 FROM DBA_DATA_FILES;
TABLESPACE_NAME FILE_NAME

BYTES

--------------- --------------------------------- --------USERS

C:\ORACLEXE\ORADATA\XE\USERS.DBF 104857600

SYSAUX

C:\ORACLEXE\ORADATA\XE\SYSAUX.DBF 461373440

UNDO

C:\ORACLEXE\ORADATA\XE\UNDO.DBF

SYSTEM

C:\ORACLEXE\ORADATA\XE\SYSTEM.DBF 356515840

MY_SPACE

C:\TEMP\MY_SPACE.DBF

MY_SPACE

C:\TEMP\MY_SPACE_2.DBF

10485760
5242880

SQL> SELECT TABLESPACE_NAME, FILE_ID, BYTES


2 FROM USER_FREE_SPACE
3 WHERE TABLESPAE_NAME IN ('MY_SPACE');
TABLESPACE_NAME

FILE_ID

BYTES

------------------------------ ---------- ---------MY_SPACE

94371840

5177344

MY_SPACE

5 10354688

This script created one tablespace with two data files.


What Happens If You Lost a Data File?
After you shuting down an Oracle database, you accidently deleted a data file from the operating
system. If you try to start the database again you will get error when Oracle tries to open the
database after mounting the database. The following tutorial examples shows you what will happen
if the data file c:\temp\my_space.dbf is deleted. Oracle can still start the database instance and
mount the database. But it will fail on openning the database as shown below in a SQL*Plus session:
>sqlplus /nolog
SQL> connect SYSTEM/fyicenter AS SYSDBA
SQL> STARTUP
ORACLE instance started.

Total System Global Area 100663296 bytes


Fixed Size

1285956 bytes

Variable Size

58720444 bytes

Database Buffers
Redo Buffers

37748736 bytes
2908160 bytes

Database mounted.
ORA-01157: cannot identify/lock data file 5 - see DBWR
trace file
ORA-01110: data file 5: 'C:\TEMP\MY_SPACE.DBF'
SQL> SHUTDOWN;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
How Remove Data Files befor opening a Database?

Let's say you have a corrupted data file or lost a data file. Oracle can mount the database. But it
will not open the database. What you can do is to set the bad data file as offline befor opening the
database. The tutorial exercise shows you how to set two data files offline and open the database
without them:
>sqlplus /nolog
SQL> connect SYSTEM/fyicenter AS SYSDBA
SQL> STARTUP MOUNT;
ORACLE instance started.
Total System Global Area 100663296 bytes
Fixed Size

1285956 bytes

Variable Size

58720444 bytes

Database Buffers
Redo Buffers

37748736 bytes
2908160 bytes

Database mounted.
SQL> ALTER DATABASE DATAFILE '\temp\my_space.dbf'
2 OFFLINE DROP;
Database altered.
SQL> ALTER DATABASE DATAFILE '\temp\my_space_2.dbf'
2 OFFLINE DROP;
Database altered.
SQL> ALTER DATABASE OPEN;
Database altered.
SQL> col file_name format a36;
SQL> col tablespace_name format a16;
SQL> SELECT TABLESPACE_NAME, FILE_NAME, BYTES
2 FROM DBA_DATA_FILES;
TABLESPACE_NAME FILE_NAME

BYTES

--------------- --------------------------------- --------USERS

C:\ORACLEXE\ORADATA\XE\USERS.DBF 104857600

SYSAUX

C:\ORACLEXE\ORADATA\XE\SYSAUX.DBF 503316480

UNDO

C:\ORACLEXE\ORADATA\XE\UNDO.DBF

SYSTEM

C:\ORACLEXE\ORADATA\XE\SYSTEM.DBF 367001600

MY_SPACE

C:\TEMP\MY_SPACE.DBF

MY_SPACE

C:\TEMP\MY_SPACE_2.DBF

94371840

At this point, if you don't care about the data in MY_SPACE, you can drop it now with the database
opened.

SPACE MANAGEMENT
Oracle locally managed tablespace benefits
There are a number of benefits that locally-managed tablespaces offer:

Less contention - OLTP systems profit from fewer dictionary concurrency problems because
Oracle manages space in the tablespace rather than the data dictionary. Recursive space
management calls become a thing of the past. Folks who endure parallel server (or RAC)
installations will appreciate this success indicator, as "pinging" between nodes may be substantially
reduced

No high extent penalty - Objects can have nearly unlimited numbers of space extents with
apparently no performance degradation. Such a feature eliminates the problem of object extent
fragmentation outright.

Better free space management - Free space found in datafiles does not have to be coalesced
because bitmaps track free space and allocate it much more effectively than dictionary-managed
tablespaces. This benefit eliminates the problem of honeycomb fragmentation completely.

Efficient space management - Uniform or system-managed extent sizes are automatically


controlled for the database administrator, resulting in a much more efficient space management
process. The result is an end to the problem of tablespace bubble fragmentation
There may two Cause for SNAPSHOT-TOO-OLD error:(1) Since space managemnt in undo segment follow LRU algorihm.So in space allocated for to undo
segment will so small to data may frequently swaped out from undo segement and may cause
SNAPSHOT-TOO-OLD error.

(2) It also depend on the undo retention policy set by the DBA.If the undo retention time is set to
very low the the data will sweped out too early and may cause SNAPSHOT-TOO-OLD error.
When any DML operation is taking long time which may lead reuse of datablocks of undo segment by
another DML, in this case oracle will throw snapshot too old error.For any DML oracle stores the
undo image in rollback segment, suppose transaction A is in progress which cause datablock from
undo segment been used by this transaction.And now if another transaction B is started which need
datablocks from undo segment to keep undo copy, but if rollback segment is not large enough to
provide the datablocks for second transaction B, then transaction B will use the datablock which are
already in use to retain the undo image for transaction A, and this will lead to snap shot too old.
Simple solution change the commit point by chaning checkpoint frequency. And if it's possible then
increase undo segment size by adding datafile to undo tablespace.

Anyways, ORA-1555 snapshot too old error is thrown by a "query" when it fails to get a read
consistent image of data its querying.
What is read consistency?
When a long running query(running into hours) is issued, its possible that before the query finishes
and gives u result some other DML "transaction" may change the data that the query was
reading.This will cause the query to return inconsistent result(which is not allowed as per the ACID
properties). To avoid this Oracle has something called as Undo segments which will store the old
value of changed data blocks.So now if a query hits a data block which was changed after it started,
it will go to the UNDO and pick up the old value(the one which was prevalent when the query has
started its execution.this is also the READ CONSISTENT copy).
Ok, now when will ORA-1555 occur? If the query is unable to get the old(read consistent) copy of the
data in the UNDO-because it may have be overwritten-then...yes my friend you are right..thats the
time the query throws the ORA-1555 error.

1. Explain the difference between a hot backup and a cold backup and the benefits
associated with each.
A hot backup is basically taking a backup of the database while it is still up and running and it
must be in archive log mode. A cold backup is taking a backup of the database while it is shut
down and does not require being in archive log mode. The benefit of taking a hot backup is
that the database is still available for use while the backup is occurring and you can recover
the database to any point in time. The benefit of taking a cold backup is that it is typically
easier to administer the backup and recovery process. In addition, since you are taking cold
backups the database does not require being in archive log mode and thus there will be a slight
performance gain as the database is not cutting archive logs to disk.
2. You have just had to restore from backup and do not have any control files. How would
you go about bringing up this database?
I would create a text based backup control file, stipulating where on disk all the data files are
and then issue the recover command with the using backup control file clause.
3. How do you switch from an init.ora file to a spfile?
Issue the create spfile from pfile command.

4. Explain the difference between a data block, an extent and a segment.


A data block is the smallest unit of logical storage for a database object. As objects grow they
take chunks of additional storage that are composed of contiguous data blocks. These groupings
of contiguous data blocks are called extents. All the extents that an object takes when grouped
together are considered the segment of the database object.A segment can be named while a
data block cant be.
5. Give two examples of how you might determine the structure of the table DEPT.
Use the describe command or use the dbms_metadata.get_ddl package.
6. Where would you look for errors from the database engine?
In the alert log.
background_dump_dest in parameter file.
F:\oracle\admin\orcl\bdump
On UNIX the default location is
$ORACLE_HOME/rdbms/log
7. Compare and contrast TRUNCATE and DELETE for a table.
Both the truncate and delete command have the desired outcome of getting rid of all the rows
in a table. The difference between the two is that the truncate command is a DDL operation
and just moves the high water mark and produces a now rollback. The delete command, on the
other hand, is a DML operation, which will produce a rollback and thus take longer to
complete.
8. Give the reasoning behind using an index.
Faster access to data blocks in a table.
9. Give the two types of tables involved in producing a star schema and the type of data
they hold.
Fact tables and dimension tables. A fact table contains measurements while dimension tables
will contain data that will help describe the fact tables.
10. . What type of index should you use on a fact table?
A Bitmap index.
11. Give two examples of referential integrity constraints.
A primary key and a foreign key.
12. A table is classified as a parent table and you want to drop and re-create it. How would
you do this without affecting the children tables?

Disable the foreign key constraint to the parent, drop the table, re-create the table, enable
the foreign key constraint.
13. Explain the difference between ARCHIVELOG mode and NOARCHIVELOG mode and the
benefits and disadvantages to each.
ARCHIVELOG mode is a mode that you can put the database in for creating a backup of all
transactions that have occurred in the database so that you can recover to any point in time.
NOARCHIVELOG mode is basically the absence of ARCHIVELOG mode and has the disadvantage
of not being able to recover to any point in time. NOARCHIVELOG mode does have the
advantage of not having to write transactions to an archive log and thus increases the
performance of the database slightly.
14. What command would you use to create a backup control file?
Alter database backup control file to trace.
15. Give the stages of instance startup to a usable state where normal users may access it.
STARTUP NOMOUNT - Instance startup
STARTUP MOUNT - The database is mounted
STARTUP OPEN - The database is opened
16. What column differentiates the V$ views to the GV$ views and how?
The INST_ID column which indicates the instance in a RAC environment the information came
from.
17. How would you go about generating an EXPLAIN plan?
Create a plan table with utlxplan.sql.
Use the explain plan set statement_id = 'tst1' into plan_table for a SQL statement
Look at the explain plan with utlxplp.sql or utlxpls.sql
18. How would you go about increasing the buffer cache hit ratio?
Use the buffer cache advisory over a given workload and then query the v$db_cache_advice
table. If a change was necessary then I would use the alter system set db_cache_size
command.
19. Explain an ORA-01555 ? SNAPSHOT TOO OLD
You get this error when you get a snapshot too old within rollback. It can usually be solved by
increasing the undo retention or increasing the size of rollbacks. You should also look at the
logic involved in the application getting the error message.
20. Explain the difference between $ORACLE_HOME and $ORACLE_BASE.
ORACLE_BASE is the root directory for oracle. ORACLE_HOME located beneath ORACLE_BASE is
where the oracle products reside.

COLD BACKUP Vs HOT BACK UP

A cold backup is when the database is not running - i.e. users are not logged on - hence no
activity going on and easier to backup. This is also known as an offline backup.
In contrast, a hot backup would have to be taken if your database is mission critical, i.e. it has
to run 24 hours a day, 7 days a week. In this case you will have to perform an online or a hot
backup.
Import/export is logical backup (just backing up data and table structrues).
Physical copy of database files (datafiles+controlfiles+redlog files) itself can be divided into
cold and hot backups.
Copying physical files when the database is up is called hot back up. This is achieved by putting
the tablespace in backup mode (available for users) and then copying all the datafile using the
ocopy commands and then bringing it back to normal state.
Alter tablespace begin backup;
host ocopy
Alter tablespace end backup;
Whereas if you copy the same files when the db is down, it is called cold backup.
21. How would you determine the time zone under which a database was operating?
select DBTIMEZONE from dual;
22. Explain the use of setting GLOBAL_NAMES equal to TRUE.
Setting GLOBAL_NAMES dictates how you might connect to a database. This variable is either
TRUE or FALSE and if it is set to TRUE it enforces database links to have the same name as the
remote database to which they are linking.
23. What command would you use to encrypt a PL/SQL application?
WRAP
24. Name three advisory statistics you can collect.
Buffer Cache Advice, Segment Level Statistics, & Timed Statistics.
25. Where in the Oracle directory tree structure are audit traces placed?
In unix $ORACLE_HOME/rdbms/audit, in Windows the event viewer
28. Explain materialized views and how they are used.
Materialized views are objects that are reduced sets of information that have been

summarized, grouped, or aggregated from base tables. They are typically used in data
warehouse or decision support systems.
29. When a user process fails, what background process cleans up after it?
PMON
30. What background process refreshes materialized views?
The Job Queue Processes.
31. How would you determine what sessions are connected and what resources they are
waiting for?
Use of V$SESSION and V$SESSION_WAIT
32. Describe what redo logs are.
Redo logs are logical and physical structures that are designed to hold all the changes made to
a database and are intended to aid in the recovery of a database.
33. How would you force a log switch?
ALTER SYSTEM SWITCH LOGFILE;
34. Give two methods you could use to determine what DDL changes have been made.
You could use Logminer or Streams
35. What does coalescing a tablespace do?
Coalescing is only valid for dictionary-managed tablespaces and de-fragments space by
combining neighboring free extents into large single extents.
36. What is the difference between a TEMPORARY tablespace and a PERMANENT
tablespace?
A temporary tablespace is used for temporary objects such as sort structures while permanent
tablespaces are used to store those objects meant to be used as the true objects of the
database.
37. Name a tablespace automatically created when you create a database.
The SYSTEM tablespace.
38. When creating a user, what permissions must you grant to allow them to connect to the
database?
Grant the CONNECT to the user.
39. How do you add a data file to a tablespace?
ALTER TABLESPACE ADD DATAFILE SIZE
40. How do you resize a data file?

ALTER DATABASE DATAFILE RESIZE ; (old method )


ALTER DATABASE DATAFILE /tmp/ash.dbf resize 100M.
While in 10G we can do it like this
ALTER TABLESPACE tbs_name RESIZE 100M .
41. What view would you use to look at the size of a data file?
DBA_DATA_FILES
42. What view would you use to determine free space in a tablespace?
DBA_FREE_SPACE
43. How would you determine who has added a row to a table?
Turn on fine grain auditing for the table.
44. How can you rebuild an index?
ALTER INDEX REBUILD;
45. Explain what partitioning is and what its benefit is.
Partitioning is a method of taking large tables and indexes and splitting them into smaller,
more manageable pieces.
46. You have just compiled a PL/SQL package but got errors, how would you view the
errors?
SHOW ERRORS
47. How can you gather statistics on a table?
The ANALYZE command.
48. How can you enable a trace for a session?
Use the DBMS_SESSION.SET_SQL_TRACE or
Use ALTER SESSION SET SQL_TRACE = TRUE;
49. What is the difference between the SQL*Loader and IMPORT utilities?
These two Oracle utilities are used for loading data into the database. The difference is that
the import utility relies on the data being produced by another Oracle utility EXPORT while the
SQL*Loader utility allows data to be loaded that has been produced by other utilities from
different data sources just so long as it conforms to ASCII formatted or delimited files.
50. Name two files used for network connection to a database.
TNSNAMES.ORA and SQLNET.ORA

How does one create a new database?


One can create and modify Oracle databases using the Oracle "dbca" (Database Configuration
Assistant) utility. The dbca utility is located in the $ORACLE_HOME/bin directory. The Oracle
Universal Installer (oui) normally starts it after installing the database server software to create
the starter database.
One can also create databases manually using scripts. This option, however, is falling out of
fashion as it is quite involved and error prone. Look at this example for creating and Oracle 9i or
higer database:
CONNECT SYS AS SYSDBA
ALTER SYSTEM SET DB_CREATE_FILE_DEST='/u01/oradata/';
ALTER SYSTEM SET DB_CREATE_ONLINE_LOG_DEST_1='/u02/oradata/';
ALTER SYSTEM SET DB_CREATE_ONLINE_LOG_DEST_2='/u03/oradata/';
CREATE DATABASE;

Back to top of file

How does one rename a database?


Follow these steps to rename a database:
1. Start by making a full database backup of your database (in case you need to restore if this
procedure is not working).
2. Execute this command from sqlplus while connected to 'SYS AS SYSDBA':
ALTER DATABASE BACKUP CONTROLFILE TO TRACE RESETLOGS;

2. Locate the latest dump file in your USER_DUMP_DEST directory (show parameter
USER_DUMP_DEST) - rename it to something like dbrename.sql.
3. dbrename.sql, remove all headers and comments, and change the database's name. Also
change "CREATE CONTROLFILE REUSE ..." to "CREATE CONTROLFILE SET ...".
4. Shutdown the database (use SHUTDOWN NORMAL or IMMEDIATE, don't ABORT!) and run
dbrename.sql.
5. Rename the database's global name:
ALTER DATABASE RENAME GLOBAL_NAME TO new_db_name;

Back to top of file

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 use smaller block sizes, but the performance cost is significant. Your
choice should depend on the type of application you are running. If you have many small
transactions as with OLTP, use a smaller block size. With fewer but larger transactions, as with a
DSS application, use a larger block size.
If you are using a volume manager, consider your "operating system block size" to be 8K. This is
because volume manager products use 8K blocks (and this is not configurable).
Back to top of file

How does one 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. With Oracle 7.3 one can manually coalesce a tablespace using the ALTER
TABLESPACE ... COALESCE; command, until then use:
SQL> alter session set events 'immediate trace name coalesce level n';
where 'n' is the tablespace number you get from SELECT TS#, NAME FROM SYS.TS$;
You can get status information about this process by selecting from the
SYS.DBA_FREE_SPACE_COALESCED dictionary view.
Back to top of file

How does one 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.
Thiru Vadivelu contributed the following:
Use the same extent size for all the segments in a given tablespace. Locally Managed
tablespaces (available from 8i onwards) with uniform extent sizes virtually eliminates any
tablespace fragmentation. Note that the number of extents per segment does not cause any

performance issue anymore, unless they run into thousands and thousands where additional I/O
may be required to fetch the additional blocks where extent maps of the segment are stored.
Back to top of file

Where can one find the high water mark for a table?
There is no single system table which contains the high water mark (HWM) for a table. A table's
HWM can be calculated using the results from the following SQL statements:
SELECT BLOCKS
FROM

DBA_SEGMENTS

WHERE

OWNER=UPPER(owner) AND SEGMENT_NAME = UPPER(table);

ANALYZE TABLE owner.table ESTIMATE STATISTICS;

SELECT EMPTY_BLOCKS
FROM

DBA_TABLES

WHERE

OWNER=UPPER(owner) AND TABLE_NAME = UPPER(table);

Thus, the tables' HWM = (query result 1) - (query result 2) - 1


NOTE: You can also use the DBMS_SPACE package and calculate the HWM = TOTAL_BLOCKS
- UNUSED_BLOCKS - 1.
Back to top of file

How are extents allocated to a segment?


Oracle8 and above rounds off extents to a multiple of 5 blocks when more than 5 blocks are
requested. If one requests 16K or 2 blocks (assuming a 8K block size), Oracle doesn't round it up
to 5 blocks, but it allocates 2 blocks or 16K as requested. If one asks for 8 blocks, Oracle will
round it up to 10 blocks.
Space allocation also depends upon the size of contiguous free space available. If one asks for 8
blocks and Oracle finds a contiguous free space that is exactly 8 blocks, it would give it you. If it is
9 blocks, Oracle would also give it to you. Clearly Oracle doesn't always round extents to a
multiple of 5 blocks.
The exception to this rule is locally managed tablespaces. If a tablespace is created with local
extent management and the extent size is 64K, then Oracle allocates 64K or 8 blocks assuming
8K block size. Oracle doesn't round it up to the multiple of 5 when a tablespace is locally
managed.
Back to top of file

Can one rename a database user (schema)?


No, this is listed as Enhancement Request 158508. Workaround:
Do a user-level export of user A
create new user B
import system/manager fromuser=A touser=B
drop user A

Back to top of file

Can one rename a tablespace?


No, this is listed as Enhancement Request 148742. Workaround:
Export all of the objects from the tablespace
Drop the tablespace including contents
Recreate the tablespace
Import the objects

Back to top of file

Can one resize tablespaces and data files?


One can manually increase or decrease the size of a datafile from Oracle 7.2 using the
ALTER DATABASE DATAFILE 'filename2' RESIZE 100M;

command.
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 estimations 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
DEFAULT STORAGE (

MAXSIZE UNLIMITED

INITIAL 10240
NEXT 10240
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0)

ONLINE
PERMANENT;

Back to top of file

How does one create a standby database?


While your production database is running, take an (image copy) backup and restore it on
duplicate hardware. Note that an export will not work!!!
On your standby database, issue the following commands:
ALTER DATABASE CREATE STANDBY CONTROLFILE AS 'file_name';
ALTER DATABASE MOUNT STANDBY DATABASE;
RECOVER STANDBY DATABASE;

On systems prior to Oracle 8i, write a job to copy archived redo log files from the primary
database to the standby system, and apply the redo log files to the standby database (pipe it).
Remember the database is recovering and will prompt you for the next log file to apply.
Oracle 8i onwards provide an "Automated Standby Database" feature which will send archived
log files to the remote site via NET8, and apply then to the standby database.
When one needs to activate the standby database, stop the recovery process and activate it:
ALTER DATABASE ACTIVATE STANDBY DATABASE;

Back to top of file

How does one give developers access to trace files


(required as input to tkprof)?

The "alter session set sql_trace=true" command generates trace files in


USER_DUMP_DEST that can be used by developers as input to tkprof. On Unix the default file
mask for these files are "rwx r-- ---".
There is an undocumented INIT.ORA parameter that will allow everyone to read (rwx r-- r--) these
trace files:
_trace_files_public = true

Include this in your INIT.ORA file and bounce your database for it to take effect.
Thanks to Erlie

Flynn

Back to top of file

How does one see the uptime for a database?


Look at the following SQL query:
SELECT to_char(startup_time,'DD-MON-YYYY HH24:MI:SS') "DB Startup
Time"
FROM

sys.v_$instance;

Marco Bergman provided the following alternative solution:


SELECT to_char(logon_time,'Dy dd Mon HH24:MI:SS') "DB Startup Time"
FROM

sys.v_$session

WHERE

sid=1

/* this is pmon */

Users still running on Oracle 7 can try one of the following queries:
column STARTED format a18 head 'STARTUP TIME'
select C.INSTANCE,
to_date(JUL.VALUE, 'J')
|| to_char(floor(SEC.VALUE/3600),

'09'

|| ':'
-- || substr (to_char(mod(SEC.VALUE/60, 60), '09'), 2, 2)
|| substr (to_char(floor(mod(SEC.VALUE/60, 60)), '09'), 2, 2)
|| '.'
|| substr (to_char(mod(SEC.VALUE,
from SYS.V_$INSTANCE JUL,

60), '09'), 2, 2)

STARTED

SYS.V_$INSTANCE SEC,
SYS.V_$THREAD

where JUL.KEY like '%JULIAN%'


and SEC.KEY like '%SECOND%';

select

to_date(JUL.VALUE, 'J')
|| to_char(to_date(SEC.VALUE, 'SSSSS'), ' HH24:MI:SS') STARTED

from SYS.V_$INSTANCE JUL,


SYS.V_$INSTANCE SEC
where JUL.KEY like '%JULIAN%'
and SEC.KEY like '%SECOND%';

select

to_char(to_date(JUL.VALUE, 'J') + (SEC.VALUE/86400), -- Return

a DATE
'DD-MON-YY HH24:MI:SS') STARTED
from V$INSTANCE JUL,
V$INSTANCE SEC
where JUL.KEY like '%JULIAN%'
and SEC.KEY like '%SECOND%';

(Last 2 queries contributed by Carl Lindberg)


Back to top of file

Where are my TEMPFILES, I dont see them in


V$DATAFILE or DBA_DATA_FILE?
Tempfiles, unlike normal datafiles, are not listed in v$datafile or dba_data_files. Instead query
v$tempfile or dba_temp_files:
SELECT * FROM v$tempfile;
SELECT * FROM dba_temp_files;

Back to top of file

How do I find used/free space in a TEMPORARY


tablespace?

Unlike normal tablespaces, true temporary tablespace information is not listed in


DBA_FREE_SPACE. Instead use the V$TEMP_SPACE_HEADER view:
SELECT tablespace_name, SUM(bytes_used), SUM(bytes_free)
FROM

V$temp_space_header

GROUP

BY tablespace_name;

Back to top of file

How can one see who is using a temporary segment?


For every user using temporary space, there is an entry in SYS.V$_LOCK with type 'TS'.
All temporary segments are named 'ffff.bbbb' where 'ffff' is the file it is in and 'bbbb' is first block of
the segment.
If your temporary tablespace is set to TEMPORARY, all sorts are done in one large temporary
segment. For usage stats, see SYS.V_$SORT_SEGMENT
From Oracle 8.0, one can just query SYS.v$sort_usage. Look at these examples:
select s.username, u."USER", u.tablespace, u.contents, u.extents,
u.blocks
from

sys.v_$session s, sys.v_$sort_usage u

where

s.saddr = u.session_addr

select s.osuser, s.process, s.username, s.serial#,


sum(u.blocks)*vp.value/1024 sort_size
from

sys.v_$session s, sys.v_$sort_usage u, sys.v_$parameter vp

where

s.saddr = u.session_addr

and

vp.name = 'db_block_size'

and

s.osuser like '&1'

group

by s.osuser, s.process, s.username, s.serial#, vp.value

Back to top of file

How does one get the view definition of fixed


views/tables?

Query v$fixed_view_definition. Example:


SELECT * FROM v$fixed_view_definition WHERE view_name='V$SESSION';

What strategies are available for backing-up an Oracle


database?
The following methods are valid for backing-up an Oracle database:
Export/Import - Exports are "logical" database backups in that they extract logical definitions and

data from the database to a file. See the Import/ Export FAQ for more details.
Cold or Off-line Backups - Shut the database down and backup up ALL data, log, and control
files.
Hot or On-line Backups - If the database is available and in ARCHIVELOG mode, set the
tablespaces into backup mode and backup their files. Also remember to backup the control files
and archived redo log files.
RMAN Backups - While the database is off-line or on-line, use the "rman" utility to backup the
database.

It is advisable to use more than one of these methods to backup your database. For example, if
you choose to do on-line database backups, also cover yourself by doing database exports. Also
test ALL backup and recovery scenarios carefully. It is better to be safe than sorry.
Regardless of your strategy, also remember to backup all required software libraries, parameter
files, password files, etc. If your database is in ARCHIVELOG mode, you also need to backup
archived log files.
Back to top of file

What is the difference between on-line and off-line


backups?
A hot backup is a backup performed while the database is on-line and available for read/write.
Except for Oracle exports, one can only do on-line backups when running in ARCHIVELOG
mode.
A cold backup is a backup performed while the database is off-line and unavailable to its users.
Back to top of file

What is the difference between restoring and


recovering?

Restoring involves copying backup files from secondary storage (backup media) to disk. This can
be done to replace damaged files or to copy/move a database to a new location.
Recovery is the process of applying redo logs to the database to roll it forward. One can rollforward until a specific point-in-time (before the disaster occurred), or roll-forward until the last
transaction recorded in the log files.
sql> connect SYS as SYSDBA
sql> RECOVER DATABASE UNTIL TIME '2001-03-06:16:00:00' USING BACKUP
CONTROLFILE;

Back to top of file

How does one backup a database using the export


utility?
Oracle exports are "logical" database backups (not physical) as they extract data and logical
definitions from the database into a file. Other backup strategies normally back-up the physical
data files.
One of the advantages of exports is that one can selectively re-import tables, however one
cannot roll-forward from a restored export file. To completely restore a database from an
export file one practically needs to recreate the entire database.
Always do full system level exports (FULL=YES). Full exports include more information about the
database in the export file than user level exports. For more information about the Oracle export
and import utilities, see the Import/ Export FAQ.
Back to top of file

How does one do off-line database backups?


Shut down the database from sqlplus or server manager. Backup all files to secondary storage
(eg. tapes). Ensure that you backup all data files, all control files and all log files. When
completed, restart your database.
Do the following queries to get a list of all files that needs to be backed up:
select name from sys.v_$datafile;
select member from sys.v_$logfile;
select name from sys.v_$controlfile;

Sometimes Oracle takes forever to shutdown with the "immediate" option. As workaround to this
problem, shutdown using these commands:
alter system checkpoint;

shutdown abort
startup restrict
shutdown immediate

Note that if you database is in ARCHIVELOG mode, one can still use archived log files to roll
forward from an off-line backup. If you cannot take your database down for a cold (off-line)
backup at a convenient time, switch your database into ARCHIVELOG mode and perform hot
(on-line) backups.
Back to top of file

How does one do on-line database backups?


Each tablespace that needs to be backed-up must be switched into backup mode before copying
the files out to secondary storage (tapes). Look at this simple example.
ALTER TABLESPACE xyz BEGIN BACKUP;
! cp xyfFile1 /backupDir/
ALTER TABLESPACE xyz END BACKUP;

It is better to backup tablespace for tablespace than to put all tablespaces in backup mode.
Backing them up separately incurs less overhead. When done, remember to backup your control
files. Look at this example:

ALTER SYSTEM SWITCH LOGFILE;


file headers

-- Force log switch to update control

ALTER DATABASE BACKUP CONTROLFILE TO '/backupDir/control.dbf';

NOTE: Do not run on-line backups during peak processing periods. Oracle will write complete
database blocks instead of the normal deltas to redo log files while in backup mode. This will lead
to excessive database archiving and even database freezes.
Back to top of file

How does one backup a database using RMAN?


The biggest advantage of RMAN is that it will only backup used space in the database. Rman
doesn't put tablespaces in backup mode, saving on redo generation overhead. RMAN will re-read
database blocks until it gets a consistent image of it. Look at this simple backup example.
rman target sys/*** nocatalog
run {
allocate channel t1 type disk;
backup
format '/app/oracle/db_backup/%d_t%t_s%s_p%p'

( database );
release channel t1;
}

Example RMAN restore:


rman target sys/*** nocatalog
run {
allocate channel t1 type disk;
# set until time 'Aug 07 2000 :51';
restore tablespace users;
recover tablespace users;
release channel t1;
}

The examples above are extremely simplistic and only useful for illustrating basic concepts. By
default Oracle uses the database controlfiles to store information about backups. Normally one
would rather setup an RMAN catalog database to store RMAN metadata in. Read the Oracle
Backup and Recovery Guide before implementing any RMAN backups.
Note: RMAN cannot write image copies directly to tape. One needs to use a third-party media
manager that integrates with RMAN to backup directly to tape. Alternatively one can backup to
disk and then manually copy the backups to tape.
Back to top of file

How does one put a database into ARCHIVELOG mode?


The main reason for running in archivelog mode is that one can provide 24-hour availability and
guarantee complete data recoverability. It is also necessary to enable ARCHIVELOG mode
before one can start to use on-line database backups.
To enable ARCHIVELOG mode, simply change your database startup command script, and
bounce the database:
SQLPLUS> connect sys as sysdba
SQLPLUS> startup mount exclusive;
SQLPLUS> alter database archivelog;
SQLPLUS> archive log start;
SQLPLUS> alter database open;

NOTE1: Remember to take a baseline database backup right after enabling archivelog mode.
Without it one would not be able to recover. Also, implement an archivelog backup to prevent the
archive log directory from filling-up.
NOTE2: ARCHIVELOG mode was introduced with Oracle V6, and is essential for database pointin-time recovery. Archiving can be used in combination with on-line and off-line database
backups.
NOTE3: You may want to set the following INIT.ORA parameters when enabling ARCHIVELOG
mode: log_archive_start=TRUE, log_archive_dest=..., and log_archive_format=...
NOTE4: You can change the archive log destination of a database on-line with the ARCHIVE
LOG START TO 'directory'; statement. This statement is often used to switch archiving between a
set of directories.
NOTE5: When running Oracle Real Application Server (RAC), you need to shut down all nodes
before changing the database to ARCHIVELOG mode. See the RAC FAQ for more details.
Back to top of file

How does one backup archived log files?


One can backup archived log files using RMAN or any operating system backup utility.
Remember to delete files after backing them up to prevent the archive log directory from filling up.
If the archive log directory becomes full, your database will hang! Look at this simple RMAN
backup script:
RMAN> run {
2> allocate channel dev1 type disk;
3> backup
4>

format '/app/oracle/arch_backup/log_t%t_s%s_p%p'

5>

(archivelog all delete input);

6> release channel dev1;


7> }

Back to top of file

Does Oracle write to data files in begin/hot backup


mode?
Oracle will stop updating file headers, but will continue to write data to the database files even if a
tablespace is in backup mode.
In backup mode, Oracle will write out complete changed blocks to the redo log files. Normally
only deltas (changes) are logged to the redo logs. This is done to enable reconstruction of a block

if only half of it was backed up (split blocks). Because of this, one should notice increased log
activity and archiving during on-line backups.
Back to top of file

My database was terminated while in BACKUP MODE,


do I need to recover?
If a database was terminated while one of its tablespaces was in BACKUP MODE (ALTER
TABLESPACE xyz BEGIN BACKUP;), it will tell you that media recovery is required when you try
to restart the database. The DBA is then required to recover the database and apply all archived
logs to the database. However, from Oracle7.2, you can simply take the individual datafiles out of
backup mode and restart the database.
ALTER DATABASE DATAFILE '/path/filename' END BACKUP;

One can select from V$BACKUP to see which datafiles are in backup mode. This normally saves
a significant amount of database down time. See script end_backup2.sql in the script section of
this FAQ.
Thiru Vadivelu contributed the following:
From Oracle9i onwards, the following command can be used to take all of the datafiles out of
hotbackup mode:
ALTER DATABASE END BACKUP;

The above command needs to be issued when the database is mounted.


Back to top of file

My database is down and I cannot restore. What now?


Recovery without any backup is normally not supported, however, Oracle Consulting can
sometimes extract data from an off-line database using a utility called DUL (Disk UnLoad). This
utility reads data in the data files and unloads it into SQL*Loader or export dump files. DUL does
not care about rollback segments, corrupted blocks, etc, and can thus not guarantee that the data
is not logically corrupt. It is intended as an absolute last resort and will most likely cost your
company a lot of money!!!
"Life is DUL without it!"
Back to top of file

I've lost my REDOLOG files, how can I get my DB back?

The following INIT.ORA parameter may be required if your current redologs are corrupted or
blown away. Caution is advised when enabling this parameter as you might end-up losing your
entire database. Please contact Oracle Support before using it.
_allow_resetlogs_corruption = true

Back to top of file

I've lost some Rollback Segments, how can I get my DB


back?
Re-start your database with the following INIT.ORA parameter if one of your rollback segments is
corrupted. You can then drop the corrupted rollback segments and create it from scratch. Caution
is advised when enabling this parameter as uncommitted transactions will be marked as
committed. One can very well end up with lost or inconsistent data!!! Please contact Oracle
Support before using it.
_corrupted_rollback_segments = (rbs01,rbs01,rbs03,rbs04)

Back to top of file

What are the differences between EBU and RMAN?


Enterprise Backup Utility (EBU) is a functionally rich, high performance interface for backing up
Oracle7 databases. It is sometimes referred to as OEBU for Oracle Enterprise Backup Utility.
The Oracle Recovery Manager (RMAN) utility that ships with Oracle8 and above is similar to
Oracle7's EBU utility. However, there is no direct upgrade path from EBU to RMAN.
Back to top of file

How does one create an RMAN recovery catalog?


Start by creating a database schema (usually called rman). Assign an appropriate tablespace to it
and grant it the recovery_catalog_owner role. Look at this example:
sqlplus sys
SQL> create user rman identified by rman;
SQL> alter user rman default tablespace tools temporary tablespace
temp;
SQL> alter user rman quota unlimited on tools;
SQL> grant connect, resource, recovery_catalog_owner to rman;

SQL> exit;

Next, log in to rman and create the catalog schema. Prior to Oracle 8i this was done by running
the catrman.sql script.
rman catalog rman/rman
RMAN> create catalog tablespace tools;
RMAN> exit;

You can now continue by registering your databases in the catalog. Look at this example:

rman catalog rman/rman target backdba/backdba


RMAN> register database;

Back to top of file

What are the common RMAN errors (with solutions)?


Some of the common RMAN errors are:
RMAN-20242: Specification does not match any archivelog in the recovery catalog.
Add to RMAN script: sql 'alter system archive log current';
RMAN-06089: archived log xyz not found or out of sync with catalog
Execute from RMAN: change archivelog all validate;
Back to top of file

What third party tools can be used with Oracle EBU/


RMAN?
The following Media Management Software Vendors have integrated their media management
software packages with Oracle Recovery Manager and Oracle7 Enterprise Backup Utility. The
Media Management Vendors will provide first line technical support for the integrated
backup/recover solutions.
Veritas NetBackup
EMC Data Manager (EDM)
HP OMNIBack II
IBM's Tivoli Storage Manager - formerly ADSM
Legato Networker
ManageIT Backup and Recovery
Sterling Software's SAMS:Alexandria - formerly from Spectralogic
Sun Solstice Backup
CommVault
etc...
Back to top of file

How does one create a new database?


One can create and modify Oracle databases using the Oracle DBCA (Database
Configuration Assistant) utility. The dbca utility is located in the $ORACLE_HOME/bin
directory. The Oracle Universal Installer (oui) normally starts it after installing the
database server software to create the starter database.
One can also create databases manually using scripts. This option, however, is falling out
of fashion as it is quite involved and error prone. Look at this example for creating and
Oracle 9i or higher database:
CONNECT SYS AS SYSDBA
ALTER SYSTEM SET DB_CREATE_FILE_DEST='/u01/oradata/';
ALTER SYSTEM SET DB_CREATE_ONLINE_LOG_DEST_1='/u02/oradata/';
ALTER SYSTEM SET DB_CREATE_ONLINE_LOG_DEST_2='/u03/oradata/';
CREATE DATABASE;

Also see Creating a New Database.

What database aspects should be monitored?


One should implement a monitoring system to constantly monitor the following aspects
of a database. This can be achieved by writing custom scripts, implementing Oracle's
Enterprise Manager, or buying a third-party monitoring product. If an alarm is
triggered, the system should automatically notify the DBA (e-mail, text, etc.) to take
appropriate action.
Infrastructure availability:

Is the database up and responding to requests


Are the listeners up and responding to requests
Are the Oracle Names and LDAP Servers up and
responding to requests
Are the Application Servers up and responding to
requests
Etc.

Things that can cause service outages:

Is the archive log destination filling up?


Objects getting close to their max extents
Tablespaces running low on free space/ Objects
what would not be able to extend
User and process limits reached
Etc.

Can one rename a tablespace?


From Oracle 10g Release 1, users can rename tablespaces. Example:
ALTER TABLESPACE ts1 RENAME TO ts2;

However, you must adhere to the following restrictions:

COMPATIBILITY must be set to at least 10.0.1


Cannot rename SYSTEM or SYSAUX
Cannot rename an offline tablespace
Cannot rename a tablespace that contains offline
datafiles

For older releases, use the following workaround:

Export all of the objects from the tablespace


Drop the tablespace including contents
Recreate the tablespace
Import the objects

Can one resize tablespaces and data files?


Add more files to tablespaces
To add more space to a tablespace, one can simply add another file to it. Example:
ALTER TABLESPACE USERS ADD DATAFILE '/oradata/orcl/users1.dbf' SIZE
100M;

Resize datafiles
One can manually increase or decrease the size of a datafile from Oracle 7.2 using the
following command:
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 estimations of space requirements.
Extend datafiles

Also, datafiles can be allowed to automatically extend if more space is required. Look at
the following commands:
CREATE TABLESPACE pcs_data_ts
DATAFILE 'c:ora_appspcspcsdata1.dbf' SIZE 3M
AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED
DEFAULT STORAGE ( INITIAL 10240
NEXT 10240
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0)
ONLINE
PERMANENT;
ALTER DATABASE DATAFILE 1 AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED;

How do I find the overall database size?


The biggest portion of a database's size comes from the datafiles. To find out how many
megabytes are allocated to ALL datafiles:
select sum(bytes)/1024/1024 "Meg" from dba_data_files;

To get the size of all TEMP files:


select nvl(sum(bytes),0)/1024/1024 "Meg" from dba_temp_files;

To get the size of the on-line redo-logs:


select sum(bytes)/1024/1024 "Meg" from sys.v_$log;

Putting it all together into a single query:


select a.data_size+b.temp_size+c.redo_size "total_size"
from ( select sum(bytes) data_size
from dba_data_files ) a,
( select nvl(sum(bytes),0) temp_size
from dba_temp_files ) b,
( select sum(bytes) redo_size
from sys.v_$log ) c;

How do I find the used space within the database size?


Select from the DBA_SEGMENTS or DBA_EXTENTS views to find the used space of a
database. Example:
SELECT SUM(bytes)/1024/1024 "Meg" FROM dba_segments;

For Indexes
ANALYZEINDEXorders_region_id_idx

VALIDATESTRUCTURE;
After running this command, query INDEX_STATSto obtain information about the
index as shown in the following example:
SELECTblocks,pct_used,distinct_keys
lf_rows,del_lf_rows
FROMindex_stats;
Reorganize the index if it has a high proportion of deleted rows. For example: when the
ratio of DEL_LF_ROWS to LF_ROWS exceeds 30%.

Who is using which UNDO or TEMP segment?


Execute the following query to determine who is using a particular UNDO or Rollback
Segment:
SQL> SELECT TO_CHAR(s.sid)||','||TO_CHAR(s.serial#) sid_serial,
2
NVL(s.username, 'None') orauser,
3
s.program,
4
r.name undoseg,
5
t.used_ublk * TO_NUMBER(x.value)/1024||'K' "Undo"
6
FROM sys.v_$rollname
r,
7
sys.v_$session
s,
8
sys.v_$transaction t,
9
sys.v_$parameter
x
10
WHERE s.taddr = t.addr
11
AND r.usn
= t.xidusn(+)
12
AND x.name = 'db_block_size'
SID_SERIAL ORAUSER
PROGRAM
UNDOSEG
Undo
---------- ---------- ------------------------------ --------------------260,7
SCOTT
sqlplus@localhost.localdomain _SYSSMU4$
8K
(TNS V1-V3)

Execute the following query to determine who is using a TEMP Segment:


SQL> SELECT b.tablespace,
2
ROUND(((b.blocks*p.value)/1024/1024),2)||'M' "SIZE",
3
a.sid||','||a.serial# SID_SERIAL,
4
a.username,
5
a.program
6
FROM sys.v_$session a,
7
sys.v_$sort_usage b,
8
sys.v_$parameter p
9
WHERE p.name = 'db_block_size'
10
AND a.saddr = b.session_addr
11 ORDER BY b.tablespace, b.blocks;

TABLESPACE SIZE
SID_SERIAL USERNAME PROGRAM
---------- ------- ---------- -------- -----------------------------TEMP
24M
260,7
SCOTT
sqlplus@localhost.localdomain
(TNS V1-V3)

How full is the current redo log file?


Here is a query that can tell you how full the current redo log file is. Handy for when you
need to predict when the next log file will be archived out.
SQL> SELECT le.leseq
"Current log sequence No",
2
100*cp.cpodr_bno/le.lesiz "Percent Full",
3
cp.cpodr_bno
"Current Block No",
4
le.lesiz
"Size of Log in Blocks"
5
FROM x$kcccp cp, x$kccle le
6
WHERE le.leseq =CP.cpodr_seq
7
AND bitand(le.leflg,24) = 8
8 /
Current log sequence No Percent Full Current Block No Size of Log in
Blocks
----------------------- ------------ -----------------------------------416
48.6669922
49835
102400

Tired of typing sqlplus '/as sysdba' every time you want


to do something?
If you are tired of typing [i]sqlplus "/as sysdba"[/i] every time you want to perform some
DBA task, implement the following shortcut:
On Unix/Linux systems:
Add the following alias to your .profile or .bash_profile file:
alias sss='sqlplus "/as sysdba"'

On Windows systems:
Create a batch file, sss.bat, add the command to it, and place it somewhere in your PATH.
Whenever you now want to start sqlplus as sysdba, just type "sss". Much less typing for
ya lazy DBA's.
Note: From Oracle 10g you don't need to put the "/AS SYSDBA" in quotes anymore.

What patches are installed within an Oracle Home?

DBA's often do not document the patches they install. This may lead to situations where a
feature works on machine X, but not on machine Y. This FAQ will show how you can list
and compare the patches installed within your Oracle Homes.
All patches that are installed with Oracle's OPatch Utility (Oracle's Interim Patch
Installer) can be listed by invoking the opatch command with the lsinventory option.
Here is an example:
$ cd $ORACLE_HOME/OPatch
$ opatch lsinventory
Invoking OPatch 10.2.0.1.0
Oracle interim Patch Installer version 10.2.0.1.0
Copyright (c) 2005, Oracle Corporation. All rights reserved..
...
Installed Top-level Products (1):
Oracle Database 10g
There are 1 products installed in this Oracle Home.
There are no Interim patches installed in this Oracle Home.

10.2.0.1.0

OPatch succeeded.

NOTE: If OPatch is not installed into your Oracle Home ($ORACLE_HOME/OPatch),


you may need to download it from Metalink and install it yourself.

You might also like