Connect to a Database

You can connect to a database in Data Infrastructure after you connect to a VM, or remotely by using Oracle Net Services.

Use SSH to connect to a VM when you need operating system access before connecting to a database. Use Oracle Net Services when you need remote database access from a client.

Connect to a Database After You Connect to a VM

After you connect to a VM, you can use operating system commands to identify a database and connect to it.

  1. Connect to the VM as the opc user.

    For detailed steps, see Connect to a VM with SSH.

  2. Switch to the oracle user.

    sudo su - oracle
  3. Use the srvctl utility located under the Oracle Grid Infrastructure home directory to list the databases in the VM Cluster.

    grid-home/bin/srvctl config database -v
  4. Identify the database instances for the database that you want to access.

    grid-home/bin/srvctl status database -d <dbname>
  5. Configure the environment settings for the database that you want to access.

    . oraenv

    At the prompt, enter the Oracle system identifier (SID) for the database.

    ORACLE_SID = [oracle] ? <dbname>
  6. Set the ORACLE_SID environment variable to the database instance that you want to access.

    export ORACLE_SID=<dbname1>
  7. Optionally, use the srvctl command to display more detailed information about the database.

    srvctl config database -d <dbname>
  8. Connect to the database by using SQL*Plus.

    sqlplus / as sysdba

Connect to a Database with Oracle Net Services

You can connect to a database in Data Infrastructure remotely by using Oracle Net Services.

Because Data Infrastructure uses Oracle Grid Infrastructure, you can make Oracle Net Services connections by using Single Client Access Name (SCAN) connections. SCAN provides a consistent mechanism for clients to access database instances running in a VM Cluster.

By default, SCAN is associated with three virtual IP addresses (VIPs). Each SCAN VIP is associated with a SCAN listener that provides a connection endpoint for database connections using Oracle Net Services. To maximize availability, Oracle Grid Infrastructure distributes the SCAN VIPs and SCAN listeners across the available VM Cluster nodes. If a node shuts down or fails, the SCAN VIPs and SCAN listeners are automatically migrated to an available node.

By using SCAN connections, Oracle AI Database clients have a reliable set of connection endpoints that can service the databases running in the VM Cluster.

The SCAN listeners are in addition to the Oracle Net listeners that run on every node in the VM Cluster, which are also known as node listeners. When an Oracle Net Services connection comes through a SCAN connection, the SCAN listener routes the connection to one of the node listeners and plays no further part in the connection. A combination of factors, including listener availability, database instance placement, and workload distribution, determines which node listener receives each connection.

This documentation provides basic requirements for connecting to databases in Data Infrastructure by using Oracle Net Services.

Prerequisites for Connecting to a Database with Oracle Net Services

Connect to a Database Using SCAN

To create an Oracle Net Services connection by using the SCAN listeners, you can select between the following approaches:

Connect to a Database Using a Connect Descriptor That References All SCAN VIPs

You can set up a connect descriptor using multiple SCAN listeners.

This approach requires you to supply all SCAN VIP addresses and enables Oracle Net Services to connect to an available SCAN listener.

  1. Use the following template to define a Net Services alias:

    <alias-name> = (DESCRIPTION=
      (ADDRESS_LIST=
        (ADDRESS=(PROTOCOL=tcp)(HOST=<SCAN-VIP-1>)(PORT=1521))
        (ADDRESS=(PROTOCOL=tcp)(HOST=<SCAN-VIP-2>)(PORT=1521))
        (ADDRESS=(PROTOCOL=tcp)(HOST=<SCAN-VIP-3>)(PORT=1521)))
      (CONNECT_DATA=(<sid-or-service-entry>)))

    where:

    • <alias-name> is the name that you use to identify the alias.
    • <SCAN-VIP-1>, <SCAN-VIP-2>, and <SCAN-VIP-3> are the IP addresses for the SCAN VIPs.
    • <sid-or-service-entry> identifies the database SID or service name using one of the following formats:
      • SID=sid-name. For example: SID=DBNAME1.
      • SERVICE_NAME=service-name. For example: SERVICE_NAME=pdb1.example.com.

By default, Oracle Net Services randomly selects one of the addresses in the address list to balance the load between the SCAN listeners.

Connect to a Database Using a Connect Descriptor That References a Custom SCAN Name

You can set up a connect descriptor using a custom SCAN name.

Using this approach, you define a custom SCAN name in your domain name server (DNS). The custom SCAN name resolves to the three SCAN VIP addresses.

  1. Use the following template to define a Net Services alias that references the custom SCAN name:

    <alias-name> = (DESCRIPTION=
      (ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=<scan-name>)(PORT=1521)))
      (CONNECT_DATA=(<sid-or-service-entry>)))

    where:

    • <alias-name> is the name that you use to identify the alias.
    • <scan-name> is the custom SCAN name.
    • <sid-or-service-entry> identifies the database SID or service name using one of the following formats:
      • SID=sid-name. For example: SID=DBNAME1.
      • SERVICE_NAME=service-name. For example: SERVICE_NAME=pdb1.example.com.
  2. Alternatively, use the Easy Connect method to specify a connect descriptor with the following format:

    <scan-name>:1521/<sid-or-service-entry>

    For example:

    dbscan.example.com:1521/DBNAME1

    or:

    dbscan.example.com:1521/pdb1.example.com

Connect to a Database Using a Node Listener

To connect to a database with a connect descriptor that bypasses the SCAN listeners, route the connection directly to a node listener.

By using this method, you give up the high availability and load balancing provided by SCAN. However, this method might be useful when you want to direct connections to a specific node or network interface.

  1. Use the following template to define a Net Services alias that directly references the node:

    <alias-name> = (DESCRIPTION=
      (CONNECT_TIMEOUT=<timeout>)
      (ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=<node>)(PORT=1521)))
      (CONNECT_DATA=(<sid-or-service-entry>)))

    where:

    • <alias-name> is the name that you use to identify the alias.
    • <timeout> specifies a timeout period, in seconds, that enables you to terminate a connection attempt without waiting for a TCP timeout. The (CONNECT_TIMEOUT=timeout) parameter is optional.
    • <node> is the host name or IP address of the VM that you want to use.
    • <sid-or-service-entry> identifies the database SID or service name using one of the following formats:
      • SID=sid-name. For example: SID=DBNAME1.
      • SERVICE_NAME=service-name. For example: SERVICE_NAME=pdb1.example.com.
  2. Alternatively, use the Easy Connect method to specify a connect descriptor with the following format:

    <node>:1521/<sid-or-service-entry>

    For example:

    node01.example.com:1521/DBNAME1

    or:

    node01.example.com:1521/pdb1.example.com