Overview of Connecting to a DB System

This article provides an introduction about various settings required to connect to an active DB system. How you connect depends on the client tool or protocol you use, the purpose of the connection, and how your cloud network is set up.

Note: You can find information on various networking scenarios in Networking Overview, but for specific recommendations on how you should connect to a database in the cloud, contact your network security administrator.

Prerequisites

If you have problems connecting, see Troubleshoot Connection Issues.

Database Services and Connection Strings

Database services allow you to control client access to a database instance depending on the functionality needed. For example, you might need to access the database for administration purposes only or you might need to connect an application to the database. Connection strings are specific to a database service.

When you provision a DB system, a default database administration service is automatically created. For 12c and later Oracle Databases, this service is for administrating the database at the CDB level. Because this service provides limited functionality, it is not suitable for connecting an application. Oracle recommends that you create a default application service for the initial database after you create your DB system. For 12c and later Oracle Databases, application services connect at the PDB level. Here are some important functions an application service can provide:

For details about these and other High Availability capabilities, see Client Failover Best Practices for Highly Available Oracle Databases.

Create an Application Service

You use the srvctl utility to create an application service. Before you can connect to the service, you must start it.

You can create an application service for a PDB or an 11g Oracle database using the following steps.

  1. Log in to the DB system host as opc.
  2. Switch to the oracle user, and set your environment to the Oracle Database you want to administer.

    sudo su - oracle
    . oraenv
    ORACLE_SID = [oracle] ? <database_name>
    The Oracle base has been set to /u01/app/oracle
  3. Create the application service for the database. Include the pdb option only if you are creating an application service for a PDB.

    srvctl add service
      -db <DB_unique_name>
      -pdb <PDB_name>
      -service <app_service_name>
      -role PRIMARY
      -notification TRUE
      -session_state dynamic
      -failovertype transaction
      -failovermethod basic
      -commit_outcome TRUE
      -failoverretry 30
      -failoverdelay 10
      -replay_init_time 900
      -clbgoal SHORT
      -rlbgoal SERVICE_TIME
      -preferred <rac_node1>,<rac_node2>
      -retention 3600

    Note that the preferred option is required only for multi-node databases to specify the hostname of the node in the RAC.

  4. Start the application service.

    srvctl start service -db <DB_unique_name> -s <app_service_name>

For more information about services for a PDB, see Administering PDBs.

Database Connection Strings

You must use the appropriate connection string to access a database administration or application service. You can use the Console or the API to get the string for connecting to the default administration service from within a VCN. For 12c and later Oracle Databases, this service is for administrating the database at the CDB level. The string is provided in both the Easy Connect and in the full connect descriptor (long) format. Use the long format for the connection if hostname resolution is not available. You can also use the long format to create an alias in the tnsnames.ora file.

For accessing a database service within the VCN, the connection string for a Real Application Cluster (RAC) DB system uses the Single Client Access Name (SCAN) while the connection string for single instance DB system uses the hostname instead.

The private SCAN name is a Round Robin DNS entry created when you launch a 2-node RAC DB system. The private SCAN name is resolvable only within the VCN. If the client and the database are in the same VCN, the connection mechanism is the same as an on-premises RAC database; all the features provided by VIPs and SCAN VIPs, such as server side load balancing and VIP failover, are available.

Note: If you manually change the DB_UNIQUE_NAME, DB_DOMAIN, or listener port on the DB system, the connection strings you see in the Console or API will not reflect your changes. Ensure that you use the actual values of these parameters when you make a connection.

Get the Connection Strings

You can get the connection strings for the default administration service using the following steps using the Console:

  1. On the DB Systems list page, select the DB system that contains the database that you want to work with. If you need help finding the list page or the DB system, see List the DB Systems.
  2. On the Databases tab, select the database that you want to work with.
  3. On the database details page, select the Connections tab. A list of connection strings is displayed.
  4. Select the applicable link to view or copy the connection string.

You can derive the connection strings for other database services by replacing part of the default application service connection string with the applicable values.

Derive the Connection String

Perform the following steps to derive the connection string for a PDB administration service or an application service.

  1. Follow the procedure to get the Easy Connect string for the default administration service. That string should have the following format:

    <hostname\|SCAN>:1521/<DB_unique_name>.<DB_domain>
  2. Make the appropriate substitution:

    • For the PDB administration service, replace DB_unique_name with the PDB name.

      <hostname\|SCAN>:1521/<PDB_name>.<DB_domain>
    • For an application service, replace DB_UNIQUE_NAME with the name of the application service.

      <hostname\|SCAN>:1521/<app_service_name>.<DB_domain>