Friday , November 8 2024

Oracle Database Architecture Part 1

In this article I will tell you about Oracle Database Architecture. Oracle Database is the most preferred database in the world, especially in large scale projects. To be able to learn the Oracle Database in detail, the first thing that should be done is knowing the Oracle Database architecture. So what happens in the background when the user starts a transaction.

When Oracle Database is running, a memory space that we call the shared global area (SGA) on the operating system is allocated to Oracle. At the same time, some processes that we call background processes are started by Oracle to meet the demands of the database. Oracle Instance consists of SGA + Background processes. The following image shows the Oracle Database architecture beautifully. I’ll explain all the concepts through this image.

Control File: The Control file is a file with a .ctl extension that is physically stored on the operating system that is a must for an Oracle database. This file also acts as the brain for our Oracle database. When the Oracle database starts, it reads the parameter file called SPFILE or PFILE and learn the location of the Control file. Because the Control file is the brain of our database, the database needs to find this file to work. If it cannot find the Control File, the Oracle database will not start and will give an error. Thats why, the control file is stored in 2 copies in the production databases. Oracle’s recommended configuration is that we store 3 copies on separate disks. We said the control file is very important. So why is important, what information is in the control file.

  • The database name is stored in this file. When the database is opened, it learns what the name of the database is after reading this file.
  • It contains the location of Datafile files where the data is physically stored.
  • It contains the physical location of the Online Redo log files(transactions are stored in this file) and archive log files(archive of redo log files).
  • It contains RMAN backup information. Therefore, if you take a Full backup without backing up the Control file, this backup becomes invalid. It cannot be restored. Therefore, when taking a backup, the Control file must also backed up.
  • The current version of the SCN (System Change Number) number used during database operations is also stored in the Control file. SCN is a number that is generated after the transactions are committed. SCN is a unique value that is incrementing in order.
  • It contains Checkpoint information. I will explain more about Checkpoint.
  • The database creation date is also stored in this file.
  • It contains the sequence number of the log files where transactions are stored.

As can be seen from the items I mentioned, the Control file is a must for our Oracle database. That’s why, an Oracle DBA must to know that when he/she takes a backup, control file also must backed up. If we configure RMAN as follows, automatic backup of control file will be active.

We can query where the control file is, as follows:

Data Files: These are physical files with the dbf extension that are stored by the Oracle database on the operating system. You can see these files as * .dbf on the operating system. When Oracle database is first created, System, sysaux, undo, user and temp datafiles are created by default. When the user initiates a transaction, Oracle first attempts to find the data that is searched in the Database Buffer Cache. If it cannot find it, it is directed to Data files to find this data. We can see all datafiles belonging to the database with the following query.

SGA: When Oracle instance starts, memory area of up to the SGA value specified during the installation phase is allocated by Oracle from the operating system. This memory area is called the System Global Area. This memory space is allocated from the physical server’s RAM until the Oracle instance is closed. When the instance is turned off, this memory space is returned to the operating system.

We determine the SGA value when creating the Oracle database, and the correct and optimum configuration of this value will directly affect oracle’s performance. We can look at the SGA value reserved for Oracle Database as follows.

PGA (Program Global Area): This is the memory space allocated from the server’s physical memory when a process is started on an Oracle instance on the server. This memory space is used until the process related to Oracle is terminated. When the process is completed, this memory space is released. You can query the specified value for this memory space in the database as follows.

Shared Pool: Shared Pool is an important memory area used in the vast majority of database operations. Because the query of all the transactions, their execution plans (work plans), the parsed and compiled PL/SQL codes are always stored in this memory area. The shared pool area consists of the following components.

Library Cache: This is one of the most important areas in the shared pool. Because when an SQL clause comes into the Oracle database, Oracle first checks whether it has been executed or not by looking at the library cache. If the queryhas been execute before, Oracle uses the previous execution plan without parsing this SQL. This process is called soft parse. If the query has not been executed before, oracle will parse the executed SQL and save it to the Shared SQL Area in the library cache. This process is called hard parse.
One of the most important tasks of a DBA is to identify and fix unnecessary hard parse operations in a database.
One of the most important reasons for unnecessary hard parse operations is that;
There are upper-lower case differences in the same SQL statements:
Another method to use as a solution is to use bind Variable for the same query types:
In the above query, personel information with an id value of 1 is requested. Imagine that this query is always requested with different id values. Oracle will repeatedly parse this query in the library cache even though the query is the same. So instead of making a soft parse and consuming less than Cpu source, it will make the hard parse and consumes unnecessary CPU resources. At this point, we assign the “bind variable” value for the id column to ensure that the query uses the same execution plan for each different incoming id value. The use of the above query with the bind variable is as follows.
If we use Bind variable, Oracle will use the same execution plan even if the id value in the queries changes.

Dictionary Cache: This memory space stores the metadata of our database.

That is, the following informations is stored in Dictionary cache:

  • Who is authorized to access a table
  • Tablespace informations
  • Column information of a table

This memory space is often used when parsing a query.

So I came to the end of my article. In the next article, I will continue to explain the Oracle Database Architecture. Other articles of the series can be found below.

Oracle Database Architecture Part 2“,
Oracle Database Architecture Part 3

Loading

About Mehmet Salih DEVECİ

Leave a Reply

Your email address will not be published. Required fields are marked *