oca 06 - managing database storage structures
TRANSCRIPT
-
7/29/2019 OCA 06 - Managing Database Storage Structures
1/49
06 - Managing Database Storage
Structures
By Muhammad Asghar Khan
Reference: OCA Oracle Database 11g - Admin I Exam Guide by John Watson
-
7/29/2019 OCA 06 - Managing Database Storage Structures
2/49
Agenda
http://asghars.blogspot.com2
Understand Tablespaces and Datafiles
Tablespaces Segment Oracle Block Extents Data Files OS Block Exersice 6-1: Segments, Extents, Blocks
Oracle-Managed Files (OMF)
Automatic Storage Management (ASM) Local File System Clustered File System
1/3
-
7/29/2019 OCA 06 - Managing Database Storage Structures
3/49
Agenda
http://asghars.blogspot.com3
Raw Devices
ASM Devices
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
2/3
-
7/29/2019 OCA 06 - Managing Database Storage Structures
4/49
Agenda
http://asghars.blogspot.com4
EXERCISE 6-3: Create, Alter, and Drop Tablespaces Manage Space in Tablespaces
Extent Management
Segment Management
Manual Management
EXERCISE 6-4: Change Tablespace Characteristics
3/3
-
7/29/2019 OCA 06 - Managing Database Storage Structures
5/49
Understand Tablespaces and Datafiles
http://asghars.blogspot.com5
Data is stored logically in
segments and physically in
datafiles
The separation of logical
from physical storage is anecessary part of the
relational database
paradigm
Figure shows the Oracle
storage model sketched as
ERD
1/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
6/49
Understand Tablespaces and Datafiles
http://asghars.blogspot.com6
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 maycontain all of or parts of many segments
Tablespaces are identified by name, unique in thedatabase
2/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
7/49
Understand Tablespaces and Datafiles
http://asghars.blogspot.com7
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 undosegments
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 schemaname
3/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
8/49
Understand Tablespaces and Datafiles
http://asghars.blogspot.com8
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 otheroperating systems
It is the unit of I/O for the database The block size is controlled by the parameter
DB_BLOCK_SIZE
4/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
9/49
Understand Tablespaces and Datafiles
http://asghars.blogspot.com9
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 Datafile is, physically, made up of a number of
operating system blocks
5/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
10/49
Understand Tablespaces and Datafiles
http://asghars.blogspot.com10
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 storagebecause 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 filesystems (for example, when formatting an NTFS file system youcan choose from 512 B to 64 KB), but typically system
administrators leave it on default (512 B for NTFS, 1 KB forext3)
The configuration that should always be avoided would bewhere the operating system blocks were bigger than theOracle blocks
6/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
11/49
Exersice 6-1: Segments, Extents, Blocks
http://asghars.blogspot.com11
1. Identify the segment types
2. Identify precisely where a segment is
i. First creates the table HR.NEWTAB
1/3
-
7/29/2019 OCA 06 - Managing Database Storage Structures
12/49
Exersice 6-1: Segments, Extents, Blocks
http://asghars.blogspot.com12
ii. Query DBA_EXTENTS to find the segment and
extent
Two extent is in file number 4 and each is 8 blocks
longiii. Force Oracle to allocate another extent to the
segment
2/3
-
7/29/2019 OCA 06 - Managing Database Storage Structures
13/49
Exersice 6-1: Segments, Extents, Blocks
http://asghars.blogspot.com13
iv. Query shows that this new extent
v. Determine the name of the file in which the extents
were allocated, and the name of the tablespace to
which the datafile belongs
3/3
-
7/29/2019 OCA 06 - Managing Database Storage Structures
14/49
Oracle-Managed Files (OMF)
http://asghars.blogspot.com14
Use of OMF is intended to remove the necessity for theDBA to have any knowledge of the file systems
To enable OMF, set some or all of these instanceparameters:
DB_CREATE_FILE_DEST DB_CREATE_ONLINE_LOG_DEST_1
DB_CREATE_ONLINE_LOG_DEST_2
DB_CREATE_ONLINE_LOG_DEST_3
DB_CREATE_ONLINE_LOG_DEST_4
DB_CREATE_ONLINE_LOG_DEST_5 DB_RECOVERY_FILE_DEST
OMF will generate filenames and (by default) set thefile sizes
1/1
-
7/29/2019 OCA 06 - Managing Database Storage Structures
15/49
Automatic Storage Management (ASM)
http://asghars.blogspot.com15
Datafiles can exist on four types of device: local filesystems, 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 moresophisticated SCSI disks, or external drives
1/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
16/49
Automatic Storage Management (ASM)
http://asghars.blogspot.com16
Clustered File System
A clustered file system is external disks, mountedconcurrently on more than one computer
Clustered file systems can be bought from operatingsystem vendors, or Oracle Corporations OCFS (Oracle
Clustered File System) is an excellent alternative
Raw Devices
It is possible to create datafiles on disks with no filesystem at all
In old days before clustered file systems or ASM), rawdevices were the only way to implement a Parallel Serverdatabase
Parallel Server itself was replaced with RAC in database
release 9i
2/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
17/49
Automatic Storage Management (ASM)
http://asghars.blogspot.com17
ASM Devices
ASM is a facility introduced with database release 10 g
ASM is a logical volume manager designed for Oracledatabase files
It cannot be used for the Oracle Home, or for the alert logand trace files
To set up ASM, the system administrators must providethe physical volumes. These can be actual disks, partitionsof 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
3/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
18/49
Automatic Storage Management (ASM)
http://asghars.blogspot.com18
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
4/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
19/49
Automatic Storage Management (ASM)
http://asghars.blogspot.com19
Mirroring is also enabled by default
If a volume group consists of just two disks and athird is added, ASM will automatically launch arebalance operation to bring it into use by restripingthe ASM files
Similarly, if a disk leaves the group, the disk group willimmediately rebalance itself to reinstantiate lostmirrors
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
5/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
20/49
Automatic Storage Management (ASM)
http://asghars.blogspot.com20
6/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
21/49
EXERCISE 6-2 Document a Databases Physical
Structure
http://asghars.blogspot.com21
1. Determine the name and size of the controlfile(s)
2. Determine the name
and size of the online
redo log file members
1/2
-
7/29/2019 OCA 06 - Managing Database Storage Structures
22/49
EXERCISE 6-2 Document a Databases Physical
Structure
http://asghars.blogspot.com22
3. Determine the name andsize of the datafiles and the
tempfiles
2/2
-
7/29/2019 OCA 06 - Managing Database Storage Structures
23/49
Create and Manage Tablespaces
http://asghars.blogspot.com23
All databases must have a SYSTEM tablespace and aSYSA UX tablespace, and (for practical purposes) atemporary tablespace and an undo tablespace
Subsequently, the DBA may create many moretablespaces for user data, and possible additionaltablespaces for undo and temporary data
Types of tablespaces
Permanent
A permanent tablespace stores regular schema objects, suchas tables and indexes
We can also enable the encryption for permanenttablespace
1/12
-
7/29/2019 OCA 06 - Managing Database Storage Structures
24/49
Create and Manage Tablespaces
http://asghars.blogspot.com24
Temporary
Temporary tablespaces are used to store the temporarytables, temporary indexes and intermediate sort results
Undo
Undo tablespace stores only system-managed undo
segments Tablespace extent management
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
2/12
-
7/29/2019 OCA 06 - Managing Database Storage Structures
25/49
Create and Manage Tablespaces
http://asghars.blogspot.com25
Locally Managed
Locally managed tablespaces are managed via bitmaps
Extent allocation be automatic or uniform by
specifying the size
Tablespace segment management
Segement management for a tablespace can be
automatic or manual
Automatic segment management offers highperformance for free space managemen
3/12
-
7/29/2019 OCA 06 - Managing Database Storage Structures
26/49
Create and Manage Tablespaces
http://asghars.blogspot.com26
Create Tablespace To create a tablespace with EM Database Control,
navigate Home PageServer Tab Storage Section
Tablespaces linkCreate Button
The Create Tablespace window prompts for a tablespacename, and the values for Extent Management, Type, and
Status
4/12
-
7/29/2019 OCA 06 - Managing Database Storage Structures
27/49
Create and Manage Tablespaces
http://asghars.blogspot.com27
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
5/12
-
7/29/2019 OCA 06 - Managing Database Storage Structures
28/49
Create and Manage Tablespaces
http://asghars.blogspot.com28
The Storage tab gives access to options for extent
management and compression
6/12
-
7/29/2019 OCA 06 - Managing Database Storage Structures
29/49
Create and Manage Tablespaces
http://asghars.blogspot.com29
Taking a Tablespace Online or Offline 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
7/12
-
7/29/2019 OCA 06 - Managing Database Storage Structures
30/49
Create and Manage Tablespaces
http://asghars.blogspot.com30
Rename a Tablespace and Its Datafiles 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
8/12
-
7/29/2019 OCA 06 - Managing Database Storage Structures
31/49
Create and Manage Tablespaces
http://asghars.blogspot.com31
Mark a Tablespace as Read Only
Making a tablespace read only, none of the objectswithin 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
9/12
-
7/29/2019 OCA 06 - Managing Database Storage Structures
32/49
Create and Manage Tablespaces
http://asghars.blogspot.com32
Changing Alert Thresholds
The MMON process of the instance monitors, how full everytablespace is
If a tablespace fills up beyond a certain point, MMON will raisean alert
The easiest way to see alerts, is to look at the database home
page of Database Control, where they are displayed in theAlerts section
To view or change the alert levels, select the tablespace andclick the Edit button, then in the Edit Tablespace window takethe Thresholds tab
The alert system uses the maximum possible size of thetablespace as the basis for its calculations, which ismeaningless if the tablespaces datafiles were created with thesyntax AUTOEXTEND ON MAXSIZE UMLIMITED, or if a MAXSIZEwas not specified
10/12
-
7/29/2019 OCA 06 - Managing Database Storage Structures
33/49
Create and Manage Tablespaces
http://asghars.blogspot.com33
When using automatic extension, it is goo d practice
to set a maximum limit
11/12
-
7/29/2019 OCA 06 - Managing Database Storage Structures
34/49
Create and Manage Tablespaces
http://asghars.blogspot.com34
Dropping Tablespaces To drop a tablespace, use the DROP TABLESPACE
command
12/12
-
7/29/2019 OCA 06 - Managing Database Storage Structures
35/49
EXERCISE 6-3: Create, Alter, and Drop Tablespaces
http://asghars.blogspot.com35
1.
Create a tablespace
2. Create a table in the new tablespace, anddetermine the size of the first extent
1/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
36/49
EXERCISE 6-3: Create, Alter, and Drop Tablespaces
http://asghars.blogspot.com36
3.
Add extents manually, and observe the size ofeach new extent
2/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
37/49
EXERCISE 6-3: Create, Alter, and Drop Tablespaces
http://asghars.blogspot.com37
4. Take the tablespace offline, observe the effect,
and bring it back online
3/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
38/49
EXERCISE 6-3: Create, Alter, and Drop Tablespaces
http://asghars.blogspot.com38
5. Make the tablespace read only, observe the effect,
and make it read-write again
4/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
39/49
EXERCISE 6-3: Create, Alter, and Drop Tablespaces
http://asghars.blogspot.com39
6. Enable OMF for datafile creation and create a
tablespace, using the minimum syntax now
possible
7. Determine the characteristics of the OMF file
5/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
40/49
EXERCISE 6-3: Create, Alter, and Drop Tablespaces
http://asghars.blogspot.com40
8. Adjust the OMF file to have more sensible
characteristics
9. Drop the tablespace, and use an operating system
command to confirm that the file has indeed gone
6/6
-
7/29/2019 OCA 06 - Managing Database Storage Structures
41/49
Manage Space in Tablespaces
http://asghars.blogspot.com41
Space management in tablespace occuers at thefollowing levels
Tablespace, done by sizing data files (already discussed)
Segment, done by allocating extents
Row, done by maintaing bitmaps
Extent Management
There are two techniques for managing extent usage:dictionary management or local management
Dictionary 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
1/5
-
7/29/2019 OCA 06 - Managing Database Storage Structures
42/49
Manage Space in Tablespaces
http://asghars.blogspot.com42
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
2/5
-
7/29/2019 OCA 06 - Managing Database Storage Structures
43/49
Manage Space in Tablespaces
http://asghars.blogspot.com43
If a database has been upgraded from previous
versions, it will include dictionary-managed tablespaces
Any dictionary-managed tablespaces should beconverted 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
Automatic Management should always be used
3/5
-
7/29/2019 OCA 06 - Managing Database Storage Structures
44/49
Manage Space in Tablespaces
http://asghars.blogspot.com44
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
4/5
-
7/29/2019 OCA 06 - Managing Database Storage Structures
45/49
Manage Space in Tablespaces
http://asghars.blogspot.com45
As rows are inserted, are deleted, or change size
through updates, the bitmaps get updated accordingly
Manual Management
The old manual space management method used a free
list, which stated which blocks were available for insertbut without any information on how full they were
To see if any tablespaces are using manual
management
It is not possible to convert tablespace from manual to
automatic segment space management
5/5
-
7/29/2019 OCA 06 - Managing Database Storage Structures
46/49
EXERCISE 6-4: Change Tablespace Characteristics
http://asghars.blogspot.com46
1. Create a tablespace using manual segment space
management
2. Confirm that the new tablespace is indeed using
the manual technique
1/4
2/4
-
7/29/2019 OCA 06 - Managing Database Storage Structures
47/49
EXERCISE 6-4: Change Tablespace Characteristics
http://asghars.blogspot.com47
3. 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
2/4
3/4
-
7/29/2019 OCA 06 - Managing Database Storage Structures
48/49
EXERCISE 6-4: Change Tablespace Characteristics
http://asghars.blogspot.com48
5. Move the objects into the new tablespace:
6. Confirm that the objects are in the correcttablespace
3/4
4/4
-
7/29/2019 OCA 06 - Managing Database Storage Structures
49/49
EXERCISE 6-4: Change Tablespace Characteristics
7. Drop the original tablespace
8. Rename the new tablespace to the original name.
This is often necessary, because some application
software checks tablespaces names
9. Tidy up by dropping the tablespace, first with this
command
4/4