Вы находитесь на странице: 1из 13

Difference between locks and latches

Locks are used to protect the data or resources from the simultaneous use of them by
multiple sessions which might set them in inconsistent state. Locks are external mechanism,
means user can also set locks on objects by using various oracle statements.
Latches are for the same purpose but works at internal level. Latches are used to Protect
and control access to internal data structures like various SGA buffers. They are handled
and maintained by oracle and we cant access or set it.
Setting the audit_trail parameter in the database to db, it generates lot of
records in sys.aud$ table. Can you suggest any method to overcome this issue?
1. When you set audit it does audit for every single activity on the database. So it may lead
into performance problem.
You have to disable every single audit(<> noaudit) before or after you set the parameter
and then enable one by one based on the requirement.
2. You should monitor the growth of sys.aud$ and archive it properly or maintain the space.
How to change the topnsql of AWR Snapshot in 10g
Select * from DBA_HIST_WR_CONTROL
1898043910 +00 01:00:00.000000 +01 00:00:00.000000 DEFAULT
exec DBMS_WORKLOAD_REPOSITORY.MODIFY_SNAPSHOT_SETTINGS(topnsql => 30);
Select * from DBA_HIST_WR_CONTROL
1898043910 +00 01:00:00.000000 +01 00:00:00.000000 30
How to detect whos causing excessive redo generation
SELECT S1.SID, S1.SERIAL_NUM, S1.USER_NAME, S1.PROGRAM, T1.USED_UBLK,
T1.USED_UREC FROM V$SESSION S1, V$TRANSACTION T1 WHERE S1.TADDR = T1.ADDR
ORDER BY 5 DESC, 6 DESC, 1, 2, 3, 4;
Tracking undo generation by all session
SELECT S1.SID, S1.USER_NAME, R1.NAME, T1.START_TIME, T1.USED_UBLK ,
T1.USED_UREC FROM V$SESSION S1, V$TRANSACTION T1, V$ROLLNAME R1 WHERE T1.ADDR
= S1.TADDR AND R1.USN = T1.XIDUSN;
Or you can collect Statistics from V$SESSTAT to AWR
How do you remove an SPFILE parameter (not change the value of, but actually
purge it outright)?
Use "ALTER SYSTEM RESET ..." (For database versions 9i and up)
Syntax:
ALTER SYSTEM RESET PARAMETER SID='SID|*'
ALTER SYSTEM RESET "_TRACE_FILES_PUBLIC" SCOPE=SPFILE SID='*';
NOTE: The "SID='SID|*'" argument is REQUIRED!
Can you use RMAN to recover RMAN?
Yes, you can!
Which situation Exist condition is better than IN
If the resultant of sub query is small then IN is typically more appropriate where as
resultant of sub query is big/large/long then EXIST is more appropriate. The Exist always
results full scan of table where as first query can make use of index on Table.
Is Oracle really quicker on Windows than Solaris?
I found in my experience that Yes, windows perform better on comparable hardware just
about any UNIX box. I am working on Windows but once I installed Solaris trying to test. I
found the windows installations always outperformed the Solaris ones both on initial loading
the pool cache and subsequent runs. The test package is rather large (5000+ lines), which
is used in a form to display customer details. On Solaris I was typically getting an initial
return time of 5 seconds and on windows, typically, 1 second. Even subsequent runs (i.e.
cached) the windows outperformed Solaris. The parameter sizes for the SGA were approx.
the same and the file systems are the conventional method. In both cases the disk
configuration is local.
What is Difference between DBname and instance_name?
A database is a set of files (data, redo, ctl and so on) where as An instance is a set of
processes (SMON, PMON, DBWR, etc) and a shared memory segment (SGA).
A database may be mounted and opened by many INSTANCES (Parallel Server)
concurrently. An instance may mount and open ANY database -- however it may only open
a single database at any time. There for you need unique (for the set of files).
Does DBCA create instance while creating database?
DBCA does not create instance. It create database (set of files). The instance is only
feelings do a shutdown and goodbye instance and on windows it registers the necessary
services that can be used to start an instance when you want.
Is there any way to create database without DBCA?
Yes, you can used oradim directly
What's the difference between connections, sessions and processes?
A connection is a physical circuit between you and the database. A connection might be one
of many types -- most popular begin DEDICATED server and SHARED server. Zero, one or
more sessions may be established over a given connection to the database as show above
with sqlplus. A process will be used by a session to execute statements. Sometimes there
is a one to one relationship between CONNECTION->SESSION->PROCESS (eg: a normal
dedicated server connection). Sometimes there is a one to many from connection to
sessions (eg: like autotrace, one connection, two sessions, one process). A process does
not have to be dedicated to a specific connection or session however, for example when
using shared server (MTS), your SESSION will grab a process from a pool of processes in
order to execute a statement. When the call is over, that process is released back to the
pool of processes.
SQL>select username from v$session where username is not null;
you can see one session, me
SQL>select username, program from v$process;
you can see all of the backgrounds and my dedicated server...
Autotrace for statistics uses ANOTHER session so it can query up the stats for your
CURRENT session without impacting the STATS for that session!
SQL>select username from v$session where username is not null;
now you can see two session but...
SQL>select username, program from v$process;
Same 14 processes...
What about Fragmentation situation (LMT) in oracle 8i and up?
Fragmentation is that if you have many small holes (regions of contiguous free space) that
are too small to be the next extent of any object. These holes of free space resulted from
dropping some object (or truncating them) and the resulting free space cannot be used by
any other object in that tablespace. This is a direct result of using pctincrease that is not
zero and having many weird sized extents (every extents is unique size and shape). In
oracle 8i and above we all are using locally managed tablespace. These would use either
uniform sizing or our automatic allocation scheme. In either case it is almost impossible to
get into a situation where you have unusable free space.
To see if you suffer from fragmentation you can query from DBA_FREE_SPACE (best to do
an alter tablespace to ensure all contiguous made into 1 big free region). You would look
any free space that is smaller then the smallest next extent size for any object in that
tablespace. Check with below query:
Select * from dba_free_space
where tablespace_name = 'T' and bytes <= ( select min(next_extent)
from dba_segments where tablespace_name = 'T') order by block_id
Is there a way we can flush out a known data set from the database buffer cache?
No you dont, in real life; the cache would never be empty. It is true that 10g introduce an
alter system flush buffer_cache, but it is not really worthwhile. Having empty buffer cache is
fake, if no more so than what you are currently doing.
What would be the best approach to benchmark the response time for a particular
query?
run query q1 over and over (with many different inputs)
run query q2 over and over (with many different inputs)
discard first couple of observations, and last couple
use the observations in the middle
What is difference between Char and Varchar2 and which is better approach?
A CHAR datatype and VARCHAR2 datatype are stored identically (eg: the word 'WORD'
stored in a CHAR(4) and a varchar2(4) consume exactly the same amount of space on disk,
both have leading byte counts).
The difference between a CHAR and a VARCHAR is that a CHAR(n) will ALWAYS be N bytes
long, it will be blank padded upon insert to ensure this. A varchar2(n) on the other hand
will be 1 to N bytes long, it will NOT be blank padded. Using a CHAR on a varying width field
can be a pain due to the search semantics of CHAR.
Consider the following examples:
SQL> create table t ( x char(10) );
Table created.
SQL> insert into t values ( 'Hello' );
1 row created.
SQL> select * from t where x = 'Hello';
X
----------
Hello
SQL> variable y varchar2(25)
SQL> exec :y := 'Hello'
PL/SQL procedure successfully completed.
SQL> select * from t where x = :y;
no rows selected
SQL> select * from t where x = rpad(:y,10);
X
----------
Hello
Notice how when doing the search with a varchar2 variable (almost every tool in the world
uses this type), we have to rpad() it to get a hit. If the field is in fact ALWAYS 10 bytes
long, using a CHAR will not hurt -- HOWEVER, it will not help either.
Rman always shows date in DD-MON-YY format. How to set date format to
M/DD/YYYY HH24:MI:SS in rman ?
You can just set the NLS_DATE_FORMAT before going into RMAN:
In Rman list backup how do i get time column that shows me date and time
including seconds as generally it is showing only date.
Before connecting the rman target set the date format on command prompt:
export NLS_DATE_FORMAT=dd-mon-yyyy hh24:mi:ss - Linux
Set NLS_DATE_FORMAT=dd-mon-yyyy hh24:mi:ss - windows
then try to connect rman target
rman target sys/oralce@orcl3 catalog rman/rman@shaan
rman> list backupset 10453
Why not use O/S backups instead of RMAN?
There is nothing wrong with doing just OS backups. OS backups are just as valid as RMAN
backups. RMAN is a great tool but it is not the only way to do it. Many people still prefer
using a scripting tool of there choice such as perl or ksh to do this.
RMAN is good if you have lots of databases. The catalog it uses remembers lots of details
for you. You don't have as much to think about.
RMAN is good if you do not have good "paper work" skills in place. Using OS backups, it is
more or less upto you to remember where they are, what they are called and so on. You
have to do all of the book keeping RMAN would do.
RMAN provides incremental backups, something you cannot get without RMAN.
RMAN provides tablespace point in time recovery. You can do this without RMAN but you
have to do it by yourself and it can be rather convoluted.
RMAN is more integrated with OEM. If you do OS backups, you'll have to do everything
yourself. With RMAN you may have less scripting to develop, test and maintain.
RMAN if the catalog/controlfile are damaged? what is the next step?
If you lose rman, you rebuild from the controlfiles of the backed up databases but, you
should not lose the rman catalog using proper techniques of backup itself.
How to switch between Noarchivelog and archivelog in oracle 10g
connect "/ as sysdba"
alter system set log_archive_start=true scope=spfile;
alter system set log_archive_dest='......' scope=spfile;
shutdown immediate;
startup mount
alter database archivelog;
alter database open;
connect /
-and-
connect "/ as sysdba"
shutdown immediate
startup mount
alter database noarchivelog;
alter database open;
connect /
How to Update millions or records in a table?
If we had to update millions of records I would probably opt to NOT update.
I would more likely do:
CREATE TABLE new_table as select <do the update "here"> from old_table;
index new_table
grant on new table
add constraints on new_table
etc on new_table
drop table old_table
rename new_table to old_table;
You can do that using parallel query, with nologging on most operations generating very
little redo and no undo at all in a fraction of the time it would take to update the
data.
SQL>create table new_emp as select empno, LOWER(ename) ename, JOB,
MGR, HIREDATE, SAL, COMM, DEPTNO from emp;
SQL>drop table emp;
SQL>rename new_emp to emp;
How to convert database server sysdate to GMT date?
Select sysdate,
sysdate+(substr(tz_offset(dbtimezone),1,1)||1)*to_dsinterval(0
||substr(tz_offset( DBTIMEZONE ),2, 5)||:00) from dual;



