Saturday, January 13, 2018

Overview of Data Blocks

The Database Block or simply Data Block, is the smallest size unit for input/output from/to disk in an Oracle database.Oracle Database manages the logical storage space in the data files of a database in a unit called a data block, also called an Oracle block or page. A data block is the minimum unit of database I/O.
Data Blocks and Operating System Blocks At the physical level, database data is stored in disk files made up of operating system blocks.A data block may be equal to an operating system block in terms of size, or may be larger in size, and should be a multiple of the operating system block. The database requests data in multiples of data blocks, not operating system blocks.

DB_OS_block
When the database requests a data block, the operating system translates this operation into a requests for data in permanent storage. The logical separation of data blocks from operating system blocks has the following implications:
  • Applications do not need to determine the physical addresses of data on disk.
  • Database data can be striped or mirrored on multiple physical disks etc.
Oracle Data Block

Data Blocks is smallest logical unit to store Oracle Data.
  • One data block represent specific number of bytes on physical hard disk
  • Data Block in Oracle is also called as  logical blocks, Oracle blocks, or pages
  • Data Block size is usually multiple of operating system block size
  • You can have multiple block sizes with in single database
  • Block Size is specified by initialization parameter DB_BLOCK_SIZE
Architecture of Oracle Data Block

Every data block has a format or internal structure that enables the database to track the data and free space in the block. This format is similar whether the data block contains table, index, or table cluster data.

Data Block Overhead

Oracle Database uses the block overhead to manage the block itself. The block overhead is not available to store user data.The data block header, table directory, and row directory are referred to collectively as overhead. Some block overhead is fixed in size; the total block overhead size is variable. On average, the fixed and variable portions of data block overhead total 84 to 107 bytes.
DB_block


Header (Common and Variable) part contains general information about the block, including disk address and segment type(for example, data or index). For blocks that are transaction-managed, the block header contains active and historical transaction information
Table Directory portion of the data block contains information about the table having rows in this block it also contains metadata about tables whose rows are stored in this block and In a table cluster, multiple tables can store rows in the same block.
Row Directory  describes the location of rows in the data portion of the block.The row directory entry contains a address(pointer) to the location of the row on the data block .
Free space is allocated for insertion of new rows and for updates to rows that require additional space (for example, when a trailing null is updated to a nonnull value).
Row Data  part of the block contains the actual data, such as table rows or index key entries

Logical Database Structure


Oracle Database allocates logical space for all data in the database. The logical units of database space allocation are data blocks, extents, segments, and tablespaces. At a physical level, the data is stored in data files on disk. The data in the data files is stored in operating system blocks.
Oracle database logically divided into tow or more tablespaces ,a database is divided into logical storage units called tablespaces, which group related data blocks, extents, and segments.
The combined size of the datafiles in a tablespace is the total storage capacity of the tablespace.Every Oracle database contains a SYSTEM tablespace and a SYSAUX tablespace. Oracle Database creates them automatically when the database is created.
Below diagram for physical and logical storage

Logical_structure
Tablespaces :

Tablespaces logically organize data that are physically stored in datafiles.
  • A tablespace belongs to only one database, and has at least one datafile that is used to store data for the associated tablespace.
  • The term "tablespaces" is misleading because a tablespace can store tables, but can also store many other database objects such as indexes, views, sequences, etc.
  • Datafiles are always assigned to only one tablespace and, therefore, to only one database.
  • Tablespace is contain one or more segments (table,index etc).
Logical_stru01

Logical Storage Hierarchy:

A segment contains one or more extents, each of which contains multiple data blocks.
logical_desc02
Data Block

A data block is the smallest logical unit of data storage in Oracle Database.
One logical data block corresponds to a specific number of bytes of physical disk space, for example, 2 KB. Data blocks are the smallest units of storage that Oracle Database can use or allocate.

Extent

An extent is a set of logically contiguous data blocks allocated for storing a specific type of information .In the preceding graphic, the 24 KB extent has 12 data blocks, while the 72 KB extent has 36 data blocks.

Segment

A segment is a set of extents allocated for a specific database object, such as a table.
For example, the data for the employees table is stored in its own data segment, whereas each index for employees is stored in its own index segment. Every database object that consumes storage consists of a single segment.
A tablespace is a database storage unit that contains one or more segments.
storage_tru01
  • A database is made up of one or more tablespaces
  • A tablespace is made up of one or more data files, a tablespace contains segments
  • A segment (table, index, etc) is made up of one or more extents. A segment exists in a tablespace but may have data in many data files within a tablespace.
  • An extent is a continuous set of blocks on a disk. An extent is in a single tablespace and is always in a single file within that tablespace.
  • A block is the smallest unit of allocation in the database. A block is the smallest unit of i/o used by the database.

Physical Database Storage Architecture

An Oracle database consists of files
  • Datafiles
  • Temp files
  • Control Files
  • Online Redo Log Files
  • Archived Redo Log Files
  • Parameter Files
  • Password Files
  • Alert and Trace Log Files
  • Backup Files
db_storage
Datafiles:

