Top Banner
7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4
27

7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

Dec 30, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

7202ICT Database Administration

Lecture 7

Managing Database Storage

Part 2Orale Concept Manuel Chapter 3 & 4

Page 2: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

INDEX SEGMENTS

• B-TREE• If indexes are created on a table, then an index segment is created for

each index.• Index Segment Features

Balanced tree indexes can quickly locate key values ROWID addresses (hexadecimal values) can provide direct access to the data

block Queries that reference indexes columns can be resolved in the index without

even touching the table data segment Index searches are an alternative to full table scans Index segments are physically separate and independent from their associated

table segments Each index can have its own storage parameters Indexes are generally much smaller than their associated table Indexes can be stored in a different tablespace for optimization

Page 3: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

Example:

• Create an index on the EMP tableSQL> CREATE INDEX emp_ename /* Index name */

ON emp (ename) /* table and column name */

STORAGE (INITIAL 500K NEXT 500K PCTINCREASE 0)

TABLESPACE IDX_SPACE;

Page 4: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

TEMPORARY SEGMENTS

• Temporary segments provide workspace for the RDBMS to sort and join tables while performing complex searches.

• Temporary Segments Are created automatically by ORACLE to perform complex

operations such as joins, group by, creating an index, and anything that requires sorting

Are created in memory if enough memory space is available, or in data files if not

Created when needed on a per transaction basis Space is reclaimed at the end of the transaction by the SMON

background process Each tablespace may contain temporary segments

Page 5: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

TEMPORARY SEGMENTS (cont)

Space allocation for temporary segments is determined by the DEFAULT STORAGE clause of the tablespace that the temporary segments are being created in

Dynamic extension of temporary tables during sort operations may cause tablespace fragmentation

The DBA may define which tablespace each user uses for temporary segments, thus it is possible to manage the temporary segments and even have a dedicated tablespace for them

Temporary segments are not protected by use of the REDO LOG since they pose no threat to data integrity

Page 6: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

ROLLBACK SEGMENTS

• Rollback segment entries are written in a circular fashion for rollback, read consistency, and recovery.

– Each Rollback Segment Consists of several rollback entries from multiple transactions Stores block information such as file and block ID, as well as

data as it existed before being modified Must be created under special circumstances and brought

online before being used by any transaction May grow in size due to large or long running transactions Will automatically shrink to OPTIMAL if extended beyond it Can be assigned to a transaction automatically or explicitly

Page 7: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

Rollback Segment Storage Parameters

INITIAL NEXT MINEXTENTS MAXEXTENTS OPTIMAL

Page 8: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

Parameter Notes

OPTIMAL specifies the optimal size of a rollback segment in bytes

ORACLE de-allocates extents when a rollback segment is larger than OPTIMAL

PCTINCREASE cannot be specified for rollback segments and is always zero

MINEXTENTS must be at least 2 to accommodate the segment being written to in a circular fashion

Page 9: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

Example

• Create a rollback segment using the space utilization parameters, then bring the rollback segment online.

SQL> CREATE ROLLBACK SEGMENT rbs01

TABLESPACE RBS

STORAGE (INITIAL 10K NEXT 10K

OPTIMAL 20K MAXEXTENTS 121);

SQL> ALTER ROLLBACK SEGMENT rbs01 ONLINE;

Page 10: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

SYSTEM SEGMENT

• The system segment contains data dictionary tables to be loaded when the database is opened.

• System Segment Also referred to as the cache segment It cannot be read modified or dropped Exists in the STSTEM tablespace and is owned by the

user SYS Requires no action on the part of the DBA Usually needs less than 50 ORACLE blocks

Page 11: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

TABLESPACES AND DATA FILES

• Data in an ORACLE database is logically stored in tablespaces and physically stored in database files.

• An ORACLE can be subdivided into smaller logical areas of space known as tablespaces.

Page 12: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

Tablespaces

Each tablespace contains one or more operating system files

Tablespace can be brought online while the database is running

Tablespace can be taken offline while the tablespace is running, except for the SYSTEM tablespace which must always remain online

Objects created in a tablespace can never be allocated space outside of their original tablespace

Page 13: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

Useful Features of the Tablespace

Control of space allocation and assigning space quotas to users

Control availability of data by taking individual tablespaces online or offline

Distribute data storage across devices to improve I/O performance and reduce I/O against a single disk

Perform partial backup and partial recovery operations

Page 14: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

Note :

• A database always consists of at least one tablespace, SYSTEM. Generally, additional tablespaces are added to the database for increased control and long term ease of maintenance.

• Essentially, ORACLE sees the entire database made up of two types of tablespaces: SYSTEM and non-SYSTEM.

Page 15: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

SYSTEM Tablespace

Required in all databases for database operation Contains data dictionary information, definitions of

stored procedures, packages, and database triggers Contains the SYSTEM rollback segment Can contain user data if so desired

Page 16: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

Non-System Tablespace

Allows more flexibility in database administration Consists of:

