Post Contents

Connecting to an Oracle 19c Database Instance

Connecting to an Oracle 19c Database Instance

Connecting to an Oracle Database instance is a fundamental task for database administrators and developers. With Oracle 19c, there are several methods available to establish this connection, depending on the network configuration and security requirements. This guide covers the most commonly used methods, configuration tips, and tools, including TNS, Easy Connect, Wallet usage, JDBC, OCI, and advanced features such as Transparent Application Failover (TAF) and Database Resident Connection Pooling (DRCP).

Oracle Connection Overview

Establishing an Oracle connection is crucial for interacting with the database and performing various tasks. This involves not only configuring the network components but also ensuring secure access to the database instance. Whether you’re working with a local Oracle instance or connecting to a remote Oracle database, you need to properly configure Oracle Net Listener and the client environment to facilitate this communication.

TNS Configuration for Oracle Connection

The Oracle connection relies heavily on the correct configuration of the Transparent Network Substrate (TNS). TNS enables networked Oracle databases to communicate with each other and with client applications. Configuring TNS involves creating or modifying the tnsnames.ora file, which stores service definitions for Oracle databases. These definitions allow client applications to locate and connect to the appropriate database instance.

An example of a basic TNS entry in the tnsnames.ora file is as follows:

ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = myhost)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = orclpdb1)
)
)

This configuration specifies the protocol (TCP), the host (myhost), and the port (1521). Additionally, it identifies the database service name (orclpdb1), allowing the client to locate and connect to the desired database instance.

đŸ“¢ You might also like: Oracle 19c Dedicated and Shared Server Configurations (Category: Oracle Database Admin)

Easy Connect Method

One of the simplest ways to establish an Oracle connection is through the Easy Connect method. Easy Connect does not require the configuration of a tnsnames.ora file. Instead, it allows you to directly specify the connection details within the connection string. For example:

sqlplus username/password@//myhost:1521/orclpdb1

In this method, the user connects to the Oracle database by specifying the host, port, and service name directly in the connection string. Many prefer this method in environments where simplicity is key or when multiple clients need to connect without managing the complexity of TNS configurations.

JDBC Connection to Oracle

Java applications typically connect to Oracle databases using JDBC (Java Database Connectivity). JDBC is a standard API that enables Java applications to interact with relational databases. Oracle provides a JDBC driver that allows Java applications to connect to Oracle databases.

To establish a JDBC connection to Oracle, use the following connection string in your Java code:

String url = "jdbc:oracle:thin:@myhost:1521:orclpdb1";
Connection conn = DriverManager.getConnection(url, "username", "password");

In this example, the thin driver is used, which is a lightweight, platform-independent option. The connection string specifies the host (myhost), port (1521), and service name (orclpdb1). The DriverManager.getConnection() method is used to establish the connection to the database.

OCI (Oracle Call Interface) Connection

The Oracle Call Interface (OCI) is a lower-level API that allows applications written in C or C++ to interact directly with an Oracle database. OCI provides more control over the connection and operations, making it suitable for applications that require fine-grained control over database interactions.

To use OCI, you need to configure the Oracle Instant Client and use the oci connection string format:

sqlplus username/password@oci://myhost:1521/orclpdb1

Applications that require direct interaction with the database typically use OCI connections in performance-sensitive environments. It is also the foundation for many higher-level Oracle connection methods, such as those used in Oracle’s ProC and ProCOBOL precompilers.

Using Oracle Wallet for Secure Connections

Security is a critical concern when establishing a connection to an Oracle database. Using Oracle Wallet is one of the most secure ways to manage database credentials, eliminating the need to expose passwords in scripts or applications.

Let’s consider a realistic scenario where a team of database administrators manages multiple Oracle instances in a corporate environment. In this case, they use Oracle Wallet to securely store connection credentials.

Creating the Wallet

First, you create the Oracle Wallet and add credentials for a database named myprod. In this example, myprod represents the production database:

mkstore -wrl /opt/oracle/admin/wallets -create

This creates the wallet in the specified directory. Next, add the connection credentials for the myprod database, including the password for the dbadmin user:

mkstore -wrl /opt/oracle/admin/wallets -createCredential myprod dbadmin secure_password123

This command securely stores the credentials (dbadmin and secure_password123) in the wallet.

Configuring the Wallet in sqlnet.ora

After creating and configuring the Oracle Wallet, you need to ensure that the Oracle client knows where to find it. This is done by configuring the sqlnet.ora file to point to the wallet location and enable password override:

