Thursday, April 19, 2007

Oracle9i DBA -- Database: Fundamentals I (17)

Managing Privileges

##CONTINUE##

  • System privilegea enable users to perform certain actions in the database while object privilege enables users to access and manipulate specific objects.
  • ALTER SESSION is a system privilege the information can be queried from DBA_SYS_PRIVS and USER_SYS_PRIVS views.
  • To ensure that system privileges allow access on all schemas except SYS the 07_DICTIONARY_ACCESSIBILITY parameter must be set to FALSE.
  • Oraenv is to switch between databases. Imp and exp are import and export. Sqlldr is for SQL*Loader
  • Execute privilege on a procedure is a object privilege the information can be gathered from ALL_TAB_PRIVS, USER_TAB_PRIVS, DBA_TAB_PRIVS
  • The Object privilege has a cascading effect. The System does not have any cascading effect.

Oracle9i DBA -- Database: Fundamentals I (16)

Managing Users

##CONTINUE##

  • A user can be authenticated by the data dictionary, operating system and network.
  • ORACNV is a script which can be executed to create a centralized repository of user accounts leading to ease of administration.
  • The unlimited tablespace privilege takes priority over quota settings.
  • To encrypt a user’s password the ORA_ENCRYPT_LOGIN parameter must be set to true.
  • OS_AUTHENT_PREFIX = “” is used to set user name format to a NULL prefix. OS_AUTHENT_PREFIX = OPS$ will allow the user to be authenticated by the OS or the Oracle server. Create User OPS$xxx IDENTIFIED EXTERNALLY will allow the user to be authenticated by the OS. REMOTE_OS_AUTHENT=TRUE specifies that a usr can be authenticated by a remote os.

Oracle9i DBA -- Database: Fundamentals I (15)

Managing Password Security and Resources
##CONTINUE##

  • Resource Limits can be set at session level and call level
  • Profiles are assigned to users by the CREATE USER or ALTER USER command
  • Enforce the resource limits

    1. by enabling the parameter with the ALTER SYSTEM command

    ALTER SYSTEM SET RESOURCE_LIMIT=TRUE

    2. Set the RESOURCE_LIMIT parameter to TRUE

  • Profiles cannot be created by the CREATE user command.


Wednesday, April 18, 2007

Oracle9i DBA -- Database: Fundamentals I (14)

Maintaining Data Integrity
##CONTINUE##

  • The utlexcptl.sql script can create the EXCEPTIONS table
  • CHECK constraint can be defined at both column and table level. Environment functions such as SYSDATE cannot be used to evaluate check condition.
  • Use the SET CONSTRAINTS statement to make constraints either DEFERRED or IMMEDIATE. The ALTER SESSION statement also has cluses to SET CONSTRAINTS to DEFERRED or IMMEDIATE.
  • DBA_CONSTRAINTS view is required to return the name of the foreign key constraint(CONSTRAINTS_NAME) and the referenced primary key(R_CONSTRAINTS_NAME).
  • Both unique and primary key constraints require index.

Oracle9i DBA -- Database: Fundamentals I (13)

Managing Indexes
##CONTINUE##

  • When you encounter index fragmentation, you can rebuild or coalesce the index. coalesce on an index is a block rebuild that is done online.
  • DBA_INDEXES : index name , index type, table owner, index owner.
  • Index rebuilds have the following characteristics

    O A new index is built using an existing index as the data source

    O Sorts are not needed when an index is built using an existing index, resulting in better performance.

    O The old index is deleted after the new index is build. During the rebuild, sufficient space is needed to accommodate both the old and the new index in their respective tablespaces.

    O The resulting index does not contain any deleted entries. This index uses space more efficiently

    O Queries can continue to use the existing index while the new index is being built.

  • DBA_IND_EXPRESSIONS : Provides information on columns or expressions used to create index
  • V$OBJECT_USAGE : Provide information on usage of index
  • Cluster maintains a “Cluster Index” that is used to locate rows and other information
  • B-tree indexes work well in single indexes rather than multiple indexes. B-tree support row-level both unique and non-unique indexes. B-tree index are suitable for retrival of a small number of rows.
  • The individual partitions are stored in separate segments whether it is a table partition or index partition. Partitions are beneficial in large objects that are read or written to simultaneously.

Tuesday, April 17, 2007

Oracle9i DBA -- Database: Fundamentals I (12)

Managing Tables

