Ivan Kartik - Oracle and Linux Blog

Configuring automatic startup of Oracle Database under systemd on RHEL 7/OEL 7/CentOS 7

There are several methods how to start Oracle Database automatically during/after OS boot. You can use Oracle CRS, other clusterware or init implemented in Linux. Starting RHEL 7 SysV init has been replaced by systemd or simply said systemd is the new init system.

In these days not only group of Linux users became polarized but also whole Linux world became polarized as well. Mostly Redhat based distributions have adopted systemd, other distributions are reluctant to implement systemd and either are continuing to use SysV init or migrated to another solutions e.g. Upstart. Despite this fact most of the Oracle certified Linux distributions (such as Redhat or SuSE and their (even not certified) clones) are using the systemd.

This post briefly shows how to configure systemd service for automatic start of Oracle Databases and Listener and these steps are applicable for Redhat Enterprise Linux 7, Oracle Enterprise Linux 7, CentOS 7 or SuSE Linux Enteprise Server 12 and Fedora 15 (or later).

Typically systemd startup configuration consists of two parts:

  • unit file - using ".service" suffix (in case of service), typically stored in /usr/lib/systemd/system or /etc/systemd/system directory for units provided by installed packages or /usr/lib/systemd/user or /etc/systemd/user directory for units installed by administrator
  • environment file (optional) - typically stored in /etc/sysconfig directory on RHEL and it's clones. We don't need it in our case.

Creating the unit for automatic startup/shutdown of Oracle Database manually

Logon as root user create and edit /etc/systemd/system/oracle-rdbms.service and add following content:

# /etc/systemd/system/oracle-rdbms.service
#   Invoking Oracle scripts to start/shutdown Instances defined in /etc/oratab
#   and starts Listener

[Unit]
Description=Oracle Database(s) and Listener
Requires=network.target

[Service]
Type=forking
Restart=no
ExecStart=/opt/oracle/12102/bin/dbstart /opt/oracle/12102
ExecStop=/opt/oracle/12102/bin/dbshut /opt/oracle/12102
User=oracle

[Install]
WantedBy=multi-user.target

 Note that this configuration assumes that our ORACLE_HOME is /opt/oracle/12102. It's recommended to use PIDFile while using "forking" type but we don't need it. As you can see well known scripts (shipped with Oracle Database) are executed for startup/shutdown using path to Oracle Home in order to specify the Oracle Home for Listener process. As shown these scripts are executed under "oracle" user account/privileges. More over service can be started once network is cofigured (started) and service starts in multi-user level (more less equivalent of runlevel 3 in SysV init)

Now we have to reload systemd in order to register unit file (as root) and enable the service.

systemctl daemon-reload
systemctl enable oracle-rdbms

 So, now the startup service should be created and enabled but to be sure we can check it by following command (Note: first line is OS command, other lines is the output):

systemctl status oracle-rdbms
oracle-rdbms.service - Oracle Database(s) and Listener
   Loaded: loaded (/etc/systemd/system/oracle-rdbms.service; enabled)

According to output our service is enabled succesfully and should be started on next OS boot. To start the service without reboot of machine you can use following command:

systemctl start oracle-rdbms

 

Creating the unit for automatic startup/shutdown of Oracle Database using script

I have created a simple script which automatically performs above tasks for creating and enabling startup service. This scripts contains simple checks (as I've tried to make the script bulletproof), then lists available Oracle homes that exist on OS and then asks to specify Oracle home from which the Listener will be started. Note that it's important to specify Oracle home for the highest version of Oracle software as Listener will be handling connections for all Oracle homes.

#!/usr/bin/bash

# This script configures systemd startup service for Oracle Databases and Listener
# Ivan Kartik http://ivan.kartik.sk

if [ `whoami` != "root" ]; then
   echo "root login required!"
   exit
fi

if [ `uname -s` != "Linux" ]; then
   echo "This is not Linux!"
   exit
fi

if [ `ps -e|grep " 1 ?"|cut -d " " -f15` != "systemd" ]; then
   echo "Systemd is not present, use Init scripts instead!"
   exit
fi

echo "List of existing Oracle Homes:"
echo "------------------------------"
cat `cat /etc/oraInst.loc|grep inventory_loc|cut -d '=' -f2`/ContentsXML/inventory.xml|grep "HOME NAME"|cut -d '"' -f 4
echo 

echo "Enter ORACLE_HOME of Oracle Listener [$ORACLE_HOME]:"
read NEWHOME

case "$NEWHOME" in
     "")         ORAHOME="$ORACLE_HOME" ;;
     *)          ORAHOME="$NEWHOME" ;;
