0% found this document useful (0 votes)
171 views

Database Optimization Interview: Answer

The document contains questions and answers about database optimization and performance tuning. Some key points addressed include: 1. Reasons for poor query performance include lack of indexes, excessive recompilations, triggers without SET NOCOUNT, complex joins, high normalization, and excessive cursors/temp tables. 2. Index tuning uses query analysis to recommend indexes to improve performance. It analyzes changes in index usage and query performance. 3. Transaction coding efficiency tips include short transactions, lower isolation levels, minimal data access and input during transactions. The document covers database optimization, performance tuning, indexing, query execution plans, and transaction coding best practices.

Uploaded by

Rajesh Bhardwaj
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
171 views

Database Optimization Interview: Answer

The document contains questions and answers about database optimization and performance tuning. Some key points addressed include: 1. Reasons for poor query performance include lack of indexes, excessive recompilations, triggers without SET NOCOUNT, complex joins, high normalization, and excessive cursors/temp tables. 2. Index tuning uses query analysis to recommend indexes to improve performance. It analyzes changes in index usage and query performance. 3. Transaction coding efficiency tips include short transactions, lower isolation levels, minimal data access and input during transactions. The document covers database optimization, performance tuning, indexing, query execution plans, and transaction coding best practices.

Uploaded by

Rajesh Bhardwaj
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Database Optimization Interview

1. Question 1. Reasons Of Poor Performance Of Query?

Answer :

o No indexes
o Excess recompilations of stored procedures.
o Procedures and triggers without SET NOCOUNT ON.
o Poorly written query with unnecessarily complicated joins
o Highly normalized database design.
o Excess usage of cursors and temporary tables.
2. Question 2. Tell Me In Brief The Cursor Optimization Tips?

Answer :

The following are few tips for cursor optimization:

o When the cursor is not needed, close the cursor


o Deallocate the cursor after closing it.
o Fetch less number of rows.
o Avoid triggers – because trigger executes whenever data gets updated, leads to
overload of the system.
o When the rows are not need to update, use the option FORWARD ONLY
o Use where instead of having clause unless it is essential

RDBMS Interview Questions

3. Question 3. How Is Index Tuning Used To Improve Query Performance?

Answer :

The Index tuning wizard can be used to improve the performance of queries and
databases. It uses the following measures to do so:

o It uses the query optimizer to perform the analysis of queries with respect to the
workload and based on this knowledge, it recommends the best usage of indexes.
o The changes in the usage of index, query distribution and their performance are
analysed for checking the effect.
o It also recommends ways of tuning the database for a small set of problem
queries.
4. Question 4. Tell Me What Is Index Tuning?

Answer :
Index tuning is part of database tuning for selecting and creating indexes. The index
tuning goal is to reduce the query processing time. Potential use of indexes in dynamic
environments with several ad-hoc queries in advance is a difficult task. Index tuning
involves the queries based on indexes and the indexes are created automatically on-the-
fly. No explicit actions are needed by the database users for index tuning.

Software Development Lifecycle (SDLC) Tutorial

5. Question 5. What Are The Ways To Code Efficient Transactions?

Answer :

o We shouldn't allow input from users during a transaction.


o We shouldn't open transactions while browsing through data.
o We should keep the transaction as short as possible.
o We should try to use lower transaction isolation levels.
o We should access the least amount of data possible while in a transaction.

Database Interview Questions

6. Question 6. Do You Know What Are The Ways To Code Efficient Transactions?

Answer :

o We shouldn't allow input from users during a transaction.


o We shouldn't open transactions while browsing through data.
o We should keep the transaction as short as possible.
o We should try to use lower transaction isolation levels.
o We should access the least amount of data possible while in a transaction.
7. Question 7. Explain Some Disadvantages Of The Indexes?

Answer :

Indexes improve query performance but it slows down data modification operations.

Indexes consume disk space.

Database Design Interview Questions

8. Question 8. Explain Execution Plan?

Answer :

o SQL Server caches the plan of execution of query or stored procedure which it
uses in subsequent call.
o This is a very important feature with regards to performance enhancement.
o You can view execution plan of data retrieval graphically or textually.
9. Question 9. Explain In Brief The Cursor Optimization Tips?

Answer :

o Close cursor when it is not required.


