Upload
amberlynn-neal
View
215
Download
1
Tags:
Embed Size (px)
Citation preview
IT 21003 Database AdministrationIT 21003 Database Administration
Section 03Section 03
Tablespaces and the DBATablespaces and the DBA Important for DBAs – logical units of database Important for DBAs – logical units of database storagestorage
Made up of physical operating-system files (one or Made up of physical operating-system files (one or more)more)
Can be madeCan be made READ ONLY (data warehouse)READ ONLY (data warehouse) PERMANENT or TEMPORARY (holds sort data)PERMANENT or TEMPORARY (holds sort data)
Can be put Online or OfflineCan be put Online or Offline
Tablespaces: The IssuesTablespaces: The Issues Schemes for space allocation for users and Schemes for space allocation for users and applicationsapplications
Give users resource quotas on tablespacesGive users resource quotas on tablespaces Provide separate default storage parameters for each Provide separate default storage parameters for each tablespacetablespace
Design tablespaces for different styles of activityDesign tablespaces for different styles of activity Group tables belonging to one applicationGroup tables belonging to one application Put tables of high activity on certain physical devicesPut tables of high activity on certain physical devices
Tablespaces: The IssuesTablespaces: The Issues Positioning index and table data – spread the I/OPositioning index and table data – spread the I/O
Spread large active tables across disks (table striping)Spread large active tables across disks (table striping)
Tablespaces for rollback segmentsTablespaces for rollback segments Have separately designed tablespaces for rollback Have separately designed tablespaces for rollback segmentssegments
Tablespaces for TEMPORARY segmentsTablespaces for TEMPORARY segments Used to temporarily store sort runs for many types of Used to temporarily store sort runs for many types of queriesqueries
Points to ConsiderPoints to Consider Tablespaces are transferable across databases Tablespaces are transferable across databases with version 8i and upwith version 8i and up May go offline when certain errors occurMay go offline when certain errors occur Access to data is restricted if an index is in an Access to data is restricted if an index is in an offline tablespaceoffline tablespace Recovery can be performed tablespace by Recovery can be performed tablespace by tablespacetablespace
The SYSTEM tablespace – at least 60mbThe SYSTEM tablespace – at least 60mb Every database must have a tablespace called Every database must have a tablespace called SYSTEMSYSTEM
Automatically built by CREATE DATABASE with default Automatically built by CREATE DATABASE with default storage characteristics as specified in the file sql.bsqstorage characteristics as specified in the file sql.bsq
The SYSTEM tablespace containsThe SYSTEM tablespace contains The Data DictionaryThe Data Dictionary SYSTEM rollback segmentsSYSTEM rollback segments Bootstrap segmentBootstrap segment
The SYSTEM tablespace – cont’dThe SYSTEM tablespace – cont’d May be enlarged – with careful forethoughtMay be enlarged – with careful forethought
Do not store any user data in SYSTEMDo not store any user data in SYSTEM Reserved only for OracleReserved only for Oracle
Must always be online for normal operationsMust always be online for normal operations Can be set to be locally managed with theCan be set to be locally managed with the
Extent Management Local statement in the Create Extent Management Local statement in the Create Database clauseDatabase clause
Creating Additional TablespacesCreating Additional Tablespaces The creator must have DBA role or be granted the The creator must have DBA role or be granted the CREATE TABLESPACE system privilegeCREATE TABLESPACE system privilege Example CREATE TABLESPACE statementExample CREATE TABLESPACE statement
Create TablespaceCreate Tablespace user_data_01 user_data_01
DatafileDatafile ‘e:\oraclass\database\user_data_01.dbf’ size ‘e:\oraclass\database\user_data_01.dbf’ size 200M200M
Autoextend on next maxsize unlimitedAutoextend on next maxsize unlimited
Default storageDefault storage ( (InitialInitial 1M 1M NextNext 2M 2M
PctincreasePctincrease 0 0
MaxextentsMaxextents 100) 100)
PermanentPermanent;;
The SYSTEM tablespace – Example cont’dThe SYSTEM tablespace – Example cont’d Uses a 200 MB file as storage for the tablespaceUses a 200 MB file as storage for the tablespace
This will automatically expand as it becomes fullThis will automatically expand as it becomes full
Objects without their own storage definition will be Objects without their own storage definition will be allocated an initial 1MB of space, and all other allocated an initial 1MB of space, and all other extents will be 2MBextents will be 2MB Objects can expand to a maximum of 100 extentsObjects can expand to a maximum of 100 extents
Creating the first additional tablespace(s)Creating the first additional tablespace(s) Non-SYSTEM tablespace data cannot make use Non-SYSTEM tablespace data cannot make use of the system rollback segment, so…of the system rollback segment, so…
Create the tablespace(s)Create the tablespace(s) Create rollback segments as required (at least one) in Create rollback segments as required (at least one) in the new tablespace(s)the new tablespace(s) Bring the rollback segments online so that transactions Bring the rollback segments online so that transactions on non-SYSTEM tablespace data can use a rollback on non-SYSTEM tablespace data can use a rollback segmentsegment
This is not online by defaultThis is not online by default
Edit the parameter file to include names of the new Edit the parameter file to include names of the new rollback segments in order to make them active when rollback segments in order to make them active when opening the databaseopening the database
Altering TablespacesAltering Tablespaces Why alter tablespaces?Why alter tablespaces?
Add a file to satisfy additional space requirementsAdd a file to satisfy additional space requirements Rename files because they need to be moved to other devicesRename files because they need to be moved to other devices Make the tablespace available or unavailable to usersMake the tablespace available or unavailable to users Perform an online backup of the tablespacePerform an online backup of the tablespace Change the way in which files behave when, and if, they expandChange the way in which files behave when, and if, they expand Change the maximum size of any auto-expandable filesChange the maximum size of any auto-expandable files Change to read-only or read/writeChange to read-only or read/write Force coalescence of free spaceForce coalescence of free space Change the default storage parametersChange the default storage parameters Change a tablespace from temporary to permanentChange a tablespace from temporary to permanent Change the extent managementChange the extent management
Particularly important for temporary tablespacesParticularly important for temporary tablespaces
Altering Tablespaces: Adding DatafilesAltering Tablespaces: Adding Datafiles Enlarging tablespaces (adding datafiles)Enlarging tablespaces (adding datafiles)
Alter TablespaceAlter Tablespace tablespacename tablespacename
Add DatafileAdd Datafile ‘filename.dbf’ [ ‘filename.dbf’ [SizeSize interger [k|m] ] interger [k|m] ]
Tablespace may be online or offline, but the Tablespace may be online or offline, but the database must be opendatabase must be open
The extra file is automatically enabled and availableThe extra file is automatically enabled and available Default file size is 10MBDefault file size is 10MB
If SIZE is specified the file must not exist and is If SIZE is specified the file must not exist and is created with the specified size created with the specified size
Altering Tablespaces: Relocating FilesAltering Tablespaces: Relocating Files Renaming files in a tablespaceRenaming files in a tablespace Alter TablespaceAlter Tablespace tablespacename tablespacename
Rename DatafileRename Datafile ‘/usr1/data2.dbf’ ‘/usr1/data2.dbf’ ToTo ‘/usr2/data3.dbf’; ‘/usr2/data3.dbf’;
Renaming (relocating) a datafile actually requires Renaming (relocating) a datafile actually requires a number of operationsa number of operations
Take the tablespace offlineTake the tablespace offline Use the OS to copy the old file to the new locationUse the OS to copy the old file to the new location Use the RENAME DATAFILE statementUse the RENAME DATAFILE statement Make the tablespace ONLINEMake the tablespace ONLINE Delete the old file using the OSDelete the old file using the OS Backup the database and control filesBackup the database and control files This method requires the database to be OPENThis method requires the database to be OPEN
Altering Tablespaces: Relocating Files cont’dAltering Tablespaces: Relocating Files cont’d Files can also be renamed when the database is Files can also be renamed when the database is in a MOUNT state and OPENin a MOUNT state and OPEN
Alter Database Rename File Alter Database Rename File ’/usr1/system_data2.dbs’’/usr1/system_data2.dbs’
ToTo ‘/usr2/system_data3.dbf’; ‘/usr2/system_data3.dbf’;
This statement does not physically move the filesThis statement does not physically move the files
01-27-200501-27-2005
Altering Tablespaces: Changing the Default StorageAltering Tablespaces: Changing the Default Storage
Alter Tablespace Alter Tablespace usr1usr1
Default Storage Default Storage ( ( InitialInitial 1M 1M
NextNext 2M 2M
MinextentsMinextents 1 1
MaxextentsMaxextents 100 100
PctincreasePctincrease 50); 50);
The new values have no retro-effectThe new values have no retro-effect They do not change any existing storage allocationThey do not change any existing storage allocation
Altering Tablespaces: Online and OfflineAltering Tablespaces: Online and Offline Bring tablespaces onlineBring tablespaces online
Alter TablespaceAlter Tablespace tablespacename tablespacename OnlineOnline;;
Tablespace becomes available for useTablespace becomes available for use Will be successful if there are no errors in the Will be successful if there are no errors in the datafiles in the tablespacedatafiles in the tablespace
Altering Tablespaces: Online and OfflineAltering Tablespaces: Online and Offline Bring tablespaces offlineBring tablespaces offline
Alter TablespaceAlter Tablespace tablespacename tablespacename OfflineOffline
[[ Normal Normal || Immediate Immediate || Temporary Temporary || For Recover For Recover ];];
Taking a tablespace offline enables the following Taking a tablespace offline enables the following actions:actions:
Make the data temporarily unavailable to usersMake the data temporarily unavailable to users Change disksChange disks Handle disk failuresHandle disk failures
Altering Tablespaces: Offline OptionsAltering Tablespaces: Offline Options NORMALNORMAL
No media recovery necessaryNo media recovery necessary The datafiles in the tablespace are checkpointedThe datafiles in the tablespace are checkpointed NOARCHIVELOG modeNOARCHIVELOG mode
IMMEDIATEIMMEDIATE Not available in NOARCHIVELOG mode because the Not available in NOARCHIVELOG mode because the tablespace will require media recovery before tablespace will require media recovery before subsequent usesubsequent use No checkpoint is performed and files do not need to No checkpoint is performed and files do not need to existexist ARCIVELOG mode onlyARCIVELOG mode only
Altering Tablespaces: Offline Options cont’dAltering Tablespaces: Offline Options cont’d TEMPORARYTEMPORARY
Can be done if one of the datafiles is already offlineCan be done if one of the datafiles is already offline All remaining datafiles within the tablespace are All remaining datafiles within the tablespace are checkpointedcheckpointed Media recovery will be required for any of the files that Media recovery will be required for any of the files that are offlineare offline ARCIVELOG mode onlyARCIVELOG mode only
FOR RECOVERFOR RECOVER Takes tablespaces offline for point in time tablespace Takes tablespaces offline for point in time tablespace recoveryrecovery ARCIVELOG mode onlyARCIVELOG mode only
Dropping TablespacesDropping Tablespaces
Drop TablespaceDrop Tablespace tablespacename; tablespacename;
If data is present, the INCLUDING CONTENTS If data is present, the INCLUDING CONTENTS clause must be used clause must be used
Drop TablespaceDrop Tablespace tablespacename tablespacename Including Including ContentsContents; ;
Dropping Tablespaces cont’dDropping Tablespaces cont’d If foreign key constraints are acting on the data If foreign key constraints are acting on the data from tables in other tablespaces, use the from tables in other tablespaces, use the CASCADE CONTENTS clauseCASCADE CONTENTS clause
Drop TablespaceDrop Tablespace tablespacename tablespacename
Including Contents Cascade ContentsIncluding Contents Cascade Contents; ;
Dropping Tablespaces cont’dDropping Tablespaces cont’d The DROP TABLESPACE command is a DDL The DROP TABLESPACE command is a DDL statement; hence, no rollback is possible!statement; hence, no rollback is possible!
A Permanent ActionA Permanent Action Recommended to take the tablespace offline before Recommended to take the tablespace offline before dropping it, and backup the database before and after dropping it, and backup the database before and after the dropthe drop Cannot be dropped if active rollback segments are Cannot be dropped if active rollback segments are presentpresent
Read-Only TablespacesRead-Only Tablespaces
Alter TablespaceAlter Tablespace tablespacename tablespacename Read OnlyRead Only;;
Useful forUseful for Static DataStatic Data Data WarehouseData Warehouse Preventing UpdatesPreventing Updates Simplifying the backup strategySimplifying the backup strategy
Read-Only TablespacesRead-Only Tablespaces
PrerequisitesPrerequisites Tablespace must be onlineTablespace must be online No active transactions in the tablespaceNo active transactions in the tablespace No active rollback segments in the tablespaceNo active rollback segments in the tablespace No online backup currently runningNo online backup currently running
Making a Tablespace Read-OnlyMaking a Tablespace Read-Only Make sure the prerequisites are metMake sure the prerequisites are met Set the tablespace to be read-onlySet the tablespace to be read-only Backup the tablespaceBackup the tablespace Amend the backup strategy and scriptsAmend the backup strategy and scripts If could also be useful to scan all blocks in the If could also be useful to scan all blocks in the tablespace to force block clean-out before making tablespace to force block clean-out before making the tablespace read-onlythe tablespace read-only To return a tablespace to read/write statusTo return a tablespace to read/write status
Alter TablespaceAlter Tablespace tablespacename tablespacename Read WriteRead Write;;
Temporary TablespacesTemporary Tablespaces Scratch areas used by OracleScratch areas used by Oracle Tablespaces specially designed to hold data from intermediate sort Tablespaces specially designed to hold data from intermediate sort runsruns
Large sorts may require too much space to be managed within Large sorts may require too much space to be managed within memorymemory
The creation of an index could require a temporary segment The creation of an index could require a temporary segment twice as large as the storage allocated for the actual indextwice as large as the storage allocated for the actual index The temporary sort data will be placed transiently on disk thenThe temporary sort data will be placed transiently on disk then
Beware: The default tablespace for temporary data is SYSTEMBeware: The default tablespace for temporary data is SYSTEM The SYSTEM tablespace could become fragmented due to extents The SYSTEM tablespace could become fragmented due to extents being continually allocated and deallocated to the sort runsbeing continually allocated and deallocated to the sort runs Each user should have a specified temporary tablespace for their Each user should have a specified temporary tablespace for their sort datasort data
Temporary Tablespaces cont’dTemporary Tablespaces cont’d The temporary tablespace should have a default The temporary tablespace should have a default storage pattern so that each extent is exactly the storage pattern so that each extent is exactly the same size (uniform extents)same size (uniform extents)
Makes it easier for Oracle to find free space extents of Makes it easier for Oracle to find free space extents of the required sizethe required size
Locally Managed Temporary TablespacesLocally Managed Temporary Tablespaces Preferred methodPreferred method
Create Temporary TablespaceCreate Temporary Tablespace tablespacename tablespacename TempfileTempfile ‘tablespacename_fl.tmp’ ‘tablespacename_fl.tmp’ SizeSize 50M 50M
Extent Management Local Uniform SizeExtent Management Local Uniform Size 8M; 8M;
Extent management must be local when using this syntaxExtent management must be local when using this syntax This tablespace cannot be renamed or made read-onlyThis tablespace cannot be renamed or made read-only Media recovery does not recognize tempfiles becauseMedia recovery does not recognize tempfiles because
There is no need to back them upThere is no need to back them up They are easy to re-create anytime neededThey are easy to re-create anytime needed
Coalescing Free Space in TablespacesCoalescing Free Space in Tablespaces Free-space fragmentation needs to be avoidedFree-space fragmentation needs to be avoided
Caused by allocation and deallocation of storage to Caused by allocation and deallocation of storage to objects leaving small pieces of free spaceobjects leaving small pieces of free space
Each piece may not be large enough for any future allocation Each piece may not be large enough for any future allocation of contiguous storageof contiguous storage
Free space coalescion can be forced byFree space coalescion can be forced by
Alter TablespaceAlter Tablespace tablespacename tablespacename CoalesceCoalesce;;
Retrieving Information about FragmentationRetrieving Information about Fragmentation
SelectSelect tablespace_name tablespace_name As As tablespace,tablespace,
file_id file_id AsAs File_No, File_No, CountCount(*) (*) AsAs Pieces, Pieces,
MaxMax(blocks) (blocks) AsAs Max, Max, MinMin(blocks) (blocks) AsAs Min, Min,
AvgAvg(block) (block) AsAs Ave, Ave, SumSum(blocks) (blocks) AsAs Tot Tot
FromFrom dba_free_space dba_free_space
WhereWhere tablespace_name = ‘&tablespace’ tablespace_name = ‘&tablespace’
Group ByGroup By tablespace_name, file_id; tablespace_name, file_id;
The higher the pieces amount the greater the The higher the pieces amount the greater the fragmentation fragmentation
Oracle FilesOracle Files Datafiles - operating-system files that are used toDatafiles - operating-system files that are used to
Store Oracle DataStore Oracle Data Position the physical separation of objectsPosition the physical separation of objects
Indexes from dataIndexes from data Enable the “Table Striping” techniqueEnable the “Table Striping” technique Support Table PartitioningSupport Table Partitioning
Redo Log Files store (all) changes to database Redo Log Files store (all) changes to database data and containdata and contain
Before ImagesBefore Images After ImagesAfter Images Commit and Rollback StatusCommit and Rollback Status Checkpoint InformationCheckpoint Information
Oracle Files cont’dOracle Files cont’d Control files store startup and backup/recovery Control files store startup and backup/recovery informationinformation Parameter files store initialization parametersParameter files store initialization parameters Password filesPassword files Trace, log, and networking filesTrace, log, and networking files DatafilesDatafiles
Datafiles per TablespaceDatafiles per Tablespace 1023 1023 Datafiles per DatabaseDatafiles per Database 6553365533 Datafile SizeDatafile Size 4M Blocks4M Blocks DB-BLOCK_SIZEDB-BLOCK_SIZE 32KB32KB Tablespaces per DatabaseTablespaces per Database 6400064000
Resizable DatafilesResizable Datafiles To manually increase or decrease the size of a To manually increase or decrease the size of a datafile:datafile:
Alter Database DatafileAlter Database Datafile filename filename ResizeResize 100M; 100M;
To initiate automatic extension of a datafile:To initiate automatic extension of a datafile:
Alter Database DatafileAlter Database Datafile filename filename Autoextend On NextAutoextend On Next nM nM MaxsizeMaxsize 80M; 80M;
(Where n = the default number of blocks in one Oracle block)(Where n = the default number of blocks in one Oracle block)
Resizable Datafiles cont’dResizable Datafiles cont’d To curtail automatic extension:To curtail automatic extension:
Alter Database DatafileAlter Database Datafile filename filename Autoextend OffAutoextend Off;;
To allow unlimited expansion:To allow unlimited expansion:
Alter Database DatafileAlter Database Datafile filename filename Autoextend On Maxsize UnlimitedAutoextend On Maxsize Unlimited;;
General Database Storage PatternsGeneral Database Storage Patterns Oracle supports the use of:Oracle supports the use of:
Devices PartitionsDevices Partitions RAID systemsRAID systems Striping TechniquesStriping Techniques
Operating-System DrivenOperating-System Driven Database DrivenDatabase Driven
Device Partitions can give a 5-20% performance Device Partitions can give a 5-20% performance improvementimprovement RAID configurations supported:RAID configurations supported:
RAID 1RAID 1 RAID 5RAID 5 RAID 0+1RAID 0+1
Striping techniques are best done by the OSStriping techniques are best done by the OS
Control FilesControl Files Created at database creation time and checked Created at database creation time and checked each time Oracle is started and the database is each time Oracle is started and the database is openedopened Relatively small binary filesRelatively small binary files
Size depends partly on the number of redo log files, Size depends partly on the number of redo log files, database files, and information associated with backup database files, and information associated with backup and recoveryand recovery
Contain information about:Contain information about: Database FilesDatabase Files Redo Log Files (Name and Position)Redo Log Files (Name and Position) Timestamps of CreationsTimestamps of Creations Checkpoint InformationCheckpoint Information Backup and Recovery InformationBackup and Recovery Information
Can become quite large in sizeCan become quite large in size
Control Files cont’dControl Files cont’d Place a control file on each disk to guard against Place a control file on each disk to guard against media failuremedia failure
Copies are automatically written in synchronous fashion Copies are automatically written in synchronous fashion by Oracle with negligible performance overheadby Oracle with negligible performance overhead
Redo Log FilesRedo Log Files Contain:Contain:
Before ImagesBefore Images After ImagesAfter Images Commit InformationCommit Information Rollback InformationRollback Information Checkpoint InformationCheckpoint Information
Safeguard changes to the databaseSafeguard changes to the database Log files can be archived to enable full recoveryLog files can be archived to enable full recovery
Incurs storage and management overheadIncurs storage and management overhead
Can provide for total recoveryCan provide for total recovery
Redo Log Files cont’dRedo Log Files cont’d Should be entirely dualed (mirrored) on separate Should be entirely dualed (mirrored) on separate disksdisks
Log files can be volatileLog files can be volatile Used to store redo log entries in a sequential Used to store redo log entries in a sequential mannermanner
Minimum of two log files requiredMinimum of two log files required Used in a circular fashionUsed in a circular fashion
Contain roll forward data and backup of rollback Contain roll forward data and backup of rollback segment datasegment data
Minimum size is 50KB (Never make them this small)Minimum size is 50KB (Never make them this small) Default size is 500KBDefault size is 500KB Typically 10 – 100 MBTypically 10 – 100 MB
Questions?Questions?