Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Database structure and space Management

2 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

3 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 segments It records old values of data that was changed by each transaction.. “Undo Information”

4 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.

5 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

6 Advantages of COMMIT and ROLLBACK Statements With COMMIT and ROLLBACK statements, you can: Ensure data consistency Preview data changes before making changes permanent

7 State of the Data After ROLLBACK Discard all pending changes by using the ROLLBACK statement: 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

8

9 descriptionstatement Ends the current transaction by making all pending data changes permanent COMMIT Marks a savepoint within the current transactionSAVEPOINT name ends the current transaction by discarding all pending data changes ROLLBACK 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. ROLLBACK TO SAVEPOINT name

10 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.

11 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.

12 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.

13 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

14 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

15 Data Block Components

16 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

17 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

18 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.

19 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

20 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.

21 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

22 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


Download ppt "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."

Similar presentations


Ads by Google