{"id":3187,"date":"2016-07-30T21:08:45","date_gmt":"2016-07-30T19:08:45","guid":{"rendered":"https:\/\/adrhc.go.ro\/wordpress\/?p=3187"},"modified":"2017-10-07T18:56:11","modified_gmt":"2017-10-07T16:56:11","slug":"oracle-systemd","status":"publish","type":"post","link":"https:\/\/adrhc.go.ro\/blog\/oracle-systemd\/","title":{"rendered":"Oracle and systemd"},"content":{"rendered":"<pre class=\"brush:bash shell;toolbar: false\">\r\n# http:\/\/docs.oracle.com\/database\/121\/index.htm\r\n# https:\/\/172.16.148.137:5500\/em\/login\r\n# start db:\r\n[oracle@redhat7 ~]$ sqlplus \/ AS SYSDBA\r\nSTARTUP\r\n# start TNS listener\r\n[oracle@redhat7 ~]$ lsnrctl start\r\n# TNS listener status\r\n[oracle@redhat7 ~]$ lsnrctl status\r\ncat \/u01\/app\/oracle\/product\/12.1.0\/dbhome_1\/network\/admin\/listener.ora\r\n# stop TNS listener\r\n[oracle@redhat7 ~]$ lsnrctl stop\r\n# TNS listener status\r\nps -ef | grep [t]nslsnr\r\n# oracle + listener startsqlplus system\/Yxx32145 AS SYSDBA\r\n# for this you need the apropiate environment variables in \/home\/oracle\/.bash_profile e.g.:\r\nTMPDIR=$TMP; export TMPDIR\r\nORACLE_BASE=\/u01\/app\/oracle; export ORACLE_BASE\r\nORACLE_HOME=$ORACLE_BASE\/product\/12.1.0\/dbhome_1; export ORACLE_HOME\r\nORACLE_SID=orcl; export ORACLE_SID\r\nPATH=$ORACLE_HOME\/bin:$PATH; export PATH\r\nLD_LIBRARY_PATH=$ORACLE_HOME\/lib:\/lib:\/usr\/lib:\/usr\/lib64; export LD_LIBRARY_PATH\r\nCLASSPATH=$ORACLE_HOME\/jlib:$ORACLE_HOME\/rdbms\/jlib; export CLASSPATH\r\n# then allow dbstart in \/etc\/oratab to start a specific instance:\r\n[root@redhat7 ~]# sed -i s\/\"N$\"\/\"Y\"\/ \/etc\/oratab\r\n[oracle@redhat7 ~]$ $ORACLE_HOME\/bin\/dbstart $ORACLE_HOME\r\n# oracle status:\r\nps -ef | grep [o]racle\r\nps -ef | grep [o]ra_\r\n# oracle status from sqlplus:\r\n[oracle@redhat7 ~]$ sqlplus \/ AS SYSDBA\r\nselect INSTANCE_NAME, STARTUP_TIME, STATUS, ARCHIVER, \"THREAD#\", LOGINS, INSTANCE_ROLE, ACTIVE_STATE from v$instance;\r\nselect SPID as \"Process ID\" , STID as \"Thread ID\", PNAME as \"Process Name\", EXECUTION_TYPE as \"Process Type\" from v$process order by 4,1,2;\r\n# stop db:\r\n[oracle@redhat7 ~]$ sqlplus \/ AS SYSDBA\r\nSHUTDOWN IMMEDIATE\r\n# or allow dbstart in \/etc\/oratab to start a specific instance (stop db + listener):\r\n# see http:\/\/docs.oracle.com\/database\/121\/UNXAR\/strt_stp.htm#UNXAR417\r\n# see https:\/\/oracle-base.com\/articles\/linux\/automating-database-startup-and-shutdown-on-linux\r\n[root@redhat7 ~]# sed -i s\/\"N$\"\/\"Y\"\/ \/etc\/oratab\r\n[oracle@redhat7 ~]$ $ORACLE_HOME\/bin\/dbshut $ORACLE_HOME\r\ntailf $ORACLE_HOME\/startup.log\r\n# list options existing in a response file:\r\ngrep -v -P \"^#|=$\" KIT\/Oracle\/db.rsp | grep -v \"^$\"\r\n# Log messages are written to:\r\n\/u01\/app\/oracle\/diag\/rdbms\/orcl\/orcl\/trace\/alert_orcl.log\r\n\/u01\/app\/oracle\/diag\/rdbms\/orcl\/orcl\/alert\/log.xml\r\nfind \/u01 -name log.xml\r\n\r\n# when after normal shutdown oracle processes are still running do a shutdown abort from sqlplus\r\n\r\n# show oracle pid (for systemd):\r\n[oracle@redhat7 ~]$ output=$(sqlplus -S \/ AS SYSDBA &lt;&lt;EOF\r\nselect SPID from v\\$process where PNAME = 'PMON';sysman\r\nEOF\r\n);echo \"$output\" | grep -P \"\\d+\"\r\n# or show this way:\r\nps -e | grep [p]mon_orcl | awk '{print $1;}'\r\n\r\n# change $ORACLE_HOME\/bin\/dbstart in order to show PMON's PID:\r\n\tOS_PID=$(sqlplus -S \/ AS SYSDBA &lt;&lt;EOF\r\nselect SPID from v\\$process where PNAME = 'PMON';\r\nEOF\r\n)\r\n\tOS_PID=$(echo \"$OS_PID\" | grep -P \"\\d+\")\r\n\techo \"$0: ${INST} \\\"${ORACLE_SID}\\\" warm started (PID $OS_PID).\"\r\n\tif [ -d \/run\/oracle ]; then\r\n\t\techo \"$OS_PID\" > \/run\/oracle\/oracle.pid\r\n\t\techo \"created \/run\/oracle\/oracle.pid\"\r\n\tfi\r\n# or change like this:\r\n\tOS_PID=$(ps -e | grep [p]mon_orcl | awk '{print $1;}')\r\n\techo \"$0: ${INST} \\\"${ORACLE_SID}\\\" warm started (PID $OS_PID).\"\r\n\tif [ -d \/run\/oracle ]; then\r\n\t\techo \"$OS_PID\" > \/run\/oracle\/oracle.pid\r\n\t\techo \"created \/run\/oracle\/oracle.pid\"\r\n\tfi\r\n# in order to use dbstart and dbshut with systemd you'll have to also change them \r\n# so that awk, cat, cut, grep, touch, chmod commands \r\n# are used with their absolute path (e.g. \/bin\/cat)\r\n\r\n# systemd oracle.service\r\n[Unit]\r\nDescription=Oracle 12c\r\nAfter=local-fs.target\r\nWants=local-fs.target\r\n[Service]\r\nType=forking\r\nUser=oracle\r\nGroup=oinstall\r\nRuntimeDirectory=oracle\r\nPIDFile=\/run\/oracle\/oracle.pid\r\nRestart=on-failure\r\nRestartSec=3\r\nTimeoutSec=0\r\nExecStart=\/u01\/app\/oracle\/product\/12.1.0\/dbhome_1\/bin\/dbstart \/u01\/app\/oracle\/product\/12.1.0\/dbhome_1\r\nExecStop=\/u01\/app\/oracle\/product\/12.1.0\/dbhome_1\/bin\/dbshut \/u01\/app\/oracle\/product\/12.1.0\/dbhome_1\r\n[Install]\r\nWantedBy=multi-user.target\r\n\r\n# all users of the database visible to the current user\r\nselect username from all_users order by username;\r\n\r\n# tables for schema\/user\r\nSELECT DISTINCT OBJECT_NAME FROM ALL_OBJECTS WHERE OBJECT_TYPE = 'TABLE' AND OWNER = 'HR';\r\n\r\n# change user's password:\r\nALTER USER sys IDENTIFIED BY \"Yxx32145\";\r\nALTER USER system IDENTIFIED BY \"Yxx32145\";\r\nsqlplus system\/Yxx32145 AS SYSDBA\r\n\r\n# Enterprise Manager\r\n# http:\/\/www.dba-oracle.com\/t_11g_connect_sysdba_ora_01031.htm\r\nsys - allowed to connect AS SYSDBA\r\nsystem - not allowed to connect AS SYSDBA\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p># http:\/\/docs.oracle.com\/database\/121\/index.htm # https:\/\/172.16.148.137:5500\/em\/login # start db: [oracle@redhat7 ~]$ sqlplus \/ AS SYSDBA STARTUP # start TNS listener [oracle@redhat7 ~]$ lsnrctl start # TNS listener status [oracle@redhat7 ~]$ lsnrctl status cat \/u01\/app\/oracle\/product\/12.1.0\/dbhome_1\/network\/admin\/listener.ora # stop TNS listener [oracle@redhat7 ~]$ lsnrctl stop [&hellip;]<\/p>\n<div class=\"link-more\"><a href=\"https:\/\/adrhc.go.ro\/blog\/oracle-systemd\/#more-3187\" class=\"more-link\">Continue reading &#10142; <span class=\"screen-reader-text\">Oracle and systemd<\/span><\/a><\/div>","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,11,33],"tags":[],"class_list":["post-3187","post","type-post","status-publish","format-standard","hentry","category-howto","category-linux","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/adrhc.go.ro\/blog\/wp-json\/wp\/v2\/posts\/3187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adrhc.go.ro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/adrhc.go.ro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/adrhc.go.ro\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/adrhc.go.ro\/blog\/wp-json\/wp\/v2\/comments?post=3187"}],"version-history":[{"count":0,"href":"https:\/\/adrhc.go.ro\/blog\/wp-json\/wp\/v2\/posts\/3187\/revisions"}],"wp:attachment":[{"href":"https:\/\/adrhc.go.ro\/blog\/wp-json\/wp\/v2\/media?parent=3187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adrhc.go.ro\/blog\/wp-json\/wp\/v2\/categories?post=3187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adrhc.go.ro\/blog\/wp-json\/wp\/v2\/tags?post=3187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}