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.envfiles, lists the databases and connects to the one you pick.validar_env.sh(Administration › Utility scripts › Connectivity): checks a.envfile before you use it.
How to read the output
statusshould beOPEN.MOUNTEDorSTARTEDmeans the database is not fully up.open_modeis normallyREAD WRITEon a primary.READ ONLYorMOUNTEDusually means a standby.database_roletells you if this is aPRIMARYor aPHYSICAL 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 sysdbafails with ORA-01034 or ORA-27101, the instance is down orORACLE_SIDis wrong. Checkps -ef | grep pmonand escalate if the instance should be running.
Risk level
READ ONLY Safe to run at any time. It only queries the data dictionary.