Presentation is loading. Please wait.

Presentation is loading. Please wait.

IT 21003 Database Administration Section 07. Space Management Managing Space: An Introduction  Organizing database storage is a major responsibility.

Similar presentations


Presentation on theme: "IT 21003 Database Administration Section 07. Space Management Managing Space: An Introduction  Organizing database storage is a major responsibility."— Presentation transcript:

1 IT 21003 Database Administration Section 07

2 Space Management Managing Space: An Introduction  Organizing database storage is a major responsibility for the DBA  Need to ensure tablespaces are set up with appropriate default storage definitions  Objects should be created for optimal space usage and performance  Situation must be monitored continually  Garbage collection on Oracle requires DBA assistance or intervention  DBAs need to understand how extents and blocks are used  The use of extents and blocks can be controlled by the DBA using a variety of techniques

3 Space Management Database Storage Relationships – E-R Diagram Tablespace Segment Datafile Extent Block LogicalPhysical Logical – Kinda Physical

4 Space Management Structure of Data Segments  The space occupied by a database object is called a segment  Segment types can be:  Data  Index  Rollback  Temporary  Each segment is contained within a tablespace and consists of one or more extents of contiguous data blocks

5 Space Management Structure of Data Segments  Tablespace: tbspc1 Segment 1 Extent1 of Seg1Extent2 of Seg1Extent3 of Seg1 Segment 2 Extent1 of Seg2Extent2 of Seg2Extent3 of Seg2 Segment 3 Extent1 of Seg3Extent2 of Seg3 Oracle Data Blocks

6 Space Management Specifying Storage Parameters for Data Segments  INITIAL Size of first extent Size of first extent Default is five Oracle blocks Default is five Oracle blocks  NEXT Size of the second extent to be allocated Size of the second extent to be allocated Default is five Oracle blocks Default is five Oracle blocks  PCTINCREASE  Factor by which the next extent is larger than the most recent extent to be allocated  Default is 50%

7 Space Management Specifying Storage Parameters for Data Segments  MINEXTENTS Minimum number of extents to be used by the segment Minimum number of extents to be used by the segment Default is 1 Default is 1  MAXEXTENTS Maximum number of extents that can be allocated Maximum number of extents that can be allocated Default depends on block size Default depends on block size Maximum value is 2,147,483,645 or approximately 2GB Maximum value is 2,147,483,645 or approximately 2GB  INITRANS  Minimum number of transactions that have space allocated within each block  Space reserved for the Interested Transaction List (ITL)  Default is 1 for Tables  Default is 2 for Indexes  Maximum is 255

8 Space Management Specifying Storage Parameters for Data Segments  MAXTRANS Maximum number of simultaneous transactions that can consume space in a block at any one time Maximum number of simultaneous transactions that can consume space in a block at any one time Default value is 255 Default value is 255 Maximum is 255 Maximum is 255  FREELISTS  Number of segment freelists  Default value is 1

9 Space Management Sizing Extents  Tablespaces are made up of datafiles The storage within a datafile is regarded as contiguous The storage within a datafile is regarded as contiguous Datafiles need not be contiguous with each other Datafiles need not be contiguous with each other  A possible scenario  Tablespace size is 40MB  Made up of three datafiles, 20MB, 10MB, 10MB  Size of largest possible extent is 20MB, not 40MB, because extents cannot span datafiles

10 Space Management Sizing Extents  Storage structures are allowed unlimited numbers of extents  Not allowed for objects within the SYSTEM tablespace  Limited number of extents based on DB_BLOCK_SIZE

11 Space Management Sizing Extents  To size extents we need the following information: How will the table be used? How will the table be used? How will it grow (insert activity)? How will it grow (insert activity)? Volatility? Volatility? Types of queries? Types of queries?  Reasons for allowing tables to occupy multiple extents  Access using an index  Involves a direct lookup on a table, no need for blocks to be contiguous  Full-Table scans in a mult-iuser environment  No real impact because disk arm will be servicing requests across all users  Full-Table scans in a single-user environment  Performance impact, but not if extents are reasonably large

12 Space Management Sizing Extents  Extents should be sized in multiples of  DB_BLOCK_SIZE * DB_FILE_MULTIBLOCK_READ_COUNT (DBFMRC)  Oracle brings DBFMRC blocks into memory in one fetch  Example:  DB_BLOCK_SIZE is 4KB  DBFMRC is set at the default of 8  4KB * 8 = 32KB  Extents should therefore be in multiples of 32KB

