Note:
- This tutorial requires access to Oracle Cloud. To sign up for a free account, see Get started with Oracle Cloud Infrastructure Free Tier.
- It uses example values for Oracle Cloud Infrastructure credentials, tenancy, and compartments. When completing your lab, substitute these values with ones specific to your cloud environment.
Implement Oracle True Cache Service with Oracle Database 23ai
Introduction
Oracle True Cache is an in-memory, consistent, and automatically managed SQL and key-value (object or JSON) cache for Oracle Database.
Oracle True Cache is an in-memory, read-only cache in front of an Oracle Database. Like Oracle Active Data Guard, Oracle True Cache is a fully functional, read-only replica of the primary database, except that it is mostly diskless.
Modern applications often require a high number of connections and fast, low-latency access to the data. A popular approach is to place caches in front of the database because applications typically perform many more reads than updates, and they can read from the cache without affecting the database performance. For example, an airline reservation system reads data frequently as people shop for flights, and it is okay if the data is not the most current compared to what is in the database. The application only needs to access the most current data when someone reserves a flight.
Unlike conventional caches, Oracle True Cache automatically keeps the most frequently accessed data in the cache, and it keeps the cache consistent with the primary database, other objects in the same cache, and other caches. It caches all Oracle Database objects and data types, including JSON.
Because Oracle True Cache implements Oracle Database security policies, you can control access to the cache. This enables you to cache sensitive data, like private personal information, that you might not ordinarily cache.
Environment Details:
-
Primary Database:
-
Database Version:
23.5.0.24
-
Operating System: Virtual Machine (VM) database system.
-
Oracle True Cache Instance: 1 Node Oracle Database Configuration Assistant (DBCA) node with Oracle Database 23ai database software version (NON-ASM).
-
Objectives
- Implement Oracle True Cache service and redirect the read-only (select) application requests to Oracle True Cache instance.
Prerequisites
-
Set up a network path to access the primary (source) database with an Easy Connect (EZConnect) string from the Oracle True Cache node.
-
Ensure that a primary database is running on the primary node in archive logging (ARCHIVELOG) mode.
Task 1: Copy Password File and Transparent Data Encryption (TDE) Wallet
Copy the password file, and optionally the TDE wallet from the primary database to the Oracle True Cache node. You can use either of the following methods:
-
Manually copy the primary database password file (and optional TDE wallet) to any location on the Oracle True Cache node.
Or
-
Run DBCA command on the primary database to package the password file (and optional TDE wallet) into a configuration BLOB file. Then copy the file to the Oracle True Cache node and ensure that the file is owned by the Oracle Home User.
Use the following command to prepare the configuration BLOB file on the primary database.
mkdir -p /tmp/passconfig $ORACLE_HOME/bin/dbca -configureDatabase -prepareTrueCacheConfigFile -sourceDB cdb1db1 -trueCacheBlobLocation /tmp/passconfig -silent
Example Output:
mkdir -p /tmp/passconfig [oracle@proddb ~]$ $ORACLE_HOME/bin/dbca -configureDatabase -prepareTrueCacheConfigFile -sourceDB DB1218 -trueCacheBlobLocation /tmp/passconfig -silent Enter password for the TDE wallet: Session ID of the current execution is: 1 Log file location: /u01/app/oracle/cfgtoollogs/dbca/DB1218_xts_iad/trace.log_2024-12-18_12-47-36PM_42681 ----------------- Running Initialization job Completed Initialization job 33% complete ----------------- Running Validate_dataguard job Skipping. Job is detected as not applicable. 40% complete ----------------- Running Validate_db_version job Completed Validate_db_version job 47% complete ----------------- Running Validate_tde_credentials job Completed Validate_tde_credentials job 53% complete ----------------- Running Validate_true_cache_instance job Completed Validate_true_cache_instance job 60% complete ----------------- Running Validate_archive_log_mode job Completed Validate_archive_log_mode job 67% complete ----------------- Running Prepare_blob job Completed Prepare_blob job 100% complete ---------- PLUGIN NOTES ---------- Successfully created blob file: /tmp/passconfig/blob_2024-12-18_12-47-36PM.tar.gz ---------- END OF PLUGIN NOTES ---------- Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/DB1218_xts_iad/DB1218_xts_iad0.log" for further details. [oracle@proddb ~]$
Copy the BLOB file to the Oracle True Cache instance node.
scp -i <private_key> <blob_file_name> opc@<true cache instance ip>:/tmp
Task 2: Drop Unneeded Database on Oracle True Cache Node
On the Oracle True Cache node, drop existing database on the Oracle True Cache hosts if database already exists and is not required.
sqlplus / as sysdba
SQL> shut immediate
SQL> startup mount restrict
SQL> drop database;
Task 3: Test Primary Database Connection String from True Cache Host
Run the following command to test primary database connection string from Oracle True Cache host.
sqlplus sys/<sys_password>@<primary_database_hostname>:1521/<primary_database_service> as sysdba
Task 4: Configure and Start Oracle True Cache
On the Oracle True Cache node, run the -createTrueCache
command to complete the Oracle True Cache configuration and to start Oracle True Cache.
$ORACLE_HOME/bin/dbca -createTrueCache -gdbName true_cache_global_name -sid true_cache_sid -sourceDBConnectionString primary_db_easy_connect_string -trueCacheBlobFromSourceDB true_cache_config_blob_path -sgaTargetInMB sga_memory_size -pgaAggregateTargetInMB pga_memory_size -tdeWalletLoginType AUTO_LOGIN -listeners listener_name -silent
Example Output:
[oracle@test1 ~]$ $ORACLE_HOME/bin/dbca -createTrueCache -gdbName test1 -sid test1 -sourceDBConnectionString proddb.sub12101216100.dbnet.oraclevcn.com.:1521/DB1218_xts_iad.sub12101216100.dbnet.oraclevcn.com -trueCacheBlobFromSourceDB /home/oracle/blob_2024-12-18_12-47-36PM.tar.gz -sgaTargetInMB 25000 -pgaAggregateTargetInMB 12000 -initParams db_create_file_dest=/u02/app/oracle/oradata -listeners LISTENER -silent
Enter Remote DB SYS user password:
Enter password for the source database TDE wallet:
Session ID of the current execution is: 1
Log file location: /u01/app/oracle/cfgtoollogs/dbca/test1/trace.log_2024-12-18_01-01-33PM_61716
-----------------
Running Extract_password_file_from_blob_file job
Completed Extract_password_file_from_blob_file job
25% complete
-----------------
Running Create_static_listener job
Skipping. Job is detected as not applicable.
38% complete
-----------------
Running Register_listener job
Completed Register_listener job
50% complete
-----------------
Running Extract_tde_wallet_from_blob_file job
Completed Extract_tde_wallet_from_blob_file job
54% complete
-----------------
Running Setup_required_directories job
Skipping. Job is detected as not applicable.
57% complete
-----------------
Running Create_pfile job
Completed Create_pfile job
61% complete
-----------------
Running Start_nomount_instance job
Completed Start_nomount_instance job
64% complete
-----------------
Running Create_TDE_wallet job
Completed Create_TDE_wallet job
68% complete
-----------------
Running Create_truecache_instance job
Completed Create_truecache_instance job
71% complete
-----------------
Running Add_oratab_entry job
Completed Add_oratab_entry job
75% complete
-----------------
Running Reopen_wallet job
Completed Reopen_wallet job
100% complete
---------- PLUGIN NOTES ----------
Successfully created True Cache.
In order to complete the operation,configure the True Cache database application services from the primary database.
---------- END OF PLUGIN NOTES ----------
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/test1/test1.log" for further details.
[oracle@test1 ~]$
Task 5: Create and Verify Pluggable Database (PDB) Level Application Service for Oracle True Cache
Create and start a primary database (at PDB level) application service to use with the Oracle True Cache service, and verify that the service is running.
For single instance primary databases, use the DBMS_SERVICE
PL/SQL package. For services that are specific to a PDB, connect to the specific PDB, or set the correct PDB container in your session before starting the service using DBMS_SERVICE
.
Example Output:
alter session set container=<PDB_NAME>;
show pdbs
BEGIN
DBMS_SERVICE.CREATE_SERVICE('SALES', 'SALES');
DBMS_SERVICE.START_SERVICE('SALES');
END;
/
PL/SQL procedure successfully completed.
Task 6: Configure Oracle True Cache on the Primary Database
Run the dbca -configureDatabase
command with the -configureTrueCacheInstanceService
parameter to configure Oracle True Cache on the primary database. This configures the Oracle True Cache database application service on the primary database and then starts the Oracle True Cache service on Oracle True Cache.
Run the following command for each Oracle True Cache database application service.
$ORACLE_HOME/bin/dbca -configureDatabase -configureTrueCacheInstanceService -sourceDB primary_db_sid_or_db_unique_name -trueCacheConnectString true_cache_easy_connect_string -trueCacheServiceName true_cache_service_name -serviceName primary_db_service_name -pdbName primary_pdb_name -silent
Example Output:
[oracle@proddb ~]$ $ORACLE_HOME/bin/dbca -configureDatabase -configureTrueCacheInstanceService -sourceDB DB1218 -trueCacheConnectString test1.sub12101216100.dbnet.oraclevcn.com:1521/test1.sub12101216100.dbnet.oraclevcn.com -trueCacheServiceName sales_tc1 -serviceName sales -pdbName DB1218_PDB1 -silent
Session ID of the current execution is: 7
Log file location: /u01/app/oracle/cfgtoollogs/dbca/DB1218/trace.log_2024-12-18_02-39-50PM_60536
-----------------
Running Initialization job
Enter SYS user password:
Completed Initialization job
33% complete
-----------------
Running Validate_true_cache_instance_connection job
Completed Validate_true_cache_instance_connection job
37% complete
-----------------
Running Validate_dataguard job
Skipping. Job is detected as not applicable.
41% complete
-----------------
Running Validate_db_version job
Completed Validate_db_version job
44% complete
-----------------
Running Validate_true_cache_instance job
Completed Validate_true_cache_instance job
48% complete
-----------------
Running Validate_archive_log_mode job
Completed Validate_archive_log_mode job
52% complete
-----------------
Running Validate_pdb job
Completed Validate_pdb job
56% complete
-----------------
Running Validate_primary_db_service job
Completed Validate_primary_db_service job
59% complete
-----------------
Running Validate_true_cache_db_service job
Completed Validate_true_cache_db_service job
63% complete
-----------------
Running Validate_true_cache_instance_open_mode job
Completed Validate_true_cache_instance_open_mode job
67% complete
-----------------
Running Create_truecache_service job
Completed Create_truecache_service job
73% complete
-----------------
Running Add_network_entry job
Completed Add_network_entry job
80% complete
-----------------
Running Modify_primary_service job
Completed Modify_primary_service job
87% complete
-----------------
Running Start_truecache_service job
Completed Start_truecache_service job
93% complete
-----------------
Running Enable_service_registration job
Completed Enable_service_registration job
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/DB1218/DB12183.log" for further details.
[oracle@proddb ~]$
Task 7: Start Service on Oracle True Cache Node
Run the following command to start the service on Oracle True Cache instance node.
alter session set container=<PDB_NAME>;
show pdbs
BEGIN
DBMS_SERVICE.START_SERVICE('sales_tc1');
END;
/
Task 8: Update Parameters in the Primary Database
-
Update the following parameters in the primary database
listener.ora
file.VALID_NODE_CHECKING_REGISTRATION_LISTENER = OFF REGISTRATION_INVITED_NODES_LISTENER=(<true_cache_instance_ip>)
-
Restart or reload the listener on the primary database server.
Task 9: Verify Oracle True Cache Services in the Primary Database Listener
Run the following command to verify that the Oracle True Cache (sales_tc
) services are running under the primary database listener.
SQL> select name,open_mode,database_role from gv$database;
NAME OPEN_MODE DATABASE_ROLE
------------------------------ -------------------- ----------------
DB1218 READ WRITE PRIMARY
SQL> select * from v$true_cache;
MY_DG_ID REMOTE_DG_ID DEST_ID TRUE_CACHE PRIMARY_NAME STATUS REMOTE_VERSION CON_ID
---------- ------------ ---------- ---------- -------------------- ---------- ------------------ ----------
4079357444 576841986 2 test1 DB1218_xts_iad HEALTHY 0.0.0.0.0 0
4079357444 2149296628 3 test2 DB1218_xts_iad HEALTHY 0.0.0.0.0 0
SQL> SELECT name, true_cache_service FROM DBA_SERVICES WHERE name='sales';
NAME TRUE_CACHE_SERVICE
------------------------------ ------------------------------
sales sales_tc2
[oracle@proddb ~]$ lsnrctl status LISTENER|grep -i sales_tc1
Service "sales_tc1.sub12101216100.dbnet.oraclevcn.com" has 1 instance(s).
[oracle@proddb ~]$
Task 10: Verify True Cache Services on Oracle True Cache Instance Node
Run the following command to verify that the Oracle True Cache (sales_tc
) services are running on the Oracle True cache instance node.
SQL> select name,open_mode,database_role from gv$database;
NAME OPEN_MODE DATABASE_ROLE
--------- -------------------- ----------------
DB1218 READ ONLY WITH APPLY TRUE CACHE
SQL> select * from v$true_cache;
MY_DG_ID REMOTE_DG_ID DEST_ID TRUE_CACHE PRIMARY_NAME STATUS REMOTE_VERSION CON_ID
---------- ------------ ---------- ---------- -------------------- ---------- ------------------ ----------
576841986 4079357444 0 test1 DB1218_xts_iad HEALTHY 23.0.0.0.0 0
[oracle@test1 ~]$ lsnrctl status LISTENER|grep sales_tc
Service "sales_tc1.sub12101216100.dbnet.oraclevcn.com" has 1 instance(s).
[oracle@test1 ~]$
Task 11: Test Oracle True Cache Service
Add the following Transparent Network Substrate (TNS) entry to the application.
TEST_TC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = test1.sub12101216100.dbnet.oraclevcn.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = sales_tc1.sub12101216100.dbnet.oraclevcn.com)
)
)
sqlplus sys/<sys_password>@TEST_TC as sysdba
select name,open_mode,database_role from v$database;
show pdbs
Related Links
Acknowledgments
- Authors - Pavan Yennampelli (Senior Cloud Engineer, Oracle North America Cloud Services - NACIE), Sravan Kumar K B (Senior Cloud Engineer, Oracle North America Cloud Services - NACIE), Bandari Chandu (Senior Cloud Engineer, Oracle North America Cloud Services - NACIE), Anupam Abhishek (Senior Cloud Engineer, Oracle North America Cloud Services - NACIE)
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Implement Oracle True Cache Service with Oracle Database 23ai
G24118-01
January 2025