esac

if [ -z $ORAHOME ]; then
   echo "Error: Missing value!"
   exit
fi

if [ -f $ORAHOME/bin/lsnrctl ]; then
   echo '# /etc/systemd/system/oracle-rdbms.service
# Ivan Kartik http://ivan.kartik.sk
#   Invoking Oracle scripts to start/shutdown Instances defined in /etc/oratab
#   and starts Listener

[Unit]
Description=Oracle Database(s) and Listener
Requires=network.target

[Service]
Type=forking
Restart=no
ExecStart='$ORAHOME'/bin/dbstart '$ORAHOME'
ExecStop='$ORAHOME'/bin/dbshut '$ORAHOME'
User=oracle

[Install]
WantedBy=multi-user.target' > /etc/systemd/system/oracle-rdbms.service

    systemctl daemon-reload
    systemctl enable oracle-rdbms
    echo "Done! Service oracle-ordbms has been configured and will be started during next boot."
    echo "If you want to start service now, execute: systemctl start oracle-rdbms"
else
   echo "Error: No Listener script under specified ORACLE_HOME: $ORAHOME"
   exit
fi
 

You either can copy/paste this code or download here: http://ivan.kartik.sk/scripts/oracle_systemd_service.sh

Final check of service and started databases (Note: Output from systemctl status has been shortened):

# cat /etc/oratab |grep :Y
ORA12CR1:/opt/oracle/12102:Y
ORA11GR2:/opt/oracle/11204:Y

# systemctl status oracle-rdbms
oracle-rdbms.service - Oracle Database(s) and Listener
   Loaded: loaded (/etc/systemd/system/oracle-rdbms.service; enabled)
   Active: active (running) since Mon 2015-11-15 14:51:13 CET; 54s ago
  Process: 425 ExecStart=/opt/oracle/12102/bin/dbstart /opt/oracle/12102 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/oracle-rdbms.service
           ├─ 452 /opt/oracle/12102/bin/tnslsnr LISTENER -inherit
           ├─1155 ora_pmon_ORA12CR1
           ├─1171 ora_vktm_ORA12CR1
           ├─1177 ora_gen0_ORA12CR1
           ├─1181 ora_mman_ORA12CR1
           ├─1183 ora_diag_ORA12CR1
           ├─1185 ora_dbrm_ORA12CR1
           ├─1195 ora_ckpt_ORA12CR1
           ├─1197 ora_smon_ORA12CR1
           ├─1199 ora_reco_ORA12CR1
           ├─1201 ora_lreg_ORA12CR1
           ├─1289 ora_mman_ORA11GR2
.....   
           ├─1291 ora_dbw0_ORA11GR2
           ├─1293 ora_lgwr_ORA11GR2
           ├─1295 ora_ckpt_ORA11GR2
           ├─1297 ora_smon_ORA11GR2
           ├─1299 ora_reco_ORA11GR2
           ├─1301 ora_mmon_ORA11GR2
           ├─1303 ora_mmnl_ORA11GR2
           ├─1350 ora_qmnc_ORA11GR2
           └─1450 ora_q001_ORA11GR2

Nov 15 14:50:57 oel01 dbstart[425]: Processing Database instance "ORA12CR1": log file /opt/oracle/12102/startup.log
Nov 15 14:51:07 oel01 dbstart[425]: Processing Database instance "ORA11GR2": log file /opt/oracle/11204/startup.log
Nov 15 14:51:13 oel01 systemd[1]: Started Oracle Database(s) and Listener.

