Oracle DBA Job
Interview Questions
Export/import, CREATE TABLE … AS
SELECT, COPY, etc.
The IMPORT IGNORE option tells import to ignore already exists errors. If it is not specified the already existing
tables will be skipped. The default is N.
Use the rollback segment … shrink command.
The user is
assigned to the SYSTEM tablespace as a default and
temporary tablespace. This is bad because no user
object should be in SYSTEM.
Owned by the SYS user: dbms_shared_pool, dbms_utility, dbms_sql, dbms_ddl, dbms_session, dbms_output, dbms_snapshot. Also CAT*.SQL and
UTL*.SQL.
The Oracle
will use the default name of SYS_Cxxxx where xxx is a
system generated number. Hard to track.
This results in the index that is automatically generated being placed in the user’s
default tablespace. Since this will be in the same tablespace as the table, this will cause serious
performance problems.
8. What is the proper method for disabling and re-enabling a primary key
constraint?
You can use
ALTER TABLE for both. However, for the enable clause you must specify the USING
INDEX and TABLESPACE clause.
9. What happens if a primary key constraint is disabled and then
re-enabled without specifying the index clause?
The index
is created in the user’s default tablespace and all
sizing information is lost.
10. When should more than one DN writer be used? How many?
If the UNIX
system is capable of asynchronous I/O, then only one is required. If the UNIX
system is incapable of asynchronous I/O, then up to twice the number of disks
used by Oracle or twice the number of CPUs.
11. You are using a hot backup without being in ARCHIVELOG mode. Can you
recover in the event of failure? Why not?
You can’t
use a hot backup without being in ARCHICVELOG mode.
12. What causes the “Snapshot too old error”? How can this be prevented or
mitigated?
This is
caused by large or long running transactions that are either wrapped onto their
own rollback space or had another transaction write on part of their rollback
space. This can be mitigated by breaking the transactions into smaller pieces
and running them separately or increasing the size of the rollback segments and
their extents.
13. How can you tell if a database object is invalid?
By checking the status column in the DBA_OBJECTS or ALL_ and USER_
views.
14. If a user gets the
ORA-00942 error, yet you know you granted them the privilege, what else should
you check?
Check if
the user specified the full name of the object (schema), or has synonym
pointing to that object.
15. A developer is trying to create a view but the database will not let
him. He has the DEVELOPER role which has the CREATE VIEW system privilege and
the selects on the table he is using. What is the problem?
You need to
verify that the developer has direct grants on the tables on which the view is
based. You can not create a stored object based with grants given through
views.
16. If you are using an example table what is the best way to get sizing
data for the production table implementation?
The best
way is to analyze the table and then use the data provided in the dba_tables view to get the average row length and other
data for the calculation. The quick and the dirty way is
to look at the number of blocks the table is actually using and ratio the
number of rows to its number of blocks against expected number of rows.
17. How can you tell how many users are currently logged into the database?
How can you find their system ID?
Query
V$SESSION and V$PROCESS. The other is to check the current_logins
parameter in the V$SYSSTAT. Another way on UNIX is to do a “ps
–ef|grep oracle| wc –l” command, but this works only against a single
instance installation.
18. The
user selects from a sequence and gets back 2 values, his select is SELECT pk_seq.nextval FROM dual; What is the problem?
Somehow two
rows have been inserted into DUAL.
19. How do you determine if an index has to be dropped or rebuilt?
Run the
analyze index to validate structure and then calculate the ratio of LF_ROWS_LEN
/ LF_ROWS_LEN + DEL_LF_ROWS_LEN and if it is not at least 70% the index should
be rebuilt. Or id the ratio of DEL_LF_ROWS_LEN / LF_ROWS_LEN + DEL_LF_ROWS_LEN
is nearing 30%.
SQL * PLUS and SQL Job Questions
By the use
of & or && symbol. For passing in variable
numbers can be used &1, &2. To be prompted for a specific
variable, place ampersand variable into the code itself: SELECT * FROM dba_tables WHERE owner = &owner_name;
The use of double ampersand tells Oracle to reuse the
variable for subsequent times, unless ACCEPT is used to get value from the
user.
The best
way is to use the CHR() function (CHR(10) as a return
/ linefeed and the concatenation function. Another method is to use the return
/ linefeed as a part of a quoted string.
By using
EXECUTE or wrap the call in a BEGIN END block and treat it as an anonymous
block.
By using “!” or”HOST” command.
This is
called dynamic SQL. An example:
“Set lines 90
Pages 0
Termout off
Feedback off
Verify off
Spool drop_all.sql
SELECT ‘drop user ‘||username||’ cascade;’ from dba_users
Where username not in (“SYS”, “SYSTEM”);
Spool off;
This is
done with the COLUMN.
MAX(sum_of_cost), MIN(sum_of_cost), COUNT(item_no)?
The only
column you can group by is the COUNT(item_no), the rest are aggregate functions.
You can use
hints – FIRST ROWS, ALL_ROWS, RULE, USING INDEX, STAR.
If you use
MIN / MAX function against your ROWID, then select against the proposed primary
key you can squeeze out the ROWID of duplicate rows quickly.
SELECT ROWID FROM emp
e
WHERE e.ROWID > (SELECT MIN(x.ROWID)
FROM emp
x
WHERE x.emp_n0 = e.emp_no);
In a
situation if multiple columns make up the proposed key, they all must be used
in the WHERE clause.
A Cartesian
product is a result of an unrestricted of 2 or more tables.
Push the
processing of the remote data to the remote server by using a view to preselect information for the join. This will result in
only data needed for the join being sent across the network.
Ascending
The TKPROF
is a tuning tool used to determine the execution time for SQL statements. Use
it first by setting TIMED_STATISTICS parameter to TRUE and then setting the
entire instance SQL_TRACE to on or just for the session with an ALTER SESSION
command. Once that is done you run TKPROF and generate a readable report with
an explain plan.
The EXPLAIN
plan is used to tune SQL statements. You have to have the EXPLAIN_TABLE
generated for the user you are generating the explain plan for. This is done
with the utlxplan.sql. Once the EXPLAIN_TABLE exists,
you run the explain command with the statement to be explained. The explain
table then is queried to see the execution plan.
The SET
command in SQL * PLUS is used to control the number of lines generated per
pager and the width of those lines. For example SET PAGESIZE 60 LINESIZE 80
will generate reports that are 60 lines long with a line width of 80
characters.
The SET option
of TERMOUT controls output to the screen. Setting TERMOUT OFF turns off the
screen output.
The SET
option FEEDBACK and VERIFY can be set to OFF.
By use of the SPOOL command.
Oracle Performance
Tuning Job Interview Questions
Multiple
extents are not bad. However, if you also have chained rows, this can hurt
performance.
You should
always use OFA. For the best results SYSTEM, ROLLBACK, UNDO, TEMPORARY, INDEX
and DATA segments should be separated.
Ensure that
users don’t have SYSTEM tablespace as their default
and or temporary tablespace by checking DBA_USERS.
Poor data
dictionary or library cache hit ratios or getting ORA-04031. Another indication
is steadily decreasing performance with all other tuning parameters are the same.
OS almost
always reads in 64K chunks. The two should have a product of = 64K, a multiple
of 64K, or the value for read size from your OS.
Fetch by
ROWID.
The TKPROF
is a tuning tool used to determine the execution time for SQL statements. Use
it first by setting TIMED_STATISTICS parameter to TRUE and then setting the
entire instance SQL_TRACE to on or just for the session with an ALTER SESSION
command. Once that is done you run TKPROF and generate a readable report with
an explain plan.
If you get
excessive disk sorts this is bad. This means you need to tune the sorts area
parameters in the init file – SORT_AREA_SIZe is the
major one.
When you
get excessive contention of the copy latches as shown by the redo copy latch
hit ratio you can increase copy latches via the init parameter log simultenious_copies to twice the number of CPUs on your
system.
You can
look in the init.ora file or the V$PARAMETER view.
A hit ratio
is measurement of how many times the database was able to read the value from
the buffers, instead of disk. A value of 80%-90% is good. If you simply take
the ratio of existing parameters, they will be applicable to since the instance
started. If you do a comparison of readings based on some 2 arbitrary time
spans, this is the instantaneous ratio for that time span (more valuable)
The row
chaining happens when a variable length value is updated and the new value is
longer than the old value and will not fit into remaining block space. This
results in row chaining to another block. You can correct this by setting
appropriate values for the table storage clause (PCTFREE). This can be
corrected be exporting and importing the table.
Buffer busy
wait can indicate contention in redo rollback or data blocks. You need to check
the V$WAITSTAT to see what areas are causing the problem. The value of count
tells you where the problem is, class tells you with what.
Increase
the size of the shared pool.
Rollback
segments associated with structures.
The SMON
will not automatically coalesce its free space
fragments.
In Oracle
7.0 and 7.2 use the ‘ALTER SESSION SET EVENTS
IMMEDIATE TRACE NAME COALESCE LEVEL ts#’ command is
the easiest way to defragment the space. The ts# is in the ts$ table owned by
SYS. In version 7.3 alter tablespace <>
coalesce; If
the free space is not contiguous, export, drop and import the tablespace.
If a select
against DBA_FREE_SPACE shows that the count of tablespace’s
extents is greater than the count of its datafiles,
then it is fragmented.
Since the
wait time is zero – no. If the wait time is high it might indicate a need for
more or larger redo logs.
The high
value of recursive calls is caused by improper usage of cursors, extensive
dynamic space management actions, and excessive statements re-parses. You need
to determine cause and correct it by either relinking
applications to hold cursors or use proper space management techniques (proper
storage and sizing) to ensure repeated queries are placed in the packages for
proper use.
This
indicates that shared pool size is too small. Increase the size of shared pool.
You should
strive for zero reloads if possible. If you see excessive reloads – increase
the size of shared pool.
The large
number of small shrinks indicates the need to increase the size of extents of
rollback segments. Ideally, you should have no shrinks or small number of large
shrinks. To alleviate this just increase the size of extents
and adjust optimal accordingly.
A large
number of wraps indicates that rollback segment extent size is too small.
Increase the size of your extents. You can look at an average transaction size
in the same view.
No, it is
not a problem. You have 40 extents showing and an average of 40 users. Since
there is plenty of room to grow there is no problem.
As long as
they are all the same size it is not a problem.
Oracle Installation
and Configuration Job Interview Questions
OFA is
Optimal Flexible Architecture. It is a method of placing directories and files
in an Oracle system for future tuning and file placement.
At least 7
disks arrays: SYSTEM on one, two mirrored redo logs on different disks,
TEMPORARY tablespace on one, ROLLBACK tablespace on another, and still have 2 disks for data and
indexes.
Adjust
kernel parameters and disk space.
Check to
make sure that the archiver is not stuck. If archive
logging is turned on during install, this will generate an enormous amount of
archived log space. If the space is full, Oracle will stop and wait until you
free more space.
Initialization
files SQLNET.ORA, TNSNAMES.ORA and LISTENER.ORA.
SQLNET.ORA, TNSNAMES.ORA.
SQLNET and protocol – TCP/IP, etc.
Check if
the large SGA is not being swapped out.
You must
use root first, then create DBA and OINSTALL roles.
Never.
At least 2
on separate disks, not just 2 file systems.
At least 2
are required. The OFA specifies at least 3 groups with at least 2 members in
each. The logs files should be on 2 different disks mirrored by Oracle. The
files should not be on raw devices on UNIX.
At least 7 disks. See above.
Oracle Data Modeling
Job Interview Questions
All
attributes in an entity relate to the primary key and only primary key.
FALSE.
While the 3d normal form is good for logical design, most databases will not
perform well under 3NF. Usually, some entity will be denormalized
in the logical to physical transfer process.
ERD stands
for Entity relational Diagram.
Recursive
relationships (when tables are related to themselves) is bad when it is a hard
relationship (neither side is “may” both sides are a “must” as this results in
it not being possible to put on either bottom or top of the table. You resolve
them by using an intersection entity.
This means
that the two entities should probably be made one.
By adding an intersection entity table.
A derived
key comes from a sequence. Usually, it is used when a concatenated index
becomes too cumbersome to use as a foreign key.
When
performance analysis indicates it will be beneficial without compromising data
integrity?
Oracle Troubleshooting
Job Interview Questions
The
following processes will be running – smon, pmon, dbwr, lgwr.
Use the “ps –ef| grep dbwr” will show what
instances are up.
The instance
name is probably incorrect in their connection string.
The Oracle
instance is shut down. Restart the instance.
For SQL * NET V1 check for the orapsv process. You can use TCPCTL STATUS to get
the full status of SQL * NET server. For other protocols check the existence of
LISTENER process or you can use lsnrctl status
The
alert<SID>.log file located in the BACKGROUND_DUMP_DEST from V$PARAMETER
table.
The archiver destination is probably full. Backup the archive logs and remove them and archiver
will restart.
You must
check the alert<>.log for this info.
When the
database was created the DB_FILES parameter was set to 40. You can specify a
higher value up to the MAX_DATAFILES in the control files. You will have to
rebuild the control file to set the value higher than MAX_DATAFILES.
Check the
DBA_TABLESPACES for the value of PCT_INCREASE for the tablespaces.
If the PCT_INCREASE is 0 SMON will not coalesce their
free extents.
This is set
with the parameter DML_LOCKS. If the value is set too low (default) you will
get this error. If you think it is a temporary problem, you can wait till it
clears.
As long as
the datafiles are OK and he was successful with the
backup controlfile command, you can use the
following:
CONNECT
INTERNAL
STARTUP
MOUNT
(Take read
only tablespaces offline before next step ALTER
DATABASE DATAFILE <> OFFLINE;)
RECOVER
DATABASE USING BACKUP CONTROLFILE
ALTER
DATABASE RESETLOGS;
(Bring read
only tablespaces online)
Shutdown,
backup the syste, then
restart.
If no controlfile backup is avialbale,
then the following is required:
CONNECT
INTERNAL
STARTUP
MOUNT
CREATE
CONTROLFILE …;
However,
they will need to know all datafiles, logfiles and settings for the MAXLOGFILES, MAXLOGMEMBERS,
MAXLOGHISTORY, MAXDATAFILES for the database.