OCA 06 - Managing Database Storage Structures
OCA 06 - Managing Database Storage Structures
OCA 06 - Managing Database Storage Structures
1/3
Agenda
Tablespaces Segment Oracle Block Extents Data Files OS Block Exersice 6-1: Segments, Extents, Blocks
2/3
Agenda
EXERCISE 6-2 Document a Databases Physical Structure Create and Manage Tablespaces
Types of tablespaces Tablespace extent management Tablespace segment management Create Tablespace Taking a Tablespace Online or Offline Rename a Tablespace and Its Datafiles Mark a Tablespace as Read Only Resizing a Tablespace Changing Alert Thresholds Dropping Tablespaces
http://asghars.blogspot.com
3/3
Agenda
EXERCISE 6-3: Create, Alter, and Drop Tablespaces Extent Management Segment Management Manual Management EXERCISE 6-4: Change Tablespace Characteristics
http://asghars.blogspot.com
1/6
Data is stored logically in segments and physically in datafiles The separation of logical from physical storage is a necessary part of the relational database paradigm Figure shows the Oracle storage model sketched as ERD
5 http://asghars.blogspot.com
2/6
Tablespaces
There is a many-to-many relationship b/w segment & datafile The tablespace resolves the many-to-many relationship b/w segments and datafiles One tablespace can contain many segments and be made up of many datafiles This means that any one segment may be spread across multiple datafiles, and any one datafile may contain all of or parts of many segments Tablespaces are identified by name, unique in the database
http://asghars.blogspot.com
3/6
Segment
Represents any database object that stores data and therefore requires space in a tablespace Typical segment is a table, but there are other segment types, notably index segments and undo segments Any one segment can exist in only one tablespace, but the tablespace can spread it across all the files making up the tablespace Segments are schema objects, identified by the segment name qualified with the owning schema name
http://asghars.blogspot.com
4/6
Oracle Block
Datafiles are formatted into Oracle blocks, consecutively numbered The size of the Oracle blocks is fixed for a tablespace; the default (with release 11g) is 8 KB The size of an Oracle block can range from 2 KB to 16 KB on Linux or Windows, to 32 KB on some other operating systems It is the unit of I/O for the database The block size is controlled by the parameter DB_BLOCK_SIZE
http://asghars.blogspot.com
5/6
Extents
An extent is a set of consecutively numbered Oracle blocks within one datafile Managing space one block at a time would be a crippling task, so blocks are grouped into extents Every segment will consist of one or more extents, consecutively numbered
Data File
6/6
Datafiles and the operating system blocks are entirely dependent on the operating systems file system The alternatives to file systems for datafile storage are raw devices or ASM Raw devices are now very rarely used for datafile storage because of manageability issues
OS Block
An operating system block is the unit of I/O for your file system The operating system block size is configurable for some file systems (for example, when formatting an NTFS file system you can choose from 512 B to 64 KB), but typically system administrators leave it on default (512 B for NTFS, 1 KB for ext3) The configuration that should always be avoided would be where the operating system blocks were bigger than the Oracle blocks
http://asghars.blogspot.com
10
1/3
2.
i.
11
2/3
iii.
Two extent is in file number 4 and each is 8 blocks long Force Oracle to allocate another extent to the segment
http://asghars.blogspot.com
12
3/3
v.
Determine the name of the file in which the extents were allocated, and the name of the tablespace to which the datafile belongs
13
http://asghars.blogspot.com
1/1
Use of OMF is intended to remove the necessity for the DBA to have any knowledge of the file systems To enable OMF, set some or all of these instance parameters:
OMF will generate filenames and (by default) set the file sizes
14 http://asghars.blogspot.com
1/6
Datafiles can exist on four types of device: local file systems, clustered file systems, ASM disk groups, and raw devices Local File System
Files exist as normal operating system files in a directory structure on disks directly attached to the computer running the instance These could be internal IDE or SATA drives or more sophisticated SCSI disks, or external drives
15
http://asghars.blogspot.com
2/6
A clustered file system is external disks, mounted concurrently on more than one computer Clustered file systems can be bought from operating system vendors, or Oracle Corporations OCFS (Oracle Clustered File System) is an excellent alternative It is possible to create datafiles on disks with no file system at all In old days before clustered file systems or ASM), raw devices were the only way to implement a Parallel Server database Parallel Server itself was replaced with RAC in database release 9i http://asghars.blogspot.com
Raw Devices
16
3/6
ASM Devices
ASM is a facility introduced with database release 10 g ASM is a logical volume manager designed for Oracle database files It cannot be used for the Oracle Home, or for the alert log and trace files To set up ASM, the system administrators must provide the physical volumes. These can be actual disks, partitions of disks, or devices provided by a SAN (storage area network) or some form of network-attached storage (NAS) ASM is covered in detail in the second OCP examination
http://asghars.blogspot.com
17
4/6
The DBA then groups these physical volumes (known as ASM disks) into logical volumes (known as ASM disk groups) The disk groups are formatted into allocation units, which are contiguous blocks of space on a physical volume The default allocation unit size is 1 MB, but this can be increased up to 64 MB if the nature of the application is such (typically, a data warehouse) that it would benefit from this Every file created on an ASM disk group will always be striped across all the ASM disks that make up the group
http://asghars.blogspot.com
18
5/6
Mirroring is also enabled by default If a volume group consists of just two disks and a third is added, ASM will automatically launch a rebalance operation to bring it into use by restriping the ASM files Similarly, if a disk leaves the group, the disk group will immediately rebalance itself to reinstantiate lost mirrors A key feature of ASM is that it can work as a clustered file system Figure on next slide sketches the ASM structures as an entity-relationship diagram
http://asghars.blogspot.com
19
6/6
20
http://asghars.blogspot.com
1/2
2.
Determine the name and size of the online redo log file members
21
http://asghars.blogspot.com
2/2
Determine the name and size of the datafiles and the tempfiles
22
http://asghars.blogspot.com
1/12
All databases must have a SYSTEM tablespace and a SYSA UX tablespace, and (for practical purposes) a temporary tablespace and an undo tablespace Subsequently, the DBA may create many more tablespaces for user data, and possible additional tablespaces for undo and temporary data Types of tablespaces
Permanent
A permanent tablespace stores regular schema objects, such as tables and indexes We can also enable the encryption for permanent tablespace
http://asghars.blogspot.com
23
2/12
Temporary
Temporary tablespaces are used to store the temporary tables, temporary indexes and intermediate sort results Undo tablespace stores only system-managed undo segments
Undo
Dictionary Managed
Dictionary managed tablespaces are managed by the data dictionary This is for backward compatibility; it is recommended that you use locally managed tablespaces
24
http://asghars.blogspot.com
3/12
Locally Managed
Extent allocation be automatic or uniform by specifying the size Segement management for a tablespace can be automatic or manual Automatic segment management offers high performance for free space managemen
25
http://asghars.blogspot.com
4/12
Create Tablespace
To create a tablespace with EM Database Control, navigate Home Page Server Tab Storage Section Tablespaces linkCreate Button The Create Tablespace window prompts for a tablespace name, and the values for Extent Management, Type, and Status
26
http://asghars.blogspot.com
5/12
The Add button lets you specify one or more datafiles for the new tablespace. Each file must have a name and a size, and can optionally be set to autoextend up to a maximum file size
27
http://asghars.blogspot.com
6/12
The Storage tab gives access to options for extent management and compression
28
http://asghars.blogspot.com
7/12
An online tablespace or datafile is available for use; an offline tablespace or datafile exists as a definition in the data dictionary and the controlfile but cannot be used In EM on tablespaces page select newtab and clicke Edit button Select Offline from Status section and click Apply
http://asghars.blogspot.com
29
8/12
A tablespace can be renamed while it is in use, but to rename a datafile, the datafiles must be offline In edit mode on General tab you can change the name for tablespace and click Apply
To rename datafile
30
http://asghars.blogspot.com
9/12
Making a tablespace read only, none of the objects within it can be changed with DML statements Making a tablespace read only can have advantages for backup and restore operations
Resizing a Tablespace
A tablespace can be resized either by adding datafiles to it or by adjusting the size of the existing datafiles
http://asghars.blogspot.com
31
10/12
The MMON process of the instance monitors, how full every tablespace is If a tablespace fills up beyond a certain point, MMON will raise an alert The easiest way to see alerts, is to look at the database home page of Database Control, where they are displayed in the Alerts section To view or change the alert levels, select the tablespace and click the Edit button, then in the Edit Tablespace window take the Thresholds tab The alert system uses the maximum possible size of the tablespace as the basis for its calculations, which is meaningless if the tablespaces datafiles were created with the syntax AUTOEXTEND ON MAXSIZE UMLIMITED, or if a MAXSIZE was not specified
http://asghars.blogspot.com
32
11/12
33
http://asghars.blogspot.com
12/12
Dropping Tablespaces
34
http://asghars.blogspot.com
1/6
Create a tablespace
2.
Create a table in the new tablespace, and determine the size of the first extent
35
http://asghars.blogspot.com
2/6
Add extents manually, and observe the size of each new extent
36
http://asghars.blogspot.com
3/6
Take the tablespace offline, observe the effect, and bring it back online
37
http://asghars.blogspot.com
4/6
Make the tablespace read only, observe the effect, and make it read-write again
38
http://asghars.blogspot.com
5/6
Enable OMF for datafile creation and create a tablespace, using the minimum syntax now possible
7.
39
http://asghars.blogspot.com
6/6
9.
Drop the tablespace, and use an operating system command to confirm that the file has indeed gone
40
http://asghars.blogspot.com
1/5
Tablespace, done by sizing data files (already discussed) Segment, done by allocating extents Row, done by maintaing bitmaps
There are two techniques for managing extent usage: dictionary management or local management Dictionary Management
Extent Management
It uses two tables in the data dictionary SYS.UET$ has rows describing used extents, and SYS.FET$ has rows describing free extents Dictionary management should never be used
http://asghars.blogspot.com
41
2/5
Local Management
It uses bitmaps stored in each datafile Each bit in the bitmap covers a range of blocks, and when space is allocated, the appropriate bits are changed from zero to one When creating a locally managed tablespace, an important option is uniform size
If you know how big segments are likely to be, UNIFORM SIZE may well be the best option, otherwise Oracle Corporation recommends AUTOALLOCATE
http://asghars.blogspot.com
42
3/5
If a database has been upgraded from previous versions, it will include dictionary-managed tablespaces Any dictionary-managed tablespaces should be converted to local management with this PL/SQL procedure call
Segment Management
There are two techniques for managing segment space usage: manual or automatic Automatic Management
43
4/5
In an automatic management every segment created in a tablespace has a set of bitmaps that describe how full each block is There are five bitmaps for each segment, and each block will appear on exactly one bitmap The bitmaps track the space used in bands:
Blocks that are 75% to 100% used Blocks that are 50% to to 75% used Blocks that are 25% to 50% used Blocks that are 0% to 25% used
If the block size is 4 KB and the row to be inserted is 1500 bytes, an appropriate block will be found by searching the 25% to 50% bitmap
http://asghars.blogspot.com
44
5/5
As rows are inserted, are deleted, or change size through updates, the bitmaps get updated accordingly The old manual space management method used a free list, which stated which blocks were available for insert but without any information on how full they were To see if any tablespaces are using manual management
Manual Management
It is not possible to convert tablespace from manual to automatic segment space management
http://asghars.blogspot.com
45
1/4
2.
Confirm that the new tablespace is indeed using the manual technique
46
http://asghars.blogspot.com
2/4
Create a table and an index in the tablespace. These segments will be created with freelists, not bitmaps
4.
Create a new tablespace that will (by default) use automatic segment space management
47
http://asghars.blogspot.com
3/4
6.
48
http://asghars.blogspot.com
4/4
Drop the original tablespace Rename the new tablespace to the original name. This is often necessary, because some application software checks tablespaces names Tidy up by dropping the tablespace, first with this command
8.
9.
49
http://asghars.blogspot.com