For little comparison of difference commands or usage regarding SysV init and systemd, here is very nice cheat sheet created by guys from Linoxide.com it's downloadable here: http://images.linoxide.com/systemd-vs-sysVinit-cheatsheet.pdf

Systemd Homepage: http://www.freedesktop.org/wiki/Software/systemd/

 

Be(a)ware of Licensing policy changes regarding Infrastructure Repository Databases

Oracle Database 12c comes with another significant change regarding using of Infrastructure Repository Databases and which could eventually make things more complicated. Before upgrade of Oracle Database, Database Administrator or a person responsible for Software Asset Management (and Licensing) should be familiar with changes in Licensing policy which come with new release and their implications. At first let me start with little comparison of probably the most frequently used versions in production 10gR2, 11gR2 and new 12cR1 to see an "evolution".

 

Here is an excerpt from the Licensing Guide and Enterprise Manager Licensing Information Guide for 10gR2:

"Infrastructure Repository Databases

A separate Oracle Database can be installed and used as a Recovery Manager (RMAN) repository without additional license requirements, provided that all the Oracle databases managed in this repository are correctly licensed. This repository database may also be used for the Oracle Enterprise Grid Control repository. It may not be used or deployed for other uses.

A separate Oracle Database can be installed and used as an Oracle Enterprise Manager Grid Control (OEM Grid Control) repository without additional license requirements, provided that all the targets (databases, applications, and so forth) managed in this repository are correctly licensed. This database may also be used for the RMAN repository. It may not be used or deployed for other uses.

Enterprise Manager Restricted-use License

Enterprise Manager includes a restricted-use license of the Oracle Database for use as the Oracle Management Repository only."

 

Here is the excerpt from the same guides for 11gR2:

"Infrastructure Repository Databases

A separate Oracle Database can be installed and used as a Recovery Manager (RMAN) repository without additional license requirements, provided that all the Oracle databases managed in this repository are correctly licensed. This repository database may also be used for the Oracle Enterprise Grid Control repository. It may not be used or deployed for other uses.

A separate Oracle Database can be installed and used as an Oracle Enterprise Manager Grid Control (OEM Grid Control) repository without additional license requirements, provided that all the targets (databases, applications, and so forth) managed in this repository are correctly licensed. This database may also be used for the RMAN repository. It may not be used or deployed for other uses.

 Enterprise Manager Restricted-use License

Enterprise Manager includes a restricted-use license of the Oracle Database for use as the Oracle Management Repository only.

Additional database options or additional servers for disaster recovery require separate licensing. Customers receive one single-instance database with the Grid Control, or RMAN, repository. To protect the repository with Data Guard, customers need to purchase a license for the standby site. To protect the repository with Oracle Real Application Clusters, customers must license the second node for the database, and both nodes require an Oracle Real Application Clusters license."

 

And here is the excerpt from the Licensing Information Guide guide for 12cR1:

"Infrastructure Repository Databases

A separate single instance Oracle Database can be installed and used as an infrastructure repository for RMAN, Oracle Enterprise Manager Cloud Control, Automatic Workload Repository (AWR) Warehouse, Global Data Services Catalog, and Grid Infrastructure Management Repository without additional license requirements, provided that all the targets are correctly licensed. It may not be used or deployed for other uses.

The infrastructure repositories for RMAN, Oracle Enterprise Manager Cloud Control, AWR Warehouse, and Global Data Services Catalog can be shared in one database, or deployed in separate databases. Enterprise Edition must be used for the infrastructure repository database(s).

If Oracle RAC is used for the infrastructure database, then Oracle RAC licenses for all servers, and Enterprise Edition licenses for all but the first server, are required.

If Data Guard is used for the infrastructure database, then an Enterprise Edition license for the standby server is required."

 

