database structure and space management. segments the level of logical database storage above an...

22
Database structure and space Management

Upload: ross-pitts

Post on 13-Jan-2016

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

Database structure and spaceManagement

Page 2: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

Segments

• The level of logical database storage above an extent is called a segment. A segment is a set of extents allocated for a certain logical structure.

• the different types of segments include: 1. Data segments

• Every table in an Oracle database has a single data segment

2. Index segments• Every index in an Oracle database has a single index

segment holds all of its data

Page 3: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

3. Temporary segments– Temporary segments are created by

ORACLE. When a SQL statement needs a temporary work area to complete execution. When the statement finishes execution, the temporary segments extents are returned to the system for future use.

4. Rollback segmentsIt records old values of data that was changed

by each transaction.. “Undo Information”

Page 4: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

Rollback segments

Rollback segments are areas in your database which are used to temporarily save the previous values when some updates occurred

• have two main purposes : 1. If for one reason or another the user wants to

cancel his/her update with a ROLLBACK statement, the former values are restored. This is possible only during the life of the transaction. If the user executes COMMIT instead, the values in the rollback segment are marked as invalidated and the change becomes permanent.

Page 5: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

2. This is where other, concurrent sessions read the data when they access the changed tables before the transactions are committed. Note that if a SELECT starts on a table while a transaction is modifying the same table, the old value of the data will be read from a rollback segment - some queries take a pretty long time to run

Page 6: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

Advantages of COMMITand ROLLBACK Statements

• With COMMIT and ROLLBACK statements, you can: • Ensure data consistency• Preview data changes before making changes permanent

Page 7: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

State of the Data After ROLLBACK

• Discard all pending changes by using the ROLLBACKstatement:• Data changes are undone.• Previous state of the data is restored.• Locks on the affected rows are released.DELETE FROM copy_emp;22 rows deleted.ROLLBACK;Rollback complete

Page 8: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents
Page 9: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

statementdescriptionCOMMIT Ends the current transaction by making all pending

data changes permanent

SAVEPOINT name

Marks a savepoint within the current transaction

ROLLBACK ends the current transaction by discarding all pending data changes

ROLLBACK TO SAVEPOINT name

ROLLBACK TO SAVEPOINT rolls back the current transaction to the specified savepoint, thereby discarding any changes created after the savepoint to which you are rolling back. If you omit the TO SAVEPOINT clause, the ROLLBACK statement rolls back the entire transaction. As savepoints are logical, there is no way to list the savepoints you have created.

Page 10: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

Rolling Back Changes to a Marker

• Create a marker in a current transaction by using the SAVEPOINT statement.• Roll back to that marker by using the ROLLBACK TO SAVEPOINT statement.

• Example:UPDATE...........SAVEPOINT update_done; Savepoint created.INSERT...........ROLLBACK TO update_done;Rollback complete.

Page 11: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

State of the Data After COMMIT

• Data changes are made permanent in the database.

• The previous state of the data is permanently lost.

• All users can view the results.

• All savepoints are erased.

Page 12: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

Committing Data

• Make the changes. DELETE FROM employees WHERE employee_id = 99999; 1 row deleted. INSERT INTO departments VALUES (290, 'Corporate Tax', NULL, 1700); 1 row inserted.• Commit the changes.COMMIT; Commit complete.

Page 13: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

Data blocks

• An ORACLE database's data is stored in data blocks.

• One data block corresponds to a specific number of bytes of physical database space on disk.‘

• A data block size is specified for each ORACLE database when the database is created.

• A database uses and allocates free database space in ORACLE data blocks

Page 14: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

Data blocks

• Each Data Block consists of: header, free space and row data– Header - contains information about the data block

contents, and is made up of three separate subsections: the block header, the table directory, and the row directory

– Free space - is empty space that the block retains in case users update the data within the data block, and the updated data occupies more storage space than the original data

– Row Data – stores actual data values

Page 15: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

Data Block Components

Page 16: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

Physical Database Structure

• An ORACLE database's physical structure is determined by the operating system files that constitute the database.

• The files of a database provide the actual physical storage for database information

Page 17: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

Physical Database Structure

1. Datafiles – contain the actual data values

2. Redo log files - contain rollback information for uncommitted transactions and record all changes made to data

3. Control files - contain information about the database tablespaces, datafiles, redo log files, and the current state of the database Ex. Database name

Page 18: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

Data Files

• Every ORACLE database has one or more physical data files.

• A database's data files contain all the database data.

• The data of the logical database structures such as tables and indexes is physically stored in the data files allocated for a database.

Page 19: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

Data files

• A Data file can be associated with only one database

• One or more datafiles are explicitly created for each table space to physically store the data of all logical structures

Page 20: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

Redo log files

• The primary function of the redo log is to record all changes made to data.

• The information in a redo log file is used only to recover the database from a system or media failure that prevents database from being written to database's data files.

Page 21: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

Control Files

• Every ORACLE database has a control file. A control file records the physical structure of the database. For example, it contains the following types of information:

- database name - names and locations of a database's data files and redo log files - time stamp of database creation

Page 22: Database structure and space Management. Segments The level of logical database storage above an extent is called a segment. A segment is a set of extents

Summary

• Control files store information about the database structure and state

• Redo log files record information to undo action query changes through user rollback operations

• An Oracle database stores the rollback information in a rollback segment