Home > Enterprise >  Connecting to Oracle XE edition with sqlplus but without password
Connecting to Oracle XE edition with sqlplus but without password

Time:09-03

Yes, I've seen https://dba.stackexchange.com/a/140147

The command sqlplus / as sysdba mentioned in this answer and elsewhere on the web still asks me for password on my installation:

Oracle Linux 7.7

oracle-database-xe-21c-1.0-1.x86_64

However, that command still asks me for password:

[root@localhost ~]# su - oracle
Last login: Fri Sep  2 09:01:34 EDT 2022 on pts/0

[oracle@localhost bin]$ export ORACLE_HOME=/opt/oracle/product/21c/dbhomeXE

[oracle@localhost bin]$ cd /opt/oracle/product/21c/dbhomeXE/bin/

[oracle@localhost bin]$ ./sqlplus  / as sysdba

SQL*Plus: Release 21.0.0.0.0 - Production on Fri Sep 2 09:02:24 2022
Version 21.3.0.0.0

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

ERROR:
ORA-12162: TNS:net service name is incorrectly specified


Enter user-name: 

I don't really need any database in particular. My job is gathering some meta information about Oracle installation such as version, configuration file, database files dir etc.

Yes, I can read some of the info from oracle system files on RedHat and similar (Oracle Linux is compiled from RH sources, it's very similar to RH). Still, some info is only available in sqlplus.

UPDATE:

Regarding shell environment I've done as oracle user is:

export ORACLE_HOME=/opt/oracle/product/21c/dbhomeXE

[oracle@localhost bin]$ ./oraenv 
ORACLE_SID = [oracle] ? 
ORACLE_HOME = [/home/oracle] ? /opt/oracle/product/21c/dbhomeXE
The Oracle base has been set to /opt/oracle

However, following command still asks me for password:

[oracle@localhost bin]$ ./sqlplus -l / as sysdba

SQL*Plus: Release 21.0.0.0.0 - Production on Fri Sep 2 09:24:55 2022
Version 21.3.0.0.0

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

ERROR:
ORA-12162: TNS:net service name is incorrectly specified


SP2-0751: Unable to connect to Oracle.  Exiting SQL*Plus
[oracle@localhost bin]$ 
[oracle@localhost bin]$ ./sqlplus  / as sysdba

SQL*Plus: Release 21.0.0.0.0 - Production on Fri Sep 2 09:24:59 2022
Version 21.3.0.0.0

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

ERROR:
ORA-12162: TNS:net service name is incorrectly specified


Enter user-name: 

CodePudding user response:

The "Enter user-name:" prompt is appearing because the initial login attempt failed, with ORA-12162. By default it will try to log in up to three times, prompting for credentials each time - except the first time, since you provided the first set to try on the command line.

If you do ./sqlplus -l / as sysdba then it will only try to log in once, instead of reprompting on error (to slightly paraphrase the usage notes).

But it will still get that ORA-12162 error the first time.

Your environment isn't set up properly. You've manually set ORACLE_HOME, but not any other Oracle-related environment variables; specifically here ORACLE_SID (or maybe TWO_TASK to connect remotely). You probably want to set other things like PATH properly too.

The Oracle home bin directory includes an oraenv script that you can source that (rather than just executing it) to set the environment up for a specific local DB, using

. ${ORACLE_HOME}/bin/oraenv

or

source ${ORACLE_HOME}/bin/oraenv

... but you might prefer to set things manually.

I don't really need any database in particular. My job is gathering some meta information about Oracle installation such as version, configuration file, database files dir etc.

You already effectively know the database software version, 21c, from the ORACLE_HOME path, but there is an oraversion executable in the bin dir that lets you get more detailed information about the version of the Oracle binaries in that home.

The rest of the information is specific to a database. You might be able to find a text pfile, or more likely a binary spfile, but is you're using ASM those might not be on a normal local filesystem. really you do need to connect to the database to interrogate it for file and directory location etc.

(It's also possible that the database version could be slightly different to the binaries version - it shouldn't be really but I think it's possible mid-upgrade if some of the upgrade scripts haven't been run. I might be wrong though. But query v$version anyway to be sure.)

the goal is to detect software systems such as Oracle installed on all endpoints where the agent is working

If the server is acting as an Oracle database server then it should have an oratab file, usually as /etc/oratab or /var/opt/oracle/oratab or similar - you might need to locate it.

That lists all of the local databases in colon-delimited form, e.g. orcl:/opt/oracle/product/21c/dbhomeXE:Y, with the first two elements being the ORACLE_SID and ORACLE_HOME values. (The third is an auto-start flag). So you can parse that file to identify the Oracle home directory (or directories; there could be more than one), and the SID value(s) to pass to oraenv for each version and that you can attempt to log in to.

  • Related