Wednesday 23 November 2016

YUM server configuration?

What is YUM?                                                           

YUM (Yellowdog Updater Modified) is an open source command-line as well as graphical based package management tool for RPM (RedHat Package Manager) based Linux systems. It allows users and system administrator to easily install, update, remove or search software packages on a systems. It was developed and released by Seth Vidal under GPL (General Public License) as an open source, means anyone can allowed to download and access the code to fix bugs and develop customized packages. YUM uses numerous third party repositories to install packages automatically by resolving their dependencies issues.
To configure yum server, first of all we need to identify the installed Linux OS version and it's corresponding public yum repository.

[root@localhost ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)

[root@localhost ~]# cd /etc/yum.repos.d/

Now we will be creating public-yum-el5.repo named file with following details to cofig the yum server pointing public yum repository.

[root@localhost ~]# vi public-yum-el5.repo

[el5_u4_base]
name=Enterprise Linux $releasever Update 4 installation media copy ($basearch)
baseurl=http://public-yum.oracle.com/repo/EnterpriseLinux/EL5/4/base/$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=0
enabled=1


Note : Make sure you have changed the value of enabled to 1 from 0, Save and Exit;


List repository packages in Oracle Linux as shown below now.

[root@localhost ~]# yum list

Now we are ready to install any packages required with following yum install command:

[root@localhost ~]# yum install [package_name]

For example, I wanted to install elfutils-devel packages but it has dependent packages to be installed first. As we have already configured the yum server then we just need to provide some start string of the package to be installed ending with asterisk(*) then it will automatically download/install all its dependent packages along as follows:

[root@localhost yum.repos.d]# yum install elfutils*
Loaded plugins: rhnplugin, security
This system is not registered with ULN.
ULN support will be disabled.
Setting up Install Process
Package elfutils-libelf-0.137-3.el5.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package elfutils.x86_64 0:0.137-3.el5 set to be updated
---> Package elfutils-devel.i386 0:0.137-3.el5 set to be updated
---> Package elfutils-devel.x86_64 0:0.137-3.el5 set to be updated
---> Package elfutils-devel-static.i386 0:0.137-3.el5 set to be updated
---> Package elfutils-devel-static.x86_64 0:0.137-3.el5 set to be updated
---> Package elfutils-libelf.i386 0:0.137-3.el5 set to be updated
---> Package elfutils-libelf-devel.i386 0:0.137-3.el5 set to be updated
---> Package elfutils-libelf-devel.x86_64 0:0.137-3.el5 set to be updated
---> Package elfutils-libelf-devel-static.i386 0:0.137-3.el5 set to be updated
---> Package elfutils-libelf-devel-static.x86_64 0:0.137-3.el5 set to be updated
---> Package elfutils-libs.i386 0:0.137-3.el5 set to be updated
---> Package elfutils-libs.x86_64 0:0.137-3.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================
 Package                             Arch          Version              Repository          Size
=================================================================================================
Installing:
 elfutils                            x86_64        0.137-3.el5          el5_u5_base        215 k
 elfutils-devel                      i386          0.137-3.el5          el5_u5_base         61 k
 elfutils-devel                      x86_64        0.137-3.el5          el5_u5_base         62 k
 elfutils-devel-static               i386          0.137-3.el5          el5_u5_base        122 k
 elfutils-devel-static               x86_64        0.137-3.el5          el5_u5_base        119 k
 elfutils-libelf                     i386          0.137-3.el5          el5_u5_base         58 k
 elfutils-libelf-devel               i386          0.137-3.el5          el5_u5_base         24 k
 elfutils-libelf-devel               x86_64        0.137-3.el5          el5_u5_base         24 k
 elfutils-libelf-devel-static        i386          0.137-3.el5          el5_u5_base         66 k
 elfutils-libelf-devel-static        x86_64        0.137-3.el5          el5_u5_base         64 k
 elfutils-libs                       i386          0.137-3.el5          el5_u5_base        193 k
 elfutils-libs                       x86_64        0.137-3.el5          el5_u5_base        183 k

Transaction Summary
=================================================================================================
Install      12 Package(s)
Upgrade       0 Package(s)

Total download size: 1.2 M
Is this ok [y/N]: y

Note : Here you can see it asks for all dependent packages to be downloaded or not so we will press (y) to download all dependent packages.