rollback segments, temporary segments, application data, application indexes, user space, and so forth

Page 17: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

PHYSICAL DATABASE STRUCTURE

• The total amount of physical space allotted to ORACLE database objects depends upon the size of the physical operating system files created on behalf of each individual tablespace.

Each logical tablespace is physically made up of one or more operating system files

A segment, such as a table segment, can span multiple files as long as those files belong to the same tablespace

Page 18: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

Resolving Disk Contention

• Disk contention can be minimized, by separating groups of segments that will contend for disk resources among different tablespaces. Naturally, those tablespace should not all map to data files on the same disk.

To Minimize Disk Contention Separate dictionary segments from other segments Separate rollback segments from other segments Separate data segments from their corresponding index

segments

Page 19: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

Data Dictionary Views

DISPLAYING EXTENT AND SEGMENT INFORMATION

• The data dictionary contains a set of views, which can be queried to see how many extents and segments exist in the database.

DBA_EXTENTS DBA_FREE_SPACE DBA_SEGMENTS DBA_TABLESPACES DBA_DATA_FILES

Page 20: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

Example :

The DBA_SEGMENTS view can be used to gain summary information about extent allocation in the database. It is also possible to run reports on this view to determine the level of fragmentation of a segment and the danger of it reaching MAX_EXTENTS.

SQL> SELECT tablespace_name, count(*) SEGMENTS, SUM(bytes) BYTESFROM dba_segmentsGROUP BY tablespace_name;

TABLESPACE_NAME SEGMENTS BYTES------------------ ------------- ----------APPL_DATA 10 10240RBS 2 40960SYSTEM 108 2240512TEMP 0 20480

• As can be seen above, each row displays a tablespace name, the number of segments contained in that tablespace and the total number of bytes consumed by those segments from that tablespace.

Page 21: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

• List the names of the columns in DBA_TABLESPACES.

SQL> DESCRIBE dba_tablespaces

NAME NULL TYPE---------------------- -------- ---------------TABLESPACE_NAME VARCHAR2(30)INITIAL_EXTENT NUMBERNEXT_EXTENT NUMBERMIN_EXTENTS NUMBERMAX_EXTENTS NUMBERPCT_INCREASE NUMBERSTATUS VARCHAR2(9)

More Examples :

Page 22: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

• List the name and status of each tablespace.

SQL> SELECT tablespace_name, status

FROM dba_tablespaces;

TABLESPACE_NAME STATUS

----------------- -------------

SYSTEM ONLINE

APPL_DATA ONLINE

RBS ONLINE

TEMP ONLINE

More Examples :

Page 23: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

• List the names of the columns in the DBA_DATA_FILES view.

SQL> DESCRIBE dba_data_files

NAME NULL TYPE

----------------- -------- --------------------

FILE_NAME VARCHAR2(257)

FILE_ID NUMBER

TABLESPACE_NAME VARCHAR2(30)

BYTES NUMBER

BLOCKS NUMBER

STATUS VARCHAR2(9)

More Examples :

Page 24: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

• List general information about the data files belonging to each tablespace.

SQL> SELECT file_name, file_id, tablespace_name, bytes

FROM dba_data_files;

FILE_NAME FILE_ID TABLESPACE_NAME BYTES

----------------- --------- ------------------ ---------

/exp1/ora1/data

/user_01.dbf 1 SYSTEM 10485760

More Examples :

Page 25: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

• List the extents of free space in each tablespace.

SQL> SELECT *

FROM dba_free_space

ORDER BY file_id, block_id;

TABLESPACE_NAME FILE_ID BLOCK_ID BYTES BLOCKS

------------------ ------- --------- -------- ------------

SYSTEM 1 900 18432 9

SYSTEM 1 909 4096 2

SYSTEM 1 1912 6572032 3209

More Examples :

Page 26: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

• List the same free space information, as in the above example, using the names of each data file instead of its file id.

SQL> SELECT free.tablespace_name, free.block_id, free.bytes, free.blocks, df.file_nameFROM dba_free_space free, dba_data_files dfWHERE free.file_id = df.file_idORDER BY 1,2;

TABLESPACE_NAME BLOCK_ID BYTES BLOCKS FILE_NAME---------------- --------- ------ ------ -----------SYSTEM 900 18432 9 user01.dbfSYSTEM 909 4096 2 user01.dbfSYSTEM 1912 6572032 32 user01.dbf…

More Examples :

Page 27: 7202ICT Database Administration Lecture 7 Managing Database Storage Part 2 Orale Concept Manuel Chapter 3 & 4.

• List general information about all segments in the database, using the DBA_SEGMENTS view.

SQL> SELECT owner, segment_name, extents, max_extents

FROM dba_segments

ORDER BY 1,2;

OWNER SEGMENT_NAME EXTENTS MAX_EXTENTS

--------- -------------------- -------------- -----------

SCOTT EMP 5 25

SYSTEM RBS1 20 121

SYSTEM RBS2 2 121

SYS UNDO$ 50 99

More Examples :