##CONTINUE##

  • The TZ environment variable can be used to decide the how the date will be displayed.
  • Each row in the table consists of a Row header (store the number of columns in a row) and Row Data (stores the column length and value).
  • A ROWID is composed of

    O Datafile number : Is assigned to each data object, such as table or index when it is created, and it is unique within the database.

    O Relative file number : is unique to each file within a tablespace

    O Block number : Represents the position of the block, containing the row, within the file.

    O Row number : Identifies the position of the row directory slot in the block header.

  • The portioning methods available in tables are Range, Hash, List and Composite. Range portioning is useful for tables with a range of value. Hash portioning is done using Hash algorithm. When all the values that are to be stored in a column are known, list partitioning can be used. Composite partitioning is a combination of hash and range partitioning.
  • The value of the parameter COMPATIBLE must be set to Oracle 8.1 or highter to use ROWID.
  • PCTFREE, NEXT, MINEXENTS can be modified after table creation.
  • Row Migration occurs due to low PCTFREE value. Row chaining the row is divided into smaller chunks. Row migration the entire row is moved to a new block.

Oracle9i DBA -- Database: Fundamentals I (11)

Managing Undo Data

##CONTINUE##

  • For sizing a UNDO tablespace the UNDO_RETENTION in seconds, number of undo data blocks generated per second and the overhead varies based on extent and file size (db_block_size) is required.
  • Use the ALTER SYSTEM command for dynamic switching between UNDO tablespaces

    ALTER SYSTEM SET UNDO_TABLESPACE=UNDOTBS2;

  • An undo segment with the status PENDING OFFLINE still contains active transactions. When no rows return from the query, then all transactions are complete, and the tablespace can be dropped.
  • Oracle server automatically creates an UNDO tablespace called SYS_UNDOTBS when no undo tablespace name is specified.
  • Deferred undo segments are dropped automatically
  • Before any DML operation the undo information will always be stored in the undo segment.
  • ‘Snapshot too old’ error may occur if there are long running queries. This generally takes place if the database has larger rollback extents. If the rollback extents are smaller, it will lead to undo extents getting deallocated.
  • V$ROLLSTAT is used to view the undo statistic and the segment number. V$ROLLNAME is show the segment number and name. V$UNDOSTAT contains snapshots of the performance of the undo tablespace. V$TRANSACTION and V$SESSION can be used to view the active transactions.
  • The ‘Set TRANSACTION ISOLATION LEVEL SERIALIZABLE’ will ensure read consistency of the transaction, though it is derimental to its performance.
  • The different type of undo segments are SYSTEM, NONSYSTEM and Deferred. The deferred segment is created when a tablespace is brought offline. They are used for recovery when the transaction is brought online.
  • USER_SEGMENT data dictionary contains all types of segments and their storage parameters for the user.

Oracle9i DBA -- Database: Fundamentals I (10)

Storage Structure and Relationships

##CONTINUE##

  • The default size for PCTFREE is 10 and of PCTUSED is 40 ,and the PCTINCREASE 50
  • Enabling automatic segment space management uses bitmaps instead of freelists to manage free space.
  • MAXTRANS specifies the number of concurrent transactions per block.
  • INITRANS, MAXTRANS,PCTFREE,PCTUSED are associated with the block.
  • Increasing the PCTFREE parameter can control Row migration in blocks
  • Optimal Flexible Architecture (OFA) : Oracle's recommended standard database architecture layout

    Three major rules:

    O Establish a directory structure where any database file can be stored on any disk resource

    O Separate objects with different behavior into different tablespaces

    O Maximize database reliability and performance by separating database components across different disk resources

  • The Oracle blocks are the finest level of data storage identity that contains multiple operating system blocks.
  • The Dictionary Managed Tablespace automatically assume the size of NEXT clause as 5 times the DB_BLOCK_SIZE and similarly INITIAL has to be twice of DB_BLOCK_SIZE
  • Extents are deallocated whenever the segments are altered, dropped or truncated.
  • Extents are allocated to segments when the segment are altered, created or extended.
  • Bootstrap segment (Cache segment), Table , Index and IOTs have their separate segments. Nested Tables stored in their own segment.
  • The effects of using TRUNCATE command are as follows:

    1. All rows in the table are deleted.

    2. No undo data is generated and the command commits implicitly because TRUNCATE TABLE is a DDL command.

    3. Corresponding indexes are also truncated.

    4. A table that is being referenced by a foreign key cannot be truncated.

    5. The delete triggers do not fire when this command is used.

    6. It reduces the number of extents allocated to the table to the original setting for MINEXTENTS.

Monday, April 16, 2007

Oracle9i DBA -- Database: Fundamentals I (9)

Managing Tablespace and Datafiles

