oracle 100 questions

Upload: born-to-access-on-web

Post on 01-Jun-2018

241 views

Category:

Documents


1 download

TRANSCRIPT

  • 8/9/2019 Oracle 100 Questions

    1/23

    ) How to set pga size, can you change it while the database is running?

    show parameter pga_aggregate_target;alter system set pga_aggregate_target=100m;

    Yes the pga can be changed while the database is up and running.

    2) How to know which parameter is dynamic/static?

    ISSES_MODIFIABL

    E

    VARCHAR2(5

    )

    Indicates whether the parameter can be changed with ALTER

    SESSION(TRUE) or not (FALSE)

    ISSYS_MODIFIABL

    E

    VARCHAR2(9

    )

    Indicates whether the parameter can be changed with ALTER

    SYSTEMand when the change takes eect!

    IMMEDIATE" #arameter can be changed with ALTER

    SYSTEMregardless o the type o parameter ile used to start the

    instance. $he change takes eect immediately.

    DEFERRED" #arameter can be changed with ALTER

    SYSTEMregardless o the type o parameter ile used to start the

    instance. $he change takes eect in subse%uent sessions.

    FALSE" #arameter cannot be changed with ALTER

    SYSTEMunless a ser&er parameter ile was used to start the

    instance. $he change takes eect in subse%uent instances.

    '* desc &+parameter'* select distinct I''Y'_,-I/I2 rom &+parameter;

    3) How to know how much free memory available in sga?

    select 3 rom &+sgastat where name =4ree memory5;

  • 8/9/2019 Oracle 100 Questions

    2/23

    ) !hat are oracle storage structures?

    -racle storage structures are tablespace6segment6e7tent6oracle block

    ") #ist types of $racle ob%ects

    table6inde76cluster table6I-$ (Inde7 -rganisation

    $able)6unction6package6synonym6trigger6se%uence

    &) !hat is an inde', how many types of inde'es you know? !hy you need an inde'

    Inde7 is an oracle ob8ect which is used to retrie&e the data much aster rather than scanningentire table.$ypically this is like an inde7 page in a book which contains the links to thepages6where we can go through easily through out the book.I inde7 page is not there6we ha&e to search each and e&ery page or our need6so we use inde7esin oracle also to retri&e the data %uickly.

    (ypes of inde'es

    *tree inde'9sed or searches mostly when used select statements(27!pincode)bit map inde'when ha&ing low cardinolity (low priority) columns used inthestatements.or e7ample! gender columnfunction based inde'sum(salary)6 upper(ename)6 lower(ename)reverse inde'used mostly to increase the speed o inserts (its like btree only but the key isre&erse).

    +) !hat is synonym ?

    'ynonym is used to hide the comple7ity o the original ob8ect.or e7ample user :a4 has table :t4 which user :a4 wants to hide the name but user :b4 has to accessit.

    In this case user :a4 can create a synonym on table :t4 and gi&e a select pri&iledge to user :b4.'* create synonym aishu on t;'* grant select on aishu to b;

    iew! _'Y

  • 8/9/2019 Oracle 100 Questions

    3/23

    undo! to store undo segmentstemp! to store the sort segments

    01) !hat is the difference between #ocally managed tablespace and dictionary managed

    tablespace?

    ,$! ocally ,anaged $able space stores all the e7tent mapping or allocation details in theheader o the data ile,$!ictionary ,anaged $able space stores all the e7tent mapping or allocation details in thedictionary table called 92$+ and /2$+'ince e&erytime an allocation o e7tents generate some recursi&e s%l on 92$+ and /2$+ this iscontention in dictionary cache6 hence this is not good or perormance o database6 but ,$ canstore this outside o dictionary 6 co> it stores in header o the data ile.y eault rom 10g the management is ,$ only

    00) !hat is utomatic segment space management? and how to find the tablespace in

    4?

    -racle will allocates the e7tents automatically to the table or segment depending upon the si>e othe table.?e need not to gi&e the storage parameters.'*desc dba_tablespaces;'* select tablespace_name6 allocation_type6segment_space_management6e7tent_managementrom dba_tablespaces;

    02) !hat is uniform segment? How to find it?

    In uniorm segment e&ery e7tent will ha&e same si>e.'*desc dba_tablespaces;'* select tablespace_name6 allocation_type6segment_space_management6e7tent_managementrom dba_tablespaces;

    03) !here do you see the tablespace information?

    '*select 3 rom dba_tablespaces;

    0) How to find the datafiles that associated with particular tablespace? 5' ystem

    '* desc dba_data_iles'* select 3 rom dba_data_iles where tablespace_name=4'Y'$2,5;

    0") How to see which undo tablespace is used for database?

    '* show parameter undo_tablespace

  • 8/9/2019 Oracle 100 Questions

    4/23

    0&) How to see the default temporary tablespace for a database?

    '* select #B-#2B$Y_e integer E1F

    0) 6s it possible to have multiple blocksizes in a database if so how? 5'plain

    Yes it is possible but we ha&e to create multiple buer pools while setting the re%uired blocksi>e parameter.$o do that it re%uire database bounce./or e7ample i you want to ha&e k si>e along with deault Ek'* show parameter db_k_cache_si>e'*alter system set db_k_cache_si>e=100, scope=spile;'*shut immediate

    ee7ample!'*create tablespace test_k dataile :Gu01GoradataGpadduGtestk.db4 si>e 100, block si>e k;

    0.) !hat is the oracle block, can you e'plain?

    -racle block is the lowest le&el o storage structure where it contains the data(businessGoracledata)$he block has di&ided into many sections starting rom block header6row header6rowdirectory6I$ list(Intrested $ransaction ist)6ree space.

    21) 7an you change the blocksize once the database is created?

    -bsolutely no beco> once the datailes is ormatted into Ek we cannot change the database blocksi>es 6 i you need6 you ha&e to create resh database with new block si>e and restore rombackup or import.

  • 8/9/2019 Oracle 100 Questions

    5/23

    21) Can you change the database name once the database is

    created?Yes we can but the database has to be shutdown and also this

    will change all of the headers of the filesOption 1

    1) Using NI utilitya)!"#$alter database close%

    b) nid target&sys as sysdba dbname&'etan(this will change thecontrol files and headers of the datafiles with the correction of

    new name)c)cd O*+C#,-.O/,0dbs

    d) cp initaishuora init'etanorae)i init'etanorafind db-name parameter and change it to 'etan

    f)i 0etc0oratabchange the name aishu to 'etan

    g) oraenset the ariable O*+C#,-!I&'etan

    f) startup the database!"#$ startup (but the database open will error out since the

    datbase should open with resetlogs)h) alter database open resetlogs%

    Option 23y changing the control file

    a)alter database bac'up control file to trace%

    b)go to trace directory and edit the control file tracec)In control file trace update database name aishu to 'etan

    d)shut down the database

    e)remoe the control file

  • 8/9/2019 Oracle 100 Questions

    6/23

    f)i init file and change the dbname aishu to 'etan

    g)startup nomounth)e4ecute the control file trace which we modified earlier(this

    will create a new control file in the location with the newdbname )

    i) alter database open resetlogs%

    22) 7an you change the instance name once the database is created?

    '*alter system set instance_name=4test4 scope=spile;shut immediate;cp spilepaddu.ora spilekarthika.orae7port -BD2_'I=karthikastartup

    23) 7an you rename the tablespace once it is created?

    '*alter tablespace testtbs1 rename to testtbsA;

    2) 7an you rename the user once it is created?

  • 8/9/2019 Oracle 100 Questions

    7/23

    '*desc t;alter table t rename column result_cache to aishu;

    2+) !here you can see the datafile information?

    desc dba_data_iles;

    '* select tablespace_name6ile_name6autoe7tensible6 bytesG10G10 'IJ2_, romdba_data_iles;

    E) ?here you can see the tempile or tablespace inormationK(or a particular database)desc dba_temp_iles;

    desc dba_tablespaces;

    2.) !hat is the difference between v8 views and dba views?

    dba &iews are static &iews&+ &iews are dynamic &iewsdba &iews are a&ailable once the db is in open mode only+ can be &iewed e&en the database is in mount state

    31) !hat is the difference between a role and privilege , can you provide an e'ample?

    'et o pri&iliges is nothing but a role.pro&iding authorisation to an user such as create6alter6delete6drop6truncate6insert6update.

    Low many types o pri&ileges are there Ksystem pri&ileges ! create sessionGuserob8ect pri&ileges ! insert6update6delete or create table

    30) !here to view the roles and privileges assigned to a user?

    /or roles!Mdescdba_roles can be used to know what are all the roles in a database.select 3 rom dba_roles;role_sys_pri&s can used to know what are all the system pri&ileges assigned to that role.

    role_tab_pri&s can be used to know what are all the ob8ect pri&ileges assigned to that roledba_role_pri&s can be used to know the grantees assigned to that role

    9or privileges:

    dba_tab_pri&s! can be used to know what all pri&ileges assigned to a user'* select grantee6owner6table_name6grantor6pri&ilege rom dba_tab_pri&s wheregrantee=4I'L95;

  • 8/9/2019 Oracle 100 Questions

    8/23

    dba;sys;privs to know what all system privileges assigned to a user

    '* select grantee6pri&ilege rom dba_sys_pri&s where grantee=4I'L95;

    32) !hat is the difference between with grant option and with admin option while

    assigning privileges?

    Nrant option ! ?e can grant that grant to other useradmin option ! can be used or sysdba pri&ileges to grant other

    grant select on $ to aishu with grant option;ishu can grant select on table $ to any one;

    grant dba to aishu with admin option;aishu can grant or manage dba role and assign to anyone.

    3) How to reovoke privilege or role?

    re&oke select on $ rom aishu;re&oke suresh rom aishu;(suresh is a role here )

    33) How to change the default tablespace for a user?

    alter user aishu deault tablespace t;

    3) How to give a tablespace -uota to a user?

    alter user aishu grant unlimited %uota on tablespace t;

    3&) !hat are constraints? 7an you list them and when will you use them?

    Donstrains in oracle are use to protect the integrity o the data.or e7ample a not null constraint will not allow any null &alue in the columna uni%ue constraint will not allow any duplicate &alue in the columna primary key constraint will not allow any duplicate &alue and null in the column.a oreign key constraint will be rom the one o the primary key o the table which means datamust resides in the primary key table(,aster list table)

    ,aster $able (a table that contains primary key)'* create table pincode (area &archar(A0)6 pincodenum number primary key);'* insert into pincode &alues (:,iyapur46H000F);'* insert into pincode &alues(:meerpet46H000E);

    Dhild $able ( aa table that is reerred to primary key column)'* Dreate table employee (empname &archar(A0)6empid number uni%ue6address1&archar(10) check=4Lyderabad46 address &archar(0)6pincode numberconstraint pin_k oreign key(pincode) reerences pincode (pincodenum));

    '* Insert into employee &alues(:ishu46164meerpet64ine464H000EO);

  • 8/9/2019 Oracle 100 Questions

    9/23

    3+) !hat is e6 beore creating tablespace it is assumed thatyou ha&e created a db buer cache or it.

    3) !hat is row migration? !hen does it occur? !here can you find this information?

    Bow migration happens when update occurs at one column and the row is not ade%uate to it inthe block then the entire row will be mo&ed to the new block.

    select table_name6chain_cnt rom dba_tables where table_name=4tablename5;'olution!set pct_ree storage parameter or table to ade%uate.;

    3.) How to find whether the instance is using spfile or pfile?

    show parameter spile;

    1) How to create password file?

    orapwd ile=+-BD2_L-,2GdbsGpwaishu.ora entry=H ignore case=Y;

    0) How to create a database manually , can you provide steps briefly?1) create a parameter ile in Gdbs directory with necessary parameters likedb_name6instance_name6control ile locations6sga_ma7_si>e etc..)create necessary directories or datailes6trace iles6redo log iles6 control iles according -/A)prepare the create db command)create catalog &iews (compile6in&alid)H)add entries in listner.ora6tnsnames.oraP) add entry in GetcGoratab

    2) !hat is $9? !hat is the benefit of it?

    -racle /le7ible rchitecture

    ierent directory structures with di iles and we keeping the iles (redolog6control etc) in thecorresponding described locations which keeps the iles in track and we can easily managethem6Inaddition to tha IG- will be redistributed.

    3) !hat does system tablespace and sysau' tablespace contains?

    system table space stores the system tables such as dbtables6oracle base tables6dictionary ob8ectsthat related to oracle.a kind o metada(data about data)

  • 8/9/2019 Oracle 100 Questions

    10/23

    'ysau7 table space! rom 10g onwards oracle has segregated some o the dictionary ob8ects to becreated in sysau7 table space seperating rom system table space to reduce the burden on the onetable spaceor example oracle session statistics,system statistics,awr data( automaticwork load repository),oracle execution statistics

    ) o you know about statistics , what is the use of it? !hat kind of statistics e'ists in

    database?

    'tatistics is a collection inormation about data or database$here are dierent types o statistics that oracle maintainsM1)'ystemM'tatistics! statistics about the hardware like cpu speed6IG- speed6read time write timeetc ! select 3 rom au7_stats+)-b8ect statistics ! /or a table oracle collects the inormation about no.o rows6no.oblocks6a&grow length etc.?e can &iew'*select table_name6num_rows6blocks6a&g_row_len rom dba_tablesor inde7 oracle collect statistics on inde7 column about no.o rows6no.o root

    blocks6no.obranch blocks6no.o lea blocks6no.o distinct &alues etc.

    &= !hy you need statistics to be collected?

    $hese statistics wil help the %uery e7ecution engine called optimi>er to determine how best thedata can the accessed

    ") !here to find the table size?

    table=create segment in a tablespace6 that segment contains e7tents and that e7tents containsblocks

    $=100 3 E1F = E1F00000dba_segments

    >#select segment;name,bytes/012/012 from dba;segments where segment;name@A(BC

    & How to find the size of a database?

    select sum (bytes) rom dba_segments;

    &) !here to find different types of segments in oracle database?

    select distinct segment_type rom dba_segments;

    +) How to resize the datafile?

    $o resi>e a dataile the irst most thing is the data ile should be in auto e7tendable mode$2B $'2 $/I2 :Gu0GoracleGrbdb1Gstu01.db4 B2'IJ2 100,;.

  • 8/9/2019 Oracle 100 Questions

    11/23

    Dan i resi>e the dataile to lesser than it hasKI ha&e 1gbI want to 100,6ut the data in that dataile is upto H00,can i resi>e to 100mbK

    Yes we can unless the data is not abo&e 100, in the dataile.

    ) How to add datafile to a tablepsace?

    alter tablespace t add dataile :Gu01GoradataGpadduGtbs1O si>e 100,;

    .) How to delete the datafile?

    alter tablespace t drop dataile :Gu01GoradataGpadduGtbs1O

  • 8/9/2019 Oracle 100 Questions

    12/23

    ") How to create schema?

    schema is nothing but an user.

    "") How to grant privileges to user?

    using grant command

    grant create table to user;

    grant create table to user with grant option;

    e.

    ") !hat is cursor?

    Dursor is some thing which resides in the #N and dc in 'N

    cursor is a handle6 or pointer6 to the conte7t area. $hrough the cursor6 a S Dursors allow youto etch and process rows returned by a '22D$. statement6 one S. $hrough the cursor6 a

    #G' program can control the conte7t area and what happens to it as

    the statement is processed. $wo important eatures about the cursor are implict and e7plictcursors

    ".) 7an you tell various dynamic views you know about and their purpose?

  • 8/9/2019 Oracle 100 Questions

    13/23

    v8session:shows about sessions information that logged into database

    27!select sid6status6username6logon_time6blocking_session6module6e&ent6s%l_id rom &+session

    v8process (o view the process information to attached to the session

    27! select pid6spid6addr rom &+process

    v8database (o view the database information

    27! select dbid6name6open_mode6created rom &+database;

    v8instance (o view the instance information

    27! '*select I

  • 8/9/2019 Oracle 100 Questions

    14/23

    v8pgatatdisplays about pga allocated in the database

    '*select 3 rom &+pgastat;

    v8sga;resize;ops isplays information about sga resize operation when sga target is set

    '* select 3 rom &+sga_resi>e_ops;

    v8sysstat isplays the systems statistics information

    '* select 3 rom &+sysstat;

    v8sesstat isplays the information about session statistics

    '* select 3 rom &+sesstat;isplay each statistics inormation rom sysstat but or each session6 so P0 statistics T eachsession

    v8logfile isplays information about the redo log files

    '* select groupU6member6status rom &+logile;

    v8log isplays information about redolog groups

    '*select groupU6members6status rom &+log;

    &+undostat ! isplays the inormation about undo usage in the database

    &+sysau7_occupants ! isplays the inormation about ob8ects that resides in sysau7 table space

    &1) ifference between v8 views and dba;views?

    + &iews are dynamic and populated rom base table like T+L and 9'2B+ etc etc

    _33 &iews are the the &iews built on top o &+ &iews in combination. or e7ample &+sessionhas been built rom &+session6user+ etc

    &1) !here to view the session information?

    '* select sid6status6username6logon_time6machine6s%l_id6blocking_session6e&ent rom&+session where sid=V;

    I you do not know the sid replace with any column inormation you know in where condition.

    &0) !here to view the process associated with session information?

    select sid6status6username6action6program6machine rom &+session where paddr in (select addrrom &+process where spid=H0P);

  • 8/9/2019 Oracle 100 Questions

    15/23

    &0) !here to view the locks in oracle database?

    &+lockP) ?hat are locksKlocks are low le&el serialisation mechanism called end %ueues in oracle which protects thedatabase o data changes

    &3) !hat latches?

    latches are typically a kind o locks but held or &ery short time to protect the memory structureso the instance

    &) !here does $racle latch or lock occurs?

    -racle latch occurs in the memory structures i.e6 in instance e7!buer latch6redolog latch6sharedpool latch-Bacle lock occurs at block le&el to protect the integrity o the data as the data stored in theblock only e7! row lock6table lock etc

    &") !here to see the information about latches?

    &+latch and &+latch_children

    &&) How to switch from pfile to spfile?

    '*create spile rom pile;bounce the database;

  • 8/9/2019 Oracle 100 Questions

    16/23

    ,'_,2$$.N2$_(:$2464$464I'L94)@@@@@@@@@@@@@@@@@@@@@@@@@@"

    DB2$2 $2 WI'L9V.V$V( WTV BDLB(100)

    ) '2N,2

  • 8/9/2019 Oracle 100 Questions

    17/23

    +2) How to set the log archive destination? can we have multiple destinations for

    archivelogs?

    Yes we can ha&e multiple destination or achi&elogswe can ha&e A0 destination rom 11g onwardsto see destiantion you can use ollow and set accordingly

    show parameter log_archi&e

    '* alter system set log_archi&e_dest=V scope=memory;

    'ystem altered.

    '* alter system set log_archi&e_dest_1=4location=Gu0Garchi&esGpaddu4 scope=memory;

    'ystem altered.

    '* alter system set log_archi&e_dest_=4location=Gu01Garchi&esGpaddu4 scope=memory;

    'ystem altered.

    '*

    56) Can you rename a database? 7roide steps?Yes8 we can rename a database8 we hae two topins

    Until 19g8

    +s the database name is written in control file we hae tochange the database name in control file and in init file

    1 +lter atabase bac'up control file to trace%2 +boe step will create a te4t control file in user-dump-dest

    directory6 Change name of the atabase in aboe file and ininitora file

    : !;+*;U7 NO/OUN;!%rom 19g onwards

    Using NI utility

  • 8/9/2019 Oracle 100 Questions

    18/23

    If I am changing the database name 8 does mu bac'up are alid?

    Inalid8 Your database name is changed so the old bac'upbac'up in inalid as the name is old8 rman chec' with dbid and

    name+) !hy you need to do open resetlogs, what does it?

    ?hene&er there is reco&ery operation perormed speciically incomplete media reco&ery 6 thedatabase must be open with reset logs since we dont ha&e the archi&es or redo inormation untilpoint o ailure6 hence this is re%uired. urther this will reset the archi&e log se%uence

    +") How to multiple' controlfiles?

    i we are using pile!show parameter control_iles;

  • 8/9/2019 Oracle 100 Questions

    19/23

    '*drop tablespace tablespace name including contents;i you want to drop the associated datailes also with table space we should use'*drop tablespace tablespace name including contents and datailes;

    0) !hat is the difference between $racle home and oracle base

    -BD2_'2 is the root directory or oracle. -BD2_L-,2 located beneath-BD2_'2 is where the oracle products reside.

    2) !here do you check the free space of ob%ects?

    '*dba_ree_space;select 3 rom dba_ree_space;

    3) How to kill the blocking session, how to find the blocking session?

    ?e ha&e to ind the blocking session inormation by using'*select sid6username6serialU6status6e&ent6blocing_session rom &+session whereusername=4'Y'5;

  • 8/9/2019 Oracle 100 Questions

    20/23

    $otal 'N manually allocated in pools! 10,

    I ha&e also kept 'N_,T_'IJ2=00, in pile and started the database which one the -racleconsider6 10, or 00,

    10,6 i the sga_ma7_si>e is lesser than the all pools total i speciied in pile thensga_ma7_si>e parameter is ignored.

    &) #ist Drocess you follow to start looking into Derformance issue at database level F6f the

    application is running very slow, at what points do you need to go about the database in

    order to improve the performance?)

    nswer ( lthough i ha&e ne&er worked directly on perormance issues6 the below can be steps)

    Bun a $-# command in 9ni7 to see D#9 usage (identiy D#9 killer processes)

    Bun ,'$$6 'B6 and #B'$$ command to get more inormation on D#9 and memoryusage and possible blockingBun ?B report to identiy!1. $-# H ?I$ 22

  • 8/9/2019 Oracle 100 Questions

    21/23

    .0) !hat is tns string?

    tns string is an entry to identiy the database host6db port and the db name.-racle will use oracles%lplus will use this entries appropriate or right database host.

    F) ?hat is tnsentryK

    $ns entry is a address to the database host and database written in the tnsnames.ora6generally tnsnames.ora located at +-BD2_L-,2GnetworkGadmin

    .2) How to change the database into archivelog mode?

    '* archi&e log list;atabase log mode rchi&e ,odeutomatic archi&al 2nabledrchi&e destination Gu01Garchi&esGpaddu-ldest online log se%uence

  • 8/9/2019 Oracle 100 Questions

    22/23

    .+)How to set new undo tablespace in oracle database?

    create a new undo tablespace'* create undo tablespace undotbs dataile :Gu01GoradataGpadduGundotbs.dbs4 si>e 100m;

    $ablespace created.

    '* show parameter undo_tablespace;

  • 8/9/2019 Oracle 100 Questions

    23/23

    1. create user new_userS. grant S to new_user;A. e7ecute dbms_tts.transport_set_check(S);. alter tablespace S read only;H. e7p transport_tablespace=y tablespaces=S

    P. drop tablespace S including contents;X. imp transport_tablespace=y tablespaces=S datailes=S romuser=old_user touser=newuserE. create nondata ob8ects in new_user schemaF. [drop user old_user cascade;\10. alter tablespace S read write;

    Share this:

    Twitter

    Facebook

    Google

    13 thoughts on Oracle DBA Interview Question

    & Answers

    1.

    http://ishudbablog.wordpress.com/interview-questions/46-2/?share=twitter&nb=1http://ishudbablog.wordpress.com/interview-questions/46-2/?share=facebook&nb=1http://ishudbablog.wordpress.com/interview-questions/46-2/?share=google-plus-1&nb=1http://ishudbablog.wordpress.com/interview-questions/46-2/?share=facebook&nb=1http://ishudbablog.wordpress.com/interview-questions/46-2/?share=google-plus-1&nb=1http://ishudbablog.wordpress.com/interview-questions/46-2/?share=twitter&nb=1