Practice - Creating Oracle Database with ASM
Practice - Creating Oracle Database with ASM
Practice
Practice Target
In this practice you will create an Oracle database 19c with ASM.
Practice Overview
In high level, in this practice, you will perform the following tasks:
Note: In this practice, you will not use srv1 machine that we used across the course practices. You
will create a new vm (still its host name will be srv1) from the seed vm and use it for creating an
ASM-based database.
Note: Because the machine will have two instances running in it, it requires more memory in it. You
will configure the vm with a memory size 8G. This means the memory in your PC should be at least
12G.
Installation Architecture
In this practice, you will build a system the same as the following architecture diagram:
1. Download Oracle Grid Infrastructure 19c (19.3) installation file for Linux x86-64 from this link. It
is a 2.8 GB file. Copy or move the file to the sharing folder.
Alternatively, download the installation file from Oracle website. Just make sure you download
Oracle Grid Infrastructure 19.3 for Linux x86-64.
2. We assume you already have Oracle database 19c (19.3) software installation files that you used
to install Oracle database software in the other course practices so far. If not, download it from
this link. It is a 3G compressed file. Copy or move the file to the sharing folder.
3. In Oracle VirtualBox, make sure that the vm “Linux7-seed” is added and turned off. If not, add it
to Oracle VirtualBox Manager.
“Linux7-seed” is a vm that you imported into VirtualBox in the first course practice. In that
practice, the Guest Additions were updated in that vm and its network was configured.
11. Open the network settings of the VM. Obtain the IP address assigned to the VM. Make it a static
IP address.
Click on Applications > System Tools > Settings > Network > under the Wired section
click on the Gear button > highlight the IP address from the under the Details tab > right-click
on the highlighted IP and select Copy command
> click on IPv4 tab > IPv4 Method to Manual > Paste the IP address into the Address field >
set the Netmask to 255.255.255.0 > and the Gateway to 192.168.1.1
Note: Under the Wired section, you might not see any Network Profile configured. Simply, click
on the plus button beside the "Wired" label, select the MAC address from the dropdown list,
then click on Add button, as shown in the following screenshot:
12. Turn off the network adapter then turn it on again, then close the Settings window.
13. In the hosting PC, open the command prompt and ping the vm IP address to make sure it is seen
by the PC.
14. In srv1, open a terminal window then open the hosts file with vi editor.
vi /etc/hosts
15. Insert into it the following line. Replace the <ip address> with the IP address of srv1
<ip address> srv1 srv1.localdomain
Tip: In Putty, instead of creating a connection configuration for the vm from scratch, load the
settings of srv1, change its configured IP address to match the IP address of the new vm, give
the changed configuration the name "srv1-asm" and save it.
25. Set the OCR disk file name and its size.
26. Select the OCRDISK1.vdi and click on Add button to attach the disk to the vm.
27. Perform the same steps again to create the DATA disk, of size 12G. You should end up with
having two disks as follows:
28. Optionally, set a description for the appliance, then click on OK button
30. In the Putty session, switch current user to oracle and make a backup copy of the current bash
profile file:
Note: If you are working in a system where oracle user is not there, you need to create oracle
user and oinstall and dba groups. oinstall is the login group for oracle.
su - oracle
mv ~/.bash_profile ~/.bash_profile_bkp
# OS User: oracle
# Application: Oracle Database Software Owner
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
PATH=$PATH:$HOME/.local/bin:$HOME/bin
PATH=${PATH}:/usr/bin:/bin:/usr/local/bin
PATH=.:${PATH}:$ORACLE_HOME/bin
export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/oracm/lib
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib
export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE
CLASSPATH=${CLASSPATH}:$ORACLE_HOME/jlib
CLASSPATH=${CLASSPATH}:$ORACLE_HOME/rdbms/jlib
CLASSPATH=${CLASSPATH}:$ORACLE_HOME/network/jlib
export CLASSPATH
export TEMP=/tmp
export TMPDIR=/tmp
export EDITOR=vi
umask 022
33. Switch the current user back to root then run the following code to create required groups, grid
user and modify the accounts as follows. Enter the password for grid user when you are
prompted to do so.
exit
groupadd asmadmin
groupadd asmdba
usermod -a -G asmdba oracle
useradd -u 54323 -g oinstall -G asmadmin,asmdba grid
passwd grid
35. Create Oracle Database and Clusterware base and home directories:
Oracle Clusterware is the core software for Oracle Grid Infrastructure.
mkdir -p /u01/app/oracle/product/19.0.0/db_1
mkdir -p /u01/app/grid
mkdir -p /u01/app/19.0.0/grid
chown -R grid:oinstall /u01
chown -R oracle:oinstall /u01/app/oracle
chmod -R 775 /u01
36. Switch to grid user and modify its bash profile as follows:
su - grid
mv ~/.bash_profile ~/.bash_profile_bkp
vi ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
ORACLE_SID=+ASM; export ORACLE_SID
ORACLE_BASE=/u01/app/grid; export ORACLE_BASE
# the home must not be under the ORACLE_BASE
ORACLE_HOME=/u01/app/19.0.0/grid; export ORACLE_HOME
ORACLE_TERM=xterm; export ORACLE_TERM
TNS_ADMIN=$ORACLE_HOME/network/admin; export TNS_ADMIN
PATH=.:${JAVA_HOME}/bin:${PATH}:$HOME/bin:$ORACLE_HOME/bin
PATH=${PATH}:/usr/bin:/bin:/usr/local/bin
export PATH
export TEMP=/tmp
export TMPDIR=/tmp
umask 022
In the following steps, you will install ASM packages then create ASM disk volumes.
37. Exit from the current user so that the current user becomes the root
exit
39. Configure and load the ASM kernel module. Respond to the command as illustrated by the code
in red color.
oracleasm configure -i
41. List the disks as seen by the OS. You should see the disks created in the VirtualBox and attached
to the appliance.
fdisk -l | grep "Disk /dev/sd"
In the following step, you will change the kernel parameter values to the values recommended by
Oracle.
45. Create the following file then add the code that follows to it.
vi /etc/sysctl.d/97-oracle-database-sysctl.conf
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
47. Run the following code to install further packages required by Oracle software.
yum install ksh
yum install libaio-devel.x86_64
In the following steps, you will install Oracle Grid Infrastructure software in the vm. The installation
procedure automatically creates and start the Clusterware services.
Note: When Oracle Grid Infrastructure is configured with a non-RAC database, the configuration is
called Oracle Restart.
49. Make sure the Oracle Grid Infrastructure software installation file
(LINUX.X64_193000_grid_home.zip) is copied to the staging folder.
50. As grid, extract the installation file into the Oracle Grid Infrastructure software home directory
su - grid
unzip /media/sf_staging/LINUX.X64_193000_grid_home.zip -d $ORACLE_HOME
cd /u01/app/19.0.0/grid/cv/rpm/
CVUQDISK_GRP=oinstall; export CVUQDISK_GRP
rpm -iv cvuqdisk-1.0.10-1.rpm
53. Open a terminal window, change the current directory to the Grid Infrastructure software home
directory and run the gridSetup.sh script.
cd $ORACLE_HOME
./gridSetup.sh
Window Action
Configuration Option
Select the following option:
ASM Password Select the option "Use the same password for these accounts"
Enter the password ABcd##1234
Operating System Make sure the following are the selected values:
Groups
OSASM: asmadmin
OSDBA: asmdba
Installation Location Oracle Base and Oracle Grid Home should automatically point to
the values of their corresponding variables.
Note: Observe the grid home is not under the Oracle grid base
home.
Root Script Execution Mark the checkbox “Automatically run configuration scripts”
and enter the root password
Prerequisite Checks All the Prerequisite Checks should pass except the memory. It
complains the available memory is 7.5. We can ignore this
warning.
Select Ignore All checkbox then click on Next button.
Click Yes on the confirmation dialog box.
Note: If you see other warnings, you have to resolve them
before you proceed.
Install Product When the installation reaches to nearly 11%, it will display a
confirmation message. Click on Yes button.
55. After the installation is finished, you can check CRS services status:
crsctl status resource -t
In the following steps, you will create the disk group that will be used by Oracle database to store its
datafiles.
Note: In real life scenario, we might create more than one disk group. For example, one for the data
files and one for the FRA.
57. Create the disk group DATADISK by responding to the Assistant as follows:
58. Click on Yes when you see the confirmation message to close the window.
In the following steps, you will install Oracle database software in srv1 and then use dbca to create an
ASM-based database.
59. Make sure a copy of the Oracle database software installation file
(LINUX.X64_193000_db_home.zip) is there in the staging folder.
60. In the Putty session, change the current user to oracle then extract the installation file into the
Oracle database software home directory
su - oracle
unzip /media/sf_staging/LINUX.X64_193000_db_home.zip -d $ORACLE_HOME
61. Logout from the VirtualBox window and login to it again as oracle
62. In Oracle VirtualBox, create a snapshot for the vm. This snapshot will be used to restore vm in
case the database installation fails for any reason.
63. Open a terminal window, change the current directory to the Oracle database home directory and
run the runInstaller script.
cd $ORACLE_HOME
./runInstaller
Window Action
Root Script Execution Mark the checkbox “Automatically run configuration scripts”
and enter the root password
Install Product When the installation reaches to nearly 63%, if will display a
confirmation message. Click on Yes button.
65. Run the dbca and respond to the utility windows as follows:
Storage Option Select the option: "Use following for the database storage
attributes"
Make sure the "Database files storage type" is automatically set
to "ASM" and
"Database files location" is set to
"+DATA/{DB_UNIQUE_NAME}"
Fast Recovery Option Mark the option "Specify Fast Recovery Area"
click on "Browse" button and select "DATA" disk group.
Fast Recovery Size: 5000 MB.
You will be prompted for the message [DBT-06801], click on
"Yes" button
Note: In real life scenario, you should set the FRA to a size large
enough to accommodate its contents.
Database Options Deselect all the options except the Oracle JVM.
We keep the OJVM option because it is included in most
installations.
User Credantial Select the option "Use the same administrative password
for all accounts"
Set the password to ABcd##1234
67. After the installation and database creation are finished, verify the database is up and running by
logging to it as sys
sqlplus / as sysdba
exit
68. Using srvctl utility, check the status of the database (can be run as grid as well)
srvctl status database -d $ORACLE_SID
You finished creating an Oracle database with Oracle Restart. In the next sections, you will explore
this system.
In this section of the practice, you will explore the ASM components and examine its auto-restart
functionality.
76. Check the status of the resources in the Oracle Restart stack
crsctl stat res -t
80. Run the following commands to stop and then start up the database.
Because the database is registered in the Clusterware, grid is able to start, stop, and configure
the database resource.
srvctl stop database -d oradb -o immediate
srvctl status database -d oradb
srvctl start database -d oradb
srvctl status database -d oradb
Any resource registered in the Clusterware can be managed by the Clusterware. Let's try managing
the Listener.
81. Issue the following statements to shutdown the Listener and start it up again.
srvctl stop listener
srvctl status listener
srvctl start listener
srvctl status listener
One of the advantages of using Oracle Restart is that it has the functionality to check on the running
processes from Grid and database homes and automatically restart them if they unexpectedly go
down. Let's test this functionality.
82. Exit from grid session so that the current session becomes root
83. Retrieve the process ID of the pmon process of the database instance.
ps -ef|grep ora_pmon
85. Keep running the following command a few times to check if the process is respawned.
The process must be respawning by the Clusterware.
ps -ef | grep ora_pmon
In this section of the practice, you will obtain information about the ASM instance.
89. Change the current user to grid then check the status of the ASM instance.
su - grid
srvctl status asm -verbose
97. Convert the SPFILE into PFILE and display its contents.
CREATE PFILE='/tmp/asmpfile.ora' FROM SPFILE;
host cat /tmp/asmpfile.ora
In this section of the practice, you will get familiar with using asmcmd to explore the ASM contents.
101. In this mode, we submit the command to the asmcmd command prompt interface.
asmcd
102. Issue the help command to see list of the supported commands
help
help ls
ls -?
104. Issue the following commands to a navigate the directories and files.
Observe the directory names passed to the command are case-insensitive, whereas the
commands themselves are case-sensitive. Observe the database file types stored in ASM.
The full name of a file or a directory always starts with a disk group name, which in turn starts
with a plus '+' sign.
ls
cd DATA
pwd
du
lsdg
lsdsk
cp command allows us to get a file out of the ASM disks to the file system accessible by the OS.
cp <file> /tmp
In this section of the practice, you will examine create a tablespace in ASM.
107. Exit from asmcmd then change the current user to oracle
quit
exit
su - oracle
108. Invoke SQL*Plus and login to the database as sys. Start PDB1.
sqlplus / as sysdba
ALTER PLUGGABLE DATABASE PDB1 OPEN;
By default, the database creates the tablespace datafiles in the DATA disk group.
show parameter db_create_file_dest
SELECT FILE_NAME
FROM DBA_DATA_FILES
WHERE TABLESPACE_NAME='MYTBS';
112. Exit from SQL*Plus and invoke RMAN with connecting PDB1 as target database
exit
rman target sys/ABcd##1234@pdb1
RMAN allows use to take copy of the database datafiles from ASM to the normal file system.
ALTER TABLESPACE MYTBS OFFLINE;
BACKUP AS COPY TABLESPACE MYTBS FORMAT '/media/sf_staging/mytbs.bak';
ALTER TABLESPACE MYTBS ONLINE;
exit
115. Shutdown srv1 and delete the snapshot taken for it.
Caution: Do not delete this vm. You will still use it for a the next practice.
Summary
• To configure Oracle Restart, we must install Oracle Grid Infrastructure in the system
• When is connected to an ASM instance, an Oracle database can save a variety of data types in
the ASM disk groups, like data files, control files, online redo log files, parameter file, backup files
and others.
• When an Oracle database process is abnormally turned down, Oracle restart automatically
respawns the process. This feature provides more high availability than when working without
ASM.
• We can obtain information about the ASM disk group and disks using SQL statements and
asmcmd utility commands.
• When OMF points to an ASM disk group, by default, the data files of the newly create tablespaces
are automatically saved into the OMF disk group. The full path of the datafile is automatically
defined.
• Normal OS commands cannot directly access the files saved in the ASM. We can make copies of
the ASM files to the traditional file systems using asmcmd. For database files, we can use SQL,
asmcmd, or RMAN.