By comparison of above excerpts where you can see differences and changes regarding Infrastructure Repository Databases (later just IRD) for particular release. Since 12c (12cR1) there is a significant change regarding edition of the Oracle Database. Current 12c Guide simply says:

  1. If Standard Edition is used as IRD and you want to upgrade the repository database to 12c, then you have to migrate it to Enterprise Edition (later just EE)
  2. If current repository database is running in RAC mode, second or any additional node node is extra licensed (EE), moreover all servers must have RAC option licensed
  3. If current repository database is using Data Guard, a standby server has to be licensed extra licensed

 Well honestly in days of "cost cutting" where many companies are more and more looking at/for alternative solutions or even they are already in process of migration from Oracle to alternative solutions, claiming that "Oracle is expensive", then this is definitely backward step from the Oracle Corp. Oracle Database 12c comes with quite interesting and very useful features regarding Recovery Manager (RMAN) which is teasing us to use new version (of course for manipulation witch PDB's 12c version of RMAN is a must). But still there is a trade-off. To stay with the 11gR2 Recovery Manager thus use old 11gR2 Infrastructure Repository Database and as long as possible (forget about 12c RMAN features including multitenant) or even trying some other workarounds (e.g. relocate RMAN repository to some fully licensed servers or divide centralized repository (catalog) to several (repositories) catalogs and spread it across licensed HA databases) in order to prevent pay additional fees for high available Infrastructure Database. Honestly I would expect a little favor here.

But enough of blaming Oracle and let's see an example why Recovery Manager requires Enterprise Edition and what would happen when you try to use Standard Edition as a RMAN repository.

I have prepared fresh 12.1.0.1 Standard edition (12.1.0.2 isn't still available) using DB_NAME=RMANDB as a repository for RMAN catalog(s) in order to see whether EE is explicitly requested.

12.2.0.2 Enterprise Edition (EE) is used as "target" database using DBNAME=ORA12CR1

 

RMANDB:SQL> select banner from v$version where rownum = 1;

BANNER
--------------------------------------------------------------------------------
Oracle Database 12c Release 12.1.0.1.0 - 64bit Production


RMANDB:SQL> create user rman12 identified by rman default tablespace data;

User created.

RMANDB:SQL> grant recovery_catalog_owner, unlimited tablespace to rman12;

Grant succeeded.

 

Used rman command on future "target" DB host (12.1.0.2 EE):

RMAN> connect catalog rman12/rman@rmandb

connected to recovery catalog database
ORACLE error from recovery catalog database: ORA-06550: line 1, column 41:
PLS-00201: identifier 'DBMS_RCVCAT.GETPACKAGEVERSION' must be declared
ORA-06550: line 1, column 34:
PL/SQL: Statement ignored

If you got this error then you have to execute @?/rdbms/admin/dbmsrmansys.sql in order to fix this issue (I had to use this script from 12.1.0.2 home as my SE is 12.1.0.1).

 

Let's continue with creating a catalog:

RMAN> connect catalog rman12/rman@rmandb

connected to recovery catalog database

RMAN> create catalog;

error creating create_deleted_object_seq
ORACLE error from recovery catalog database: ORA-00439: feature not enabled: Partitioning

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-06433: error installing recovery catalog

If you've got error as above, it means you aren't using Enteprise Edition as Partitioning requires EE or Partitioning option is not enabled.

 

RMAN> connect catalog rman12/rman@rmandb

connected to recovery catalog database

RMAN> create catalog

recovery catalog created
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-06004: ORACLE error from recovery catalog database: ORA-00439: feature not enabled: Fine-grained access control

And finally if you've got this one, it means that you aren't using Enteprise Edition (as Fine-grained access control is available in EE) and moreover you did very nasty thing in order to overcome previous error.

 New RMAN features rely on Partitioning, Virtual Private Database and Fine-grained access control (which is a part of VPD) which definitely require Enterprise Edition. If you are using centralized repository for RMAN, you should be aware of this important change which might cause additional costs. While VPD (Fine-grained access control) is not extra licensed , question whether Partitioning Option needs to be licensed remain unanswered. As always, you should contact your Oracle Sales representative in order to consult all question regarding licensing and to learn all implications according the changes.

 

Fun part: Creating 12c RMAN catalog Oracle Database 12c Standard Edition (just illustration for fun, don't use it in production!):

Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SYS@ORA12CR1:SQL> create user rmanbckp identified by rmanbckp;

User created.

SYS@ORA12CR1:SQL> grant sysbackup to rmanbckp;

Grant succeeded.

SYS@ORA12CR1:SQL> exit
Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
[oracle@lab00 ~]$ sqlplus "sys@rmandb / as sysdba"

SQL*Plus: Release 12.1.0.2.0 Production on Wed Jul 29 20:46:54 2015

Copyright (c) 1982, 2014, Oracle.  All rights reserved.

Enter password:

Connected to:
Oracle Database 12c Release 12.1.0.1.0 - 64bit Production

SYS@RMANDB:SQL> select edition from v$instance;

EDITION
-------
SE

SYS@RMANDB:SQL> create user rman12 identified by rman default tablespace data;

User created.

SYS@RMANDB:SQL> grant recovery_catalog_owner, unlimited tablespace to rman12;

Grant succeeded.

SYS@RMANDB:SQL> exit
Disconnected from Oracle Database 12c Release 12.1.0.1.0 - 64bit Production
[oracle@lab00 ~]$ rman catalog rman12/rman@rmandb

Recovery Manager: Release 12.1.0.2.0 - Production on Wed Jul 29 20:50:49 2015

Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

connected to recovery catalog database

RMAN> create catalog

recovery catalog created

RMAN> connect target "rmanbckp/rmanbckp@ora12cr1 as sysbackup"

connected to target database: ORA12CR1 (DBID=1346475582)

RMAN> register database;

database registered in recovery catalog
starting full resync of recovery catalog
full resync complete

RMAN> backup database;

Starting backup at 29-JUL-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=42 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/storage/oradata00/ORA12CR1/data01.dbf
input datafile file number=00001 name=/storage/oradata00/ORA12CR1/system01.dbf
input datafile file number=00002 name=/storage/oradata00/ORA12CR1/sysaux01.dbf
input datafile file number=00003 name=/storage/oradata00/ORA12CR1/undo01.dbf
channel ORA_DISK_1: starting piece 1 at 29-JUL-15
channel ORA_DISK_1: finished piece 1 at 29-JUL-15
piece handle=/storage/oradata01/ORA12CR1/ARC/ORA12CR1/backupset/2015_07_29/o1_mf_nnndf_TAG20150729T205310_bvl88pd1_.bkp tag=TAG20150729T205310 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 29-JUL-15
channel ORA_DISK_1: finished piece 1 at 29-JUL-15
piece handle=/storage/oradata01/ORA12CR1/ARC/ORA12CR1/backupset/2015_07_29/o1_mf_ncnnf_TAG20150729T205310_bvl896n3_.bkp tag=TAG20150729T205310 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 29-JUL-15

RMAN>

 

As you can see using some (secret) tweaks I was able to create Oracle 12c Standard Edition for RMAN catalog. Of course this is not valid solution and it is not possible to use it for production as SE is not supported and it in fact violates the license. So no SE officially. But technically with couple of really nasty tweaks it is possible use SE as RMAN repository. ;-)

 

Hello Blog!

I was thinking about my own blog for long time. Final decision was made after answering couple of my questions such as: - Is there something meaningful you can write about? - Will you find some free time for writing posts? and so on... Answer is pretty simple: "Don't know. I'll will be writing about Oracle, Linux or other Unix-like OS and other thoughts what crossed my mind. Basicaly I will publish anything I find as interesting..." I decided to code my own blog because I couldn't found appropriate free blog software (which met all my needs) on Freshmeat site. So "Hello Blog" and I belive you enjoy it. My apologies for my English, corrections are welcomed.

Home