Install Oracle Database 12c on Red Hat AWS EC2 Instance — Part 4: Install Database and Create Instance

Luiz Eduardo Zappa
6 min readSep 5, 2021

--

This is a series of articles I’ve been describing from scratch how to provision an instance on AWS EC2 with Red Hat (RHEL 7), install the Oracle Database 12c just from the command line, and finally connect through SQL Developer from a remote computer.

So to the article doesn’t get too long, I divided it into parts. I recommended reading from the beginning, as the subjects are linked and an initial configuration can impact the final result you are here:

Part 1: Launch AWS EC2 Instance with RHEL 7 and connect with SSH (Windows using Putty)

Part 2: Setup Red Hat to receive the Oracle Database installation

Part 3: Download Oracle 12c and transfer to AWS EC2 instance with Secure Copy Client (SCP)

Part 4 (This article): Install Oracle Database and Create Instance

Install Oracle Database on Red Hat AWS EC2 Instance

In this article we will install the oracle database. You must be in the oracle user. If not, switch to this user with this command:

su - oracle

Navigate to ~/database/response

cd ~/database/response

Let’s create a backup copy of the file db_install.rsp

cp db_install.rsp db_install.rsp.bak

Edit the db_install.rsp with vi editor

vi db_install.rsp

Change the following file variables:

oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=<your-hostname>
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oraInventory
ORACLE_HOME=/u01/app/oracle/product/12.1.0.2/db_1
ORACLE_BASE=/u01/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oper
oracle.install.db.BACKUPDBA_GROUP=backupdba
oracle.install.db.DGDBA_GROUP=dgdba
oracle.install.db.KMDBA_GROUP=kmdba
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false
DECLINE_SECURITY_UPDATES=true

Change <your-hostname> by hostname defined in the first article.

Save and close the file with :wq

Navigate to folder ~/database

cd ~/database

Then, start a new screen session with screen

This will open a screen session, create a new window, and start a shell in that window. If the connection is lost during the installation, you can reconnect and resume your screen session using the following commands:

First, find the session ID of the screen with:

su - oracle
screen -ls
The highlighted number is your session id

Then restore screen with:

screen -r 4065

Returning to the installation.. Execute the installer with this command:

./runInstaller -silent -responseFile ~/database/response/db_install.rsp -ignorePrereq -ignoreSysPrereqs -waitforcompletion -showProgress

A warning message should appear indicating that the Oracle home directory is not empty. It does not affect the installation. Wait for installation.

[INS-32016] The selected Oracle home contains directories or files.

Sometimes the installation has memory errors because we are using AWS Free Tier and we have only 1GB of memory. The message is usually this:

Error in invoking target 'irman ioracle' of makefile
'/u01/app/oracle/product/12.1.0/dbhome_1/rdbms/lib/ins_rdbms.mk'.
See '/u01/app/oraInventory/logs/installActions2015(...).log' for details.

Inside the log file, the error is encountered:

INFO: collect2: ld terminated with signal 9 [Killed]

To solve this relink irman and ioracle with these commands:

cd $ORACLE_HOME/rdbms/admin
/usr/bin/make -f $ORACLE_HOME/rdbms/lib/ins_rdbms.mk ioracle
/usr/bin/make -f $ORACLE_HOME/rdbms/lib/ins_rdbms.mk irman

After installation, we need to run two scripts indicated at installation. Switch to ec2-user with logout . If you are using screen, first you need to exit screen with exit and then type logout

Run the first script:

sudo /u01/app/oraInventory/orainstRoot.sh

Run the second script:

sudo /u01/app/oracle/product/12.1.0.2/db_1/root.sh

Let’s remove the zip files to gains some space. Enter the following commands:

cd /tmp
sudo rm -rf V46095-01_1of2.zip
sudo rm -rf V46095-01_2of2.zip

Let’s test the connection. Switch back to oracle user:

su - oracle

Run the following command:

sqlplus / as sysdba

You should receive this message:

Exit sqlplus with quit

Create a database directory and flash recovery directory. Here you should initialize a new screen session (with screen) to allow you to reconnect if connection is lost during installation.

mkdir -p /u01/app/oracle/ordata_oracle12c
mkdir -p /u01/app/oracle/flash_recovery_area

Create instance:

dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname orcl -sid orcl -responseFile NO_VALUE -characterSet AL32UTF8 -sysPassword oracle -systemPassword oracle -createAsContainerDatabase true -numberOfPDBs 1 -pdbName pdborcl -pdbAdminPassword oracle -databasetype MULTIPURPOSE -automaticMemoryManagement false -totalMemory 800 -storageType FS -datafileDestination "/u01/app/oracle/ordata_oracle12c" -recoveryAreaDestination "/u01/app/oracle/flash_recovery_area" -redoLogFileSize 50 -emConfiguration NONE -listeners LISTENER -ignorePreReqs

Change the parameters in bold if you have created a SID other than the one indicated

After installation, edit the /etc/oratab file to indicate the database should be started when the system is booted. Switch to ec2-user with logout . If you are using screen, first you need to exit screen with exit and then type logout

Edit the file with:

sudo vi /etc/oratab

Paste this (remember to press i to enter vi Insert Mode), then save and close file (press ESC to exit vi Insert Mode, and type :wq)

orcl:/u01/app/oracle/product/12.1.0.2/db_1:Y

Switch back to oracle user with:

su - oracle

Let’s configure LISTENER and TNSNAMES.

netca -silent -responseFile /u01/app/oracle/product/12.1.0.2/db_1/assistants/netca/netca.rsp

Open listener.ora file:

vi $ORACLE_HOME/network/admin/listener.ora

Change the contents of the file for this:

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = redhatsrv)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_NAME = orcl)
(SID_NAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/12.1.0.2/db_1)
)
)
DEFAULT_SERVICE_LISTENER = orcl

Change the texts in bold if you used another hostname or SID name.

Save and close the file.

Reload the listener with:

lsnrctl reload

Open tnsnames.ora file:

vi $ORACLE_HOME/network/admin/tnsnames.ora

Change the contents of the file for this:

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

Change the texts in bold if you used another hostname or SID name.

Save and close the file.

Reload the listener with:

lsnrctl reload

Let’s save the state from pluggable database. Connect as sysdba:

sqlplus / as sysdba

Enter the follow command:

alter pluggable database pdborcl save state;
exit;

Our instance database is on, let’s connect to it through SQL Developer on our computer. First, install SQL Developer (download link).

Open SQL Developer, then click View > SSH. A window will appear in the left corner of your screen. Righ click on SSH Hosts, and choose New SSH Host..

Create new SSH Host on SQL Developer

Enter a name to this Host, in Host enter the Public IPv4 DNS (as described in first article), Port is 22 , Username is ec2-user , click to use key file and select the pem file downloaded when we created the EC2 instance. Click to Add a Local Port Forward, and click OK.

New SSH Host Configurations

Create a New Database Connection

New Database Connection on SQL Developer

Enter the desired name, Username is sys, Password is oracle (the password when oracle instance database was created), Role is SYSDBA, connection type is SSH, an choose the SSH Host created in the last step. SID is orcl (if you are using the same nomenclature as mine). Click Save and close the window.

SQL Developer — Connection Database configurations

It will be necessary to restart SQL Developer. After that, right click on the created database connection and choose Connect

To test the connection, in SQL Woksheet run this query:

select * from v$instance;

The ouput should be like this:

Some people have problem with SSH tunneling on SQL Developer. If you are one of them, you can perform this tunneling directly through the Windows Prompt. Open the command and enter:

ssh -i C:\path\your-key-pair.pem -N -L 8250:aws-ec2-public-IPv4-DNS:1521 ec2-user@aws-ec2-public-IPv4-DNS

Change C:\path\your-key-pair.pem to the path to the key pair file downloaded from AWS and the two entries aws-ec2-public-IPv4-DNS to your AWS EC2 public IPv4 DNS.

After you issue this command, the terminal remains open and does not return a response. Return to SQL Developer and create a new connection with the same parameters indicates a few steps back. But in connection type, use the Basic one, with hostname being localhost and port 8250.

Now the connection to the database should work.

Alright! We were able to install oracle database on an AWS EC2 instance and connect externally through SQL Developer!

--

--

Luiz Eduardo Zappa

Engineer breaking into the world of information technology 👨‍💻 I comment on what I'm developing on https://twitter.com/imluizzappa