Chapter 6 Basic Storage Concepts and Settings Oracle
Chapter 6 Basic Storage Concepts and Settings Oracle 9 i Database Administrator: Implementation and Administration 1
Objectives § Differentiate between logical and physical structures § Create many types of tablespaces § Configure and view storage for tablespaces and datafiles § Use undo data Oracle 9 i Database Administrator: Implementation and Administration 2
Introduction to Storage Structures Internal structures store: § The structure of every table, view, and other objects you create § The data you load into your tables and other objects § Information about the structure of tables, views, etc. (metadata) Oracle 9 i Database Administrator: Implementation and Administration 3
Introduction to Storage Structures Physical structures: • Datafiles • Operating system blocks • Redo log files • Control files Oracle 9 i Database Administrator: Implementation and Administration 4
Introduction to Storage Structures Logical Structures: • Data block • Extent • Segment • Schema object • Tablespace Oracle 9 i Database Administrator: Implementation and Administration 5
Introduction to Storage Structures Logical data blocks map directly to contiguous operating system blocks in datafiles Oracle 9 i Database Administrator: Implementation and Administration 6
Tablespaces and Datafiles CREATE TABLESPACE <tablespacename> DATAFILE <filename> SIZE <nn> AUTOEXTEND ON|OFF TEMPORARY|PERMANENT EXTENT MANAGEMENT LOCAL|DICTIONARY LOGGING|NOLOGGING ONLINE|OFFLINE SEGMENT SPACE MANAGEMENT MANUAL|AUTO §Add multiple files, separated by commas if needed §Clause is required for user managed files §Clause is optional when using OMF §Can be used to specify SIZE of OMF file Note: additional sub-clauses shown later Oracle 9 i Database Administrator: Implementation and Administration 7
Tablespaces and Datafiles CREATE TABLESPACE <tablespacename> DATAFILE <filename> SIZE <nn> AUTOEXTEND ON|OFF TEMPORARY|PERMANENT EXTENT MANAGEMENT LOCAL|DICTIONARY LOGGING|NOLOGGING ONLINE|OFFLINE SEGMENT SPACE MANAGEMENT MANUAL|AUTO §TEMPORARY: This option used only when creating temporary tablespaces that are dictionary -managed. §PERMANENT: Default option; stores permanent objects such as tables and indexes Oracle 9 i Database Administrator: Implementation and Administration 8
Tablespaces and Datafiles CREATE TABLESPACE <tablespacename> DATAFILE <filename> SIZE <nn> AUTOEXTEND ON|OFF TEMPORARY|PERMANENT EXTENT MANAGEMENT LOCAL|DICTIONARY LOGGING|NOLOGGING ONLINE|OFFLINE SEGMENT SPACE MANAGEMENT MANUAL|AUTO §LOCAL: Default; tablespace manages extent free space in a bitmap inside the tablespace §DICTIONARY: tablespace manages extent free space in the data dictionary Note: additional sub-clauses shown later Oracle 9 i Database Administrator: Implementation and Administration 9
Tablespaces and Datafiles CREATE TABLESPACE <tablespacename> DATAFILE <filename> SIZE <nn> AUTOEXTEND ON|OFF TEMPORARY|PERMANENT EXTENT MANAGEMENT LOCAL|DICTIONARY LOGGING|NOLOGGING ONLINE|OFFLINE SEGMENT SPACE MANAGEMENT MANUAL|AUTO §LOGGING: Default; all DML, DDL, and mass INSERT commands recorded in redo log §NOLOGGING: only DML commands recorded in redo log Oracle 9 i Database Administrator: Implementation and Administration 10
Tablespaces and Datafiles CREATE TABLESPACE <tablespacename> DATAFILE <filename> SIZE <nn> AUTOEXTEND ON|OFF TEMPORARY|PERMANENT EXTENT MANAGEMENT LOCAL|DICTIONARY LOGGING|NOLOGGING ONLINE|OFFLINE SEGMENT SPACE MANAGEMENT MANUAL|AUTO §ONLINE: Default; available for use §OFFLINE: not available for use Oracle 9 i Database Administrator: Implementation and Administration 11
Tablespaces and Datafiles CREATE TABLESPACE <tablespacename> DATAFILE <filename> SIZE <nn> AUTOEXTEND ON|OFF TEMPORARY|PERMANENT EXTENT MANAGEMENT LOCAL|DICTIONARY LOGGING|NOLOGGING ONLINE|OFFLINE SEGMENT SPACE MANAGEMENT MANUAL|AUTO: Manages segment free space in a bitmap in the tablespace MANUAL: Manages segment free space in the data dictionary Oracle 9 i Database Administrator: Implementation and Administration 12
Implementing OMF With Tablespaces DB_CREATE_FILE_DEST must be set: n In init<sid>. ora n Or, during session CREATE TABLESPACE command: n n Omit DATAFILE clause in Or, include DATAFILE clause but only include SIZE clause (omit file name) Oracle 9 i Database Administrator: Implementation and Administration 13
The DATAFILE Clause DATAFILE '<datafilename>' SIZE <nn>|REUSE AUTOEXTEND ON|OFF MAXSIZE <nn>|UNLIMITED §AUTOEXTEND ON: Allow file to expand when Oracle determines more space is needed § AUTOEXTEND OFF: Do not expand file §SIZE <nn>: Specify size in bytes, kilobytes, or megabytes § REUSE: File already exists Oracle 9 i Database Administrator: Implementation and Administration 14
The DATAFILE Clause DATAFILE '<datafilename>' SIZE <nn>|REUSE AUTOEXTEND ON|OFF MAXSIZE <nn>|UNLIMITED Used with AUTOEXTEND ON: §MAXSIZE <nn>: Specify maximum file size in bytes, kilobytes, or megabytes § UNLIMITED: File can grow to limits of operating system Oracle 9 i Database Administrator: Implementation and Administration 15
The EXTENT MANAGEMENT and SEGMENT SPACE MANAGEMENT Clauses Syntax for: EXTENT MANAGEMENT LOCAL|DICTIONARY AUTOALLOCATE|UNIFORM SIZE <nn> SEGMENT SPACE MANAGEMENT MANUAL|AUTO MINIMUM EXTENT <nn> §AUTO: Manages segment free space in a bitmap in the tablespace §MANUAL: Manages segment free space in the data dictionary DEFAULT STORAGE (INITIAL <nn> NEXT <nn> PCTINCREASE <nn> §AUTOALLOCATE: Allow the system to manage extent size for all tables MINEXTENTS MAXEXTENTS <nn>) and other objects created in the<nn> tablespace §UNIFORM SIZE <nn>: Require the specified extent size for all tables and other objects created in the tablespace Oracle 9 i Database Administrator: Implementation and Administration 16
The EXTENT MANAGEMENT and SEGMENT SPACE MANAGEMENT Clauses Syntax for dictionary-managed tablespace: EXTENT MANAGEMENT LOCAL|DICTIONARY SEGMENT SPACE MANAGEMENT MANUAL|AUTO Minimum extent size allowed for any object created in the tablespace AUTOALLOCATE|UNIFORM SIZE <nn> MINIMUM EXTENT <nn> DEFAULT STORAGE (INITIAL <nn> NEXT <nn> PCTINCREASE <nn> MINEXTENTS <nn> MAXEXTENTS <nn>) Default storage settings for any object created in the tablespace without a STORAGE clause of its own Oracle 9 i Database Administrator: Implementation and Administration 17
The EXTENT MANAGEMENT Clause Example of dictionary-managed datafile Example: A new table needing 6 M of space skips over the deallocated extents Coalesce free space periodically to combine deallocated extents Oracle 9 i Database Administrator: Implementation and Administration 18
Creating a Dictionary-Managed Tablespace n Example: CREATE TABLESPACE USER_TEST DATAFILE 'D: oracledatauser_test 01. dbf' SIZE 250 M AUTOEXTEND ON EXTENT MANAGEMENT DICTIONARY MINIMUM EXTENT 15 M DEFAULT STORAGE (INITIAL 90 M NEXT 15 M PCTINCREASE 0 MINEXTENTS 1 MAXEXTENTS 50); Oracle 9 i Database Administrator: Implementation and Administration 19
Creating a Locally Managed Tablespace Example of locally managed datafile All new tables must use extents of the same size or multiples of the size Example: A new table needing a 10 M extent would use the free space from two 5 M deallocated extents Deallocated extents are automatically coalesced Oracle 9 i Database Administrator: Implementation and Administration 20
Creating a Locally Managed Tablespace n Example: CREATE TABLESPACE USER_AUTO DATAFILE '<C: oracleoradatauser_auto 01. dbf' SIZE 20 M AUTOEXTEND OFF EXTENT MANAGEMENT LOCAL AUTOALLOCATE SEGMENT SPACE MANAGEMENT AUTO; Oracle 9 i Database Administrator: Implementation and Administration 21
Segment Types and Their Uses n n n Data segment: for tables, object tables, triggers Index segment: for indexes Temporary segment: for sorting operations and temporary tables Rollback segment: for undo data LOB segment: for LOB data stored separately from the rest of the table’s data Oracle 9 i Database Administrator: Implementation and Administration 22
Temporary Tablespaces n Oracle recommends creating locally managed temporary tablespaces n Used for temporary segments n Command syntax: CREATE TEMPORARY TABLESPACE <tablespacename> TEMPFILE <filename> SIZE <nn> AUTOEXTEND ON|OFF EXTENT MANAGEMENT LOCAL UNIFORM SIZE <nn> Oracle 9 i Database Administrator: Implementation and Administration 23
Tablespaces With Nonstandard Data Block Size n n n Can be 2 K, 4 K, 8 K, 16 K, or 32 K Requires a special memory cache that matches the block size Create cache by setting the appropriate initialization parameter: n DB_2 K_CACHE_SIZE n DB_4 K_CACHE_SIZE n DB_8 K_CACHE_SIZE n DB_16 K_CACHE_SIZE n DB_32 K_CACHE_SIZE Oracle 9 i Database Administrator: Implementation and Administration 24
Tablespaces With Nonstandard Data Block Size Example: CREATE TABLESPACE TBS_2 K DATAFILE '<C: oracleoradatatbs_2 k. dbf' SIZE 4 M BLOCKSIZE 2 K; Oracle 9 i Database Administrator: Implementation and Administration 25
Configuring and Viewing Storage Changes you can make to a tablespace: n n LOGGING/NOLOGGING n PERMANENT/TEMPORARY n READ ONLY/READ WRITE n Coalesce contiguous storage space n Add new datafile n Rename a datafile n Change size of a datafile Oracle 9 i Database Administrator: Implementation and Administration 26
Configuring and Viewing Storage Syntax: ALTER TABLESPACE <tablespacename> ADD|RENAME DATAFILE <filename> SIZE <nn> AUTOEXTEND ON|OFF REUSE DEFAULT STORAGE (INITIAL <nn> NEXT <nn> PCTINCREASE <nn> MINEXTENTS <nn> MAXEXTENTS <nn>) MINIMUM EXTENT <nn> COALESCE Oracle 9 i Database Administrator: Implementation and Administration 27
Configuring and Viewing Storage Taking a tablespace offline: n Stops it from being accessed by users Methods for taking a tablespace offline: n NORMAL: default n TEMPORARY: for damaged datafiles n IMMEDIATE: for damaged disk (media) Oracle 9 i Database Administrator: Implementation and Administration 28
Read-only Tablespaces n Can only be queried n No inserts, updates, or deletes n Example: ALTER TABLESPACE ACCOUNTING READ ONLY; Oracle 9 i Database Administrator: Implementation and Administration 29
Dropping Tablespaces n Syntax: DROP TABLESPACE <tablespacename> INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS; Use when there are constraints outside the tablespace that reference this tablespace Use when there is data in the tablespace Oracle 9 i Database Administrator: Implementation and Administration 30
Querying the Data Dictionary For Storage Data Oracle 9 i Database Administrator: Implementation and Administration 31
Querying the Data Dictionary For Storage Data Example: Find adjacent free extents that should be coalesced SELECT BLOCK_ID, BLOCK_ID+BLOCKS NEXT_BLOCK_ID, BLOCKS FROM DBA_FREE_SPACE WHERE TABLESPACE_NAME = 'USERS' ORDER BY BLOCK_ID; Oracle 9 i Database Administrator: Implementation and Administration 32
Querying the Data Dictionary For Storage Data Identifying adjacent free sets of blocks Oracle 9 i Database Administrator: Implementation and Administration 33
Overview of Undo Data n Undo data is made of undo blocks n Contain before images of data blocks n Assist in read-consistency n Two methods for managing: n n Manual: the old way (with manually created redo segments) Automatic: the new way (with undo tablespace) Oracle 9 i Database Administrator: Implementation and Administration 34
Implementing Automatic Undo Management Requirements: Set initialization parameters: n n UNDO_MANAGEMENT=AUTO n UNDO_TABLESPACE=<tablespacename> Create UNDO tablespace: n n While creating the database n Later with CREATE UNDO TABLESPACE command Oracle 9 i Database Administrator: Implementation and Administration 35
Implementing Automatic Undo Management Optional initialization parameters: n n UNDO_RETENTION: time in seconds that undo data is saved after commit (default is 900 seconds) UNDO_SURPRESS_ERRORS: defines error handling when transitioning from manual to automatic undo management Oracle 9 i Database Administrator: Implementation and Administration 36
Chapter Summary n n n Database structures are divided into logical and physical groups Physical structures include datafiles, control files, and redo log files Logical structures include tablespaces, extents, and data blocks A tablespace always has at least one datafile where its data is stored Locally managed tablespaces use a bitmap to track extent free space Oracle 9 i Database Administrator: Implementation and Administration 37
Chapter Summary n n When using OMF, omit the DATAFILE clause in the CREATE TABLESPACE command AUTOEXTEND ON allows a datafile to grow as needed Dictionary-managed tablespaces: n Use the data dictionary to track extent free space n Don’t automatically coalesce free space Locally managed tablespaces: n n Automatically coalesce free space Keep all extents the same size or a variable systemcontrolled size Oracle 9 i Database Administrator: Implementation and Administration 38
Chapter Summary n n Types of segments: data, index, temporary, and rollback Temporary tablespaces store data while sorting, and temporary tables Tablespaces can be ONLINE or OFFLINE A READ ONLY tablespace is not included in regular backups or recoveries Oracle 9 i Database Administrator: Implementation and Administration 39
Chapter Summary n n Dropping a tablespace with INCLUDING CONTENTS destroys all its data Data dictionary views for tablespaces include DBA_TABLESPACES and DBA_FREE_EXTENTS Undo data gives users read consistency Automatic undo management uses an UNDO tablespace Oracle 9 i Database Administrator: Implementation and Administration 40
- Slides: 40