13 Space Management Sizing Extents  Beware of setting DBFMRC too high  32-Bit OS’s will bring in a maximum of 64KB of data in one fetch  Setting DBFMRC such that DBFMRC * DBS is greater than 64KB has no effect on performance  64-Bit OS’s can cope with higher values  Many systems run with DB_BLOCK_SIZE = 8KB or 4KB and DBFMRC = 8  4KB * 8 = 32KB  8KB * 8 = 64KB

14 Space Management Large Extents  Can be more difficult to manage  If a table extends, there may well be enough total free space within the tablespace for the amount of storage required  But not enough contiguous storage for the new large extent  An error is returned  Tablespace needs to be reorganized or extended  Reduce the frequency of dynamic extension Possible performance improvement because dynamic allocation of space is an expensive activity, generating a lot of recursive SQL Possible performance improvement because dynamic allocation of space is an expensive activity, generating a lot of recursive SQL  A tablespace can be dedicated (designed) for a single objects  If the object has equal-sized extents of 10MB, a sensible size for the tablespace could be 100MB plus the size of one Oracle data block per datafile  Accounts for the one-block overhead for each file header

15 Space Management Initial Extents  The first extent for each object has a one-block overhead, containing no data, known as the segment header block  Segment header is the first block and contains extent information for all other extents belonging to the segment (extent map)  Finite number of entries can fit in a header block  Actual number depends on block size  Tables defined with UNLIMITED EXTENTS have chained header blocks to hold the extent information  On highly concurrent systems, transactions may queue for latches on the header block

16 Space Management Inserting New Rows  Extents are typically allocated when an INSERT operation cannot find enough space in the existing blocks  A transaction maintains a list of free blocks it has accessed  These are blocks that have been used by the transaction and still have space available for inserts  If the new insert cannot fit in any of these blocks, the segment freelist of blocks is searched  If no blocks are available on the freelist, Oracle uses a new, unused block from the current extent; if no blocks are available, it resorts to dynamic extentsion  This means allocating a new extent

17 Space Management Inserting New Rows: Allocation of New Extents  The size of the new extent is determined by the current values of NEXT and PCTINCREASE  Formula is:  (1 + PCTINCREASE/100) * NEXT  Oracle searches the free-space map for an extent of free space the required size rounded up to the nearest five blocks  If an extent of the exact required size is not found, Oracle searches the free-space map for a piece of free space larger than that required  If it finds a large piece, it splits the free space as follows:  If the piece is within five blocks of the required size, the whole amount is allocated  If it is larger, the free space is split and the required amount is allocated, leaving behind a smaller piece of free space

18 Space Management Free-Space Allocation  If a new extent of 28MB is required, and a piece of free space of size 40MB is found Used Extent Free-Space Extent of 40MB Used Extent New Extent 28MB Free Used Extent Free Space is split in appropriate fashion

19 Space Management Free-Space Allocation  If no piece of free space large enough can be found  Free-space map is searched and adjacent free extents coalesced in an attempt to produce a large enough piece of contiguous space  SMON coalesces free-space fragments periodically  Oracle then searches the free-space map looking for  An exact matching size extent  A larger piece of free space and acts as described before  If no space of the required size is available, Oracle returns an error if AUTOEXTEND is off for all datafiles in the tablespace

20 Space Management Free-Space Allocation  If a new extent is allocated, Oracle updates the segment header, free-space map, and Data Dictionary accordingly  Oracle locally managed tablespaces are managed by bitmaps  No management of free-space map because all extents are equally sized

21 Space Management Coalescing Free Space Used (Table A) Free Used (Table B) Free Used (Table A) Table B gets dropped Used (Table A) FreeFreeFree 10MB 20MB 8MB Free-space extents coalesced during a search for free space Used (Table A) Free 38MB

22 Space Management Controlling Space Usage within Data Blocks  Each segment has a list of free blocks maintained automatically by server processes affecting the segment A segment freelist is a set of blocks available for new rows to be inserted A segment freelist is a set of blocks available for new rows to be inserted  Two parameters are used to control which blocks appear on the freelist  PCTFREE specifies the amount of space in each blocks that is unavailable for inserts  Reserved for updates of existing rows already within the block  PCTUSED determines how much data should be removed from a block before the block is put back on the freelist

23 Space Management Setting PCTFREE and PCTUSED  PCTFREE + PCTUSED <= 100%  PCTFREE large (~40), PCTUSED small (~20)  Blocks remain off the freelist for long periods  Can lead to waste of space  Saves processing costs because blocks do not thrash on and off the freelist  Allows space for updates  Fewer rows per block that can impact full-table scans but reduce possible block contention PCTFREE PCTUSED

