oracle storage structure

23
Oracle Storage Model

Upload: abdur-rehman-muhammadi

Post on 25-Jul-2015

112 views

Category:

Education


4 download

TRANSCRIPT

Oracle Storage Model

Tablespaces and Datafiles

• Data is stored logically in segments and physically in files.

• The tablespace entity abstracts the two, one tablespace may many segments and datafiles.

• Why we need separation of logical and physical storage

Tablespace and Storage Structure

Oracle Storage Model

• The separation of logical storage from physical storage– Table Space– Segment– Data Block– Extent– Data File

Tablespace

• Tablespace is logical unit of data storage.– One tablespace can contain many segments and

be made up of many datafile– There is one-to-many relationship between a

tablespace and datafiles/segments• Permanent• Temporary• Big File• Small File

Segment

• The segment entity represents any database object that stores data and therefore

• Any one segment can exist in only one tablespace

• Tablespace can spread a segment on many datafiles.– Avoiding maximum file size problem due to

operating system limitations

Type of Segments

• Table • Index• RollBack• UNDOSELECT segment_type, count(*) from dba_segments group by segment_type

Data Block• The Oracle block is the unit of I/O for the database

– The size of the Oracle blocks is fixed for a tablespace– 11g default is 8 KB– It can be 2 to 32 KB– DB_BLOCK_SIZE

• Header The header contains general block information, such as the block address and the type of segment (for example, data or index)

• Table DirectoryThis portion of the data block contains information about the table having rows in this block.

• Row DirectoryThis portion of the data block contains information about the actual rows in the block (including addresses for each row piece in the row data area).

• OverheadThe data block header, table directory, and row directory are referred to collectively as overhead. Some block overhead is fixed in size; the total block overhead size is variable. On average, the fixed and variable portions of data block overhead total 84 to 107 bytes

• Row DataThis portion of the data block contains table or index data. Rows can span blocks

Extent

• An extent is a logical unit of database storage space allocation made up of a number of contiguous data blocks. One or more extents in turn make up a segment. When the existing space in a segment is completely used, Oracle allocates a new extent for the segment.

Investigate the Database’s Data Storage Structures

• Connect to the database as user SYSTEM• select segment_type,count(1) from dba_segments group by

segment_type 2 order by segment_type;• Determine the name and size of the controlfile(s):

– select name, block_size*file_size_blks bytes from v$controlfile;• Determine the name and size of the online redo log file

members:– select member,bytes from v$log join v$logfile using (group#);

• Determine the name and size of the datafiles and the tempfiles:– select name,bytes from v$datafile union all select name,bytes from

v$tempfile;

Tablespace CreationAllocated size This is the current size of the datafile(s) assigned to the tablespace. Space used This is the space occupied by segments in the tablespace that cannot be reclaimed.Allocated space used (%) A graphical representation of the previous two figures.

Allocated free space The space currently available within the tablespace.Status A green tick indicates that the tablespace is online, and therefore

that the objects within it should be accessible. Datafiles The number of datafiles.Type The type of objects that can be stored in the tablespace. Extent management The technique used for allocating extents to segments. LOCAL is the default and should always be used.Segment management The technique used for locating blocks into which insertions may be made. AUTO is the default and is recommended for all user data tablespaces.

Tablespace

• CREATE [UNDO] TABLESPACE tablespace_name DATAFILE Datafile_Options Storage_Opti

CREATE TABLESPACE ts_mydemo DATAFILE‘D:/data/ts_mydemo01.dbf' SIZE 50M;

CREATE TABLESPACE ts_mydemo DATAFILE‘D:/data/ts_mydemo01.dbf' SIZE 50M,‘D:/data/ts_mydemo02.dbf' SIZE 50M,Autoextend onNext 32m maxsize 2048m;

Tablespace Creation

1. CREATE SMALLFILE TABLESPACE "NEWTS"2. DATAFILE 'D:\APP\ORACLE\ORADATA\ORCL11G\newts01.dbf'3. SIZE 100M AUTOEXTEND ON NEXT 10M MAXSIZE 200M4. LOGGING5. EXTENT MANAGEMENT LOCAL6. SEGMENT SPACE MANAGEMENT AUTO7. DEFAULT NOCOMPRESS;

Tablespace CreationLine Explanation

Line 1 The tablespace is a SMALLFILE tablespace. This means that it can consist of many datafiles. The alternative is BIGFILE, in which case it would be impossible to add a second datafile later (though the first file could be resized.)

Line 2 The datafile name and location.

Line 3 The datafile will be created as 100 MB but when full can automatically extend in 10 MB increments to a maximum of 200 MB. By default, automatic extension is not enabled.

Line 4 All operations on segments in the tablespace will generate redo; this is the default. It is possible to disable redo generation for a very few operations (such as index generation).

Line 5 The tablespace will use bitmaps for allocating extents; this is the default.

Line 6 Segments in the tablespace will use bitmaps for tracking block usage; this is the default.

Line 7 Segments in the tablespace will not be compressed; this is the default.

Altering Tablespaces

• Renaming• Taking online and offline• Flagging as read-write or read only• Resizing• Changing alert thresholds

Renaming

• Syntax– ALTER TABLESPACE tablespaceoldname RENAME

TO tablespace_new_name;• Example– ALTER TABLESPACE ts RENAME to newTs;

Online/Offline

• An online tablespace or datafile is available for use

• An offline tablespace or datafile exists as a definition in the data dictionary and the controlfile but cannot be used.

• Syntax– ALTER TABLESPACE tablespacename OFFLINE

[NORMAL | IMMEDIATE | TEMPORARY];

Online/Offline

• Normal (default)– Every dirty buffer in DB buffer cache will be written

to datafiles then the tablespace will go to offline• IMMEDIATE – Forced the tablespace to offline without writing

dirty buffer to the data files.• TEMPORARY– offline will checkpoint all the files that can be

checkpointed.

Read Only

• Mark a Tablespace as Read Only– ALTER TABLESPACE tablespacename [READ ONLY |

READ WRITE];• Read Only– Only available to for data reading only

• Read/Write– Available for both reading and writing

Resizing a Tablespace

• A tablespace can be resized either by adding datafiles to it or by adjusting the size of the existing datafiles.

• ALTER DATABASE DATAFILE filename RESIZE n[M|G|T];– alter database datafile '/oradata/users02.dbf' resize 10m;– alter tablespace gl_large_tabs add datafile 'D:\ORADATA\

GL_LARGE_TABS_03.DBF' size 2g;– alter database datafile ‘D:\ORADATA\GL_LARGE_TABS_03.DBF'

autoextend on next 100m maxsize 4g;

Creating Tablespace

• Connect to the database as user SYSTEM• create tablespace newtbs datafile

'/home/db11g/oradata/newtbs_01.dbf' size 10m extent management local autoallocate segment space management auto;

• create table newtab(c1 date) tablespace newtbs;• select extent_id,bytes from dba_extents where

owner='SYSTEM' and segment_na me='NEWTAB';

Tablespace Dictionary

• v$controlfile• v$datafile• v$tempfile;

Tablespace Creation