Tuesday, January 8, 2008

10 Scripts Every DBA Should Have

I. Display the Current Archivelog Status :


II. Creating a Control File Trace File


III. Tablespace Free Extents and Free Space

column Tablespace_Name format A20
column Pct_Free format 999.99

select Tablespace_Name,Max_Blocks,Count_Blocks,Sum_Free_Blocks,100*Sum_Free_Blocks/Sum_Alloc_Blocks AS Pct_Free from
(select Tablespace_Name, SUM(Blocks) Sum_Alloc_Blocks
from DBA_DATA_FILES group by Tablespace_Name),(select Tablespace_Name FS_TS_NAME,MAX(Blocks) AS Max_Blocks,COUNT(Blocks) AS Count_Blocks,
SUM(Blocks) AS Sum_Free_Blocks from DBA_FREE_SPACE group by Tablespace_Name) where Tablespace_Name = FS_TS_NAME;

IV. Display Allocated Space & Quota by User

select * from DBA_TS_QUOTAS order by Tablespace_Name, Username;

V. Show Allocated Storage for All Objects

column Segment_Name format A40
select Segment_Name, Extents, Blocks
where Segment_Type = '&segment_type'
order by Segment_Name;

VI. Map a Tablespace's Used and Free Space

select Segment_Name, File_Id, Block_Id, Blocks
from DBA_EXTENTS where Tablespace_Name = '&&tablespacename'
select 'Free Space', File_Id, Block_Id, Blocks
from DBA_FREE_SPACE where Tablespace_Name = '&&tablespacename'
order by 2,3;

VII. Blocks Used by Data in a Table

select COUNT(DISTINCT(SUBSTR(ROWID,1,8)||SUBSTR(ROWID,15,4))) Blocks_Used from &table;

VIII. Reset a User's Password

select 'ALTER USER &&1 IDENTIFIED BY VALUES '||''''||Password||''''||';' from DBA_USERS where Username = UPPER('&&1');


column Name format A50
column Value format A28
select Name, Value from V$PARAMETER;

X. Show Statement Execution Path

select LPAD(' ',2*LEVEL)||Operation||' '||Options ||' '||Object_Name Q_PLAN from PLAN_TABLE where Statement_ID = 'TEST' connect by prior ID = Parent_ID and Statement_ID = 'TEST' start with ID=1;


Anonymous said...


small note: the formatting is terrible.

oracle r12 documentation said...

Wow. I am only having five of the above listed scripts that I use mostly. Its really exciting to have few more helpful scripts that you have posted. I recently got an opportunity in this field and loves to learn new points. Thanks for this great share.

oakleyses said...

tory burch outlet, polo ralph lauren, ugg boots, chanel handbags, tiffany jewelry, longchamp outlet, longchamp pas cher, gucci handbags, sac longchamp pas cher, uggs on sale, jordan pas cher, michael kors pas cher, ray ban sunglasses, oakley sunglasses, polo outlet, louboutin pas cher, longchamp outlet, burberry pas cher, louis vuitton, cheap oakley sunglasses, replica watches, replica watches, longchamp outlet, christian louboutin outlet, prada handbags, oakley sunglasses wholesale, louis vuitton outlet, oakley sunglasses, ray ban sunglasses, louis vuitton, prada outlet, nike outlet, louis vuitton outlet, christian louboutin, nike free run, nike roshe, ugg boots, nike air max, polo ralph lauren outlet online, kate spade outlet, christian louboutin uk, tiffany and co, nike free, oakley sunglasses, jordan shoes, louis vuitton outlet, nike air max, ray ban sunglasses

oakleyses said...

nike tn, ralph lauren uk, true religion outlet, nike air max uk, burberry handbags, michael kors, abercrombie and fitch uk, nike blazer pas cher, oakley pas cher, timberland pas cher, hogan outlet, uggs outlet, michael kors outlet online, replica handbags, sac vanessa bruno, true religion outlet, converse pas cher, guess pas cher, ray ban pas cher, ray ban uk, true religion outlet, michael kors outlet, mulberry uk, nike roshe run uk, hollister uk, coach outlet, kate spade, nike air max, new balance, true religion jeans, north face, coach outlet store online, uggs outlet, michael kors outlet online, polo lacoste, michael kors outlet, lululemon canada, nike air force, vans pas cher, michael kors outlet, hollister pas cher, michael kors outlet online, sac hermes, michael kors, burberry outlet, michael kors outlet online, north face uk, nike air max uk

oakleyses said...

converse, louboutin, soccer jerseys, ferragamo shoes, hermes belt, longchamp uk, p90x workout, north face outlet, baseball bats, instyler, nike trainers uk, babyliss, mont blanc pens, soccer shoes, nfl jerseys, valentino shoes, oakley, hollister clothing, abercrombie and fitch, chi flat iron, ralph lauren, nike air max, north face outlet, gucci, ray ban, vans, beats by dre, herve leger, jimmy choo outlet, giuseppe zanotti outlet, mac cosmetics, ghd hair, reebok outlet, nike roshe run, hollister, mcm handbags, timberland boots, nike air max, lululemon, bottega veneta, insanity workout, nike huaraches, vans outlet, hollister, iphone cases, wedding dresses, new balance shoes, converse outlet, asics running shoes, celine handbags

oakleyses said...

marc jacobs, ugg,uggs,uggs canada, louis vuitton, swarovski, barbour uk, montre pas cher, moncler outlet, louis vuitton, canada goose outlet, louis vuitton, pandora charms, wedding dresses, juicy couture outlet, moncler, canada goose outlet, louis vuitton, canada goose uk, ugg uk, canada goose, ugg pas cher, coach outlet, hollister, moncler, canada goose outlet, ugg, pandora jewelry, moncler outlet, karen millen uk, pandora jewelry, links of london, louis vuitton, canada goose, canada goose, swarovski crystal, moncler uk, moncler, moncler, doudoune moncler, juicy couture outlet, canada goose jackets, thomas sabo, replica watches, ugg,ugg australia,ugg italia, barbour, pandora uk, supra shoes, lancel, toms shoes

raybanoutlet001 said...

ugg outlet
ray ban sunglasses
air jordan uk
arizona cardinals jerseys
michael kors outlet
golden state warriors jerseys
nike outlet
michael kors outlet
longchamp outlet
rolex replica watches

raybanoutlet001 said...

ray ban sunglasses
ugg outlet
polo ralph lauren
nike outlet
ralph lauren uk
ugg outlet
louis vuitton sacs
ray ban sunglasses outlet
ray ban sunglasses

jeje said...

adidas nmd
michael kors factory outlet
ultra boost 3.0
balenciaga shoes
moncler jackets
bape hoodie
jordan retro 13
adidas superstar
kate spade outlet
lebron shoes