24 Space Management Setting PCTFREE and PCTUSED  PCTFREE small (~5), PCTUSED very large (~90)  Gives efficient use of space due to high block occupancy  Leads to high processing costs because blocks are frequently moved on and off the freelist  Not much space for updates of existing rows PCTFREE PCTUSED

25 Space Management Setting PCTFREE and PCTUSED  PCTFREE large (~40), PCTUSED large (~50)  Gives poor use of space due to low block occupancy  Allows space for updates  Processing costs could be high because blocks are frequently moved on and off the freelist PCTFREE PCTUSED

26 Space Management Setting PCTFREE and PCTUSED  PCTFREE small (~10), PCTUSED fairly small (~40)  These are the default values  Gives relatively efficient use of space due to high block occupancy  Not much space for large-scale updates  Processing costs are low because blocks are not frequently moved on and off the freelist PCTFREE PCTUSED

27 Space Management Setting PCTFREE and PCTUSED  PCTFREE small (~10), PCTUSED fairly small (~40)  The Block accepts both updates and inserts until it reaches 10 percent free; it then allows only updates  Once the block has dropped back down to 40% used, the block allows inserts again

28 Space Management Setting PCTFREE and PCTUSED  PCTFREE can determine the free space in an index when it is created  Can be set high to prevent excessive block splitting and reorganization  Useful for volatile indexes  Cannot be reset and has no effect as the index is updated  Use purely as an initial setting or starting point  Oracle manages the occupancy of index blocks such that they remain, on average, 70 percent full, thus overriding the PCTFREE setting  PCTUSED cannot be specified for indexes

29 Space Management Regaining Free Space: Deallocating Extents  Oracle maintains a High Water Mark (HWM) for each segment in every table The point to which actual data has grown within the segment The point to which actual data has grown within the segment Cannot return space in blocks below the HWM to free space without a reorganization Cannot return space in blocks below the HWM to free space without a reorganization  Possible to reclaim space allocated to a segment but never used  This is space above the HWM  ALTER INDEX sales_ind DEALLOCATE UNUSED;  The minimum size of the remaining space must still satisfy the size determined by INITIAL and MINEXTENTS  ALTER TABLE orders DEALLOCATE UNUSED KEEP 20M;  The KEEP clause can override MINEXTENTS and INITIAL, causing the values to be reset accordingly

30 Space Management Regaining Free Space Below the HWM  The dbms_space_unused_space procedure can be used only to return information about unused blocks and the position of the HWM  Deleting rows does not regain space – HWM remains unchanged Must use Export/Import to reorganize the table storage Must use Export/Import to reorganize the table storage  Create a new table as follows:  Create new_orders As Select * From orders;  Drop Table orders;  Rename new_orders To orders;  Causes a loss of GRANTS, etc on the original table  Needs space for the new copy

31 Space Management ROWID  ROWIDs are pseudo data types used by Oracle to uniquely address rows in the database Have a number of components Have a number of components  Shown as 18-Character strings using base-64 encoding  Extended ROWID Format 000000FFFBBBBBBSSS Data Object Number Relative file Number Block Number Slot NumberAAAASRAAFAAAAAACAAD Example ROWID Number

32 Space Management ROWIDs  Datafiles have absolute and relative addresses Observe file_id and relative_fno in the dba_files table Observe file_id and relative_fno in the dba_files table  A ROWID does not contain the absolute file address  Datafiles are identified only within a particular tablespace  The object number determines the tablespace, so that ROWID can uniquely define the file  Object Number + Relative File Number  Relative addressing allows many more files to be used by an Oracle database  Can have 64 million operating-files

33 Space Management Data Block Format Fixed Header Transaction Entry Row Directory PCTFREE PCTUSED

34 Space Management Block Organization  Header  Average size is about 85-100 bytes  Made up of a fixed header and variable header (transaction entries)  Row Directory  Two per row  Contains address of start of each row within the block

35 Space Management INITRANS and MAXTRANS  Setting INITRANS reserves space for transaction entries in the block This space is not available for data storage This space is not available for data storage If INITRANS is too low, transactions may be placed in the header If INITRANS is too low, transactions may be placed in the header  Setting MAXTRANS allows the specified number of concurrent transactions to place their entries in the block only if there is enough free space