Downloading Packages:
(1/12): elfutils-libelf-devel-0.137-3.el5.x86_64.rpm                      |  24 kB     00:00   
(2/12): elfutils-libelf-devel-0.137-3.el5.i386.rpm                        |  24 kB     00:00   
(3/12): elfutils-libelf-0.137-3.el5.i386.rpm                              |  58 kB     00:00   
(4/12): elfutils-devel-0.137-3.el5.i386.rpm                               |  61 kB     00:00   
(5/12): elfutils-devel-0.137-3.el5.x86_64.rpm                             |  62 kB     00:00   
(6/12): elfutils-libelf-devel-static-0.137-3.el5.x86_64.rpm               |  64 kB     00:00   
(7/12): elfutils-libelf-devel-static-0.137-3.el5.i386.rpm                 |  66 kB     00:00   
(8/12): elfutils-devel-static-0.137-3.el5.x86_64.rpm                      | 119 kB     00:00   
(9/12): elfutils-devel-static-0.137-3.el5.i386.rpm                        | 122 kB     00:00   
(10/12): elfutils-libs-0.137-3.el5.x86_64.rpm                             | 183 kB     00:00   
(11/12): elfutils-libs-0.137-3.el5.i386.rpm                               | 193 kB     00:00   
(12/12): elfutils-0.137-3.el5.x86_64.rpm                                  | 215 kB     00:00   
-------------------------------------------------------------------------------------------------
Total                                                             54 kB/s | 1.2 MB     00:21   
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 1e5e0159
el5_u5_base/gpgkey                                                        | 1.4 kB     00:00   
Importing GPG key 0x1E5E0159 "Oracle OSS group (Open Source Software group) <build@oss.oracle.com>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
Is this ok [y/N]: y

Note : Here it asks whether you want to install all downloaded packages so we will hit (y)

Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : elfutils-libs                                                            1/12
  Installing     : elfutils-libelf                                                          2/12
  Installing     : elfutils                                                                 3/12
  Installing     : elfutils-libs                                                            4/12
  Installing     : elfutils-libelf-devel                                                    5/12
  Installing     : elfutils-libelf-devel                                                    6/12
  Installing     : elfutils-libelf-devel-static                                             7/12
  Installing     : elfutils-libelf-devel-static                                             8/12
  Installing     : elfutils-devel-static                                                    9/12
  Installing     : elfutils-devel                                                          10/12
  Installing     : elfutils-devel                                                          11/12
  Installing     : elfutils-devel-static                                                   12/12

Installed:
  elfutils.x86_64 0:0.137-3.el5                                                                 
  elfutils-devel.i386 0:0.137-3.el5                                                             
  elfutils-devel.x86_64 0:0.137-3.el5                                                           
  elfutils-devel-static.i386 0:0.137-3.el5                                                     
  elfutils-devel-static.x86_64 0:0.137-3.el5                                                   
  elfutils-libelf.i386 0:0.137-3.el5                                                           
  elfutils-libelf-devel.i386 0:0.137-3.el5                                                     
  elfutils-libelf-devel.x86_64 0:0.137-3.el5                                                   
  elfutils-libelf-devel-static.i386 0:0.137-3.el5                                               
  elfutils-libelf-devel-static.x86_64 0:0.137-3.el5                                             
  elfutils-libs.i386 0:0.137-3.el5                                                             
  elfutils-libs.x86_64 0:0.137-3.el5                                                           

Complete!


Finally, you saw all dependent packages got installed in such an ease way by configuring yum server.

Friday 11 November 2016

Archive log mode and how to enable it?

