An Oracle Database consists of at least one database instance and one database. The database instance handles memory and processes. The database consists of physical files called data files and can be a non-container database or a multitenant container database. An Oracle Database also uses several database system files during its operation.
INSTANCE:- A database instance is a set of memory structures that manage database files. An instance has two parts:- One part is System Global Area and another is Background Process.
Diagram of Database Architecture:
SHARED GLOBAL AREA:-
The SGA is a group of shared memory area that is dedicated to the oracle instance, it contains data and control information of the instance.
PROGRAM GLOBAL AREA:-
PGA stands for Program Global Area. This is the private memory region that contains the data and control information for a server process. For every server process, a PGA will be created.
ORACLE DATABASE MEMORY STRUCTURE:-
The SGA is the memory area that contains data and control information for the instance. The SGA includes the following data structures:-
- SHARED POOL:- Caches various constructs that can be shared among users.
- DATA BUFFER CACHE:– Caches blocks of data retrieved from the database.
- REDO LOG BUFFER CACHE:– Caches redo information (used for instance recovery) until it can be written to the physical redo log files stored on the disk.
- JAVA POOL:– Used for all session-specific Java code and data in the Java Virtual Machine (JVM).
- STREAMS POOL:– Used by Oracle Streams to store information required by capture and apply.
- LARGE POOL:– Optional area that provides large memory allocations for certain large processes, such as Oracle backup and recovery operations, and I/O server processes.
- DATABASE WRITER PROCESS:- Writes dirty buffer in the database buffer cache to the disk.
A dirty buffer is a modified buffer in the database buffer cache that no longer matches the corresponding block on the disk.
- When a server process cannot find a reusable buffer after scanning the threshold number of buffers, then DBWN writes the dirty buffer asynchronously.
- Dbwn periodically writes the buffer to the advance checkpoint.
- LOG WRITER PROCESS:- LGWR writes the redo entry from the redo log buffer cache to online redo log file.
- When a user process commits a transaction.
- The redo-log buffer cache one-third is full.
- Before DBWN writes the dirty buffer to the disk.
- PROCESS MONITORING:- PMON takes care all bg process. When the user disconnects some issue then PMON clears all resources.
- Performs process recovery when a user process fails.
- Clean up the database buffer cache.
- Monitor sessions for idle session timeout.
- Dynamically registers database services with the listener.
- SYSTEM MONITORING:- SMON performs recovery at instance startup and cleans unused recovery segments. It checks regularly to see whether the process is needed.
- Performs recovery with instance startup.
- Clean up unused temporary segments.
- CHECKPOINT:- Checkpoint mainly controls the control file information and data-file header. When a checkpoint occurs, the Oracle database updates the header of all data files to record the details of the checkpoint. The CKPT process does not write blocks to disk.
CHECKPOINT MAINLY TWO TYPES 🡪
- FULL CHECKPOINT 🡪 Normal Checkpoint is when all the data is flushed to Disk, then the control file, Data file and Redo log is updated with the current SCN.
- INCREMENTAL CHECKPOINT 🡪 Incremental checkpoint is when the oldest data is flushed to disk, in that case, the Control file and redo log is updated with SCN (System Generated Number) but the header of the Data file will remain unchanged.
- SCN Number 🡪 SCN stands for system change number. It is the unique incremental number of databases. This number is incremented by every 3sec.
- ARCn PROCESS 🡪 ARCn is an Oracle background process responsible for copying the entirely filled online redo log file to the archive log. Once these files have been copied, they can be overwritten.
- PRACTICAL PROCESS ARCn
QUERY PROCESSING WORKFLOW
The Outline of the above process is:-
- A client-side cursor is opened.
- The client’s server process searches for a shareable cursor on the server side, within the SGA’s Shared Pool memory structure.
- If the search returns a reusable cursor, it’s marked as a Hit and the next step would be to execute the cursor.
- If the cursor is not found, it’s marked as a Miss and now, a new cursor area is allocated and the parsing for this new cursor would commence.
- Once the parsing of the cursor is over, the bind variables (if used) are replaced with the actual values supplied for them.
- The query may be chosen to use parallelism, i.e. use more than one process to execute it
- One the execution of the query is complete, which results in getting the required data for the given statement, the results are fetched by the server process.
- Once the data is fetched, the cursor is closed.
PROCESS OF SQL STATEMENT
When the new SQL statement is parsed, Oracle Database allocates memory from the shared pool. First, create a library cache. In this cache first of all server process will check the syntax, if the syntax is not an error then go to the next step. The next step is called semantic. It is done by a data dictionary cache.
It is a two process. First, check the object, the object is present (Table Name) then it is successful and go to the next process privilege. It parts to check the user’s permission. The permission is allowed then successful check. The entire whole work is called PARSING. Parsing is done in a new fresh instance then it is called Hard Parsing, if it is done in an old instance then it is called Soft Parsing. After the whole work is done then create a #code and an optimizer. [ n no of execution plan ]. It is executed in the library cache.