0

Scenario:

*oracle xe11g r2 is installed( and runs properly when logged in as oracle).
*logged in as user, root
*added root to groups oinstall and dba as follows:

#useradd -G oinstall root
#useradd -G dba root

*environment variables ORACLE_HOME and ORACLE_SID are set as follows:

#export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
#export ORACLE_SID=XE
#export PATH=$ORACLE_HOME/bin:$PATH

and executed:

#sudo -u oracle sqlplus / as sysdba

Output:

sudo: sqlplus: command not found

Please guide me in running sqlplus by root using sudo.

  • 1
    Why do you need to run as root? Run as another user — don’t run as the user oracle either. – Colin 't Hart Oct 29 '18 at 1:49
2

Not an Oracle error.

Sure you can put the above variables in .bash_profile of oracle, but when you use sudo like above, that will not be executed.

[root@o71 ~]# tail -3 /home/oracle/.bash_profile
export ORACLE_HOME=/u01/app/oracle/product/dbhome_1
export ORACLE_SID=ETALON
export PATH=$ORACLE_HOME/bin:$PATH
[root@o71 ~]# sudo -u oracle sqlplus / as sysdba
sudo: sqlplus: command not found

One of the many ways to work around this:

[root@o71 ~]# sudo -u oracle bash -c '. ~/.bash_profile; sqlplus / as sysdba'

SQL*Plus: Release 18.0.0.0.0 - Production on Sun Oct 28 10:52:43 2018
Version 18.4.0.0.0

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


Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0

SQL> 

I am not a fan of using .bash_profile for setting the Oracle environment, I suggest using oraenv or a custom script that is not executed automatically.

| improve this answer | |
  • 2
    My question would be, why are you working as root in the first place? Most GOOD sysadmins prevent direct logon as root, and severely restrict who can become root after logging on with their own account. – EdStevens Oct 28 '18 at 11:54
  • It would help in initial installation and configuration automation! and later the privileges assigned to root would be revoked. – AVA Oct 29 '18 at 1:52
  • @AVA. There are very specific points in the Oracle installation that must be executed by root. And of course there are certain sys admin tasks that must be performed by root. But neither of these would occasion needing to be root and then sudo from there to execute sqlplus. The very fact of 'sudo sqlplus' from root is a VERY strong indicator of using root as a 'default' connection, which is a very poor way of working. – EdStevens Oct 29 '18 at 14:25
  • I have a question, this actually works for me: sudo -u oracle bash -c '. ~/.bash_profile; sqlplus $user/$password@"@TNS"' But how can I do a SQLPLUS in silent mode?? I tried this but doesn't work: sudo -u oracle bash -c '. ~/.bash_profile; sqlplus -s $user/$password@"@TNS"' – Dani Nanan Jun 2 at 0:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.