1 / 42

Database structure and space Management

Database structure and space Management. Database Structure. An ORACLE database has both a physical and logical structure. By separating physical and logical database structure, the physical storage of data can be managed without affecting the access to logical storage structures.

kura
Download Presentation

Database structure and space Management

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Database structure and spaceManagement

  2. Database Structure • An ORACLE database has both a physical and logical structure. By separating physical and logical database structure, the physical storage of data can be managed without affecting the access to logical storage structures.

  3. Database structures Logical Physical

  4. Logical Database Structure • Tablespace - stores related database objects • Segments - stores an individual database object, such as a table or an index • Extent - a contiguous unit of storage space within a segment • Data Block - smallest storage unit that the database can address. Extents consist of data blocks

  5. Logical Database Structure Tablespace Segments Extents Extents Data blocks

  6. Tablespace • Each Database is logically divided into one or more table spaces • Table space can be online (accessible) {default} or offline (Not accessible( • You can create a new tablespace to increase the size of a database • The database Administrator can bring any tablespace in an oracle online or offline • Oracle Database automatically switches a tablespace from online to offline when certain errors are encountered. For example, Oracle Database switches a tablespace from online to offline when the database writer process, DBWn, fails in several attempts to write to a datafile of the tablespace

  7. Tablespace • Every Oracle database contains at least two tablespaces named SYSTEM and SYSUAX which Oracle Database creates automatically when the database is created. • The SYSTEM tablespace contains Data Dictionary and it’s always online when the database is open. • Data Dictionary contain Metadata which is data about data • Who created the table? • What columns are there in the table? • When the table is created? • The SYSAUX tablespace is an auxiliary tablespace to the SYSTEM tablespace. The SYSAUX tablespace provides a centralized location for database metadata that does not reside in the SYSTEM tablespace

  8. Temporary tablespace • Temporary tablespaces provide performance improvements when you have multiple sorts that are too large to fit into memory • All operations that use sorts, including joins, union, index builds, ordering (ORDER BY) and computing aggregates (GROUP BY), benefit from temporary tablespaces. • Temporary tablespace is named TEMP. It is optional and permanent in nature but their segment are temporary in nature.

  9. Read-only tablespace • The primary purpose of read-only tablespaces is to eliminate the need to perform backup and recovery of large, static portions of a database. • Oracle Database never updates the files of a read-only tablespace • Because read-only tablespaces cannot be modified, and as long as they have not been made read/write at any point, they do not need repeated backup.

  10. Database, Tablespaces, and data files • Oracle stores data logically in tablespaces and physically in datafiles associated with the corresponding tablespace.

  11. Database, Tablespaces, and data files • The relationship among databases, tablespaces, and data files : 1. Each database is logically divided into one or more tablespaces. 2. One or more data files are explicitly created for each tablespace to physically store the data of all logical structures in a tablespace. 3. The combined size of a tablespace's data files in the total storage capacity of the tablespace.4. The combined storage capacity of a database's tablespaces is the total storage capacity of the database

  12. Allocate More Space for a Database • The size of a tablespace is the size of the datafiles that constitute the tablespace. The size of a database is the collective size of the tablespaces that constitute the database. • You can enlarge a database in three ways: • Add a datafile to a tablespace • Add a new tablespace • Increase the size of a datafile • When you add another datafile to an existing tablespace, you increase the amount of disk space allocated for the corresponding tablespace

  13. Create table space • CREATE TABLESPACE tablespace_nameDATAFILE file_name [SIZE integer M] [REUSE] DEFAULT STORAGE ( INITIAL integer M NEXT integer M MINEXTENTS integer MAXEXTENTS integer PCTINCREASE integer) ONLINE or OFFLINE PERMANENT or TEMPORARY;

  14. Create table space • TABLESPACE : Tablespace in which you want the table to reside. • INITIAL SIZE: The size for the initial extent of the table. • NEXT SIZE: The value for any additional extents the table may take through growth. • MINEXTENTS and MAXEXTENTS: Identify the minimum and maximum extents allowed for the table. • PCTINCREASE: Identifies the percentage the next extent will be increased each time the table grows, or takes another extent.

  15. Example • CREATE TABLESPACE tp DATAFILE 'df.ora' SIZE 10M DEFAULT STORAGE( INITIAL 10K NEXT 50K MINEXTENTS 1 MAXEXTENTS 999 PCTINCREASE 10) ONLINE permanent;

  16. Create Table • SQL Statement:CREATE TABLE table_name(column_namedata_type [DEFAULT exp] [CONSTRAINT]) TABLESPACE tablespace_name STORAGE (INITIAL size K or M NEXT size K or M MINEXTENTS value MAXEXTENTS value PCTINCREASE value);

  17. Example • CREATE TABLE maha ( id NUMBER CONSTRAINT co_id PRIMARY KEY, name varchar(20)) TABLESPACE tp STORAGE ( INITIAL 7000 NEXT 7000 MINEXTENTS 1 MAXEXTENTS 5 PCTINCREASE 5);

  18. Table space • Most major RDBMSs have default settings for table sizes and table locations. • If you do not specify table size and location, then the table will take the defaults. • The defaults may be very undesirable, especially for large tables.

  19. 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: • Data segments • Every table in an Oracle database has a single data segment • Index segments • Every index in an Oracle database has a single index segment holds all of its data

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

  21. Rollback segments Rollback segments are areas in your database which are used to temporarily save the previous values when some updatesoccurred • have two main purposes : • 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.

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

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

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

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

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

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

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

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

  30. Data Block Components

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

  32. Physical Database Structure • Datafiles – contain the actual data values • Redo log files - record all changes made to data, including both uncommitted and committed changes. • Control files - contain information about the database tablespaces, datafiles, redo log files, and the current state of the database Ex. Database name

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

  34. Data files • A Data file can be associated with only one database • One or more datafiles are explicitly created for each tablespace to physically store the data of all logical structures

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

  36. 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 • You should create two or more copies of the control file during database creation.

More Related