36 Space Management Row Storage LastNameFirstNameMiddleNameAddressState SmithJosephAdam 123 State Street Ohio Row Overhead Number of Columns (5) Column 1 Length (15) Column 1 Data (SMITH) Column 2 Length (15) Column 2 Data (JOSEPH)… Table Columns Row

37 Space Management Row Storage  Row Overhead is made up of:  Row Header  Offset in transaction list  Number of Columns in the row that contain data  Rows with > 255 columns will have additional row overhead information

38 Space Management Storage Patterns for Data Types  VARCHAR and VARCHAR2 1 byte per alphanumeric character 1 byte per alphanumeric character Maximum is 4,000 bytes Maximum is 4,000 bytes  CHAR Fixed Length Fixed Length Maximum is 2,000 bytes Maximum is 2,000 bytes  DATE 7 bytes for all date formats 7 bytes for all date formats  NUMBER  Up to 38 digits of precision  Stored as a single base-100 digit per byte  Therefore no rounding errors in financial data

39 Space Management Storage Patterns for Data Types  ROWID 10 bytes 10 bytes  LOB Locaters about 20 bytes Locaters about 20 bytes  VARRAY User defined User defined  User-Defined Types

40 Space Management Updating Rows  When an update causes a change in the length of a data item  Oracle builds a whole new row in the block  The space occupied by the original row is labeled as free space  This is known as block fragmentation  Oracle delays reorganization of storage within the block until no more space is available within the block  If an update does not change the length of a data item, the row is updated in situ (in place)  No block re-organization is necessary

41 Space Management Row Chaining and Row Migration  Ordinarily, Oracle does one fetch for the retrieval of a single row  A row that occupies multiple blocks impacts performance because more than one I/O may be required to fetch the row  Typically happens with rows containing LOB columns  Known as Row Chaining  Not much can be done about this

42 Space Management Row Chaining and Row Migration  Updates to rows may not fit within the free space in the block  In this case the whole row is migrated into another block, leaving behind a pointer to the chained block  This Row Migration causes extra disk I/O per row because the ROWID of the migrated row is not changed  Indexes still point to the original block  PCTFREE can be used to control row migration by reserving space for updates to existing rows in blocks

43 Space Management Detecting and Handling Row Migration  Row Migration can and should be avoided  ANALYZE can be used to detect chained or migrated rows  The script utlchain.sql needs to be run in the account used to perform the analysis  Builds the chained_rows table  Use Analyze Table student List Chained Rows;  This puts data into the chained_rows table  To see the details of the chained_rows table  Select *  From chained_rows  Where table_name = ‘STUDENT’;

44 Space Management Eliminating Migrated Rows  This is a hard way to do it  Create a temporary table and copy into it all the rows found in the chained_rows table  Create Table student_mig As  Select * From student  Where Rowid In (Select head_rowid From chained_rows);  Delete the migrated rows from the original table  Delete From student Where Rowid In  (Select head_rowid From chained_rows);  Now insert the rows into the original table from the temporary table  Insert Into student Select * From student_mig;

45 Space Management Row Chaining and Row Migration  Can also be observed in user_tables  Need to run this statement first  Analyze Table table_name Compute | Estimate Statistics;  This populates columns in the user_tables view  Tables and Indexes can be analyzed this way  Analyzing tables with the COMPUTE option takes longer than a full table scan It performs a sort and requires temporary storage It performs a sort and requires temporary storage  Statistics are found in:  user_tables  user_indexes  user_tab_columns

46 Space Management Analyzing Objects  To Analyze you need to own the object or have the privilege Analyze Any system privilege  Analyzing will invalidate any currently parsed SQL statements on the table  Oracle9i has dbms_stats that can be used to analyze and monitor tables

47 Space Management Estimating Space Requirements  Tables created with badly designed storage parameters cause performance problems like: Frequent Dynamic Extension Frequent Dynamic Extension Large numbers of extents causing problems for full- table scans Large numbers of extents causing problems for full- table scans Extents too large to fit into any free-space pattern Extents too large to fit into any free-space pattern Row Chaining and Migration Row Chaining and Migration Over-allocation of space leading to the purchase of unnecessary hardware Over-allocation of space leading to the purchase of unnecessary hardware  A practical approach is to preload the table with some sample data, analyze the table, and discover the number of rows per block  Calculate a 5% overhead for safety

48 Space Management Questions?


Download ppt "IT 21003 Database Administration Section 07. Space Management Managing Space: An Introduction  Organizing database storage is a major responsibility."

Similar presentations


Ads by Google