Sub topic 12
Connecting to a cloud database with a wallet
This chapter assumes you can already connect with SQLcl using CONNECT and Easy Connect syntax, and that you know what a service name and a TNS alias are. Here you will connect to an Oracle Autonomous Database, which requires a wallet.
Why a cloud database needs a wallet
An on-premises database often accepts plain TCP connections on port 1521. An Autonomous Database does not. It accepts only encrypted connections, and by default it uses mutual TLS (mTLS). The client proves its identity with a certificate, and the client checks the server's certificate. The certificates and connection details are delivered in a file called a wallet.
The wallet you download from the Oracle Cloud console is a zip file, usually named like Wallet_MYDB.zip. It is a client credentials bundle. It is not a database user's password, and it does not replace your username and password. You still log in with a database user such as ADMIN. The wallet only makes the encrypted network path possible.
A typical wallet zip contains these files:
| File | Purpose |
|---|---|
| `tnsnames.ora` | Connect descriptors (aliases) for each service of the database |
| `sqlnet.ora` | Network settings, including where the wallet is located |
| `cwallet.sso` | Auto-login wallet holding the certificates, no password needed |
| `ewallet.p12` | The same material in PKCS#12 format, protected by a wallet password |
| `keystore.jks` and `truststore.jks` | Java key and trust stores, used by JDBC clients |
| `ojdbc.properties` | Java settings that point JDBC at the wallet |
The wallet password you set when downloading protects ewallet.p12 and the Java stores. Auto-login with cwallet.sso does not ask for it.
Service aliases in the wallet
The tnsnames.ora file inside the wallet defines one alias per consumer group. For a database named mydb, you normally get these:
| Alias | Intended use |
|---|---|
| `mydb_high` | Highest priority and resources, lowest concurrency |
| `mydb_medium` | Balanced default for many workloads |
| `mydb_low` | Lowest priority, highest concurrency |
| `mydb_tp` | Transaction processing |
| `mydb_tpurgent` | Highest-priority transaction processing |
Which aliases you see depends on the workload type of your database. Open tnsnames.ora to see the exact list. Each alias maps to a full descriptor with host, port, service name, and security settings. The following sketch shows the shape of one entry. The host and service name are placeholders, not real values:
mydb_high =
(description =
(retry_count=20)(retry_delay=3)
(address = (protocol=tcps)(port=1522)(host=adb.example-region.oraclecloud.com))
(connect_data = (service_name = example_mydb_high.adb.oraclecloud.com))
(security = (ssl_server_dn_match=yes))
)Note the protocol is tcps, not tcp, and the port is typically 1522. That is why an Easy Connect string copied from an on-premises setup will not work here without changes.
Connecting from SQLcl
SQLcl can read the wallet zip directly, so you do not need to unzip it. Use the SET CLOUDCONFIG command first, then CONNECT with an alias from the wallet:
SQL> set cloudconfig /path/to/Wallet_MYDB.zip
SQL> connect admin@mydb_high
Password? (**********?) ********
Connected.SET CLOUDCONFIG has to run before CONNECT in the same SQLcl session. SQLcl extracts what it needs to a temporary location and uses it for later connections in that session. If you start a new session, set it again.
You can also pass the wallet on the command line when you launch SQLcl:
sql -cloudconfig /path/to/Wallet_MYDB.zip admin@mydb_highOn Windows, use a path such as C:\wallets\Wallet_MYDB.zip. Quote the path if it contains spaces.
Using the unzipped wallet with TNS_ADMIN
A second approach is to unzip the wallet into a directory and point the TNS_ADMIN environment variable at it. SQLcl then finds tnsnames.ora there, as it would for any TNS alias.
unzip Wallet_MYDB.zip -d /opt/wallets/mydb
export TNS_ADMIN=/opt/wallets/mydb
sql admin@mydb_highThe sqlnet.ora in the wallet contains a line such as WALLET_LOCATION = (SOURCE = (METHOD = file) (METHOD_DATA = (DIRECTORY="?/network/admin"))). The ? stands for the Oracle home. If your client is not an Oracle home install, edit DIRECTORY to the actual folder, for example /opt/wallets/mydb. A wrong directory here is a common cause of certificate errors in clients that use the unzipped wallet.
Choose between the two methods like this:
- Use
SET CLOUDCONFIGfor quick, per-session work and when you want to keep the wallet as a single zip file. - Use
TNS_ADMINwhen other tools on the machine (for example,tnspingor an application) must share the same wallet, or when you also keep your owntnsnames.oraentries.
Connecting from SQL Developer
SQL Developer has its own connection type for this. In the New / Select Database Connection dialog:
- Enter a connection name, a username (such as
ADMIN), and the password. Tick Save Password only if the machine is yours and protected. - Set Connection Type to Cloud Wallet.
- In Configuration File, browse to the wallet zip. You do not need to unzip it.
- In Service, select an alias such as
mydb_high. SQL Developer fills the list from the wallet'stnsnames.ora. - Click Test. The status area at the bottom left should show
Status: Success. - Click Save, then Connect.
Which alias should you choose? For interactive work and ad hoc queries, _high or _medium is common. For many short parallel sessions, such as an application connection pool, _low or _tp fits better. The choice changes resource limits and concurrency, not the data you see.
Verify the session
After connecting, confirm where you are, using the same check you learned earlier:
select sys_context('USERENV', 'SESSION_USER') as session_user,
sys_context('USERENV', 'SERVICE_NAME') as service_name,
sys_context('USERENV', 'SERVER_HOST') as server_host
from dual;The service_name column should show the cloud service tied to the alias you used, for example one ending in _high.adb.oraclecloud.com. That confirms the consumer group you picked. If it is not what you expect, you probably connected through a different alias.
Saving a wallet-based connection
You can combine the wallet with saved connections. Set the cloud configuration, connect with -save, and the stored connection remembers the wallet settings:
SQL> set cloudconfig /path/to/Wallet_MYDB.zip
SQL> connect -save mydb_admin_high admin@mydb_high
SQL> connmgr list
SQL> connect -name mydb_admin_highOnly add -savepwd if the stored password is acceptable on that machine. Without it, SQLcl asks for the password when you reconnect.
Common errors with wallets
| Symptom | Likely cause | What to check |
|---|---|---|
| `ORA-12154: TNS:could not resolve the connect identifier specified` | The alias is not found | The alias spelling, `TNS_ADMIN`, or that `SET CLOUDCONFIG` ran first |
| `ORA-01017: invalid username/password; logon denied` | Wrong database user password | The `ADMIN` password set in the cloud console, not the wallet password |
| `ORA-28759: failure to open file` | Wallet file not found or unreadable | `DIRECTORY` in `sqlnet.ora`, file permissions |
| `ORA-12506` or timeouts | Network access control list blocks your IP | The database's access control list in the cloud console |
| `ORA-29024: Certificate validation failure` | Wallet is for a different database or has expired | Download a fresh wallet for this database |
Two cloud-specific points cause many of these failures:
- Wallet rotation. An administrator can rotate the wallet in the console. A wallet downloaded before rotation stops working. Download a new one.
- Network access control. If the database restricts access to certain IP addresses or private endpoints, a correct wallet still cannot connect from a disallowed network.
Exercises
Exercise
You run connect admin@mydb_high in a fresh SQLcl session and get ORA-12154. The wallet zip is at /home/me/Wallet_MYDB.zip. What is the most likely cause, and what command fixes it?
Show answer
SQLcl does not know where the wallet is, so it cannot resolve the alias mydb_high. Run set cloudconfig /home/me/Wallet_MYDB.zip first, then connect admin@mydb_high again. The cloud configuration setting applies per session, so it must be set in each new session.
Exercise
A teammate says the wallet password is the same as the ADMIN user's password. Is this right, and where is each one used?
Show answer
No. The wallet password is chosen when downloading the wallet and protects ewallet.p12 and the Java key stores. The ADMIN password belongs to the database user and is entered at the Password? prompt. A wrong ADMIN password gives ORA-01017.
Exercise
After connecting through the wallet, how can you confirm which consumer group (high, medium, low) your session uses?
Show answer
Run select sys_context('USERENV', 'SERVICE_NAME') from dual;. The service name returned ends with the consumer group, for example _high.