WALLET =
(SOURCE =
(METHOD = FILE)
(METHOD_DATA =
(DIRECTORY = /opt/oracle/admin/wallets)
)
)

SQLNET.WALLET_OVERRIDE = TRUE

This configuration instructs Oracle to use the credentials stored in the wallet instead of requiring the username and password at the time of connection.

Using Oracle Wallet for Connections

Once the wallet is configured, you can connect to the myprod production database without directly supplying the password. The connection is securely handled using the credentials stored in the wallet:

sqlplus /@myprod

In this example, Oracle Wallet stores the necessary credentials for the myprod service, allowing the database administrator dbadmin to connect to the database securely without exposing the password.

Realistic Scenario

Suppose the organization has a production database (myprod), a development database (devdb), and a test database (testdb). Each database has different users and credentials. The administrative team has created an Oracle Wallet for each environment and configured the credentials for the different databases:

mkstore -wrl /opt/oracle/admin/wallets/prod -createCredential myprod prodadmin ProdPass2024
mkstore -wrl /opt/oracle/admin/wallets/dev -createCredential devdb devadmin DevPass2024
mkstore -wrl /opt/oracle/admin/wallets/test -createCredential testdb testadmin TestPass2024

With these wallets, secure connections can be established for each database without the need to input passwords in scripts or directly on the command line:

To connect to production:

sqlplus /@myprod

Connect to development:

sqlplus /@devdb

To connect to testing:

sqlplus /@testdb

These wallets simplify credential management in a corporate environment and ensure that passwords are not exposed in configuration files or scripts.

Transparent Application Failover (TAF)

Oracle 19c introduces enhancements to Transparent Application Failover (TAF), a feature that ensures high availability during a connection failure. With TAF, if the primary instance of the database becomes unavailable, the connection automatically fails over to another instance without requiring user intervention.

To enable TAF for your Oracle connection, you can configure it in the tnsnames.ora file:

ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = primary_host)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = secondary_host)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orclpdb1)
(FAILOVER_MODE =
(TYPE = SELECT)
(METHOD = BASIC)
(RETRIES = 180)
(DELAY = 5)
)
)
)

This configuration enables failover between the primary and secondary hosts, ensuring that the database connection is maintained even in the event of a failure.

Database Resident Connection Pooling (DRCP)

For environments with high connection turnover, Database Resident Connection Pooling (DRCP) is an effective feature. DRCP pools server processes on the database side, allowing connections to be reused by different applications. This reduces the overhead of constantly establishing and tearing down connections.

To use DRCP, you configure the server pool on the database and then modify your connection string to include the SERVER=POOLED attribute:

sqlplus username/password@//myhost:1521/orclpdb1?SERVER=POOLED

By leveraging DRCP, you can improve performance and resource utilization, particularly in environments with many short-lived connections.

Connecting to Oracle via Kerberos

Kerberos authentication is another secure method for establishing an Oracle connection, particularly in environments that require centralized authentication. Oracle 19c supports Kerberos authentication, allowing users to connect to the database without supplying passwords explicitly.

To configure Kerberos authentication, you must first set up the Kerberos environment and configure the database to accept Kerberos tokens as credentials.

Example of a Kerberos connection string:

sqlplus /@mydb

This method simplifies the management of user credentials and provides strong security controls in distributed environments.

Oracle Data Provider for .NET (ODP.NET) Connection

For .NET applications, the Oracle Data Provider for .NET (ODP.NET) offers optimized data access to Oracle databases. It supports both managed and unmanaged drivers, providing flexibility in how you connect and manage database connections within .NET applications.

To establish an ODP.NET connection, use the following C# code:

using Oracle.DataAccess.Client;

string connectionString = "User Id=scott;Password=tiger;Data Source=oracle;";
OracleConnection con = new OracleConnection(connectionString);
con.Open();

ODP.NET also supports advanced features like Transparent Application Failover (TAF) and Oracle Real Application Clusters (RAC), making it a robust solution for enterprise-grade .NET applications.

Conclusion

Successfully configuring an Oracle connection in Oracle 19c requires understanding the available connection methods, security configurations, and advanced features such as TAF, DRCP, and Kerberos authentication. Whether connecting through JDBC, OCI, ODP.NET, or other methods, following best practices will ensure reliable and secure connections to your Oracle database instances.

See more on Oracle’s website!

Be Oracle Database Certified Professional, this world is full of opportunities for qualified DBAs!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top