Professional Documents
Culture Documents
There are several system views that can provide us with information
reguarding archives, such as:
V$DATABASE
Identifies whether the database is in ARCHIVELOG or NOARCHIVELOG
mode and whether MANUAL (archiving mode) has been specified.
V$ARCHIVED_LOG
Displays historical archived log information from the control file. If you
use a recovery catalog, the RC_ARCHIVED_LOG view contains similar
information.
V$ARCHIVE_DEST
Describes the current instance, all archive destinations, and the current
value, mode, and status of these destinations.
V$ARCHIVE_PROCESSES
Displays information about the state of the various archive processes
for an instance.
V$BACKUP_REDOLOG
Contains information about any backups of archived logs. If you use a
recovery catalog, the RC_BACKUP_REDOLOG contains similar
information.
V$LOG
Displays all redo log groups for the database and indicates which need
to be archived.
V$LOG_HISTORY
Contains log history information such as which logs have been archived
and the SCN range for each archived log.
Using these tables we can verify that we are infact in ARCHIVELOG
mode:
SQL> select log_mode from v$database;
LOG_MODE
a
-----------ARCHIVELOG
SQL> select DEST_NAME,STATUS,DESTINATION from V$ARCHIVE_DEST
8)How do you enable automatic archiving
A: SQL> shutdown
SQL> startup mount
SQL> alter database archivelog;
SQL> alter database open;
9)How do you do manual archiving
A: SQL>startup mount
SQL>alter database archivelog manual;
SQL> archive log list
10)How do you set the archive file format
11)What is the physical structure of your database
12)How do you verify whether instance is using pfile or spfile
A: 1) SELECT name, value FROM v$parameter WHERE name =
'spfile'; //This query will return NULL if you are using PFILE
2) SHOW PARAMETER spfile // This query will returns NULL in the value
column if you are using pfile and not spfile
3) SELECT COUNT(*) FROM v$spparameter WHERE value IS NOT
NULL; // if the count is non-zero then the instance is using a spfile, and
if the count is zero then it is using a pfile:
By Default oracle will look into the default location depends on the o/s.
Like in unix, oracle will check in $oracle_home/dbs directory and on
windows it will check in oracle_home/database directory, and the
content of pfile is just text based, but spfile content is in binary format,
that is understandable by oracle very well.
13)How do you start an instance with spfile
A: SQL> startup pfile=\\C0027\database\SPFILEZWEITEDB.ORA
14)How do you start an instance with pfile
15)How do you read the contents of spfilesss &
A: i could read the content of the spfile with , Vi editor
16)How do you change the contents of spfile
a
Description
@ ORACLE_HOME/RDBMS/ADMIN/CATALOG.SQL
5) Cloning and Standby Databases
A: Cloning is nothing but the copy of your database which can be open
in read write mode. The standby database is also a copy of your
database which is in standby mode and which is made in sink with
production database by applying the redo log generated at source
database (prodcution database). This database can not be open in read
write mode. This standby database can be mode in read write mode by
activating the database which reset's it's redo log sequence.
6) What is SCN number in Oracle? Plz any one give me the explanation
for SCN
A: The system change number (SCN) is an ever-increasing value that
uniquely identifies a committed version of the database. Every time a
user commits a transaction Oracle records a new SCN. You can obtain
SCNs in a number of ways for example from the alert log. You can then
use the SCN as an identifier for purposes of recovery.
7) Is VARCHAR2 size optimization worthwhile ?
8) How to manager Memory in Oracle Database? How to maximize nos.
of user in Oracle Database?
9) Index tablespace for a Database
A: There is no such provision in oracle to have default index
tablespace. Workaround is- you can have a job which will scan for
indexes in other tablespaces and rebuild into desired one.
10) What are the fixed memory structures inside the SGA?
A: Part of the SGA contains general information about the state of the
database and the instance which the background processes need to
access; this is called the fixed SGA. No user data is stored here. The
SGA also includes information communicated between processes such
as locking information.
With the dynamic SGA infrastructure the size of the buffer cache the
shared pool the large pool and the process-private memory can be
changed without shutting down the instance.
Dynamic SGA allows Oracle to set at run time limits on how much
virtual memory Oracle uses for the SGA. Oracle can start instances
underconfigured and allow the instance to use more memory by
growing the SGA components up to a maximum of SGA_MAX_SIZE.
LGWR writes:
1) COMMIT/ ROLLBACK
2) 1 MB of large transaction
3) Before DBWR writes
4) 1/3 of REDO LOG is full
5) time out occurs
6) Check Point encounters whenever commit,checkpoint or redolog
buffer is 1/3rd full
24) Which process writes data from data files to database buffer
cache?
25) what is the difference between local managed tablespace &
dictionary managed tablespace ?
A: The basic diff between a locally managed tablespace and a
dictionary managed tablespace is that in the dictionary managed
tablespace every time a extent is allocated or deallocated data
dictionary is updated which increases the load on data dictionary while
in case of locally managed tablespace the space information is kept
inside the datafile in the form of bitmaps every time a extent is
allocated or deallocated only the bitmap is updated which removes
burden from data dictionary.
26) What is clusters ?
A: A cluster is a data structure that improves retrieval performance. A
cluster, like an index, does not affect the logical view of the table. A
cluster is a way of storing related data values together on disk. Oracle
reads data a block at a time, so storing related values together reduces
the number of I/O operations needed to retrieve related values, since a
single data block will contain only related rows.
A cluster is composed of one or more tables. The cluster includes a
cluster index, which stores all the values for the corresponding cluster
key. Each value in the cluster index points to a data block that contains
only rows with the same value for the cluster key.
27) What is an extent
28) Database Auto extend question
A: This is an Interview Question By BMC Software.. " while installing the
Oracle 9i ( 9.2) version, automatically system takes the space of
approximately 4 GB.. thats fine.... Now, if my database is growing up
and it is reaching the 4GB of my database space...Now, i would like to
a
sessions marked for Virtual Index usage will become aware of their
existence.
3. Such indexes will be used only when the hidden parameter
_use_nosegment_indexes is set to true.
36) HOW 2 ENABLE PARTITIONING FEAUTURE IN ORACLE 8i
37) You have taken import of a table in a database. you have got the
Integrity constraint violation error. How you are going to resolve it.
A: use this DDL statement in create table script to avoid integrity
constraint violation error DROP TABLE tabl_name CASCADE
CONSTRAINTS ; cascade constraints delete foreign keys associated
with table and table frees with foreign keys.
38) Why in 10G, when you use real time apply feature in conjunction
with Maximum Protection, you can achive zero data loss, but not zero
database downtime??
A: When you say If the last standby database configured in this mode
becomes unavailable processing stops on the primary database. does
'processing stops' mean committing a transaction stops on the primary
database...if so there is data loss correct?
39) What is ORA-1555?
A: ORA-1555 error can occur in Oracle 10g also even with UNDO
RETENTION GUARANTEE enabled.
ORA-1555 happens when Oracle server process could not find the
block-image in UNDO tablespace for the read-consistency.
40) How can the problem be resolved if a SYSDBA, forgets his
password for logging into enterprise manager?
A: I think there are 2 ways to do that.
1. Login as SYSTEM and change the SYS password by using ALTER
USER.
2. Recreate the password file using orapwd and set
remote_password_file=exclusive and then restart the instance.
41) What is the correct sequence among FETCH, EXECUTE, And PARSE
A: 1. Parse
2. Execute
3. Fetch
42) What is database link
A: A database link is a pointer in the local database that allows you to
access on a remote database.
a
for example: one table have 10000 record but you want to fetch only 5
rows but in that query oracle does the full table scan.
only for 5 rows full table is scan is not a good thing so create a index
on the particular column by this way to tune the datatabse
56) How to find how many database reside in Oracle server in query?
A: select count(*) from v$database;
Or open oratab
57) What process writes from data files to buffer cache?
58) Can you tell something about Oracle password Security?
A: If user authentication is managed by the database security
administrators should develop a password security policy to maintain
database access security. For example database users should be
required to change their passwords at regular intervals and of course
when their passwords are revealed to others. By forcing a user to
modify passwords in such situations unauthorized database access can
be reduced.
Set the ORA_ENCRYPT_LOGIN environment variable to TRUE on the
client machine.
Set the DBLINK_ENCRYPT_LOGIN server initialization parameter to
TRUE.
59) What is the function of redo log
A: redo log is a part of physical structure of oracle. its basic
function is to record all the changesmade to daatabase
information. wheneveer an abnormal shutdown take place
preventing system to update the database changes can be
obtained from redolog and hence the changes are not lost.
60) What is SYSTEM tablespace and when is it created
61) How to DROP an Oracle Database?
A: You can do it at the OS level or go to dbca and click on
delete database
62) what is RAP?
63) Can you start a database without SPfile in oracle 9i?
A:no
a
DBWR_IO_SLAVES
ROLLBACK_SEGMENTS
SORT_AREA_RETAINED_SIZE
DB_BLOCK_LRU_EXTENDED_STATISTICS
SHARED_POOL_RESERVE_SIZE
C:\ORACLE\ORADATA\TSH1\CONTROL01.CTL
C:\ORACLE\ORADATA\TSH1\CONTROL02.CTL
C:\ORACLE\ORADATA\TSH1\CONTROL03.CTL
Change database ID and database name TSH1 to TSH2? (Y/[N]) => Y
Proceeding with operation
Changing database ID from 1024166118 to 1317278975
Changing database name from TSH1 to TSH2
Control File C:\ORACLE\ORADATA\TSH1\CONTROL01.CTL - modified
Control File C:\ORACLE\ORADATA\TSH1\CONTROL02.CTL - modified
a
SHUTDOWN IMMEDIATE
STEP 6: Create a new password file:
orapwd file=c:\oracle\920\database\pwdTSH2.ora password=password
entries=10
STEP 7: Rename the SPFILE to match the new DBNAME.
STEP 8: If you are using Windows you must recreate the service so the
correct name and parameter file are used:
oradim -delete -sid TSH1
oradim -new -sid TSH2 -intpwd password -startmode a -pfile
c:\oracle\920\database\spfileTSH2.ora
If you are using UNIX/Linux simply reset the ORACLE_SID environment
variable:
ORACLE_SID=TSH2; export ORACLE_SID
STEP 9: Alter the listener.ora and tnsnames.ora setting to match the
new database name and restart the listener:
lsnrctl reload
STEP 10: Open the database with RESETLOGS:
STARTUP MOUNT
ALTER DATABASE OPEN RESETLOGS;
STEP 11: Backup the database.
83. What are clusters
84. What is private database link
85. How can be determine the size of the database?
A: select sum(bytes)/1024/1024/1024 Size_in_GB from dba_data_files
86. Can you name few DBMS packages and their use?
A: DBMS_METADATA
DBMS_STATS
a
DBMS_SUPPORT
DBMS_SESSION
87. What is the view name where i can get the space in MB for tables
or views?
88. Assuming today is Monday, how would you use the DBMS_JOB
package to schedule the execution of a given procedure owned by
SCOTT to start Wednesday at 9AM and to run subsequently every other
day at 2AM?
89. How can you check which user has which Role.
A: select * from dba_role_privs order by grantee;
90. How do you find wheather the instance was started with pfile or
spfile
91. What are the Advantages of Using DBCA
A: You can use its wizards to guide you through a selection of options
providing an easy means of creating and tailoring your database. It
allows you to provide varying levels of detail. You can provide a
minimum of input and allow Oracle to make decisions for you,
eliminating the need to spend time deciding how best to set
parameters or structure the database. Optionally, it allows you to be
very specific about parameter settings and file allocations.
92. State new features of Oracle 10g.
93. What spfile/init.ora file parameter exists to force the CBO to make
the execution path of a given statement use an index, even if the index
scan may appear to be calculated as more costly?
A: CBO (Cost Based Optimizer):Generates an execution plan for a SQL
statement
optimizer_index_cost_adj parameter can be set to help CBO to
decide an execution plan which effects the speed of SQL query.
we can also make necessary changes to the following parameters to
effect CBO performance:
optimizer_search_limit & optimizer_max_permutations
94. What is a redo log
a
A: The Primary function of the redo log is to record all changes made to
data.
95. can we create index on long raw column?
A: NO we can't create index on long raw column.
96. What does database do during mounting process?
A: During database mount process, Oracle would check for the
existence of controlfiles mentioned in init.ora file but it wont check the
contents of the controlfile which is done during the opening of
database.
97. What is a database instance and Explain
98. What is Oracle table
99. What are the characteristics of data files
A: A data file can be associated with only one database. Once created
a data file can't change size.One or more data files form a logical unit
of database storage called a tablespace.
71) What are the different types of segments
72) What are the Advantages of Using DBCA
84) What are the types of database links
A: Private Database Link: You can create a private database link in a
specific schema of a database. Only the owner of a private database
link or PL/SQL subprograms in the schema can use a private database
link to access data and database objects in the corresponding remote
database.
Public Database Link : You can create a public database link for a
database. All users and PL/SQL subprograms in the database can use a
public database link to access data and database objects in the
corresponding remote database.
Global Database Link - When an Oracle network uses Oracle Names the
names servers in the system automatically create and manage global
database links for every Oracle database in the network. All users and
PL/SQL subprograms in any database can use a global database link to
access data and database objects in the corresponding remote
database.
85) When can hash cluster used
A: Hash clusters are better choice when a table is often queried with
equality queries. For such queries the specified cluster key value is
a
hashed. The resulting hash key value points directly to the area on disk
that stores the specified rows.
86) What is cluster key
A: The related columns of the tables in a cluster is called the Cluster
Key.
87) What is a private synonym
88) What is an Oracle view
89) What are Schema Objects
A: Schema objects include tables, views, sequences, synonyms,
indexes, clusters, database triggers, procedures, functions packages
and database links.
90) Can a tablespace hold objects from different schemes
A: It can be the only required option is that your tablespace have quota
assigned to any user that want to store objects in it.
91) What is a segment
92) What is row chaining
A: In Circumstances, all of the data for a row in a table may not be able
to fit in the same data block. When this occurs , the data for the row is
stored in a chain of data block (one or more) reserved for that
segment.
93) What is an index and How it is implemented in Oracle database
A: Indexes are used both to improve performence and to ensure
uniquness of a column. Oracle automatically creates an index when a
UNIQUE or PRIMARY key constarints clause is specified in a create
table command.
94) What is a schema
95) What does a control file contains
96) How to define data block size
A: stansard block size which is set with parameter DB_BLOCK_SIZE
cannot be changed after creating database. We can set non standard
parameter size later with parameter DB_nk_BLOCK_SIZE and it can be
changed.
97) What is hash cluster
Program code
Information about a connected session, even if it is not currently active
Information needed during program execution (for example, the current
state of a query from which rows are being fetched)
Information that is shared and communicated among Oracle processes
(for example, locking information)
Cached data that is also permanently stored on peripheral memory (for
example, data blocks and redo log entries)
based upon the feedback I got from many candidates who have
attended interviews in various MNC's
1. Which types of backups you can take in Oracle?
2. A database is running in NOARCHIVELOG mode then which type of
backups you can take?
A: If your Databse is in No Archivelog Mode then you must take a Cold
backup of your Database.
3. Can you take partial backups if the Database is running in
NOARCHIVELOG mode?
4. Can you take Online Backups if the the database is running in
NOARCHIVELOG mode?
A:no
5. How do you bring the database in ARCHIVELOG mode from
NOARCHIVELOG mode?
6. You cannot shutdown the database for even some minutes, then in
which mode you should run the database?
7. Where should you place Archive logfiles, in the same disk where DB
is or another disk?
8. Can you take online backup of a Control file if yes, how?
9. What is a Logical Backup?
10. Should you take the backup of Logfiles if the database is running in
ARCHIVELOG mode?
11. Why do you take tablespaces in Backup mode?
12. What is the advantage of RMAN utility?
Advantage over tradition backup system:
1). copies only the filled blocks i.e. even if 1000 blocks is allocated to datafile but 500 are
filled with data then RMAN will only create a backup for that 500 filled blocks.
2). incremental and accumulative backup.
3). catalog and no catalog option.
What is Channel?
Latest Answer : Channel is a link that RMAN requires to link to target database. This link is
required when backup and recovery operations are performed and recorded. This channel can
be allocated manually or can be preconfigured by using automatic channel ...
Recall that an offline backup is a backup of the database while it is not running.
Hence, to perform our backup we will shutdown the database from RMAN and
then mount the database. We will perform the backup. Once the backup is
complete we will restart the database again. Here is an example of this process:
RMAN>shutdown immediate
RMAN>startup mount
RMAN>backup database;
RMAN>sql alter database open;
Once this process is complete, you have completed your first backup
A recovery catalog can be used to store metadata about multiple target databases. The tables
and views constituting a recovery catalog are owned by a recovery catalog schema. Oracle
recommends creating a recovery catalog schema in a separate dedicated database and not in
the target database. A database containing a recovery catalog schema is called a recovery
catalog database.
21. Where RMAN keeps information of backups if you are using RMAN
without Catalog?
A: RMAN keeps information of backups in the control file.
22. You have taken a manual backup of a datafile using o/s. How RMAN
will know about it?
23. You want to retain only last 3 backups of datafiles. How do you go
for it in RMAN?
24. Which is more efficient Incremental Backups using RMAN or
Incremental Export?
25. Can you start and shutdown DB using RMAN?
26. How do you recover from the loss of datafile if the DB is running in
NOARCHIVELOG mode?
27. You loss one datafile and it does not contain important objects. The
important objects are there in other datafiles which are intact. How do
you proceed in this situation?
28. You lost some datafiles and you don't have any full backup and the
database was running in NOARCHIVELOG mode. What you can do now?
29. How do you recover from the loss of datafile if the DB is running in
ARCHIVELOG mode?
30. You loss one datafile and DB is running in ARCHIVELOG mode. You
have full database backup of 1 week old and partial backup of this
datafile which is just 1 day old. From which backup should you restore
this file?
31. You loss controlfile how do you recover from this?
c
32. The current logfile gets damaged. What you can do now?
33. What is a Complete Recovery?
34. What is Cancel Based, Time based and Change Based Recovery?
35. Some user has accidentally dropped one table and you realize this
after two days. Can you recover this table if the DB is running in
ARCHIVELOG mode?
36. Do you have to restore Datafiles manually from backups if you are
doing recovery using RMAN?
37. A database is running in ARCHIVELOG mode since last one month.
A datafile is added to the database last week. Many objects are created
in this datafile. After one week this datafile gets damaged before you
can take any backup. Now can you recover this datafile when you don't
have any backups?
38. How do you recover from the loss of a controlfile if you have
backup of controlfile?
39. Only some blocks are damaged in a datafile. Can you just recover
these blocks if you are using RMAN?
40. Some datafiles were there on a secondary disk and that disk has
become damaged and it will take some days to get a new disk. How
will you recover from this situation?
41. Have you faced any emergency situation. Tell us how you resolved
it?
42. At one time you lost parameter file accidentally and you don't have
any backup. How you will recreate a new parameter file with the
parameters set to previous values.
some more oracle dba interview questions
1. explain the difference between a hot backup and a cold backup and
the
benefits associated with each.
A: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 ball 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?
A:i would create a text based backup control file, stipulating where on
disk all the data files where 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?
a
A: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?
A: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
A: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.
A:oracle_base is the root directory for oracle. oracle_home located
beneath oracle_base is where the oracle products reside.
12.INDEXES-ORACLE
All About Indexes in Oracle
What is an Index?
A:An index is used to increase read access performance. A book,
having an index, allows rapid access to a particular subject area within
that book. Indexing a database table provides rapid location of specific
rows within that table, where indexes are used to optimize the speed of
access to rows. When indexes are not used or are not matched by SQL
statements submitted to that database then a full table scan is
executed. A full table scan will read all the data in a table to find a
specific row or set of rows, this is extremely inefficient when there are
many rows in the table.
*It is often more efficient to full table scan small tables. The optimizer
will often assess full table scan on small tables as being more efficient
than reading both index and data space, particularly where a range
scan rather than an exact match would be used against the index. An
index of columns on a table contains a one-to-one ratio of rows
between index and indexed table, excluding binary key groupings,
a
Types of Indexes
There are different types of indexes available in different databases.
These different indexes are applicable under specific circumstances,
generally for specific search patterns, for instance exact matches or
range matches.
The simplest form of indexing is no index at all, a heap structure. A
heap structure is effectively a collection of data units, rows, which is
completely unordered. The most commonly used indexed structure is a
B tree (Binary Tree). A B tree index is best used for exact matches and
range searches. Other methods of indexing exist.
1. Hashing algorithms produce a pre-calculated best guess on general
row location and are best used for exact matches.
2. ISAM or Indexed Sequential Access Method indexes are not used in
Oracle. 3. Bitmaps contain maps of zero's and 1's and can be highly
efficient access methods for read-only data.
4. There are other types of indexing which involve clustering of data
with indexes. In general every index type other than a B tree involves
overflow. When an index is required to overflow it means that the index
itself cannot be changed when rows are added, changed or removed.
The result is inefficiency because a search to find overflowing data
involves a search through originally indexed rows plus overflowing
rows. Overflow index space is normally not ordered. A B tree index can
be altered by changes to data. The only exception to a B tree index
coping with data changes in Oracle is deletion of rows. When rows are
deleted from a table, physical space previously used by the index for
the deleted row is never reclaimed unless the index is rebuilt.
Rebuilding of B tree indexes is far less common than that for other
types of indexes since non-B tree indexes simply overflow when row
changes are applied to them. Oracle uses has the following types of
indexing available.
B tree index. A B tree is a binary tree. General all-round index and
common in OLTP systems. An Oracle B tree index has three layers, the
first two are branch node layers and the third, the lowest, contains leaf
nodes. The branch nodes contain pointers to the lower level branch or
leaf node. Leaf nodes contain index column values plus a ROWID
pointer to the table row. The branch and leaf nodes are optimally
arranged in the tree such that each branch will contain an equal
number of branch or leaf nodes.
Reverse keys. Bytes for all columns in the index are reversed,
retaining the order of the columns. Reverse keys can help performance
in clustered server environments (Oracle8i Parallel Server / RAC
Oracle9i) by ensuring that changes to similar key values will be better
physically spread. Reverse key indexing can apply to rows inserted into
OLTP tables using sequence integer generators, where each number is
very close to the previous number. When searching for and updating
rows with sequence identifiers, where rows are searched for
Null values. Null values are generally not included in indexes.
Sorting (NOSORT). This option is Oracle specific and does not sort
an index. This assumes that data space is physically ordered in the
desired manner.
What SQL does with Indexes
A:In general a SQL statement will attempt to match the structure of
itself to an index, the where clause ordering will attempt to match
available indexes and use them if possible. If no index is matched then
a full table scan will be executed. A table scan is extremely inefficient
for anything but the smallest of tables. Obviously if a table is read
sequentially, in physical order then an index is not required. A table
does not always need an index.
What to Index
A:Use indexes where frequent queries are performed with where and
order by clause matching the ordering of columns in those indexes.
Use indexing generally on larger tables or multi-table, complex joins.
Indexes are best created in the situations listed below.
Columns used in joins.
Columns used in where clauses.
Columns used in order by clauses.
In most relational databases the order-by clause is generally
executed on the subset retrieved by the where clause, not the entire
data space. This is not always unfortunately the case for Oracle.
Traditionally the order-by clause should never include the columns
contained in the where cause. The only case where the order-by clause
will include columns contained in the where clause is the case of the
where clause not matching any index in the database or a requirement
a
for the order by clause to override the sort order of the where, typically
in highly complex, multi-table joins.
The group-by clause can be enhanced by indexing when the range
of values being
grouped is small in relation to the number of rows in the table selected.
What not to Index
A:Indexes will degrade performance of inserts, updates and deletes,
sometimes
substantially.
Tables with a small number of rows.
Static tables.
Columns with a wide range of values.
Tables changed frequently and with a low amount of data retrieval.
Columns not used in data access query select statements.
Tuning Oracle SQL Code and Using
Indexes
What is SQL Tuning?
A:Tune SQL based on the nature of your application, OLTP or read-only
Data Warehouse. OLTP applications have high volumes of concurrent
transactions and are better served with exact match SQL where many
transactions compete for small amounts of data. Read-only Data
Warehouses require rapid access to large amounts of information at
once and thus many records are accessed at once, either by many or a
small number of sessions.
The EXPLAIN PLAN command can be used to compare different
versions of SQL statements, and tune your application SQL code as
required. When tuning OLTP applications utilize sharing of SQL code in
PL/SQL procedures and do not use triggers unless absolutely necessary.
Triggers can cause problems such as self-mutating transactions where
a table can expect a lock on a row already locked by the same
transaction. This is because triggers do not allow transaction
a
Indexing
A:When building and restructuring of indexing never be afraid of
removing unused indexes.The DBA should always be aware of where
indexes are used and how.
Oracle9i can automatically monitor index usage using the ALTER
INDEX index name [NO]MONITORING USAGE; command with
subsequent selection of the USED column from the V$OBJECT_USAGE
column.
Taking an already constructed application makes alterations of any
kind much more complex. Pay most attention to indexes most often
utilized. Some small static tables may not require indexes at all. Small
static lookup type tables can be cached but will probably be force
table-scanned by the optimizer anyway; table-scans may be adversely
affected by the addition of unused superfluous indexes. Sometimes
table-scans are faster than anything else. Consider the use of
clustering, hashing, bitmaps and even index organized tables, only in
Data Warehouses. Many installations use bitmaps in OLTP databases,
this often a big mistake! If you have bitmap indexes in your OLTP
database and are having performance problems, get rid of them!
Oracle recommends the profligate use of function-based indexes,
assuming of course there will not be too many of them. Do not allow
too many programmers to create their indexes, especially not functionbased indexes, because you could end-up with thousands of indexes.
Application developers tend to be unaware of what other developers
are doing and create indexes specific to a particular requirement where
indexes may be used in only one place. Some DBA control and
approval process must be maintained on the creation of new indexes.
Remember, every table change requires a simultaneous update to all
indexes created based on that table.
SQL Statement Reorganisation
SQL statement reorganization encompasses factors as listed below,
amongst others.
WHERE clause filtering and joining orders matching indexes.
Use of hints is not necessarily a good idea. The optimizer is probably
smarter than you are.
Simplistic SQL statements and minimizing on table numbers in joins.
WHERE UPPER(SUBSTR(table1.name,1,1)) =
UPPER(SUBSTR(table2.name,1,1));
Transforming literal values is not such a problem but application of a
function to a column within a table in a where clause will use a tablescan regardless of the presence of indexes. When using a functionbased index the index is the result of the function which the optimizer
will recognize and utilize for subsequent SQL statements.
Datatypes
Try not to use mixed datatypes by setting columns to appropriate types
in the first place. If mixing of datatypes is essential do not assume
implicit type conversion because it will not always work, and implicit
type conversions can cause indexes not to be used. Function-based
indexes can be used to get around type conversion problems but this is
not the most appropriate use of function-based indexes. If types must
be mixed, try to place type conversion onto explicit values and not
columns. For instance, as shownbelow.
WHERE zip = TO_NUMBER('94066') as opposed to WHERE
TO_CHAR(zip) = '94066'
The DECODE Function
The DECODE function will ignore indexes completely. DECODE is very
useful in certain circumstances where nested looping cursors can
become extremely complex. DECODE is intended for specific
requirements and is not intended to be used prolifically, especially not
with respect to type conversions. Most SQL statements containing
DECODE function usage can be altered to use explicit literal selection
criteria perhaps using separate SELECT statements combined with
UNION clauses. Also Oracle9i contains a CASE statement which is much
more versatile than DECODE and may be much more efficient.
Join Orders
Always use indexes where possible, this applies to all tables accessed
in a join, both those in the driving and nested subqueries. Use indexes
between parent and child nested subqueries in order to utilize indexes
across a join. A common error is that of accessing a single row from the
driving table using an index and then to access all rows from a nested
subquery table where an index can be used in the nested subquery
table based on the rowretrieved by the driving table.
Put where clause filtering before joins, especially for large tables where
only a few rows are required. Try to use indexes fetching the minimum
number of rows. The order in which tables are accessed in a query is
very important. Generally a SQL statement is parsed from toptobottom and from left-to-right. The further into the join or SQL
statement, then the fewer rows should be accessed. Even consider
constructing a SQL statement based on the largest table being the
driving table even if that largest table is not the logical driver of the
SQL statement. When a join is executed, each join will overlay the
result of the previous part of the join, effectively each section (based
on each table) is executed sequentially. In the example below table1
has the most rows and table3 has the fewest rows.
SELECT * FROM table1, table2, table3
WHERE table1.index = table2.index AND table1.index = table3.index;
Hints
Use them? Perhaps. When circumstances force their use. Generally the
optimizer will succeed where you will not. Hints allow, amongst many
other things, forcing of index usage rather than full table-scans. The
optimizer will generally find full scans faster with small tables and
index usage faster with large tables. Therefore if row numbers and the
ratios of row between tables are known then using hints will probably
make performance worse. One specific situation where hints could help
are generic applications where rows in specific tables can change
drastically depending on the installation. However, once again the
optimizer may still be more capable than any programmer or DBA.
Use INSERT, UPDATE and DELETE ... RETURNING
When values are produced and contained in insert or update
statements, such as new sequence numbers or expression results, and
those values are required in the same transaction by following SQL
statements, the values can be returned into variables and used later
without recalculation of expression being required. This tactic would be
used in PL/SQL and anonymous procedures. Examples are shown
below.
INSERT INTO table1 VALUES (test_id.nextval, 'Jim Smith', '100.12',
5*10)
RETURNING col1, col4 * 2 INTO val1, val2;
UPDATE table1 SET name = 'Joe Soap'
a
Views
Do not use views as a basis for SQL statements taking a portion of the
rows defined by that view. Views were originally intended for security
and access privileges. No matter what where clause is applied to a
view the entire view will always be executed first. On the same basis
also avoid things such as SELECT * FROM , GROUP BY clauses and
aggregations such as DISTINCT. DISTINCT will always select all rows
first. Do not create new entities using joined views, it is better to create
those intersection view joins as entities themselves; this applies
particularly in the case of many-to-many relationships. Also Data
Warehouses can benefit from materialized views which are views
actually containing data, refreshed by the operator at a chosen
juncture.
Maintenance of Current Statistics and Cost Based Optimization
Maintain current statistics as often as possible, this can be automated.
Cost-based optimization, using statistics, is much more efficient than
rule-based optimization.
Regeneration and Coalescing of Indexes
Indexes subjected to constant DML update activity can become skewed
and thus become less efficient over a period of time. Use of Oracle
Btree indexes implies that when a value is searched for within the tree,
a series of comparisons are made in order to depth-firsttraverse down
through the tree until the appropriate value is found.
Oracle Btree indexes are usually only three levels, requiring three hits
on the index to find a resulting ROWID pointer to a table row. Index
searches, even into very large tables, especially unique index hits, not
index range scans, can be incredibly fast.In some circumstances
constant updating of a binary tree can cause the tree to becomemore
heavily loaded in some parts or skewed. Thus some parts of the tree
require more intensive searching which can be largely fruitless. Indexes
should sometimes be rebuilt where the binary tree is regenerated from
scratch, this can be done online in Oracle9i, as shown below.
ALTER INDEX index name REBUILD ONLINE;
Coalescing of indexes is a more physical form of maintenance where
physical space chunks which are fragmented. Index fragmentation is
usually a result of massivedeletions from table, at once or over time.
Oracle Btree indexes do not reclaim physical space as a result of row
deletions. This can cause serious performance problems as a result of
a
fruitless searches and very large index files where much of the index
space is irrelevant. The command shown below will do a lot less than
rebuilding but it can help. If PCTINCREASE is not set to zero for the
index then extents could vary in size greatly and not be reusable. In
that the only option is rebuilding.
ALTER INDEX index name REBUILD COALESCE NOLOGGING;
17.DBA BASIC QUESTIONS
1)What are the prerequisites for connecting to a database
> 1) oracle net services should be available in both server and client.
2) listner should up and running. In case of remote connection..
[oracle listiner starts up a dedicated server process and passes the
server protocal adress to client using that address the clients connect
to the server. Once the connection is established the listiner
connection is terminated]
***********************************************************************
[AND]
1) check wether database server is installed on server or not.
2) client software should be installed on client machine.
3) check database and client are running on the same network or not.
(with the help of ping
4) ensure thar oracle listiner is up and running
5) connect to server using server protocal address
2) Create a User "TESTAPPS" identified by "TESTAPPS"
> create user identified by ;
3) Connect to DB using TESTAPPS from DB Node and MT Node
> first give grant options to the user....
grant connect,resource to ;
4)How do you identify remote connections on a DB Server
> ps -ef|grep -i local [where local=no it is a remote connection... in the
os level]
5)How do you identify local connections on a DB Server
> ps -ef|grep -i local [where local=yes it is a local connection... in the
os level]
6)Can you connect remotely as a user on DB Server. If so, how?
> /@ [with the help of connecting string]
7)Do you need to acess to DB Server to connect to a system schema?
> NO , just knowing the username&password u connect from the
a
client...
8)What is the difference between "SYS" & "SYSTEM" Schema
> SYS is a super most user...
SYS has additional roles sysdba, sysoper
SYS can do only startup, shudown options
> SYSTEM schema has owns certain additional data dictonary tables..
SYSTEM donot use startup and shutdown options....
9)What are the roles/priviliges for a "SYS" Schema
>***ROLES***[select granted_role from dba_role_privs where
grantee='SYS']
IMP_FULL_DATABASE, DELETE_CATALOG_ROLE,
RECOVERY_CATALOG_OWNER, DBA, EXP_FULL_DATABASE,
HS_ADMIN_ROLE, AQ_ADMINISTRATOR_ROLE, OEM_MONITOR,
RESOURCE, EXECUTE_CATALOG_ROLE, LOGSTDBY_ADMINISTRATOR,
AQ_USER_ROLE,
SCHEDULER_ADMIN, CONNECT, SELECT_CATALOG_ROLE,
GATHER_SYSTEM_STATISTICS,
OEM_ADVISOR
***PRIVILAGES****[select privileges from dba_sys_privs where
grantee='SYS';]
CREATE ANY RULE
CREATE ANY EVALUATION CONTEXT
MANAGE ANY QUEUE
EXECUTE ANY PROCEDURE
ALTER ANY RULE
CREATE RULE SET
EXECUTE ANY EVALUATION CONTEXT
INSERT ANY TABLE
SELECT ANY TABLE
LOCK ANY TABLE
UPDATE ANY TABLE
DROP ANY RULE SET
ENQUEUE ANY QUEUE
EXECUTE ANY TYPE
CREATE RULE
ALTER ANY EVALUATION CONTEXT
CREATE EVALUATION CONTEXT
ANALYZE ANY
EXECUTE ANY RULE
DROP ANY EVALUATION CONTEXT
EXECUTE ANY RULE SET
a
this relationship.
Bigfile Tablespaces
The SYSTEM Tablespace
The SYSAUX Tablespace
Undo Tablespaces
Default Temporary Tablespace
Using Multiple Tablespaces
Managing Space in Tablespaces
Multiple Block Sizes
Online and Offline Tablespaces
Read-Only Tablespaces
Temporary Tablespaces for Sort Operations
Transport of Tablespaces Between Databases
See Also:
o Chapter 2, "Data Blocks, Extents, and Segments" for more
information about segments and extents
o Oracle Database Administrator's Guide for detailed information on
creating and configuring tablespaces
Bigfile Tablespaces
Oracle lets you create bigfile tablespaces. This allows Oracle Database
to contain tablespaces made up of single large files rather than
numerous smaller ones. This lets Oracle Database utilize the ability of
64-bit systems to create and manage ultralarge files. The consequence
of this is that Oracle Database can now scale up to 8 exabytes in size.
With Oracle-managed files, bigfile tablespaces make datafiles
completely transparent for users. In other words, you can perform
a
Caution:
Do not run any user transactions before creating the first undo
tablespace and taking it online.
Each undo tablespace is composed of a set of undo files and is locally
managed. Like other types of tablespaces, undo blocks are grouped in
extents and the status of each extent is represented in the bitmap. At
any point in time, an extent is either allocated to (and used by) a
transaction table, or it is free.
You can create a bigfile undo tablespace.
Creation of Undo Tablespaces
A database administrator creates undo tablespaces individually, using
the CREATE UNDO TABLESPACE statement. It can also be created when
the database is created, using the CREATE DATABASE statement. A set
of files is assigned to each newly created undo tablespace. Like regular
tablespaces, attributes of undo tablespaces can be modified with the
ALTER TABLESPACE statement and dropped with the DROP TABLESPACE
statement.
Note:
An undo tablespace cannot be dropped if it is being used by any
instance or contains any undo information needed to recover
transactions.
Assignment of Undo Tablespaces
You assign an undo tablespace to an instance in one of two ways:
* At instance startup. You can specify the undo tablespace in the
initialization file or let the system choose an available undo tablespace.
* While the instance is running. Use ALTER SYSTEM SET
UNDO_TABLESPACE to replace the active undo tablespace with another
undo tablespace. This method is rarely used.
You can add more space to an undo tablespace by adding more
datafiles to the undo tablespace with the ALTER TABLESPACE
statement.
You can have more than one undo tablespace and switch between
them. Use the Database Resource Manager to establish user quotas for
undo tablespaces. You can specify the retention period for undo
a
offline
* Perform partial database backup or recovery operations
* Allocate data storage across devices to improve performance
A database administrator can use tablespaces to do the following
actions:
* Create new tablespaces
* Add datafiles to tablespaces
* Set and alter default segment storage settings for segments created
in a tablespace
* Make a tablespace read only or read/write
* Make a tablespace temporary or permanent
* Rename tablespaces
* Drop tablespaces
Managing Space in Tablespaces
Tablespaces allocate space in extents. Tablespaces can use two
different methods to keep track of their free and used space:
* Locally managed tablespaces: Extent management by the tablespace
* Dictionary managed tablespaces: Extent management by the data
dictionary
When you create a tablespace, you choose one of these methods of
space management. Later, you can change the management method
with the DBMS_SPACE_ADMIN PL/SQL package.
Note:
If you do not specify extent management when you create a
tablespace, then the default is locally managed.
Locally Managed Tablespaces
A tablespace that manages its own extents maintains a bitmap in each
datafile to keep track of the free or used status of blocks in that
datafile. Each bit in the bitmap corresponds to a block or a group of
blocks. When an extent is allocated or freed for reuse, Oracle changes
the bitmap values to show the new status of the blocks. These changes
do not generate rollback information because they do not update
tables in the data dictionary (except for special cases such as
tablespace quota information).
Locally managed tablespaces have the following advantages over
a
* If the tablespace containing the tables is offline, then the table data
in the database is not accessible because the tables are required to
access the data.
If Oracle has enough information in the online tablespaces to run a
statement, it does so. If it needs data in an offline tablespace, then it
causes the statement to fail.
Read-Only Tablespaces
The primary purpose of read-only tablespaces is to eliminate the need
to perform backup and recovery of large, static portions of a database.
Oracle never updates the files of a read-only tablespace, and therefore
the files can reside on read-only media such as CD-ROMs or WORM
drives.
Note:
Because you can only bring a tablespace online in the database in
which it was created, read-only tablespaces are not meant to satisfy
archiving requirements.
Read-only tablespaces cannot be modified. To update a read-only
tablespace, first make the tablespace read/write. After updating the
tablespace, you can then reset it to be read only.
Because read-only tablespaces cannot be modified, and as long as
they have not been made read/write at any point, they do not need
repeated backup. Also, if you need to recover your database, you do
not need to recover any read-only tablespaces, because they could not
have been modified.
Temporary Tablespaces for Sort Operations
You can manage space for sort operations more efficiently by
designating one or more temporary tablespaces exclusively for sorts.
Doing so effectively eliminates serialization of space management
operations involved in the allocation and deallocation of sort space. A
single SQL operation can use more than one temporary tablespace for
sorting. For example, you can create indexes on very large tables, and
the sort operation during index creation can be distributed across
multiple tablespaces.
All operations that use sorts, including joins, index builds, ordering,
computing aggregates (GROUP BY), and collecting optimizer statistics,
benefit from temporary tablespaces. The performance gains are
a
This enables fast tempfile creation and resizing; however, the disk
could run of space later when the tempfiles are accessed.
* Tempfile information is shown in the dictionary view DBA_TEMP_FILES
and the dynamic performance view V$TEMPFILE, but not in
DBA_DATA_FILES or the V$DATAFILE view.
Overview of Control Files
The database control file is a small binary file necessary for the
database to start and operate successfully. A control file is updated
continuously by Oracle during database use, so it must be available for
writing whenever the database is open. If for some reason the control
file is not accessible, then the database cannot function properly.
Each control file is associated with only one Oracle database.
Control File Contents
A control file contains information about the associated database that
is required for access by an instance, both at startup and during
normal operation. Control file information can be modified only by
Oracle; no database administrator or user can edit a control file.
Among other things, a control file contains information such as:
*
*
*
*
*
*
*
*
*
*
*
*
dropped from the database, the control file is updated to reflect this
physical structure change. These changes are recorded so that:
* Oracle can identify the datafiles and redo log files to open during
database startup
* Oracle can identify files that are required or available in case
database recovery is necessary
Therefore, if you make a change to the physical structure of your
database (using ALTER DATABASE statements), then you should
immediately make a backup of your control file.
Control files also record information about checkpoints. Every three
seconds, the checkpoint process (CKPT) records information in the
control file about the checkpoint position in the redo log. This
information is used during database recovery to tell Oracle that all redo
entries recorded before this point in the redo log group are not
necessary for database recovery; they were already written to the
datafiles.
19.CONTROLFILES-Oracle DBA
What Is a Control File?
Every Oracle database has a control file. A control file is a small binary
file that records the physical structure of the database and includes:
* The database name
* Names and locations of associated datafiles and online redo log files
* The timestamp of the database creation
* The current log sequence number
* Checkpoint information
The control file must be available for writing by the Oracle database
server whenever the database is open. Without the control file, the
database cannot be mounted and recovery is difficult.
The control file of an Oracle database is created at the same time as
the database. By default, at least one copy of the control file is created
during database creation. On some operating systems the default is to
create multiple copies. You should create two or more copies of the
control file during database creation. You might also need to create
a
control files later, if you lose control files or want to change particular
settings in the control files.
Guidelines for Control Files
This section describes guidelines you can use to manage the control
files for a database, and contains the following topics:
* Provide Filenames for the Control Files
* Multiplex Control Files on Different Disks
* Place Control Files Appropriately
* Back Up Control Files
* Manage the Size of Control Files
Provide Filenames for the Control Files
You specify control file names using the CONTROL_FILES initialization
parameter in the database's initialization parameter file (see "Creating
Initial Control Files"). The instance startup procedure recognizes and
opens all the listed files. The instance writes to and maintains all listed
control files during database operation.
If you do not specify files for CONTROL_FILES before database creation,
and you are not using the Oracle Managed Files feature, Oracle creates
a control file and uses a default filename. The default name is
operating system specific.
Multiplex Control Files on Different Disks
Every Oracle database should have at least two control files, each
stored on a different disk. If a control file is damaged due to a disk
failure, the associated instance must be shut down. Once the disk drive
is repaired, the damaged control file can be restored using the intact
copy of the control file from the other disk and the instance can be
restarted. In this case, no media recovery is required.
The following describes the behavior of multiplexed control files:
* Oracle writes to all filenames listed for the initialization parameter
CONTROL_FILES in the database's initialization parameter file.
* The first file listed in the CONTROL_FILES parameter is the only file
read by the Oracle database server during database operation.
* If any of the control files become unavailable during database
operation, the instance becomes inoperable and should be aborted.
Note:
Oracle strongly recommends that your database has a minimum of two
control files and that they are located on separate disks.
Place Control Files Appropriately
As already suggested, each copy of a control file should be stored on a
different disk drive. One practice is to store a control file copy on every
disk drive that stores members of online redo log groups, if the online
redo log is multiplexed. By storing control files in these locations, you
minimize the risk that all control files and all groups of the online redo
log will be lost in a single disk failure.
Back Up Control Files
It is very important that you back up your control files. This is true
initially, and at any time after you change the physical structure of
your database. Such structural changes include:
* Adding, dropping, or renaming datafiles
* Adding or dropping a tablespace, or altering the read-write state of
the tablespace
* Adding or dropping redo log files or groups
The methods for backing up control files are discussed in "Backing Up
Control Files".
Manage the Size of Control Files
The main determinants of a control file's size are the values set for the
MAXDATAFILES, MAXLOGFILES, MAXLOGMEMBERS, MAXLOGHISTORY,
and MAXINSTANCES parameters in the CREATE DATABASE statement
that created the associated database. Increasing the values of these
parameters increases the size of a control file of the associated
database.
Creating Control Files
a
This section describes ways to create control files, and contains the
following topics:
* Creating Initial Control Files
* Creating Additional Copies, Renaming, and Relocating Control Files
* Creating New Control Files
Creating Initial Control Files
The initial control files of an Oracle database are created when you
issue the CREATE DATABASE statement. The names of the control files
are specified by the CONTROL_FILES parameter in the initialization
parameter file used during database creation. The filenames specified
in CONTROL_FILES should be fully specified and are operating system
specific. The following is an example of a CONTROL_FILES initialization
parameter:
CONTROL_FILES = (/u01/oracle/prod/control01.ctl,
/u02/oracle/prod/control02.ctl,
/u03/oracle/prod/control03.ctl)
If files with the specified names currently exist at the time of database
creation, you must specify the CONTROLFILE REUSE clause in the
CREATE DATABASE statement, or else an error occurs. Also, if the size
of the old control file differs from the SIZE parameter of the new one,
you cannot use the REUSE option.
The size of the control file changes between some releases of Oracle,
as well as when the number of files specified in the control file
changes. Configuration parameters such as MAXLOGFILES,
MAXLOGMEMBERS, MAXLOGHISTORY, MAXDATAFILES, and
MAXINSTANCES affect control file size.
You can subsequently change the value of the CONTROL_FILES
initialization parameter to add more control files or to change the
names or locations of existing control files.
Creating Additional Copies, Renaming, and Relocating Control Files
You can create an an additional control file copy by copying an existing
control file to a new location and adding the file's name to the list of
control files. Similarly, you rename an existing control file by copying
a
the file to its new name or location, and changing the file's name in the
control file list. In both cases, to guarantee that control files do not
change during the procedure, shut down the instance before copying
the control file.
To Multiplex or Move Additional Copies of the Current Control Files
1. Shut down the database.
2. Copy an existing control file to a different location, using operating
system commands.
3. Edit the CONTROL_FILES parameter in the database's initialization
parameter file to add the new control file's name, or to change the
existing control filename.
4. Restart the database.
Creating New Control Files
This section discusses when and how to create new control files.
When to Create New Control Files
It is necessary for you to create new control files in the following
situations:
* All control files for the database have been permanently damaged
and you do not have a control file backup.
* You want to change one of the permanent database parameter
settings originally specified in the CREATE DATABASE statement. These
settings include the database's name and the following parameters:
MAXLOGFILES, MAXLOGMEMBERS, MAXLOGHISTORY, MAXDATAFILES,
and MAXINSTANCES.
For example, you would change a database's name if it conflicted with
another database's name in a distributed environment. Or, as another
example, you can change the value of MAXLOGFILES if the original
setting is too low.
The CREATE CONTROLFILE Statement
You can create a new control file for a database using the CREATE
CONTROLFILE statement. The following statement creates a new
control file for the prod database (formerly a database that used a
different database name):
CREATE CONTROLFILE
SET DATABASE prod
LOGFILE GROUP 1 ('/u01/oracle/prod/redo01_01.log',
'/u01/oracle/prod/redo01_02.log'),
GROUP 2 ('/u01/oracle/prod/redo02_01.log',
'/u01/oracle/prod/redo02_02.log'),
GROUP 3 ('/u01/oracle/prod/redo03_01.log',
'/u01/oracle/prod/redo03_02.log')
NORESETLOGS
DATAFILE '/u01/oracle/prod/system01.dbf' SIZE 3M,
'/u01/oracle/prod/rbs01.dbs' SIZE 5M,
'/u01/oracle/prod/users01.dbs' SIZE 5M,
'/u01/oracle/prod/temp01.dbs' SIZE 5M
MAXLOGFILES 50
MAXLOGMEMBERS 3
MAXLOGHISTORY 400
MAXDATAFILES 200
MAXINSTANCES 6
ARCHIVELOG;
Cautions:
* The CREATE CONTROLFILE statement can potentially damage
specified datafiles and online redo log files. Omitting a filename can
cause loss of the data in that file, or loss of access to the entire
a
5. Create a new control file for the database using the CREATE
CONTROLFILE statement.
When creating a new control file, select the RESETLOGS option if you
have lost any online redo log groups in addition to control files. In this
case, you will need to recover from the loss of the redo logs (Step 8).
You must also specify the RESETLOGS option if you have renamed the
database. Otherwise, select the NORESETLOGS option.
6. Store a backup of the new control file on an offline storage device.
See "Backing Up Control Files" for instructions for creating a backup.
7. Edit the CONTROL_FILES initialization parameter for the database to
indicate all of the control files now part of your database as created in
Step 5 (not including the backup control file). If you are renaming the
database, edit the DB_NAME parameter to specify the new name.
8. Recover the database if necessary. If you are not recovering the
database, skip to Step 9.
If you are creating the control file as part of recovery, recover the
database. If the new control file was created using the NORESETLOGS
option (Step 5), you can recover the database with complete, closed
database recovery.
If the new control file was created using the RESETLOGS option, you
must specify USING BACKUP CONTROL FILE. If you have lost online or
archived redo logs or datafiles, use the procedures for recovering those
files.
9. Open the database using one of the following methods:
* If you did not perform recovery, or you performed complete, closed
database recovery in Step 8, open the database normally.
ALTER DATABASE OPEN;
* If you specified RESETLOGS when creating the control file, use the
ALTER DATABASE statement, indicating RESETLOGS.
ALTER DATABASE OPEN RESETLOGS;
The database is now open and available for use.
Troubleshooting After Creating Control Files
online redo log also protects rollback data. When you recover the
database using redo data, Oracle reads the change vectors in the redo
records and applies the changes to the relevant blocks.
Redo records are buffered in a circular fashion in the redo log buffer of
the SGA (see "How Oracle Writes to the Online Redo Log") and are
written to one of the online redo log files by the Oracle background
process Log Writer (LGWR). Whenever a transaction is committed,
LGWR writes the transaction's redo records from the redo log buffer of
the SGA to an online redo log file, and a system change number (SCN)
is assigned to identify the redo records for each committed transaction.
Only when all redo records associated with a given transaction are
safely on disk in the online logs is the user process notified that the
transaction has been committed.
Redo records can also be written to an online redo log file before the
corresponding transaction is committed. If the redo log buffer fills, or
another transaction commits, LGWR flushes all of the redo log entries
in the redo log buffer to an online redo log file, even though some redo
records may not be committed. If necessary, Oracle can roll back these
changes.
How Oracle Writes to the Online Redo Log
The online redo log of a database consists of two or more online redo
log files. Oracle requires a minimum of two files to guarantee that one
is always available for writing while the other is being archived (if in
ARCHIVELOG mode).
LGWR writes to online redo log files in a circular fashion. When the
current online redo log file fills, LGWR begins writing to the next
available online redo log file. When the last available online redo log
file is filled, LGWR returns to the first online redo log file and writes to
it, starting the cycle again. Figure 7-1 illustrates the circular writing of
the online redo log file. The numbers next to each line indicate the
sequence in which LGWR writes to each online redo log file.
Filled online redo log files are available to LGWR for reuse depending
on whether archiving is enabled.
* If archiving is disabled (NOARCHIVELOG mode), a filled online redo
log file is available once the changes recorded in it have been written
to the datafiles.
unused. In this case, it is better to decrease the size of the online redo
log files slightly, so that two log groups could be archived for each
tape.
With multiplexed groups of online redo logs, all members of the same
group must be the same size. Members of different groups can have
different sizes. However, there is no advantage in varying file size
between groups. If checkpoints are not set to occur between log
switches, make all groups the same size to guarantee that checkpoints
occur at regular intervals.
Choosing the Number of Online Redo Log Files
The best way to determine the appropriate number of online redo log
files for a database instance is to test different configurations. The
optimum configuration has the fewest groups possible without
hampering LGWR's writing redo log information.
In some cases, a database instance may require only two groups. In
other situations, a database instance may require additional groups to
guarantee that a recycled group is always available to LGWR. During
testing, the easiest way to determine if the current online redo log
configuration is satisfactory is to examine the contents of the LGWR
trace file and the database's alert log. If messages indicate that LGWR
frequently has to wait for a group because a checkpoint has not
completed or a group has not been archived, add groups.
Consider the parameters that can limit the number of online redo log
files before setting up or altering the configuration of an instance's
online redo log. The following parameters limit the number of online
redo log files that you can add to a database:
* The MAXLOGFILES parameter used in the CREATE DATABASE
statement determines the maximum number of groups of online redo
log files for each database. Group values can range from 1 to
MAXLOGFILES. The only way to override this upper limit is to re-create
the database or its control file. Thus, it is important to consider this
limit before creating a database. If MAXLOGFILES is not specified for
the CREATE DATABASE statement, Oracle uses an operating system
specific default value.
* The MAXLOGMEMBERS parameter used in the CREATE DATABASE
statement determines the maximum number of members for each
group. As with MAXLOGFILES, the only way to override this upper limit
is to re-create the database or control file. Thus, it is important to
consider this limit before creating a database. If no MAXLOGMEMBERS
a
To rename online redo log members, you must have the ALTER
DATABASE system privilege. Additionally, you might also need
operating system privileges to copy files to the desired location and
privileges to open and back up the database.
Before relocating your redo logs, or making any other structural
changes to the database, completely back up the database in case you
experience problems while performing the operation. As a precaution,
after renaming or relocating a set of online redo log files, immediately
back up the database's control file.
Use the following steps for relocating redo logs. The example used to
illustrate these steps assumes:
* The log files are located on two disks: diska and diskb.
* The online redo log is duplexed: one group consists of the
members /diska/logs/log1a.rdo and /diskb/logs/log1b.rdo, and the
second group consists of the members /diska/logs/log2a.rdo and
/diskb/logs/log2b.rdo.
* The online redo log files located on diska must be relocated to diskc.
The new filenames will reflect the new location: /diskc/logs/log1c.rdo
and /diskc/logs/log2c.rdo.
Steps for Renaming Online Redo Log Members
1. Shut down the database.
SHUTDOWN
2. Copy the online redo log files to the new location.
Operating system files, such as online redo log members, must be
copied using the appropriate operating system commands. See your
operating system specific documentation for more information about
copying files.
Note:
You can execute an operating system command to copy a file (or
perform other operating system commands) without exiting SQL*Plus
by using the HOST command. Some operating systems allow you to
use a character in place of the word HOST. For example, you can use !
in UNIX.
To drop an online redo log group, you must have the ALTER DATABASE
system privilege. Before dropping an online redo log group, consider
the following restrictions and precautions:
* An instance requires at least two groups of online redo log files,
regardless of the number of members in the groups. (A group is one or
more members.)
* You can drop an online redo log group only if it is inactive. If you need
to drop the current group, first force a log switch to occur.
* Make sure an online redo log group is archived (if archiving is
enabled) before dropping it. To see whether this has happened, use the
V$LOG view.
SELECT GROUP#, ARCHIVED, STATUS FROM V$LOG;
GROUP# ARC STATUS
--------- --- ---------------1 YES ACTIVE
2 NO CURRENT
3 YES INACTIVE
4 YES INACTIVE
Drop an online redo log group with the SQL statement ALTER
DATABASE with the DROP LOGFILE clause.
The following statement drops redo log group number 3:
ALTER DATABASE DROP LOGFILE GROUP 3;
When an online redo log group is dropped from the database, and you
are not using the Oracle Managed Files feature, the operating system
files are not deleted from disk. Rather, the control files of the
associated database are updated to drop the members of the group
from the database structure. After dropping an online redo log group,
make sure that the drop completed successfully, and then use the
appropriate operating system command to delete the dropped online
redo log files.
that the drop completed successfully, and then use the appropriate
operating system command to delete the dropped online redo log file.
To drop a member of an active group, you must first force a log switch.
Forcing Log Switches
A log switch occurs when LGWR stops writing to one online redo log
group and starts writing to another. By default, a log switch occurs
automatically when the current online redo log file group fills.
You can force a log switch to make the currently active group inactive
and available for online redo log maintenance operations. For example,
you want to drop the currently active group, but are not able to do so
until the group is inactive. You may also wish to force a log switch if the
currently active group needs to be archived at a specific time before
the members of the group are completely filled. This option is useful in
configurations with large online redo log files that take a long time to
fill.
To force a log switch, you must have the ALTER SYSTEM privilege. Use
the ALTER SYSTEM statement with the SWITCH LOGFILE clause.
The following statement forces a log switch:
ALTER SYSTEM SWITCH LOGFILE;
Verifying Blocks in Redo Log Files
You can configure Oracle to use checksums to verify blocks in the redo
log files. If you set the initialization parameter DB_BLOCK_CHECKSUM
to TRUE, block checking is enabled for all Oracle database blocks
written to disk, including redo log blocks. The default value of
DB_BLOCK_CHECKSUM is FALSE.
If you enable block checking, Oracle computes a checksum for each
redo log block written to the current log. Oracle writes the checksum in
the header of the block. Oracle uses the checksum to detect corruption
in a redo log block. Oracle tries to verify the redo log block when it
writes the block to an archive log file and when the block is read from
an archived log during recovery.
If Oracle detects a corruption in a redo log block while trying to archive
it, the system attempts to read the block from another member in the
group. If the block is corrupted in all members the redo log group, then
archiving cannot proceed.
a
Note:
There is some overhead and decrease in database performance with
DB_BLOCK_CHECKSUM enabled. Monitor your database performance to
decide if the benefit of using data block checksums to detect
corruption outweights the performance impact.
Clearing an Online Redo Log File
An online redo log file might become corrupted while the database is
open, and ultimately stop database activity because archiving cannot
continue. In this situation the ALTER DATABASE CLEAR LOGFILE
statement can be used reinitialize the file without shutting down the
database.
The following statement clears the log files in redo log group number 3:
ALTER DATABASE CLEAR LOGFILE GROUP 3;
This statement overcomes two situations where dropping redo logs is
not possible:
* If there are only two log groups
* The corrupt redo log file belongs to the current group
If the corrupt redo log file has not been archived, use the UNARCHIVED
keyword in the statement.
ALTER DATABASE CLEAR UNARCHIVED LOGFILE GROUP 3;
This statement clears the corrupted redo logs and avoids archiving
them. The cleared redo logs are available for use even though they
were not archived.
If you clear a log file that is needed for recovery of a backup, then you
can no longer recover from that backup. Oracle writes a message in
the alert log describing the backups from which you cannot recover.
Note:
If you clear an unarchived redo log file, you should make another
backup of the database.
To see the names of all of the member of a group, use a query similar
to the following:
SELECT * FROM V$LOGFILE;
GROUP# STATUS MEMBER
------ ------- ---------------------------------1 D:\ORANT\ORADATA\IDDB2\REDO04.LOG
2 D:\ORANT\ORADATA\IDDB2\REDO03.LOG
3 D:\ORANT\ORADATA\IDDB2\REDO02.LOG
4 D:\ORANT\ORADATA\IDDB2\REDO01.LOG
21.Undo Tablespace Management
Managing the Undo Tablespace
This chapter describes how to manage the undo tablespace, which
stores information used to roll back changes to the Oracle Database. It
contains the following topics:
What Is Undo?
Every Oracle Database must have a method of maintaining information
that is used to roll back, or undo, changes to the database. Such
information consists of records of the actions of transactions, primarily
before they are committed. These records are collectively referred to
as undo.
Undo records are used to:
Roll back transactions when a ROLLBACK statement is issued
Recover the database
Provide read consistency
Analyze data as of an earlier point in time by using Oracle Flashback
Query
Recover from logical corruptions using Oracle Flashback features
Initialization
Parameter
Description
provided that the undo tablespace has space available for new
transactions. When available space for new transactions becomes
short, the database begins to overwrite expired undo. If the undo
tablespace has no space for new transactions after all expired undo is
overwritten, the database may begin overwriting unexpired undo
information. If any of this overwritten undo information is required for
consistent read in a current long-running query, the query could fail
with the snapshot too old error message.
The following points explain the exact impact of the UNDO_RETENTION
parameter on undo retention:
The UNDO_RETENTION parameter is ignored for a fixed size undo
tablespace. The database may overwrite unexpired undo information
when tablespace space becomes low.
For an undo tablespace with the AUTOEXTEND option enabled, the
database attempts to honor the minimum retention period specified by
UNDO_RETENTION. When space is low, instead of overwriting
unexpired undo information, the tablespace auto-extends. If the
MAXSIZE clause is specified for an auto-extending undo tablespace,
when the maximum size is reached, the database may begin to
overwrite unexpired undo information.
Retention Guarantee
To guarantee the success of long-running queries or Oracle Flashback
operations, you can enable retention guarantee. If retention guarantee
is enabled, the specified minimum undo retention is guaranteed; the
database never overwrites unexpired undo data even if it means that
transactions fail due to lack of space in the undo tablespace. If
retention guarantee is not enabled, the database can overwrite
unexpired undo when space is low, thus lowering the undo retention
for the system. This option is disabled by default.
WARNING:
Enabling retention guarantee can cause multiple DML operations to
fail. Use with caution.
You enable retention guarantee by specifying the RETENTION
GUARANTEE clause for the undo tablespace when you create it with
either the CREATE DATABASE or CREATE UNDO TABLESPACE statement.
Or, you can later specify this clause in an ALTER TABLESPACE
statement. You disable retention guarantee with the RETENTION
NOGUARANTEE clause.
a
DBMS_ADVISOR.SET_TASK_PARAMETER(tname, 'TARGET_OBJECTS',
oid);
DBMS_ADVISOR.SET_TASK_PARAMETER(tname, 'START_SNAPSHOT', 1);
DBMS_ADVISOR.SET_TASK_PARAMETER(tname, 'END_SNAPSHOT', 2);
DBMS_ADVISOR.SET_TASK_PARAMETER(name, 'INSTANCE', 1);
DBMS_ADVISOR.execute_task(tname);
end;
/
After you have created the advisor task, you can view the output and
recommendations in the Automatic Database Diagnostic Monitor in
Enterprise Manager. This information is also available in the
DBA_ADVISOR_* data dictionary views.
Managing Undo Tablespaces
This section describes the various steps involved in undo tablespace
management and contains the following sections:
Creating an Undo Tablespace
There are two methods of creating an undo tablespace. The first
method creates the undo tablespace when the CREATE DATABASE
statement is issued. This occurs when you are creating a new
database, and the instance is started in automatic undo management
mode (UNDO_MANAGEMENT = AUTO). The second method is used with
an existing database. It uses the CREATE UNDO TABLESPACE
statement.
You cannot create database objects in an undo tablespace. It is
reserved for system-managed undo data.
Oracle Database enables you to create a single-file undo tablespace.
Single-file, or bigfile, tablespaces are discussed in "Bigfile
Tablespaces".
Using CREATE DATABASE to Create an Undo Tablespace
You can create a specific undo tablespace using the UNDO TABLESPACE
clause of the CREATE DATABASE statement.
a
BEGIN
utbsiz_in_MB := DBMS_UNDO_ADV.RBU_MIGRATION;
end;
/
The function returns the sizing information directly.
Viewing Information About Undo
This section lists views that are useful for viewing information about
undo space in the automatic undo management mode and provides
some examples. In addition to views listed here, you can obtain
information from the views available for viewing tablespace and
datafile information.
Oracle Database also provides proactive help in managing tablespace
disk space use by alerting you when tablespaces run low on available
space.
In addition to the proactive undo space alerts, Oracle Database also
provides alerts if your system has long-running queries that cause
SNAPSHOT TOO OLD errors. To prevent excessive alerts, the long query
alert is issued at most once every 24 hours. When the alert is
generated, you can check the Undo Advisor Page of Enterprise
Manager to get more information about the undo tablespace.
The following dynamic performance views are useful for obtaining
space information about the undo tablespace:
View
Description
V$UNDOSTAT
V$ROLLSTAT
V$TRANSACTION
DBA_UNDO_EXTENTS Shows the status and size of each extent in the undo
tablespace.
DBA_HIST_UNDOSTAT Contains statistical snapshots of V$UNDOSTAT
information.
Shut immediate I used and I use shut abort how can I know which has
brought down the database?
Which background process write to log buffer?
what does contains Shared pool ?
23.Oracle DBA-interview qns(dont get anywhere)
Use the ipcs command to obtain a list of the system's current shared
memory and
semaphore segments, and their identification number and owner.
You can modify the kernel parameters by using the /proc file system.
To modify kernel parameters using the /proc file system:
1.Log in as root user.
2.Change to the /proc/sys/kernel directory.
3.Review the current semaphore parameter values in the sem file using
the
cat or more utility. For example,
# cat sem
The output will list, in order, the values for the SEMMSL, SEMMNS,
SEMOPM,
and SEMMNI parameters. The following example shows how the output
will appear.
250 32000 32 128
In the preceding example, 250 is the value of the SEMMSL parameter,
32000 is
the value of the SEMMNS parameter, 32 is the value of the SEMOPM
parameter, and
128 is the value of the SEMMNI parameter.
4.Modify the parameter values using the following command:
# echo SEMMSL_value SEMMNS_value SEMOPM_value SEMMNI_value >
sem
In the preceding command, all parameters must be entered in order.
5.Review the current shared memory parameters using the cat or more
utility.
For example,
# cat shared_memory_parameter
In the preceding example, the shared_memory_parameter is either the
SHMMAX or
SHMMNI parameter. The parameter name must be entered in
lowercase letters.
6.Modify the shared memory parameter using the echo utility. For
example,
to modify the SHMMAX parameter, enter the following:
# echo 2147483648 > shmmax
7.Write a script to initialize these values during system startup and
include
the script in your system init files.
See Also:
For more information on script files and init files, refer to your system
vendor's documentation.
Refer to the following table to determine if your system shared
memory and
semaphore kernel parameters are set high enough for Oracle9i. The
a
parameters
in the following table are the minimum values required to run Oracle9i
with a
single database instance.
SEMMNI=100
- Defines the maximum number of semaphore sets in the entire
system.
SEMMNS=256
- Defines the maximum semaphores on the system. This setting is a
minimum
recommended value, for initial installation only. The SEMMNS
parameter should
be set to the sum of the PROCESSES parameter for each Oracle
database, adding
the largest one twice, and then adding an additional 10 for each
database.
SEMMSL=100
- Defines the maximum number of semaphores for each Oracle
database. The SEMMSL
setting should be 10 plus the largest PROCESSES parameter of any
Oracle
database on the system.
SEMOPM=100
- Defines the maximum number of operations per semop call.
SEMVMX=32767
- Defines the maximum value of a semaphore.
SHMMAX=2147483648
- Defines the maximum allowable size of the shared memory. The
SHMMAX parameter
does not affect how much shared memory is used or needed by
Oracle9i, the
operating system, or the operating system kernel. One-half the size of
your
system's physical memory. Check your system for additional
restrictions.
SHMMIN=1
- Defines the minimum allowable size of a single shared memory
segment.
SHMMNI=100
- Defines the maximum number of shared memory segments in the
entire system.
SHMSEG=4096
- Defines the maximum number of shared memory segments one
process can attach.
Note: These are minimum kernel requirements for Oracle9i. If you have
a
previously
tuned your kernel parameters to levels equal to or higher than these
values,
continue to use the higher values. A system restart is necessary for
kernel
changes to take effect.