Interview question with Answer Part 9
What is the difference between to back up the current control file and to backup
up control file copy?
If you backup current control file you backup control file which is currently open by an
instance where as If you backup controlfile file copy" you backup the copy of control file
which is created either with SVRMGRL command "alter system backup controlfile to .." or
with RMAN command "copy current controlfile to ...". In the other words, the control file
copy is not current controlfile backup current controlfile creates a BACKUPSET containing
controlfile. You don't have to give the FILENAME where as backup controlfile copy
<filename> creates a BACKUPSET from a copy of controlfile. You
have to give the FILENAME.
How much of overhead in running BACKUP VALIDATE DATABASE and RESTORE
VALIDATE DATABASE commands to check for block corruptions using RMAN? Can I
run these commands anytime?
Backup validate works against the backups not against the live database so no impact on
the live database, same for restore validate they do not impact the real thing (it is reading
the files there only).
Is there a way to force rman to use these obsolete backups or once it is marked
obsolete?
As per my understanding it is just a report, they are still there until you delete them.
Can I use the same snapshot controlfile to backup multiple databases(one after
another) running on the same server?
This file is only use temporarily like a scratch file. Only one rman session can access the
snapshot controlfile at any time so this would tend to serialize your backups if you do that.
Why does not oracle keep RMAN info after recreating the controlfile?
Creating the new controlfile from scratch how do you expect the create controlfile to "make
up" the missing data? that would be like saying similarly we have drop and recreated my
table and now it is empty similarly here recreating from the scratch means the contents
there will be naturally will be gone. Use the rman catalog to deal this situation. It is just a
suggestion.
What is the advantage of using PIPE in rman backups? In what circumstances one
would use PIPE to backup and restore?
It lets 3rd parties (anyone really) build an alternative interface to RMAN as it permits
anyone
that can connect to an Oracle instance to control RMAN programmatically.
How To turn Debug Feature on in rman?
run {
allocate channel c1 type disk;
debug on;
}
rman>list backup of database;
now you will see a output
You can always turn debug off by issuing
rman>debug off;
Assuming I have a "FULL" backup of users01.dbf containing employees table that
contains 1000 blocks of data. If I truncated employees table and then an
incremental level 1 backup of users tablespace is taken, will RMAN include 1000
blocks that once contained data in the incremental backup?
The blocks were not written to the only changes made by the truncate was to the data
dictionary (or file header) so no, it won't see them as changed blocks since they were not
changed.
Where should the catalog be created?
The recovery catalog to be used by Rman should be created in a separate database other
than the target database. The reason is that the target database will be shutdown while
datafiles are restored.
How many times does oracle ask before dropping a catalog?
The default is two times one for the actual command, the other for confirmation.
What are the various reports available with RMAN?
rman>list backup; rman> list archive;
What is the use of snapshot controlfile in terms of RMAN backup?
Rman uses the snapshot controlfile as a way to get a read consistent copy of the controlfile,
it uses this to do things like RESYNC the catalog (else the controlfile is a moving target,
constantly changing and Rman would get blocked and block the database)
Can RMAN write to disk and tape Parallel? Is it possible?
Rman currently won't do tape directly, you need a media manager for that, regarding disk
and tape parallel not as far as I know, you would run two backups separately (not sure).
May be trying to maintain duplicate like that could get the desired.
qq..What is the difference between DELETE INPUT and DELETE ALL command in
backup?
Generally speaking LOG_ARCHIVE_DEST_n points to two disk drive locations where we
archive the files, when a command is issued through rman to backup archivelogs it uses one
of the location to backup the data. When we specify delete input the location which was
backed up will get deleted, if we specify delete all (all log_archive_dest_n) will get
deleted.
DELETE all applies only to archived logs.
delete expired archivelog all;
Is it possible to restore a backupset (actually backup pieces) from a different
location to where RMAN has recorded them to be.
With 9.2 and earlier it is not possible to restore a backupset (actually backup pieces) from a
different location to where RMAN has recorded them to be. As a workaround you would
have to create a link using the location of where the backup was originally located. Then
when restoring, RMAN will think everything is the same as it was.
Starting in 10.1 it is possible to catalog the backup pieces in their new location into the
controlfile and recovery catalog. This means they are available for restoration by RMAN
without creating the link.
What is difference between Report obsolete and Report obsolete orphan
Report obsolete backup are reported unusable according to the users retention policy where
as Report obsolete orphan report the backup that are unusable because they belong to
incarnation of the database that are not direct ancestor of the current incarnation.
How to Increase Size of Redo Log
1. Add new log files (groups) with new size
ALTER DATABASE ADD LOGFILE GROUP
2. Switch with alter system switch log file until a new log file group is in state current
3. Now you can delete the old log file
ALTER DATABASE DROP LOGFILE MEMBER
What is the difference between alter database recover and sql*plus recover
command?
ALTER DATABASE recover is useful when you as a user want to control the recovery where
as SQL*PLUS recover command is useful when we prefer automated recovery.
Difference of two view V$Backup_Set and Rc_Backup_Set in respect of Rman
The V$Backup_Set is used to check the backup details when we are not managing Rman
catalog that is the backup information is stored in controlfile where as Rc_Backup_Set is
used when we are using catalog as a central repository to list the backup information.
Can I cancel a script from inside the script? How I cancil a select on Windows
client?
Use ctl-c
How to Find the Number of Oracle Instances Running on Windows Machine
C:\>net start |find OracleService
How to create an init.ora from the spfile when the database is down?
Follow the same way as you are using
SQL> connect sys/oracle as sysdba
SQL> shutdown;
SQL> create pfile from spfile;
SQL> create spfile from pfile;
When you shutdown the database, how does oracle maintain the user session
i.e.of sysdba?
You still have your dedicated server
!ps -auxww | grep ora920
sys@ORA920> !ps -auxww | grep ora920
sys@ORA920> shutdown
sys@ORA920> !ps -auxww | grep ora920
You can see you still have your dedicated server. When you connect as sysdba, you fire up
dedicated server that is where it is.
What is ORA-002004 error? What you will do in that case?
A disk I/O failure was detected on reading the control file. Basically you have to check
whether the control file is available, permissions are right on the control file, spfile/init.ora
right to the right location, if all checks were done still you are getting the error, then from
the multiplexed control file overlay on the corrupted one.
Let us say you have three control files control01.ctl, control02.ctl and control03.ctl and now
you are getting errors on control03.ctl then just copy control01.ctl over to control03.ctl and
you should be all set.
In order to issue ALTER DATABASE BACKUP CONTROLFILE TO TRACE; database should be
mounted and in our case it is not mounted then the only other option available is to restore
control file from backup or copy the multiplexed control file over to the bad one.
Why do we need SCOPE=BOTH clause?
BOTH indicates that the change is made in memory and in the server parameter file. The
new setting takes effect immediately and persists after the database is shut down and
started up again. If a server parameter file was used to start up the database, then BOTH is
the default. If a parameter file was used to start up the database, then MEMORY is the
default, as well as the only scope you can specify.
How to know Number of CPUs on Oracle
Login as SYSDBA
SQL>show parameter cpu_count
NAME TYPE VALUE
cpu_count integer 2
Could you please tell me what are the possible reason for Spfile corruption and
Recovery?
It should not be corrupt under normal circumstances, if it were, it would be a bug or failure
of some component in your system. It could be a file system error or could be a bug.
You can easily recover however from
a) Your alert log has the non-default parameters in it from your last restart.
b) it should be in your backups
c) strings spfile.ora > init$ORACLE_SID.ora - and then edit the resulting file to clean it up
would be options.
How you will check flashback is enabled or not?
Select flashback_on from v$database;
In case Revoke CREATE TABLE Privilege from an USER giving ORA-01952. What is
the issue? How to do in that case?
SQL> revoke create table from Pay_payment_master;
ORA-01952: system privileges not granted to PAY_PAYMENT_MASTER
This is because this privilege is not assigned to this user directly rather it was assigned
through role CONNECT If you remove connect role from the user then you will not be able
to create session (Connect) to database. So basically we have to Revoke the CONNECT Role
and Grant other than create table privilege to this user.
What kind of information is stored in UNDO segments?
Only before image of data is stored in the UNDO segments. If transaction is rolled back
information from UNDO is applied to restore original datafile. UNDO is never multiplexed.
How to Remove Oracle Service in windows environment?
We can add or remove Oracle Service using oradim which is available in ORACLE_HOME/bin
C:\Oradim delete sid
or
Oradim delete svrc
Qqqqq.Why ORA-28000: the account is locked? What you will do in that case?
The Oracle 10g default is to lock an account after 10 bad password attempts and giving
ORA-28000: the account is locked. In that case one of the solutions is increase default limit
of the login attempts.
SQL> Alter profile default limit FAILED_LOGIN_ATTEMPTS unlimited;
How to Reduce the Physical Reads on Statistics?
You need to increase the Buffer Cache
Consider the situation Buffer Cache of the database is 300MB. One SQL gave the Physical
read as 100. I increased as 400MB and now the same SQL giving the Physical read value is
0
How many redo groups are required for a Oracle DB?
At least 2 redo groups are required for a Oracle database to be working normally.
My spfile is corrupt and now I cannot start my database running on my laptop. Is there a
way to build spfile again?
if you are on unix then
$ cd $ORACLE_HOME/dbs
$ strings spfilename temp_pfile.ora
edit the temp_pfile.ora, clean it up if there is anything "wrong" with it and then
SQL> startup pfile=temp_pfile.ora
SQL> create spfile from pfile;
SQL> shutdown
SQL> startup
On windows -- just try editing the spfile [do not try with the prod db first try to check on
test db. It can be dangerous], create a pfile from it. save it, and do the same or if you got
problem you can startup the db from the command line using sqlplus create a pfile, do a
manual startup (start the oracle service, then use sqlplus to start the database)
What is a fractured block? What happens when you restore a file containing
fractured block?
A block in which the header and footer are not consistent at a given SCN. In a user-
managed backup, an operating system utility can back up a datafile at the same time that
DBWR is updating the file. It is possible for the operating system utility to read a block in a
half-updated state, so that the block that is copied to the backup media is updated in its
first half, while the second half contains older data. In this case, the block is fractured.
For non-RMAN backups, the ALTER TABLESPACE ... BEGIN BACKUP or ALTER DATABASE
BEGIN BACKUP command is the solution for the fractured block problem. When a tablespace
is in backup mode, and a change is made to a data block, the database logs a copy of the
entire block image before the change so that the database can reconstruct this block if
media recovery finds that this block was fractured.
The block that the operating system reads can be split, that is, the top of the block is
written at one point in time while the bottom of the block is written at another point in time.
If you restore a file containing a fractured block and Oracle reads the block, then the block
is considered a corrupt.
You recreated the control file by using backup control file to trace and using
alter database backup controlfile to location command what have you lost in that
case?
You lost all of the backup information as using backup controlfile to trace where as using
other ALTER DATABASE BACKUP CONTROLFILE to D:\Backup\control01.ctl. All backup
information is retained when you take binary control file backup.
If a backup is issued after shutdown abort command what kind of backup
is that?
It is an inconsistent backup. If you are in noarchivelog mode ensure that you issue the
shutdown immediate command or startup force is another option that you can issue:
startup force->shutdown abort; followed by shutdown immediate