##CONTINUE##

  • The free extents are managed in the tablespaces via the bitmaps. Bit values are used to indicate free or used space.
  • Automatic segment-space management can be enabled at the tablespace level only, for locally managed tablespaces.

    CREATE TABLESPACE data02

    DATAFILE ‘/u01/oradata/data02.dbf’ SIZE 5M

    EXTENT MANAGEMENT LOCAL UNIFORM SIZE 64K

    SEGMENT SPACE MANAGEMENT AUTO;

    Ps. Free space is managed in the undo tablespace for a tablespace created with automatic segment-space management.

  • Using the CREATE TABLESPACE statement and specifying the blocksize clause can create tablespaces of non-standard block size. DB_CACHE_SIZE and DB_nK_CACHE_SIZE
  • The sum of the size of all data files specified in the CREATE TABLESPACE statement determines the initial size of a tablespace.
  • Datafiles can belong to only one tablespace and database
  • Moving Data Files:

    O ALTER DATABASE :

    ALTER DATABASE RENAME

    FILE '/u01/oradata/system01.dbf'

    TO '/u03/oradata/system01.dbf';

    1. Shut down the database.

    2. Use an operating system command to move the files.

    3. Mount the database.

    4. Execute the ALTER DATABASE RENAME FILE command.

    5. Open the database.

    SYSTEM tablespace cannot be taken offline, you must use this method to move

    data files in the SYSTEM tablespace.

    O Moving Data Files: ALTER TABLESPACE

    ALTER TABLESPACE userdata

    RENAME DATAFILE '/u01/oradata/userdata01.dbf'

    TO '/u01/oradata/userdata01.dbf';

    1.Take the tablespace offline.

    2. Use an operating system command to move or copy the files.

    3. Execute the ALTER TABLESPACE RENAME DATAFILE command.

    4. Bring the tablespace online.

    5. Use an operating system command to delete the file if necessary.

  • When a datafile is made read-only it can reside only on read-only media.
  • The Read-only tablespace can be deleted in the same manner the READ WRITE tablespace is.
  • The Default temporary tablespace is a locally managed tablespace.It cannlt be altered to a permanent tablespace.
  • When a tablespace is taken offline with the immediate clause, it need to do media recovery when bringing the tablespace online.

  • Locally managed tablespaces :

O Free extents recorded in bitmap
O Each bit corresponds to a block or group of blocks
O Bit value indicates free or used

O Reduced contention on data dictionary tables

O No undo generated when space allocation or deallocation occurs

O No coalescing required





  • Dictionary-managed tablespaces :

  • O Default method

    O Free extents recorded in data dictionary tables

    O Extents are managed in the data dictionary

    O Each segment stored in the tablespace can have a different storage clause

    O Coalescing required

    • Locally managed tablespaces have the following advantages over dictionary-managed tablespaces:

    1. Local management avoids recursive space management operations, which can occur in dictionary-managed tablespaces if consuming or releasing space in an extent results in another operation that consumes or releases space in a undo segment or data dictionary table.

    2. Because locally managed tablespaces do not record free space in data dictionary tables, it reduces contention on these tables.

    3. Local management of extents automatically tracks adjacent free space, eliminating the need to coalesce free extents.

    4. The sizes of extents that are managed locally can be determined automatically by the system. Alternatively, all extents can have the same size in a locally managed tablespace

    5. Changes to the extent bitmaps do not generate undo information because they do not update tables in the data dictionary (except for special cases such as tablespace quota information).

    • FOR RECOVERY clause freezes the checkpoint information wherever it is, by not updating it. Because a point-in-time recovery is desired, if a backup had to be taken, he would have updated the checkpoint information in datafile headers and control files by using either NORMAL(default) or TEMPORARY option
    • Dictionary Managed Tablespace cause recursive space management that slows down the systens, however it provides individual STORAGE clause to satisfy user custom needs. It has to be coalesced to fee space.
    • Segments in dictionary managed tablespaces can have a customized storage, this is more flexible than locally managed tablespaces but much less efficient.
    • Add more space in an existing TABLESPACE e

    ALTER DATABASE DATAFILE ‘/u1/d.dbf’ RESIZE 10M

    ALTER TABLESPACE tbs ADD DATAFILE ‘/u1/d2.dbf’ size 10M

    • Tablespace can store multiple datafiles on different disks, but don’t provide multiplexing (store same contents in multiple files)
    • Resizing a Tablespace

    A Tablespace can be resized by :

    O Changing the size of a data file

    - Automatically using AUTOEXTEND

    - Manually using ALTER DATABASE

    O Adding a data file using ALTER TABLESPACE

    • Enabling Automatic Extension of Data Files:

    When a data file is created, the following SQL commands can be used to enable automatic extension of the data file:

    - CREATE DATABASE

    - CREATE TABLESPACE ... DATAFILE

    - ALTER TABLESPACE ... ADD DATAFILE

    Query the DBA_DATA_FILES views to determine whether AUTOEXTEND is enabled.

Oracle9i DBA -- Database: Fundamentals I (8)

Managing Tablespace and Datafiles

