Tuesday 18 August 2020

Installing Oracle DB 19c on Oracle Linux 8.2 in VirtualBox

This post is part of my Oracle DB Developers VM series. Based on the previous postings on how to set up Oracle Linux 8 on VirtualBox, this post will show how to install the Oracle DB 19.3 in this environment on a beginners level.
The Oracle DB installation on Oracle Linux is straight forward as expected. In this post, I will only list the needed steps for the Oracle Developer VM configuration. For a full documentation and/or installing a production environment, follow the official Oracle documentation and/or have a look at the guide on Oracle-Base. The official documentation is longer for a reason. It covers many more options like other Linux distros (inclusive Linux on IBM System Z), clustering, other storage and networking options. If these are not needed, this post is a quick installation guide.
In this example, we will use the new Image-Based Oracle Database Installation. Download the Oracle DB 19.3 software image from the Oracle Software Delivery Cloud or OTN. If you download it from the host OS, put the zip file somewhere into the shared folders of your VM. I recommend downloading from the host OS, because you can use the install media for several VM's without needing extra space on your HDD.

sudo mkdir -p /u01/app/oracle/product/19.0.0/dbhome_1
sudo chown -R oracle:oinstall

Create the Oracle install directory on the volume we created in the last episode and grant it to the oracle user and group.

Edit .bashrc and add the following to set a minimal environment:

export TMP=/tmp
export TMPDIR=$TMP

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/19.0.0/dbhome_1
export ORACLE_SID=orcl

export PATH=$ORACLE_HOME/bin:$PATH

export TNS_ADMIN=$ORACLE_HOME/network/admin

Also add the following line to your .bash_profile to run .bashrc on logon:

. .bashrc

Next extract the software to the Oracle home directory and run the installer, in my case

cd $ORACLE_HOME
unzip ~/ddrive/Install/Linux-x64/LINUX.X64_193000_db_home.zip
export CV_ASSUME_DISTID=OEL8.2
./runInstaller
The DISTID is needed to suppress a warning message.

The installation is straight forward, mostly clicking Next on each step:


 Give it a password and ignore the message

 Allow it to run the root script and give it your root password

Click Yes because that is what we gave it the root password for and get a coffee.
When finished, the installer invites you to Oracle Enterprise Manger Database Express
Close the installer and open the URL, accept the https exception in your browser and log in with system and your password.
Looks good. Close the browser and go back to the shell to double check if the command line tools are working.
Check the listener with lsnrctl stat.
Try sqlplus / as sysdba with show sga ...
... and it's younger brother SQLcl with sql / as sysdba  and any complex SQL statement you can think of.

To not always need to run .oraenv on every new shell, especially when mostly using the same database anyways, also add the following to your .bashrc:

export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES

By setting ORAENV_ASK back to YES, you can always use .oraenv to switch to a different database.

Add the PDB to your $ORACLE_HOME/network/admin/tnsnames.ora


  (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))


ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

ORCLPDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orclpdb)
    )
  )

Just copy the entry for ORCL and replace both occurrences with ORCLPDB.

To have at least one user to play with, enable the HR schema. Connect to the DB with sql system@orclpdb and enter:

alter user hr account unlock identified by hr;
grant connect, resource to hr;

Of course this are no security best practices and you will wisely choose a secure password and will grant fine granulated rights.

Optional: connect from the outside
If you only plan to use this DB with the tooling from inside the VM, you are already done. For connecting from the outside, make sure that the Listener listens on the host only network adapter.
Open /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/listener.ora in your editor. If it only listens on localhost it will not listen to traffic on the host only network vor VirtualBox like here:


LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

Change the localhost to the hostname of your VM, the same that you put into /etc/hosts.
(Note: for whatever reason, the hostname does not work on my system, so I used the IP address instead)

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.56.104)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) )

Restart your Listener with lsnrctl stop and lsnrctl start, then check it's status with lsnrctl stat.
It should now listen on both, your external and local IP addresses.

The fastest and easiest way of getting a development instance of the Oracle DB is using the Oracle Cloud. But when a local installation is needed, having a proper set up Linux machine or VM, installing a simple Oracle DB for Developers is quick and easy.