o You shouldn’t forget to deallocate cursor after closing it.
o You should fetch least number of records.
o You should use FORWARD ONLY option when there is no need to update rows.

Database Administration Interview Questions

10. Question 10. Tell Me What Are The Types Of Indexes?

Answer :

o Indexes can be clustered and non-clustered indexes.


o Clustered index keeps all the records in the database in the order of clustered
index key.
o There can be only one clustered index per table.
o Non-clustered indexes are stored as B-tree structure in their own storage separate
from data storage in the table.
11. Question 11. What Are Indexes?

Answer :

o Index can be thought as index of the book that is used for fast retrieval of
information.
o Index uses one or more column index keys and pointers to the record to locate
record.
o Index is used to speed up query performance.
o Both exist as B-tree structure.
o Kind of the indexes are clustered and non-clustered.

Oracle Performance Tuning

 Question 1. What Is Performance Tuning?

Answer :

Making optimal use of system using existing resources called performance tuning.
 Question 2. What Are The Types Of Tunings?

Answer :

 CPU Tuning
 Memory Tuning
 IO Tuning
 Application Tuning
 Database Tuning

Oracle DBA Interview Questions

 Question 3. What Mainly Database Tuning Contains?

Answer :

 Hit Ratios
 Wait Events

 Question 4. What Is An Optimizer?

Answer :

Optimizer is a mechanism which will make the execution plan of an sql statement.

 Question 5. What Are The Types Of Optimizers?

Answer :

 RBO(Rule Based Optimizer)


 CBO(Cost Based Optimizer)

Oracle RAC/ASM Interview Questions

 Question 6. Which Optimizer Is The Best One?

Answer :

CBO

 Question 7. What Are The Pre Requsited To Make Use Of Optimizer?

Answer :

 Set the optimizer mode


 Collect the statistics of an object

RMAN (Recovery Manager) Interview Questions

 Question 8. How Do You Collect Statistics Of A Table?

Answer :

Analyze table emp compute statistics or analyze table emp estimate statistics.

 Question 9. What Is The Diff Between Compute And Estimate?

Answer :

If you use compute, The FTS will happen, if you use estimate just 10% of the table will be read

Database Administration Interview Questions

 Question 10. Data Dictionary Follows Which Optimizer Mode?

Answer :

RBO.

 Question 11. How Do You Delete Statistics Of An Object?

Answer :

Analyze table emp delete statistics.

Oracle Exadata Database Interview Questions

 Question 12. How Do You Collect Statistics Of A User/schema?

Answer :

exec dbms_stats.gather_schema_stats(scott)

Oracle DBA Interview Questions

 Question 13. How Do You See The Statistics Of A Table?

Answer :

select num_rows,blocks,empty_blocks from dba_tables where tab_name=’emp’


 Question 14. What Are Chained Rows?

Answer :

These are rows, it spans in multiple blocks.

 Question 15. How Do You Collect Statistics Of A User In Oracle Apps?

Answer :

fnd_stats package.

 Question 16. How Do You Know What Sql Is Currently Being Used By The Session?

Answer :

By goind v$sql and v$sql_area.

 Question 17. What Is A Execution Plan?

Answer :

Its a road map how sql is being executed by oracle db..

Oracle DBA Troubleshooting Interview Questions

 Question 18. How Do You Get The Index Of A Table And On Which Column The
Index Is?

Answer :

dba_indexes and dba_ind_columns

Oracle RAC/ASM Interview Questions

 Question 19. Which Init Parameter You Have To Set To Bypass Parsing?

Answer :

cursor_sharing=force

 Question 20. How Do You Know Which Session Is Running Long Jobs?

Answer :

by going v$session_longops
Oracle Data Guard Interview Questions

 Question 21. How Do You Flush The Shared Pool?

Answer :

alter system flush shared_pool

 Question 22. How Do You Get The Info About Fts?

Answer :

using v$sysstat

 Question 23. How Do You Increase The Db Cache?

Answer :

alter table emp cache

 Question 24. Where Do You Get The Info Of Library Cache?

Answer :

v$librarycache

 Question 25. How Do You Get The Information Of Specific Session?

Answer :

v$mystat

 Question 26. How Do You See The Trace Files?

Answer :

using tkprof usage: tkprof allllle.trc llkld.txt

 Question 27. How Many Types Of Hits Are There And What Are They?

