Tuesday, December 15, 2009

What is the difference between table & View?

View is a virtual table made of one or tables of the database using complex/simple join logic. The view has some useful purposes. Some are as under:

1. Simplification of database:

A schema may have hundreds of tables. Applications can be simplified if they can access predefined views which embed complex join logic.

2. Easy Maintenance:

Views can contain complex column expressions that are transparent in the views. Changes to these expressions need only be made in the view.

3. Change management:

Views can reduce maintenance to the application as they can hide schema changes that affect the view's query.

4. Security purpose:

Views can embed selection logic and present a subset of a table's content. You can create additional schema that contains just views of the main schema, limiting what may be accessed. Different user groups enter through one of these other schema, each group having a different view of the overall database.

Monday, December 14, 2009

How to free up database space in Tablespace in Oracle?

Oracle uses the high-water mark after deleted rows in database, you can free up this space at the table level with following methods.

1 . using export/import of table -

For a complete restructuring of table and space freeing up export/import of a table allows us to restructure our files and release the lost space.

2. using dbms_redefinition -

This procedure will reorganize a table while it remains online for updates.

3. using alter table tmp shrink -

If you are using Oracle 10g and later, you could use
alter table tmp shrink space compact.

4. using coalesing table -

It removes space above the high-water mark, It puts together the uncontiguous fragmented extents.

The honeycomb fragmentation and Swiss Cheese fragmentation are mainly occured in oracle. When the free extents are side by side, its in honeycomb fragmentation, and when the extents are separated by live segments, its in Swiss Cheese fragmentation.

alter table tmp coalesce;

5. using deallocate unused space -

Oracle uses it to explicitly deallocate unused space at the end of a segment and makes that space available for other segments within the tablespace.

alter table tmp deallocate unused space;

Oracle deallocates unused space beginning from the end of the objects and moving downwards toward the beginning of the object, continuing down until it reaches the high water mark (HWM). For indexes, deallocate unused space coalesces all leaf blocks within same branch of b-tree, and quickly frees up index leaf blocks for use.

How to reclaim or release the size of fragmented data files of tablespaces?

All Database objects like, tables,triggers,procedures,packages,functions,etc. are resided in tablespaces will naturally fragment as a function of update activity and Oracle has many methods for reclaiming disk space.

The Segment Advisor which will recommend us when database objects will get benefit from a reorganization to free up disk space.

Oracle has several tools to help reclaim disk space:

1 . Alter database datafile tempdb.dbf resize 50 M

This will remove spaces by physically. if the datafile, and this will not work, any of the segments of the tablespace are extended beyond your resize boundary. So, apply proper datafile size while using this.

2. Alter tablespace tempdb coalesce

This will reclaim space from honeycomb fragmentation.