Senior Oracle DBA Interview Questions
Senior Oracle DBA Interview Questions
TYPE
VALUE
undo_tablespace
string
UNDOTBS3
SQL>
16) How to see the default temporary tablespace for a database?
SQL> select PROPERTY_NAME,PROPERTY_VALUE from database_properties where
PROPERTY_NAME like %TEMP%';
PROPERTY_NAME
PROPERTY_VALUE
DEFAULT_TEMP_TABLESPACE
TEMP2
17) How to see what is the default block size for a database ?
SQL> show parameter block_size;
NAME
TYPE
VALUE
db_block_size
integer
8192
22) Can you change the instance name once the database is created?
SQL>alter system set instance_name=test scope=spfile;
shut immediate;
cp spfilepaddu.ora spfilekarthika.ora
export ORACLE_SID=karthika
startup
23) Can you rename the tablespace once it is created?
SQL>alter tablespace testtbs1 rename to testtbs3;
24) Can you rename the user once it is created?
No there is no direct command to change the user name but there is a work around.
1) export user
exp / as sysdba owner=paddu file=/home/oracle/paddu.dmp
sqlplus / as sysdba
SQL> drop user paddu cascade;
QL>create user aishu identified by aishu;
SQL>grant connect,resource to aishu;
SQL> exit
imp file=/home/oracle/paddu.dmp fromuser=paddu touser=aishu
sqlplus / as sysdba
SQL>select username from dba_users;
25) Can you rename the table once it is created?
Yes
connect to user aishu
SQL>connect aishu/aishu
SQl>select * from tab
SQL> create table t as select * from user_tables;
(or)
SQL> create table dummy (id number,name varchar2(50),salary number);
SQL>rename t to t1
26) Can you rename the column in a table?
yes
SQL>desc t;
alter table t rename column result_cache to aishu;
27) Where you can see the datafile information?
desc dba_data_files;
SQL> select tablespace_name,file_name,autoextensible, bytes/1024/1024 SIZE_MB from
dba_data_files;
28) Where you can see the tempfile or tablespace information?(for a particular database)
desc dba_temp_files;
desc dba_tablespaces;
29) What is the difference between v$ views and dba views?
dba views are static views
v$ views are dynamic views
dba views are available once the db is in open mode only
V$ can be viewed even the database is in mount state
30) What is the difference between a role and privilege , can you provide an example?
Set of priviliges is nothing but a role.
providing authorisation to an user such as create,alter,delete,drop,truncate,insert,update.
How many types of privileges are there ?
system privileges : create session/user
object privileges : insert,update,delete or create table
31) Where to view the roles and privileges assigned to a user?
For roles:-desc
dba_roles can be used to know what are all the roles in a database.
select * from dba_roles;
role_sys_privs can used to know what are all the system privileges assigned to that role.
role_tab_privs can be used to know what are all the object privileges assigned to that role
dba_role_privs can be used to know the grantees assigned to that role
For privileges:dba_tab_privs: can be used to know what all privileges assigned to a user
SQL> select grantee,owner,table_name,grantor,privilege from dba_tab_privs where grantee=AISHU';
dba_sys_privs: to know what all system privileges assigned to a user
SQL> select grantee,privilege from dba_sys_privs where grantee=AISHU';
32) What is the difference between with grant option and with admin option while assigning
privileges?
Grant option : We can grant that grant to other user
admin option : can be used for sysdba privileges to grant other
grant select on T to aishu with grant option;
Aishu can grant select on table T to any one;
grant dba to aishu with admin option;
aishu can grant or manage dba role and assign to anyone.
34) How to reovoke privilege or role?
revoke select on T from aishu;
revoke suresh from aishu;(suresh is a role here )
33) How to change the default tablespace for a user?
alter user aishu default tablespace t;
34) How to give a tablespace quota to a user?
alter user aishu grant unlimited quota on tablespace t;
36) What are constraints? Can you list them and when will you use them?
Constrains in oracle are use to protect the integrity of the data.
for example a not null constraint will not allow any null value in the column
a unique constraint will not allow any duplicate value in the column
a primary key constraint will not allow any duplicate value and null in the column.
a foreign key constraint will be from the one of the primary key of the table which means data must
resides in the primary key table(Master list table)
Master Table (a table that contains primary key)
SQL> create table pincode (area varchar2(30), pincodenum number primary key);
SQL> insert into pincode values (Miyapur,500049);
SQL> insert into pincode values(Ameerpet,500084);
Child Table ( aa table that is referred to primary key column)
SQL> Create table employee (empname varchar2(30),empid number unique,address1 varchar2(10)
check=Hyderabad, address2 varchar2(20),pincode number
constraint pin_fk foreign key(pincode) references pincode (pincodenum));
SQL> Insert into employee values(Aishu,1,Ameerpet,Line,500084);
37) What is Row chaining? When does it occur? where can you find it? What is the solution?
When the row is not adequate to fit in the block while inserting oracle will insert half row in one
block and half in another block leaving a pointer between these two blocks.
select table_name,chain_cnt from dba_tables where table_name=tablename';
Solutions:
create a table with bigger the block size
1) Create tablespace ts data file /u01/oradata/aishu/paddu.dbf size 100m blocksize 16k;
2) alter table employee move to ts;
Here TS is the tablespace name with bigger size, before creating tablespace it is assumed that you
have created a db buffer cache for it.
38) What is row migration? When does it occur? Where can you find this information?
Row migration happens when update occurs at one column and the row is not adequate to fit in the
block then the entire row will be moved to the new block.
select table_name,chain_cnt from dba_tables where table_name=tablename';
Solution:
set pct_free storage parameter for table to adequate.;
39) How to find whether the instance is using spfile or pfile?
show parameter spfile;
40) How to create password file?
orapwd file=$ORACLE_HOME/dbs/pwaishu.ora entry=5 ignore case=Y;
41) How to create a database manually , can you provide steps briefly?
1) create a parameter file in /dbs directory with necessary parameters like
db_name,instance_name,control file locations,sga_max_size etc..
2)create necessary directories for datafiles,trace files,redo log files, control files according OFA
3)prepare the create db command
4)create catalog views (compile,invalid)
SQL> @?/rdbms/admin/catalog.sql
SQL> @?/rdbms/admin/catproc.sql
SQL>desc dba_profiles;
SQL> select username,profile from dba_users;
52) How to change the profile of a user?
alter user username profile profile name
53) How to create user?
create user username identified by password default tablespace testtbs1 profile test;
ex: create user paddu identified by paddu default tablespace testtbs1 profile test;
SQL> select username,profile from dba_users;
SQL> grant connect,resource to paddu;
54) How to create schema?
schema is nothing but an user.
55) How to grant privileges to user?
using grant command
grant create table to user;
grant create table to user with grant option;
Note: with grant option provides user to grant the privilege to other users as well, kind of admin
56) Can you delete alert log while database is up and running?
show parameter background;
Yes database can create a new alert log file,but whenever any activity happens in the database it
creates a new alert log file
Yes one can delete or move the alert log file while the database is up and running there will be no
impact,oracle will automatically creates a new alert log if it not found any in the directory
57) What is fragmentation of table?
Fragmentation of a table is something when ever there is a purge or deletion of a table.Oracle will
not use those unused blocks and always try to allocate the extents above high watermark.this leads
the table to grow larger than its size.
Two important features about the cursor are implicit and explicit cursors.
An implicit cursor is one created "automatically" for you by Oracle when you execute a query. It is
simpler to code, but suffers from
Inefficiency (the ANSI standard specifies that it must fetch twice to check if there is more than one
record).
Vulnerability to data errors (if you ever get two rows, it raises a TOO_MANY_ROWS exception).
Example :SELECT col INTO var FROM table WHERE something;
An explicit cursor is one you create yourself. It takes more code, but gives more control - for
example, you can just open-fetch-close if you only want the first record and don't care if there are
others.
Example:DECLARE
CURSOR cur IS SELECT col FROM table WHERE something;
BEGIN
OPEN cur;
FETCH cur INTO var;
CLOSE cur;
END;
59) Can you tell various dynamic views you know about and their purpose?
v$session-shows about sessions information that logged into database
Ex:select sid,status,username,logon_time,blocking_session,module,event,sql_id from v$session
v$process : To view the process information to attached to the session
Ex: select pid,spid,addr from v$process
v$database: To view the database information
Ex: select dbid,name,open_mode,created from v$database;
X VARCHAR2(100)
X VARCHAR2(100)
Log switch occurs when the current redo log is full and the log writer has to go to next redo log
group.
71) Where to view the undo usage information?
v$undostat
72) How to set the log archive destination? can we have multiple destinations for
archivelogs?
Yes we can have multiple destination for achivelogs
we can have 30 destination from 11g onwards
to see destiantion you can use follow and set accordingly
show parameter log_archive
SQL> alter system set log_archive_dest= scope=memory;
System altered.
SQL> alter system set log_archive_dest_1=location=/u02/archives/paddu scope=memory;
System altered.
SQL> alter system set log_archive_dest_2=location=/u01/archives/paddu scope=memory;
System altered.
SQL>
73) Can you rename a database? Provide steps?
Yes, we can rename a database, we have two topins
Until 10g,
As the database name is written in control file we have to change the database name in control file
and in init file.
1. Alter Database backup control file to trace;
2. Above step will create a text control file in user_dump_dest directory.
3. Change name of the Database in above file and ininit.ora file.
4. STARTUP NOMOUNT
5. Run the script that was modified in step 3
6. ALTER DATABASE OPEN RESETLOGS;
From 10g onwards
Using NID utility
If I am changing the database name , does mu backup are valid?
Invalid, Your database name is changed so the old backup backup in invalid as the name is old, rman
check with dbid and name.
74) Why you need to do open resetlogs, what does it?
Whenever there is recovery operation performed specifically incomplete media recovery , the
database must be open with reset logs since we dont have the archives or redo information until
point of failure, hence this is required. further this will reset the archive log sequence
75) How to multiplex controlfiles?
if we are using pfile:
show parameter control_files;
Note down the control file location
shut down the database
copy the control file old location to newer location
add the new control file location in parameter file
startup the database
show parameter control_files;(this shows the old and new location as well)
if we are using spfile:
show parameter control_files;
alter system set controlfile=oldlocation,newlocation scope=spfile
shut down the database
copy the control file from old location to new location
startup the database
76) How to multiplex redo log files?
alter database add log to group3;
77) How to add redo log groups to a database?
alter database add log size 50m group6;
v$log or v$logfiles;
78) Can you drop the redo log groups while the database is up and running?
Yes we can drop the redolog group but the redo log should be inactive
79) Can you drop the system tablespace, if so what happened to database?
No we cant drop the system tablespace.Oracle will not allow it
80) Can you drop the normal tablespace, if so what happened to database?
Yes we can drop the normal table spaces but the associated objects will be dropped
Archive Mode
Automatic archival
Enabled
Archive destination
/u01/archives/paddu
24
26
TYPE
VALUE
undo_tablespace
string
UNDOTBS3
2212448 bytes
Variable Size
167775648 bytes
Database Buffers
Redo Buffers
88080384 bytes
4980736 bytes
Database mounted.
Database opened.
SQL> show parameter undo_tablespace;
NAME
TYPE
VALUE
undo_tablespace
string
UNDOTBS4
SQL>
100) Renaming schema
Fastest Way, since the original import will not happen only metadata creation will happen, as
the transportable import has been performed, In TTS the associated datafiles will be attached
to new user , hence the datafiles with existing object(tables/indexex etc) will be point to new
user.
1. create user new_user
2. grant to new_user;
3. execute dbms_tts.transport_set_check();
4. alter tablespace read only;
5. exp transport_tablespace=y tablespaces=
6. drop tablespace including contents;
7. imp transport_tablespace=y tablespaces= datafiles= fromuser=old_user touser=newuser
8. create nondata objects in new_user schema
9. [drop user old_user cascade;]
10. alter tablespace read write;