##CONTINUE##

  • The free extents are managed in the tablespaces via the bitmaps. Bit values are used to indicate free or used space.
  • Automatic segment-space management can be enabled at the tablespace level only, for locally managed tablespaces.

    CREATE TABLESPACE data02

    DATAFILE ‘/u01/oradata/data02.dbf’ SIZE 5M

    EXTENT MANAGEMENT LOCAL UNIFORM SIZE 64K

    SEGMENT SPACE MANAGEMENT AUTO;

    Ps. Free space is managed in the undo tablespace for a tablespace created with automatic segment-space management.

  • Using the CREATE TABLESPACE statement and specifying the blocksize clause can create tablespaces of non-standard block size. DB_CACHE_SIZE and DB_nK_CACHE_SIZE
  • The sum of the size of all data files specified in the CREATE TABLESPACE statement determines the initial size of a tablespace.
  • Datafiles can belong to only one tablespace and database
  • Moving Data Files:

    O ALTER DATABASE :

    ALTER DATABASE RENAME

    FILE '/u01/oradata/system01.dbf'

    TO '/u03/oradata/system01.dbf';

    1. Shut down the database.

    2. Use an operating system command to move the files.

    3. Mount the database.

    4. Execute the ALTER DATABASE RENAME FILE command.

    5. Open the database.

    SYSTEM tablespace cannot be taken offline, you must use this method to move

    data files in the SYSTEM tablespace.

    O Moving Data Files: ALTER TABLESPACE

    ALTER TABLESPACE userdata

    RENAME DATAFILE '/u01/oradata/userdata01.dbf'

    TO '/u01/oradata/userdata01.dbf';

    1.Take the tablespace offline.

    2. Use an operating system command to move or copy the files.

    3. Execute the ALTER TABLESPACE RENAME DATAFILE command.

    4. Bring the tablespace online.

    5. Use an operating system command to delete the file if necessary.

  • When a datafile is made read-only it can reside only on read-only media.
  • The Read-only tablespace can be deleted in the same manner the READ WRITE tablespace is.
  • The Default temporary tablespace is a locally managed tablespace.It cannlt be altered to a permanent tablespace.
  • When a tablespace is taken offline with the immediate clause, it need to do media recovery when bringing the tablespace online.

  • Locally managed tablespaces :

O Free extents recorded in bitmap
O Each bit corresponds to a block or group of blocks
O Bit value indicates free or used
  • O Reduced contention on data dictionary tables

    O No undo generated when space allocation or deallocation occurs

    O No coalescing required

    n Dictionary-managed tablespaces :

    O Default method

    O Free extents recorded in data dictionary tables

    O Extents are managed in the data dictionary

    O Each segment stored in the tablespace can have a different storage clause

    O Coalescing required

    n Locally managed tablespaces have the following advantages over dictionary-managed tablespaces:

    1. Local management avoids recursive space management operations, which can occur in dictionary-managed tablespaces if consuming or releasing space in an extent results in another operation that consumes or releases space in a undo segment or data dictionary table.

    2. Because locally managed tablespaces do not record free space in data dictionary tables, it reduces contention on these tables.

    3. Local management of extents automatically tracks adjacent free space, eliminating the need to coalesce free extents.

    4. The sizes of extents that are managed locally can be determined automatically by the system. Alternatively, all extents can have the same size in a locally managed tablespace

    5. Changes to the extent bitmaps do not generate undo information because they do not update tables in the data dictionary (except for special cases such as tablespace quota information).

    n FOR RECOVERY clause freezes the checkpoint information wherever it is, by not updating it. Because a point-in-time recovery is desired, if a backup had to be taken, he would have updated the checkpoint information in datafile headers and control files by using either NORMAL(default) or TEMPORARY option

    n Dictionary Managed Tablespace cause recursive space management that slows down the systens, however it provides individual STORAGE clause to satisfy user custom needs. It has to be coalesced to fee space.

    n Segments in dictionary managed tablespaces can have a customized storage, this is more flexible than locally managed tablespaces but much less efficient.

    n Add more space in an existing TABLESPACE e

    ALTER DATABASE DATAFILE ‘/u1/d.dbf’ RESIZE 10M

    ALTER TABLESPACE tbs ADD DATAFILE ‘/u1/d2.dbf’ size 10M

    n Tablespace can store multiple datafiles on different disks, but don’t provide multiplexing (store same contents in multiple files)

    n Resizing a Tablespace

    A Tablespace can be resized by :

    O Changing the size of a data file

    - Automatically using AUTOEXTEND

    - Manually using ALTER DATABASE

    O Adding a data file using ALTER TABLESPACE

    n Enabling Automatic Extension of Data Files:

    When a data file is created, the following SQL commands can be used to enable automatic extension of the data file:

    - CREATE DATABASE

    - CREATE TABLESPACE ... DATAFILE

    - ALTER TABLESPACE ... ADD DATAFILE

    Query the DBA_DATA_FILES views to determine whether AUTOEXTEND is enabled.

n

n