Answer :

There are two types of hits, they are

1. Buffer hit
2. library hit
 Question 28. What Are The Types Of Wait Events?

Answer :

 cpu time
 direct path read

 Question 29. A Table Space Has A Table With 30 Extents In It. Is This Bad? Why Or
Why Not?

Answer :

Multiple extents in and of themselves aren’t bad. However if you also have chained rows this can
hurt performance.

 Question 30. How Do You Set Up Tablespaces During An Oracle Installation?

Answer :

You should always attempt to use the Oracle Flexible Architecture standard or another
partitioning scheme to ensure proper separation of SYSTEM, ROLLBACK, REDO LOG,
DATA, TEMPORARY and INDEX segments.

 Question 31. You See Multiple Fragments In The System Tablespace, What Should You
Check First?

Answer :

Ensure that users don’t have the SYSTEM tablespace as their TEMPORARY or DEFAULT
tablespace assignment by checking the DBA_USERS view.

 Question 32. What Are Some Indications That You Need To Increase The
Shared_pool_size Parameter?

Answer :

Poor data dictionary or library cache hit ratios, getting error ORA-04031. Another indication is
steadily decreasing performance with all other tuning parameters the same.

 Question 33. What Is The General Guideline For Sizing Db_block_size And
Db_multi_block_read For An Application That Does Many Full Table Scans?

Answer :

Oracle almost always reads in 64k chunks. The two should have a product equal to 64 or a
multiple of 64.
 Question 34. What Is The Fastest Query Method For A Table?

Answer :

Fetch by rowid.

 Question 35. Explain The Use Of Tkprof? What Initialization Parameter Should Be
Turned On To Get Full Tkprof Output?

Answer :

The tkprof tool is a tuning tool used to determine cpu and execution times for SQL statements.
You use it by first setting timed_statistics to true in the initialization file and then turning on
tracing for either the entire database via the sql_trace parameter or for the session using the
ALTER SESSION command. Once the trace file is generated you run the tkprof tool against the
trace file and then look at the output from the tkprof tool. This can also be used to generate
explain plan output.

 Question 36. When Looking At V$sysstat You See That Sorts (disk) Is High. Is This
Bad Or Good? If Bad, How Do You Correct It?

Answer :

If you get excessive disk sorts this is bad. This indicates you need to tune the sort area
parameters in the initialization files. The major sort are parameter is the SORT_AREA_SIZe
parameter.

 Question 37. When Should You Increase Copy Latches? What Parameters Control
Copy Latches?

Answer :

When you get excessive contention for the copy latches as shown by the “redo copy” latch hit
ratio. You can increase copy latches via the initialization parameter
LOG_SIMULTANEOUS_COPIES to twice the number of CPUs on your system.

 Question 38. Where Can You Get A List Of All Initialization Parameters For Your
Instance? How About An Indication If They Are Default Settings Or Have Been Changed?

Answer :

You can look in the init.ora file for an indication of manually set parameters. For all parameters,
their value and whether or not the current value is the default value, look in the v$parameter
view.
 Question 39. Describe Hit Ratio As It Pertains To The Database Buffers. What Is The
Difference Between Instantaneous And Cumulative Hit Ratio; Which Should Be Used For
Tuning?

Answer :

Hit ratio is a measure of how many times the database was able to read a value from the buffers
verses how many times it had to re-read a data value from the disks. A value greater than 80-
90% is good, less could indicate problems. If you take the ratio of existing parameters this will
be a cumulative value since the database started. If you do a comparison between pairs of
readings based on some arbitrary time span, this is the instantaneous ratio for that time span.
Generally speaking an instantaneous reading gives more valuable data since it will tell you what
your instance is doing for the time it was generated over.

 Question 40. Discuss Row Chaining, How Does It Happen? How Can You Reduce It?
How Do You Correct It?

Answer :

Row chaining occurs when a VARCHAR2 value is updated and the length of the new value is
longer than the old value and won’t fit in the remaining block space. This results in the row
chaining to another block. It can be reduced by setting the storage parameters on the table to
appropriate values. It can be corrected by export and import of the effected table.

Oracle DBA Troubleshooting Interview Questions

 Question 41. When Looking At The Estate Events Report You See That You Are