Archive log mode:-
Incase of disk failure also if we cannot afford to lose any data in your database then use Archive log mode.
Running a database in noarchive log mode:-
When you run your database in NOARCHIVELOG mode, you disable the archiving of the redo log. The database control file indicates that filled groups are not required to be archived. Therefore, when a filled group becomes inactive after a log switch, the group is available for reuse by LGWR.
NOARCHIVELOG mode protects a database from instance failure but not from media failure. Only the most recent changes made to the database, which are stored in the online redo log groups, are available for instance recovery. If a media failure occurs while the database is in NOARCHIVELOG mode, you can only restore the database to the point of the most recent full database backup. You cannot recover transactions subsequent to that backup.
In NOARCHIVELOG mode you cannot perform online tablespace backups, nor can you use online tablespace backups taken earlier while the database was in ARCHIVELOG mode. To restore a database operating in NOARCHIVELOG mode, you can use only whole database backups taken while the database is closed. Therefore, if you decide to operate a database in NOARCHIVELOG mode, take whole database backups at regular, frequent intervals.
Running a database in archive log mode:-
When you run a database in ARCHIVELOG mode, you enable the archiving of the redo log. The database control file indicates that a group of filled redo log files cannot be reused by LGWR until the group is archived. A filled group becomes available for archiving immediately after a redo log switch occurs.
The archiving of filled groups has these advantages:
·         A database backup, together with online and archived redo log files, guarantees that you can recover all committed transactions in the event of an operating system or disk failure.
·         If you keep an archived log, you can use a backup taken while the database is open and in normal system use.
·         You can keep a standby database current with its original database by continuously applying the original archived redo logs to the standby.
You can configure an instance to archive filled redo log files automatically, or you can archive manually. For convenience and efficiency, automatic archiving is usually best.
SQL> archive log list          (it will show db log mode and sequence)
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     132
Current log sequence           133
Here the database is in no archivelog mode.we need to enable it.
Archive log mode takes the snap of redologfiles and those redolog files are kept into destination.
steps:-
1)First shut down the database.
SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Pr                                                                                     oduction.With the Partitioning, OLAP, Data Mining and Real Application Testing options.
2) [subbu@subbuapps ~]$ mkdir -p /u01/app/subbu/arch
created a folder arch to archive log files.
3)open pfile in location  cd $ORACLE_HOME/dbs
[subbu@subbuapps dbs]$ vi initsubbu.ora
add
log_archive_dest=/u01/app/subbu/arch
:wq
4)startup the database in mount mode
SQL> startup mount
ORACLE instance started.
Total System Global Area  732352512 bytes
Fixed Size                  1367144 bytes
Variable Size             369099672 bytes
Database Buffers          356515840 bytes
Redo Buffers                5369856 bytes
Database mounted.
SQL> archive log list
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     132
Current log sequence           133
SQL> alter database archive log;
alter database archive log
                       *
ERROR at line 1:
ORA-02231: missing or invalid option to ALTER DATABASE


SQL> alter database archivelog;
Database altered.
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     132
Next log sequence to archive   133
Current log sequence           133
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
MOUNTED
SQL> alter database open;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ WRITE


Monday 7 November 2016

ORACLE DATABASE ARCHITECTURE

ORACLE DATABASE  ARCHITECTURE:
·        Oracle database is a combination of oracle instance and datafiles on the file system.
·     Oracle instance is the combination of SGA and background process.with the help of instance only    we can acess the database objects.without database instance have no meaning.

What is Database?
Database is the collection of oraganized data.every running oracle database is assosciated with oracle instance.database consists of 2 phases.
                        1)logical phase--->objects-->tables
                        2)physical phaseàfiles-->filesystem-->os--->devicedrivers(harddisk)
                                                                        1)controlfiles
                                                                        2)redolog files
                                                                        3)datafiles
                                                                        4)archive redo log files(optional)
·        The purpose of physical phase is for storing
·        The purpose of logical phase is to access the database.

SGA: [System global area or shared global area]

When instance startsup memory structure called SGA is allocated.The total memory allocated to the oracle database can be broadly categorized into SGA and PGA[program global area].
SGA contains following data structure:
 1)DBBC[database buffer cache]
2)shared pool.
3)RLBC[redolog buffer cache]
4)Java Pool
5)large pool
6)streams pool
SGA can be categorized into 2 types:
1)Fixed SGA:- is a component of the SGA that varies in size from platform to platform and release to release. The size of the fixed SGA is something over which we have no control and it is generally very small.we cannot alter the size of fixed SGA.
2)Variable SGA:- Variable SGA contains 4 main components as listed above, those are “Database Buffer Cache”, “Redo Log Buffer”, “Shared Pool” and “Large Pool”. We call it variable SGA because we can alter the size of each of these components manually using ALTER SYSTEM command. The size of each of the components of variable SGA is determined by INIT.ORA parameters. Following are the INIT.ORA parameter for each of the component.
Database Buffer Cache – db_block_buffers
Redo Log Buffer – log_buffer
Shared Pool – shared_pool_size
Large Pool – Large_pool_size

