Install Oracle Database 19c/21c on RHEL 8: prerequisites, patching and post-install settings
RHEL 8 preparation (groups, packages, kernel, limits), installation, OPatch update and post-install settings for Oracle 19c/21c.
This article summarises the preparation of a Red Hat Enterprise Linux 8 server for a single-instance Oracle Database 19c/21c installation (OS groups and user, packages, kernel and shell limits, environment scripts), the OPatch/Release Update procedure and a set of post-installation settings (control files, archive logs, OMF, ADR purge policy, HugePages, systemd autostart).
Passwordless sudo for an administration account
su -
echo -e "dba\tALL=(ALL)\tNOPASSWD: ALL" > /etc/sudoers.d/020_sudo_dba
cat /etc/sudoers.d/020_sudo_dba
Optional: minimal server and X11 forwarding for the installer
To run on a server without a full desktop (see the Red Hat solution 3887371 for the minimal graphical stack):
sudo dnf groupinstall -y "Minimal Install"
sudo dnf groupremove -y "Server with GUI"
sudo dnf groupinstall -y "Server"
sudo subscription-manager repos --enable=codeready-builder-for-rhel-8-x86_64-rpms
sudo yum install xorg-x11-server-Xorg xorg-x11-xauth xorg-x11-apps -y
In /etc/ssh/sshd_config:
AllowTcpForwarding yes
X11UseLocalhost yes
X11DisplayOffset 10
X11Forwarding yes
On the client side, enable forwarding in /etc/ssh/ssh_config:
sudo sed -i -E 's/#\s+ForwardX11 no/ForwardX11 yes/' /etc/ssh/ssh_config
Useful extras: sysstat (sar) and net-snmp if the server is monitored through SNMP.
sudo yum install sysstat
sudo systemctl enable sysstat
sudo systemctl start sysstat
OS groups and oracle user
Check which groups already exist:
getent group | grep oinstall
getent group | grep dba
getent group | grep oper
getent group | grep dgdba
getent group | grep kmdba
getent group | grep backupdba
Create the missing ones and the oracle user:
groupadd -g 54321 oinstall
groupadd -g 54322 dba
groupadd -g 54323 oper
sudo groupadd -g 65539 dgdba
sudo groupadd -g 65540 kmdba
sudo groupadd -g 65538 backupdba
sudo useradd -u 54321 -g oinstall -G dba,oper,backupdba,dgdba,kmdba oracle
If the oper GID is already used by another group (for example a monitoring group), pick a free GID.
Required packages
yum install -y bc binutils elfutils-libelf elfutils-libelf-devel fontconfig-devel \
glibc glibc-devel ksh libaio libaio-devel libXrender libXrender-devel libX11 libXau \
libXi libXtst libgcc librdmacm-devel libstdc++ libstdc++-devel libxcb make \
smartmontools sysstat net-tools gcc
compat-libcap1, compat-libstdc++-33 and libdtrace-ctf-devel do not exist on RHEL 8 and can be skipped.
If a perl binary of the installer fails with error while loading shared libraries: libnsl.so.1: cannot open shared object file, install:
dnf install -y libnsl libnsl.i686 libnsl2 libnsl2.i686
Kernel parameters
/etc/sysctl.d/99-oracle.conf:
fs.file-max = 6815744
kernel.sem = 250 32000 100 128
kernel.shmmni = 4096
kernel.shmall = 1073741824
kernel.shmmax = 4398046511104
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 2
net.ipv4.ip_local_port_range = 9000 65500
Apply without rebooting:
/sbin/sysctl -p
sysctl --system
Shell limits
/etc/security/limits.d/99-oracle-limits.conf:
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft nproc 16384
oracle hard nproc 16384
oracle soft stack 10240
oracle hard stack 32768
oracle soft memlock 134217728
oracle hard memlock 134217728
Optional system settings
- Transparent HugePages (if the server crashes, see My Oracle Support Doc ID 1557478.1): add
transparent_hugepage=nevertoGRUB_CMDLINE_LINUXin/etc/default/grub. - Firewall (only if your security policy allows it):
systemctl stop firewalld
systemctl disable firewalld
- SELinux in
/etc/selinux/config:
SELINUX=permissive
- Add the server name to
/etc/hosts, for example192.0.2.10 oradb01.example.com oradb01.
Directories
Example layout: ORACLE_BASE=/u1/app/oracle, ORACLE_HOME=/u1/app/oracle/product/19c/dbhome_1, data in /u2/oradata, recovery and dumps in /u3.
mkdir -p /u1/app/oracle/product/19c/dbhome_1
mkdir -p /u1/app/oraInventory
mkdir -p /u2/oradata
mkdir -p /u3/oracle/fast_recovery_area
mkdir -p /u3/oracle/archivelog
chown -R oracle:oinstall /u1 /u2 /u3
chmod -R 775 /u1 /u2 /u3
Environment and start/stop scripts (oracle user)
mkdir /home/oracle/scripts/
cat > /home/oracle/scripts/setEnv.sh <<EOF
# Oracle Settings
export TMP=/tmp
export TMPDIR=\$TMP
export ORACLE_HOSTNAME=oradb01.example.com
export ORACLE_UNQNAME=ORCL
export ORACLE_BASE=/u1/app/oracle
export ORACLE_HOME=\$ORACLE_BASE/product/19c/dbhome_1
export ORA_INVENTORY=/u1/app/oraInventory
export ORACLE_SID=ORCL
export DATA_DIR=/u2/oradata
export PATH=/usr/sbin:/usr/local/bin:\$PATH
export PATH=\$ORACLE_HOME/bin:\$PATH
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib
EOF
echo ". /home/oracle/scripts/setEnv.sh" >> /home/oracle/.bash_profile
cat > /home/oracle/scripts/start_all.sh <<EOF
#!/bin/bash
. /home/oracle/scripts/setEnv.sh
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES
dbstart \$ORACLE_HOME
EOF
cat > /home/oracle/scripts/stop_all.sh <<EOF
#!/bin/bash
. /home/oracle/scripts/setEnv.sh
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES
dbshut \$ORACLE_HOME
EOF
chown -R oracle:oinstall /home/oracle/scripts
chmod u+x /home/oracle/scripts/*.sh
Installation
Unzip the software into the Oracle home and start the installer:
unzip /u2/temp/LINUX.X64_213000_db_home.zip -d /u1/app/oracle/product/21c/dbhome_1
cd /u1/app/oracle/product/21c/dbhome_1
./runInstaller
If the installer's prerequisite check does not recognise RHEL 8, set the assumed distribution id before launching it:
sed -i 's/#CV_ASSUME_DISTID=OEL5/CV_ASSUME_DISTID=OEL8/' $ORACLE_HOME/cv/admin/cvu_config
When the installation is finished, check the alert log: nothing abnormal should be reported.
Patching: update OPatch and apply a Release Update
Back up and replace OPatch with the version matching your release (downloaded from My Oracle Support, patch 6880880):
DATE=$(date '+%Y%m%d%H%M%S')
cd $ORACLE_HOME
tar -zcvf OPatch-${DATE}.tgz $ORACLE_HOME/OPatch
mv *.tgz /u3/oracle/backup/
tar -tvf /u3/oracle/backup/OPatch-${DATE}.tgz
cp /u2/temp/p6880880_210000_Linux-x86-64.zip $ORACLE_HOME
cd $ORACLE_HOME
rm -rf OPatch/
unzip p6880880_210000_Linux-x86-64.zip
export PATH=$PATH:$ORACLE_HOME/OPatch
$ORACLE_HOME/OPatch/opatch lsinventory
Unzip the Release Update, then check conflicts and free space before applying it:
cd /u2/temp/
unzip <patch_zip_file>
$ORACLE_HOME/OPatch/opatch prereq CheckConflictAgainstOHWithDetail -phBaseDir /u2/temp/<patch_id>/<sub_patch_id>
cat > /tmp/patch_list_dbhome.txt <<EOF
/u2/temp/<patch_id>/<sub_patch_id_1>
/u2/temp/<patch_id>/<sub_patch_id_2>
EOF
$ORACLE_HOME/OPatch/opatch prereq CheckSystemSpace -phBaseFile /tmp/patch_list_dbhome.txt
Apply it (database and listener stopped), then run datapatch:
cd <UNZIPPED_PATCH_LOCATION>/<patch_id>/<sub_patch_id>
opatch apply
sqlplus /nolog
connect / as sysdba
startup
quit
cd $ORACLE_HOME/OPatch
./datapatch -verbose
$ORACLE_HOME/OPatch/opatch lsinventory
If opatch apply complains that a library is in use, find and stop the processes holding it, then retry:
/sbin/fuser $ORACLE_HOME/lib/libclntsh.so.<version>
ps -ef | grep <pid>
kill -9 <pid>
Post-installation settings
Save the parameter file
column TODAY new_value datestr;
SELECT TO_CHAR (SYSDATE, 'YYYYMMDDHH24MISS') "TODAY" FROM DUAL;
define myv = &DATESTR._spfile.ora
define myv
create pfile='/u3/oracle/fast_recovery_area/ORCL/&myv' from spfile;
Multiplex the control files on separate file systems
Current location:
select name from v$controlfile;
set linesize 400
column NAME_COL_PLUS_SHOW_PARAM format A40
column TYPE format A20
column VALUE_COL_PLUS_SHOW_PARAM format A100
show parameter control_files;
Change the parameter, then (with the database shut down) move/copy the files to the new locations and start the database:
alter system set control_files='/u1/app/oracle/admin/ORCL/control01.ctl',
'/u2/oradata/ORCL/control02.ctl',
'/u3/oracle/fast_recovery_area/ORCL/control03.ctl'
scope=spfile;
mv /u2/oradata/ORCL/control01.ctl /u1/app/oracle/admin/ORCL/control01.ctl
cp /u1/app/oracle/admin/ORCL/control01.ctl /u2/oradata/ORCL/control02.ctl
mv /u3/oracle/fast_recovery_area/ORCL/control02.ctl /u3/oracle/fast_recovery_area/ORCL/control03.ctl
Move the archive logs out of the fast recovery area
show parameter log_archive_dest_1;
show parameter db_recovery;
alter system set log_archive_dest_1 = 'LOCATION=/u3/oracle/archivelog/ORCL';
alter system set db_recovery_file_dest = '';
show parameter log_archive_dest_1
alter system set LOG_ARCHIVE_FORMAT = "log%t_%s_%r.arc" scope=spfile;
Oracle Managed Files (OMF)
show parameter db_create_file_dest
show parameter db_create_online_log_dest
alter system set db_create_file_dest = '/u2/oradata/ORCL/datafile' scope=both;
alter system set db_create_online_log_dest_1 = '/u2/oradata/ORCL/onlinelog' scope=both;
ADR retention policy (adrci)
show homes
set home diag/rdbms/orcl/ORCL
show control
set control (SHORTP_POLICY=14)
set control (LONGP_POLICY=21)
purge
show base
Purge manually by age (in minutes, 168 hours here is 10080 minutes):
purge -age 10080 -type TRACE
purge -age 10080 -type ALERT
To apply a policy to every ADR home, loop over the output of adrci exec="show home":
#!/bin/sh
for ADRHOME in `adrci exec="show home"`
do
if [ $ADRHOME = "ADR" -o $ADRHOME = "Homes:" ]
then
continue;
fi
echo $ADRHOME
adrci <<EOF
set home $ADRHOME
set control (SHORTP_POLICY = 168)
set control (LONGP_POLICY = 168)
purge
exit
EOF
done
HugePages and swappiness
In /etc/sysctl.conf (the group id is the one of the dba group, check it with getent group dba):
vm.nr_hugepages=1003
vm.hugetlb_shm_group=54322
vm.swappiness = 0
Reboot, then check:
grep Huge /proc/meminfo
Other database settings
ALTER SYSTEM SET FILESYSTEMIO_OPTIONS=SETALL SCOPE=SPFILE;
Example of memory parameters on a small instance (show parameter pga, show parameter sga): pga_aggregate_target 250M, pga_aggregate_limit 2G, sga_target and sga_max_size 1504M.
Add redo log members (one per group, on another file system):
ALTER DATABASE ADD LOGFILE MEMBER '/u2/oradata/ORCL/redo01b.log' TO GROUP 1;
ALTER DATABASE DROP LOGFILE MEMBER '/u2/oradata/ORCL/redo02.log';
ALTER DATABASE ADD LOGFILE MEMBER '/u2/oradata/ORCL/redo02b.log' TO GROUP 2;
Autostart with systemd
Create /etc/systemd/system/oracle-db.service (see Martin Bach's article on starting a single-instance database with systemd):
[Unit]
Description=a service to start databases and listener automatically
After=syslog.target network.target
[Service]
LimitNOFILE=1024:65536
LimitNPROC=2047:16384
LimitSTACK=10485760:33554432
LimitMEMLOCK=infinity
Type=forking
User=oracle
Group=oinstall
ExecStart=/u1/app/oracle/product/19c/dbhome_1/bin/dbstart /u1/app/oracle/product/19c/dbhome_1
ExecStop=/u1/app/oracle/product/19c/dbhome_1/bin/dbshut /u1/app/oracle/product/19c/dbhome_1
RemainAfterExit=True
Restart=no
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable oracle-db
sudo systemctl start oracle-db
sudo systemctl status oracle-db
Read-only monitoring account
Example of grants for a monitoring tool (the password is a placeholder):
CREATE USER monitor_usr IDENTIFIED BY "<PASSWORD>" DEFAULT TABLESPACE "USERS" TEMPORARY TABLESPACE "TEMP";
GRANT CREATE SESSION TO monitor_usr;
GRANT SELECT_CATALOG_ROLE TO monitor_usr;
GRANT CONNECT TO monitor_usr;
GRANT SELECT ANY DICTIONARY TO monitor_usr;
GRANT SELECT ON V_$SYSSTAT TO monitor_usr;
GRANT SELECT ON V_$INSTANCE TO monitor_usr;
GRANT SELECT ON V_$LOG TO monitor_usr;
GRANT SELECT ON SYS.DBA_DATA_FILES TO monitor_usr;
GRANT SELECT ON SYS.DBA_FREE_SPACE TO monitor_usr;
ALTER USER monitor_usr DEFAULT ROLE "SELECT_CATALOG_ROLE","CONNECT";
GRANT SELECT ANY TABLE TO monitor_usr;
Notes
- Sendmail is deprecated since RHEL 7 in favour of postfix. If mail sending from scripts fails after installing it, the following helped:
sudo yum install postfix mailx -y
sudo mkfifo /var/spool/postfix/public/pickup
sudo systemctl restart postfix
- The source mixes 19c and 21c paths: adapt the Oracle home path and the patch/OPatch file names to your release.
- Disabling the firewall and setting SELinux to permissive are shortcuts; apply your own security policy.
kill -9on processes holding a library should only be used after checking what they are.