Skip to main content

Connecting to the database

When to use it

At the start of every session, and every time you switch between servers or databases.

Run this

On the database server, as the oracle operating system user:

# 1. See which databases exist on this server
cat /etc/oratab

# 2. Point your shell to the one you want
export ORACLE_SID=YOUR_SID
export ORAENV_ASK=NO
. oraenv

# 3. Connect locally as SYSDBA
sqlplus / as sysdba

Then confirm where you are:

SELECT instance_name, host_name, version, status FROM v$instance;
SELECT name, db_unique_name, open_mode, database_role FROM v$database;

Two helper scripts on this shelf make this faster when you work with many databases:

  • connect_from_env.sh (Administration › Utility scripts › Connectivity): reads .env files, lists the databases and connects to the one you pick.
  • validar_env.sh (Administration › Utility scripts › Connectivity): checks a .env file before you use it.

How to read the output

  • status should be OPEN. MOUNTED or STARTED means the database is not fully up.
  • open_mode is normally READ WRITE on a primary. READ ONLY or MOUNTED usually means a standby.
  • database_role tells you if this is a PRIMARY or a PHYSICAL STANDBY. Many commands must only run on the primary.
  • On a container database you start in CDB$ROOT. See the page "Containers and PDBs".

What to do next

  • If the host or instance is not the one you expected, stop and reconnect. This is the most common cause of serious mistakes.
  • If sqlplus / as sysdba fails with ORA-01034 or ORA-27101, the instance is down or ORACLE_SID is wrong. Check ps -ef | grep pmon and escalate if the instance should be running.

Risk level

READ ONLY Safe to run at any time. It only queries the data dictionary.