Every Oracle database has one or more physical datafiles, which contain all the database data. The data of logical database structures, such as tables and indexes, is physically stored in the datafiles allocated for a database.
At the operating system level, Oracle Database stores database data in structures called data files. Every Oracle database must have data file.

Tempfiles:

Tempfiles are used with TEMPORARY tablespaces and are used for storing temporary data like sort ,spill-over or data for global temporary tables.

Control Files:

Every Oracle Database has a control file, which is a small binary file that records the physical structure of the database. The control file includes: The database name. Names and locations of associated datafiles and redo log files.Every time an instance of an Oracle database is started, its control file identifies the datafiles, tempfiles, and redo log files that must be opened for database operation to proceed.

Redo Log Files :

The most crucial structure for recovery operations is the redo log, which consists of two or more pre-allocated files that store all changes made to the database as they occur. Every instance of an Oracle Database has an associated redo log to protect the database in case of an instance failure.
Redo log files contain a chronological record of changes made to the database, and enable recovery when failures occur.To protect against a failure involving the redo log itself, Oracle Database lets you create a multiplexed redo log so that two or more copies of the redo log can be maintained on different disks.

Archived Redo Log Files:

Archived redo log files are database-generated offline copies of online redo log files. Oracle Database automatically archives redo log files when the database is in ARCHIVELOG mode. Oracle recommends that you enable automatic archiving of the online redo log.Archive redo log files contain history of data changes (redo) that is generated by instance .
When the database is running in ARCHIVELOG mode, the log writer process (LGWR) cannot reuse and hence overwrite a redo log group until it has been archived.An archived redo log file is a copy of one of the filled members of a redo log group.

Parameter Files:

Parameter  files contain a list of configuration parameters for that instance and database.There are two types of parameter files.

PFILE : The init.ora file (also called the PFILE) is a static parameter file. It contains parameters that specify how the database instance is to start up. For example, some parameters will specify how to allocate memory to the various parts of the system global area.

SPFILE : The spfile.ora is a dynamic parameter file. It also stores parameters to specify how to startup a database; however, its parameters can be modified while the database is running.

Password file : specifies which *special* users are authenticated to startup/shut down an Oracle Instance. its use to authenticate users over network.

Trace Log Files : Each server and background process can write to an associated trace file. When an internal error is detected by a process, the process dumps information about the error to its trace file. Some of the information written to a trace file is intended for the database administrator, while other information is for Oracle Support Services. Trace file information is also used to tune applications and instances.

Alert Files : The alert file, or alert log, is a special trace file. The alert log of a database is a chronological log of messages and errors.

Backup files :

To restore a file is to replace it with a backup file. Typically, you restore a file when a media failure or user error has damaged or deleted the original file.
User-managed backup and recovery requires you to actually restore backup files before you can perform a trial recovery of the backups.
Server-managed backup and recovery manages the backup process, such as scheduling of backups, as well as the recovery process, such as applying the correct backup file when recovery is needed.

Connecting to Oracle Instance

Connecting to an Oracle Instance (User Process & Server Process)




Before users can submit SQL statements to an Oracle database, they must connect to an instance.

User Process: 
User_process
A database user who needs to request information from the database must first make a connection with the Oracle server. The connection is requested using a database interface tool, such as SQL*Plus, and beginning the user process. The user process does not interact directly with the Oracle server. Rather it generates calls through the user program interface (UPI), which creates a session and starts a server process.

Server Process:
server_process

Once a user has established a connection, a server process is started to handle the user processes requests. A server process can be either a dedicated server process or a shared server process. In a dedicated server environment, the server process handles the request of a single user process. Once a user process disconnects, the server process is terminated. In a shared server environment, the server process handles the request of several user processes.The server process communicates with the Oracle server using the Oracle Program Interface.

Connecting to an Oracle Instance:

The user starts a tool such as SQL*Plus,sql developer,toad or runs an application developed using a tool such as Oracle Forms. This application or tool is executed as a user process.
In the most basic configuration, when a user logs on to the Oracle server, a process is created on the computer running the Oracle server. This process is called a server process. The server process communicates with the Oracle instance on behalf of the user process that runs on the client. The server process executes SQL statements on behalf of the user.
user_connection2

User Process is started at the time a database user request  a connection to the oracle server .Server Process connect to the oracle instance and started when a user establish a session .
user process & server process are used to manage the execution of sql/plsql statements.
one-to-one correspondence between the User and Server Processes. This is called a Dedicated Server connection. An alternative configuration is to use a Shared Server where more than one User Process shares a Server Process.
Server Process is the go-between for a Client Process and the Oracle Instance.

Dedicated Server environment – there is a single Server Process to serve each Client Process.

Shared Server environment – a Server Process can serve several User Processes, although with some performance reduction

Connection

A connection is a communication pathway between a user process and an Oracle server. A database user can connect to an Oracle server using tool, sqlplus etc.

Sessions

A session is a specific connection of a user to an Oracle server. The session starts when the user is validated by the Oracle server, and it ends when the user logs out or when there is an abnormal termination. For a given database user, many concurrent sessions are possible if the user logs on from many tools, applications, or terminals at the same time.

user_connection3