Database Buffer CacheThis is used to hold the data into the memory. When ever a user access the data, it gets fetched into database buffer cache and it will be managed according to LRU (Least recently used) algorithm. Advantages – If a user is requesting data, which gets fetched into the buffer cache, then next time if he ask for same data with in a short period of time, the data will be read from buffer cache and Oracle process does not have to fetch data again from disk. Reading data from buffer cache is a faster operation. Another advantage is that if a user is modifying the data, it can be modified in the buffer cache which is a faster operation then modifying the data directly on the disk.

Redo Log BufferThis memory block hold the data which is going to be written to redo log file. Why do we need this data? To rollback the changes if the need be. But instead of writing the data directly to the redo log files, it is first written to log buffer which improves performance and then with the occurrence of certain event it will be written to redo log file.

Shared PoolThis contains 2 memory section, 1) Library Cache 2) Dictionary Cache. Library cache hold the parsed SQL statement and execution plans and parsed PLSQL codes. Dictionary cache hold the information about user privileges, tables and column definitions, passwords etc. These 2 memory components are included in the size of shared pool.

Large Pool If defined then used for heavy operations such as bulk copy during backup or during restore operation.
The total size of SGA is determined by a parameter SGA_MAX_SIZE. Below is the simple calculation of memory sizes.
SQL> show sga
Total System Global Area  577574308 bytes
Fixed Size                   452004 bytes
Variable Size             402653184 bytes
Database Buffers          163840000 bytes
Redo Buffers               10629120 bytes

This will show fixed and variable size SGA. Fixed size SGA, as I said is not in our control. However we can verify the size of variable SGA and other memory values shown above.
Database Buffers          163840000 bytes
SQL> show parameters db_block_buffer
NAME                                 TYPE        VALUE
———————————— ———– ——————————
db_block_buffers                     integer     20000

This value is in terms of blocks. we can find the size of a block using DB_BLOCK_SIZE parameter
SQL> show parameters db_block_size
NAME                                 TYPE        VALUE
———————————— ———– ——————————
db_block_size                        integer     8192
So Database Buffers = db_block_buffers X db_block_size = 20000 X 8192 = 163840000 bytes
Also Variable size = “Shared Pool Size” + “Large Pool Size” + “Java Pool size” (some times defined)
SQL> SELECT pool, sum(bytes) from v$sgastat group by pool;
POOL        SUM(BYTES)
java pool     50331648
shared pool  352321536

PGA:-[program global area]   sga is allocated when oracle instance startsup
And PGA is allocated when server process startsup.

BACKGROUND PROCESSES:   will starts when oracle instance startsup.

1)SMON:[system monitor]

The system monitor process (SMON) performs recovery, if necessary, at instance startup. SMON is also responsible for cleaning up temporary segments that are no longer in use and for coalescing contiguous free extents within dictionary managed tablespaces. If any terminated transactions were skipped during instance recovery because of file-read or offline errors, SMON recovers them when the tablespace or file is brought back online. SMON checks regularly to see whether it is needed. Other processes can call SMON if they detect a need for it.

2)PMON:[process monitor]

The process monitor (PMON) performs process recovery when a user process fails. PMON is responsible for cleaning up the database buffer cache and freeing resources that the user process was using. For example, it resets the status of the active transaction table, releases locks, and removes the process ID from the list of active processes.
PMON periodically checks the status of dispatcher and server processes, and restarts any that have stopped running (but not any that Oracle has terminated intentionally). PMON also registers information about the instance and dispatcher processes with the network listener.
Like SMON, PMON checks regularly to see whether it is needed and can be called if another process detects the need for it.

3)LGWR[log writer]

The log writer process (LGWR) is responsible for redo log buffer management.writing the redo log buffer to a redo log file on disk. LGWR writes all redo entries that have been copied into the buffer since the last time it wrote.

4)DBWN[database writer]

The database writer process (DBWn) writes the contents of buffers to datafiles. The DBWn processes are responsible for writing modified (dirty) buffers in the database buffer cache to disk. Although one database writer process (DBW0) is adequate for most systems, you can configure additional processes (DBW1 through DBW9) to improve write performance if your system modifies data heavily.

5)CKPT[check point]

