Site icon IT Tutorial

Oracle Database Architecture -1 Controlfile, Datafile, SGA and PGA

In this article I will explain the Oracle Database Architecture. Let’s review the Controlfile Datafile SGA and PGA | Oracle Architecture detailed.

 

 

Controlfile Datafile SGA and PGA | Oracle 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.

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.

 

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;

 

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

 

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Thu Oct 3 11:47:59 2013

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> show parameter control_file;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_files                        string      /oracle/data/TESTDB/control01.ctl, /oracle/data/TESTDB/control02.ctl
SQL>

 

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.

 

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Thu Oct 3 13:26:26 2013

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> set lines 800
SQL> select FILE_NAME,FILE_ID,TABLESPACE_NAME,BYTES,BLOCKS,MAXBYTES,ONLINE_STATUS from dba_data_files;

FILE_NAME     FILE_ID TABLESPACE_NAME                     BYTES     BLOCKS   MAXBYTES ONLINE_
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------- ------------------------------ ---------- ---------- ---------- -------
/oracle/data/TESTDB/system01.dbf   1 SYSTEM                          734003200      89600 3.4360E+10 SYSTEM
/oracle/data/TESTDB/sysaux01.dbf   2 SYSAUX                          744488960      90880 3.4360E+10 ONLINE
/oracle/data/TESTDB/undotbs01.dbf   3 UNDOTBS1                        519045120      63360 3.4360E+10 ONLINE
/oracle/data/TESTDB/users01.dbf    4 USERS                             5242880        640 3.4360E+10 ONLINE
/oracle/data/TESTDB/fda01.dbf   5 FDA                            1073741824     131072          0 ONLINE

SQL>

 

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.

 

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Thu Oct 3 15:31:32 2013

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> show parameter sga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
lock_sga                             boolean     FALSE
pre_page_sga                         boolean     FALSE
sga_max_size                         big integer 512M
sga_target                           big integer 512M
SQL>

 

 

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.

 

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Fri Oct 4 14:56:59 2013

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> show parameter pga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
pga_aggregate_target                 big integer 2635M
SQL>

 

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:
1 nolu sorgu: select * from hr.personel;
2 nolu sorgu: select * from hr.Personel;

 

Another method to use as a solution is to use bind Variable for the same query types:
SQL> select name,surname,phone from hr.personel where id=1;

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.

 

SQL> variable person_id number
SQL> exec :person_id : =180251;
SQL> select name,surname,phone from hr.personel where id :=person_id;

 

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.

 

 

 

 

 

Read second article by clicking this link.

 

 

 

 

Do you want to learn Oracle Database for Beginners, then Click and read the following articles.

Oracle Database Tutorials for Beginners ( Junior Oracle DBA )

Exit mobile version