Script: How to Schedule Export Backup in Windows Env.
It is a simple script for exporting the entire database using system user today for Microsoft
Windows based implementation. This batch file exports a .dmp file to a user specified directory.

FOR /F "tokens=2-4 delims=/ " %%a IN ('date/t') DO exp system/password@connectionstring
full = y file=d:\backup\exp_%%b%%a%%c.dmp

Save this script inside a .bat or .cmd file (Eg: Exportbackup.bat or Exportbackup.cmd). Now
schedule this batch file by using windows task schedular
HOW TO SCHEDULE TASK USING "SCHEDULED TASK"
Step1: Go to controlpanel click on "SCHEDULED TASK"
Click Next to Continue... then browse the file location and ADD it.


















Now right click go to properties of this (Export.bat) file and set the Start in:
D:\Backup\Tested_Batch

then click on Apply and provide the OS password











Note: The username must have administrative privileges


Now set the Schedule Day, Time and click on OK


























There is no need to shutdown the database in order to facilitate the export. Once exported is
completed it should look like as: exp_23052012.dmp
After estimating the completion time of job by runing this script 2 or 3 times. now you can
schedule here a batch file to copy the backup from one server to another as an alternative backup
to meet the situation of disaster. How to schdule the script to copy backup from live server to
another server. check my older post for the same:

How to append date stamp on your Export dumps.
expdate='date '+%d%m%Y''
dat='date '+%m%d%y %H:%M:%S''
Now define in script:
On Unix:
./expdp system/system directory=export_dir dumpfile=exp_swx_$expdate.dmp
logfile=exp_swx_$expdate.log schemas=swx
On Windows:
Date: %date:~4,2%-%date:~7,2%-%date:~12,2%
Time: %time:~0,2%-%time:~3,2%-%time:~6,2%
For Example:
copy C:\Trial.txt C:\Trail-%date:~4,2%-%date:~7,2%-%date:~12,2%.txt will output C:\Trial-
mm-dd-yy.txt

exp edate/edate file=edate%date:~4,2%-%date:~7,2%-%date:~12,2%.dmp
log=edate%date:~4,2%-%date:~7,2%-%date:~12,2%.txt owner=edate statistics=none

Techmentro