Getting Busy Buffer Waits. Is This Bad? How Can You Find What Is Causing It?

Answer :

Buffer busy waits may indicate contention in redo, rollback or data blocks. You need to check
the v$waitstat view to see what areas are causing the problem. The value of the “count” column
tells where the problem is, the “class” column tells you with what. UNDO is rollback segments,
DATA is data base buffers.

 Question 42. If You See Contention For Library Caches How Can You Fix It?

Answer :

Increase the size of the shared pool.

 Question 43. If You See Statistics That Deal With “undo” What Are They Really
Talking About?

Answer :
Rollback segments and associated structures.

 Question 44. If A Tablespace Has A Default Pct Increase Of Zero What Will This Cause
(in Relationship To The Smon Process)?

Answer :

The SMON process won’t automatically coalesce its free space fragments.

 Question 45. If A Tablespace Shows Excessive Fragmentation What Are Some Methods
To Defragment The Tablespace? (7.1,7.2 And 7.3 Only)

Answer :

In Oracle 7.0 to 7.2 The use of the ‘alter session set events ‘immediate trace name coalesce level
ts#’;’ command is the easiest way to defragment contiguous free space fragmentation. The ts#
parameter corresponds to the ts# value found in the ts$ SYS table. In version 7.3 the ‘alter
tablespace coalesce;’ is best. If free space isn’t contiguous then export, drop and import of the
tablespace contents may be the only way to reclaim non-contiguous free space.

 Question 46. How Can You Tell If A Tablespace Has Excessive Fragmentation?

Answer :

If a select against the dba_free_space table shows that the count of a tablespaces extents is
greater than the count of its data files, then it is fragmented.

 Question 47. You See The Following On A Status Report:


redo Log Space Requests 23
redo Log Space Wait Time 0
is This Something To Worry About? What If Redo Log Space Wait Time Is High? How
Can You Fix This?

Answer :

Since wait time is zero, no. If wait time was high it might indicate a need for more or larger redo
logs.

 Question 48. What Can Cause A High Value For Recursive Calls? How Can This Be
Fixed?

Answer :

A high value for recursive calls is cause by improper cursor usage, excessive dynamic space
management actions, and or excessive statement re-parses. You need to determine the cause and
correct it By either relinking applications to hold cursors, use proper space management
techniques (proper storage and sizing) or ensure repeat queries are placed in packages for proper
reuse.

 Question 49. If You See A Pin Hit Ratio Of Less Than 0.8 In The Estate Library Cache
Report Is This A Problem? If So, How Do You Fix It?

Answer :

This indicates that the shared pool may be too small. Increase the shared pool size.

 Question 50. If You See The Value For Reloads Is High In The Estate Library Cache
Report Is This A Matter For Concern?

Answer :

Yes, you should strive for zero reloads if possible. If you see excessive reloads then increase the
size of the shared pool.

 Question 51. You Look At The Dba_rollback_segs View And See That There Is A Large
Number Of Shrinks And They Are Of Relatively Small Size, Is This A Problem? How Can
It Be Fixed If It Is A Problem?

Answer :

A large number of small shrinks indicates a need to increase the size of the rollback segment
extents. Ideally you should have no shrinks or a small number of large shrinks. To fix this just
increase the size of the extents and adjust optimal accordingly.

 Question 52. You Look At The Dba_rollback_segs View And See That You Have A
Large Number Of Wraps Is This A Problem?

Answer :

A large number of wraps indicates that your extent size for your rollback segments are probably
too small. Increase the size of your extents to reduce the number of wraps. You can look at the
average transaction size in the same view to get the information on transaction size.

 Question 53. In A System With An Average Of 40 Concurrent Users You Get The
Following From A Query On Rollback Extents:
rollback Cur Extents
r01 11
r02 8
r03 12
r04 9
system 4
you Have Room For Each To Grow By 20 More Extents Each. Is There A Problem?
Should You Take Any Action?

Answer :

No there is not a problem. You have 40 extents showing and an average of 40 concurrent users.
Since there is plenty of room to grow no action is needed.

 Question 54. You See Multiple Extents In The Temporary Tablespace. Is This A
Problem?

Answer :

As long as they are all the same size this isn’t a problem. In fact, it can even improve
performance since Oracle won’t have to create a new extent when a user needs one.

You might also like