When a checkpoint occurs, Oracle must update the headers of all datafiles to record the details of the checkpoint. This is done by the CKPT process. The CKPT process does not write blocks to disk; DBWn always performs that work.

6)RECO[recoverer]

The RECO process is present only if the instance permits distributed transactions and if the DISTRIBUTED_TRANSACTIONS parameter is greater than zero. If this initialization parameter is zero, RECO is not created during instance startup.

7)ARCN[archiver process]

The archiver process (ARCn) copies online redo log files to a designated storage device after a log switch has occurred. ARCn processes are present only when the database is in ARCHIVELOG mode, and automatic archiving is enabled.
An Oracle instance can have up to 10 ARCn processes (ARC0 to ARC9). The LGWR process starts a new ARCn process whenever the current number of ARCn processes is insufficient to handle the workload. The ALERT file keeps a record of when LGWR starts a new ARCn process.


1)startup and shutdown modes?

STARTUP MODES:
         
1)nomount--->instance creation-->oracle is going to read the p-file[parameter file].from the parameter file it will find how much is the memory allocation for SGA and it will allocate those memory structure and background process will be created.instartup nomount we can modify the controlfile.

2)mount----->instance will read the controlfile and locates the datafiles and redologfiles.in mount we can rename datafiles,enable or disable archive redolog,full database recovery.

 3)open------->it will open the datafiles and redologfiles.if the database is in mount state.we can open by alter database open;

SHUTDOWN MODES:

1)normal shutdown---->during normal shutdown before the oracle database is shutdown oracle will wait for all the active users to disconnect their sessions.As the parameter name suggests use this option to shutdown the database under normal conditions.
            
2)shutdown immediate---->during shutdown immediate before the oracle database is shutdown oracle will rollback active transaction and disconnect all active users.use this option  when there is a problem with your database and you dont have enough time to request users to log off.
           
3)shut abort---->during shut abort before the the oracle database is shutdown all user sessions will be terminated immediately.uncommited transactions will not be rolledback.use this                 option only during emergency situations when the shutdown and shut immmediate does not work.
           
2)what happens in background when we enter select statement?
user process cannot directly interact with the instance.so user process will send to server process.server process makes use of data dictionary cache.the data dictionary cache will check whether the user has the proper privileges are not.If the user has the proper privileges the pl/sql statements by the user will send to library cache.the parsing of sql and pl/sql statements are done in shared pool.parsing is of two types
            1)hard parsing--->if the statement is executing for the first time.
            2)soft parsing--->if the statement is not there it will fetch from dbf.
parsing consists of 3 steps
            1)syntax check-->it will check whether the statement by the user is correct or not it will check.
            2)schemantic check-->it will check whether the user has proper privilges to access the table or not.
            3)hash value generation-->hash value is created on the basis of adding all the ASCII values of the statement.it is stored in cursor.and then there is an execution plan that also made             for each sql statement which is also created by optimizer.optimizer generates n number of execution plan among them it will take the best execution plan which consumes less system             resources.
this execution plan will be stored in library cache and goes TO dbbc if it is not there it will fetch from userdata1,dbf and sends to userprocess.

TABLESPACES and DATAFILES:
Tablespaces:- An Oracle database consists of at least two logical storage units called tablespaces, which collectively store all of the database's data. You must have the SYSTEM and SYSAUX tablespaces and a third tablespace, called TEMP, is optional.

Datafiles:- Each tablespace in an Oracle database consists of one or more files called datafiles.datafiles contains actual business data.The extensions for datafiles is .dbf. The size of datafile will be in MB’S or GB’S depends up on the company.

Controlfiles:-
It contains the crucial information of the database.i.e
1)database name.
2)timestamp of db creation.
3)names and locations of assosciated datafiles and redologfile.
4)datafile offline ranges.
5)the log history.
6)archive log information.
7)backup set and backup piece information.
8)backup datafile and redologfile information.
9)datafile copy information.
10)the current log scn.[system change number-A SCN is a logical,internal time stamp used by oracle db.every transaction has a scn.for example if a transaction updates a row then database records the SCN at which this update occurred.]

Redologfiles:-
it contains the latest transactions for recovery.
Restore--->getting yesterdays data.
Recovery--->getting todays data.
The extension for redologfile is .log.

The size of redologs is in mb’s.The redologfiles are used to recover the database in the event of application program failures,instance failures and other minor failures.