6 Connecting to Oracle Database Free

Connecting Locally using OS Authentication

When you install Oracle Database Free, the oracle user is granted SYSDBA privileges. You can use the following commands to connect to the database.

$ cd $ORACLE_HOME/bin
$ ./sqlplus / as sysdba

These commands connect you to the root container CDB$ROOT of the multitenant database (CDB) as database user SYS. This method of connecting to the database works even if the Net Services listener is not running.

An output similar to the following confirms that you are now connected to the database.

SQL*Plus: Release 23.0.0.0.0 - Production on Sat Apr 06 03:27:05 2024
Version 23.4.0.24.05

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

Connected to:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.4.0.24.05

Net Services Listener and Default Services

The Net Services database listener for Oracle Database Free allows you to connect to the database over TCP/IP from the same machine or other machines on the network. The configuration of the Listener can be viewed using the following commands run from the command prompt:

$ cd $ORACLE_HOME/bin
$ lsnrctl status
LSNRCTL for Linux: Version 23.0.0.0.0 - Production on 26-MAR-2024 08:35:46

Copyright (c) 1991, 2024, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost.example.com)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 23.0.0.0.0 - Production
Start Date                26-MAR-2024 08:35:46
Uptime                    0 days 0 hr. 5 min. 7 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Default Service           FREE
Listener Parameter File /opt/oracle/product/23ai/dbhomeFree/network/admin/listener.ora
Listener Log File /opt/oracle/diag/tnslsnr/dbhost/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=dbhost.example.com)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "FREE.dbhost.example.com" has 1 instance(s).
  Instance "FREE", status READY, has 1 handler(s) for this service...
Service "FREEXDB.dbhost.example.com" has 1 instance(s).
  Instance "FREE", status READY, has 1 handler(s) for this service...
Service "dbhost.example.com" has 1 instance(s).
  Instance "FREE", status READY, has 1 handler(s) for this service...
Service "freepdb1.dbhost.example.com" has 1 instance(s).
  Instance "FREE", status READY, has 1 handler(s) for this service...
The command completed successfully
The output from the lsnrctl command shows values of a number of important parameters:
  • the port the listener listens on
  • the list of services registered with the listener
  • the name of the configuration file used by the listener
  • the name of the log file

You must specify a service when connecting to the database through the listener. The default services created by Oracle Database Free are FREE and FREEPDB1. The Oracle Database Free service connects you to the root container of the database (CDB$ROOT) and the FREEPDB1 service connects you to the default pluggable database FREEPDB1, created during installation. For each new pluggable database (PDB), there is a new default service created with the same name as the PDB.

Note:

If you shut down the Oracle Database Free instance, then the lsnrctl status command does not show any services that you can connect to.

Connecting to Oracle Database Using Easy Connect Naming Method

You can connect to the database using the following Easy Connect strings:
  • Multitenant container database: host[:port]

  • Pluggable database: host[:port]/service_name

FREEPDB1 is the service name defined for the first PDB created by default. You can replace FREEPDB1 with the name of another PDB you want to connect to.

Specifying the port is optional when the listener is setup with the default port 1521. You must specify the port number if you use another port.

Connection strings for local connections were provided on the final screen of the install. If you are connecting from a remote computer, you must enter the hostname (where Oracle Database Free is installed) instead of localhost.

The Net Services database listener must be running on the database host of the specified port for the connections to succeed.

For example, you can connect to the root container of the database from a client computer with SQL*Plus using the following commands:
$ cd $ORACLE_HOME/bin
$ ./sqlplus system@dbhost.example.com:1521
You can connect to the default PDB FREEPDB1 using the following commands:
$ cd $ORACLE_HOME/bin
$ ./sqlplus system@dbhost.example.com:1521/FREEPDB1

Replace dbhost.example.com with your database host name. If required, replace 1521 with the port number the listener listens on. You can replace FREEPDB1 with the name of another PDB that you want to connect to.

To shorten connect strings or to avoid hard coding of the host name and the port in the application code and DBA scripts, you can define an alias for the connect string in the configuration file ORACLE_HOME/network/admin/tnsnames.ora on the database clients. See Configuring the Local Naming Method for more details.