DBMS_CACHE Package
The DBMS_CACHE package facilitates automatic caching for Lake Caches in an Autonomous AI Database instance, including caches created for external tables and for tables exposed through mounted catalogs.
Summary of DBMS_CACHE Subprograms
This table summarizes the subprograms included in the DBMS_CACHE package.
| Subprogram | Description |
|---|---|
| CLEAR Procedure | Clears all Lake Caches for a specified user. |
| ENABLE_AUTO Procedure | Enables automatic caching globally or for one or more schemas and optionally sets GLOBAL_CACHE_SIZE or GLOBAL_CACHE_PERCENT. |
| GET_GLOBAL_PROPERTY Procedure | Retrieves automatic Lake Cache properties. |
| GET_USER_PROPERTY Procedure | Retrieves automatic Lake Cache properties for a specified user. |
| REFRESH Procedure | Refreshes all Lake Caches for a specified user. |
| SET_GLOBAL_PROPERTY Procedure | Specifies the automatic Lake Cache preference for all database users. |
| SET_USER_PROPERTY Procedure | Specifies the automatic Lake Cache preference for a specified user. |
CLEAR Procedure
Use the DBMS_CACHE.CLEAR procedure to drop all Lake Caches for a specified user.
The DBMS_CACHE.CLEAR procedure drops all the Lake Caches and release the storage space, similar to how the DROP command works on a database table.
Syntax
DBMS_CACHE.CLEAR (
owner IN VARCHAR2
);Parameters
| Parameter | Description |
|---|---|
owner |
Specifies the schema name. |
Example
BEGIN
DBMS_CACHE.CLEAR (
owner => 'SALES');
END;
/Usage Note
- You must be logged in as the
ADMINuser or haveEXECUTEprivilege on theDBMS_CACHEpackage to clear a cache.
ENABLE_AUTO Procedure
Use the DBMS_CACHE.ENABLE_AUTO procedure to enable automatic caching globally or for one or more schemas and optionally set the global cache quota.
Syntax
DBMS_CACHE.ENABLE_AUTO (
users IN CLOB DEFAULT NULL,
global_cache_size IN NUMBER DEFAULT NULL,
global_cache_pct IN NUMBER DEFAULT NULL
);Parameters
| Parameter | Description |
|---|---|
users |
Specifies a JSON array in CLOB format that contains schema names. If users is NULL, automatic caching is enabled globally for all users. |
global_cache_size |
Specifies the maximum global cache quota, in bytes, for the database. |
global_cache_pct |
Specifies the global cache quota as a percentage of the maximum database size. |
Usage Notes
-
The procedure enables automatic caching by setting
AUTO_CACHE. -
If
global_cache_sizeorglobal_cache_pctis provided, the procedure sets the corresponding global quota property. -
If neither
global_cache_sizenorglobal_cache_pctis provided, the procedure setsGLOBAL_CACHE_PERCENTto20. -
Use
DBMS_CACHE.SET_GLOBAL_PROPERTYorDBMS_CACHE.SET_USER_PROPERTYwithAUTO_CACHE = 0to disable automatic caching.
Examples
Example to enable automatic caching globally:
BEGIN
DBMS_CACHE.ENABLE_AUTO(
users => NULL,
global_cache_pct => 20);
END;
/Example to enable automatic caching for selected schemas:
DECLARE
l_users CLOB := '["HR","SALES"]';
BEGIN
DBMS_CACHE.ENABLE_AUTO(
users => l_users,
global_cache_size => 21474836480);
END;
/GET_GLOBAL_PROPERTY Procedure
The DBMS_CACHE.GET_GLOBAL_PROPERTY procedure retrieves the automatic Lake Cache preferences for all users in the database. This procedure is overloaded.
Syntax
DBMS_CACHE.GET_GLOBAL_PROPERTY (
property_name IN VARCHAR2,
property_value_num OUT NUMBER);
DBMS_CACHE.GET_GLOBAL_PROPERTY (
property_name IN VARCHAR2,
property_value_str OUT VARCHAR2);Parameters
| Parameter | Description |
|---|---|
property_name |
Specifies the property name. Following are the valid values for
|
property_value_num |
Retrieves a NUMBER value for the specified property name. |
property_value_str |
Retrieves a STRING value for the specified property name. |
Example
SET SERVEROUTPUT ON;
DECLARE
l_auto_cache NUMBER;
BEGIN
DBMS_CACHE.GET_GLOBAL_PROPERTY(
property_name => 'AUTO_CACHE',
property_value_num => l_auto_cache);
DBMS_OUTPUT.PUT_LINE('AUTO_CACHE=' || l_auto_cache);
END;
/Usage Notes
-
You must be logged in as the
ADMINuser or haveEXECUTEprivilege on theDBMS_CACHEpackage to run this procedure. -
GLOBAL_CACHE_SIZEandGLOBAL_CACHE_PERCENTdefine quota only. They do not enable automatic caching. UseAUTO_CACHEorDBMS_CACHE.ENABLE_AUTOto enable automatic caching. -
If both
GLOBAL_CACHE_SIZEandGLOBAL_CACHE_PERCENTare set, the larger value is used. If neither global quota property is explicitly set,GLOBAL_CACHE_PERCENTdefaults to20. -
If both
MAX_CACHE_SIZEandMAX_CACHE_PERCENTare set, the larger value is used. If neither default quota property is explicitly set,MAX_CACHE_PERCENTdefaults to20.
SET_GLOBAL_PROPERTY Procedure
Use DBMS_CACHE.SET_GLOBAL_PROPERTY to set global automatic-caching properties for the database. This procedure is overloaded.
AUTO_CACHE enables or disables automatic caching at the database scope. GLOBAL_CACHE_SIZE and GLOBAL_CACHE_PERCENT define the global cache quota for all external table caches. MAX_CACHE_SIZE and MAX_CACHE_PERCENT define default schema-level quota preferences for schemas that do not have a user-level override. Setting GLOBAL_CACHE_SIZE, GLOBAL_CACHE_PERCENT, MAX_CACHE_SIZE, or MAX_CACHE_PERCENT does not, by itself, enable automatic caching.
Syntax
DBMS_CACHE.SET_GLOBAL_PROPERTY (
property_name IN VARCHAR2,
property_value_num IN NUMBER);
DBMS_CACHE.SET_GLOBAL_PROPERTY (
property_name IN VARCHAR2,
property_value_str IN VARCHAR2);Parameters
| Parameter | Description |
|---|---|
property_name |
Specifies the property name. Following are the valid values for
|
property_value_num |
Provides a NUMBER value for the specified property name. |
property_value_str |
Provides a STRING value for the specified property name. |
Examples
BEGIN
DBMS_CACHE.SET_GLOBAL_PROPERTY(
property_name => 'AUTO_CACHE',
property_value_num => 1);
END;
/BEGIN
DBMS_CACHE.SET_GLOBAL_PROPERTY(
property_name => 'GLOBAL_CACHE_PERCENT',
property_value_num => 20);
END;
/BEGIN
DBMS_CACHE.SET_GLOBAL_PROPERTY(
property_name => 'MAX_CACHE_PERCENT',
property_value_num => 25);
END;
/BEGIN
DBMS_CACHE.SET_GLOBAL_PROPERTY(
property_name => 'BEHAVIOR',
property_value_str => 'COOPERATIVE');
END;
/BEGIN
DBMS_CACHE.SET_GLOBAL_PROPERTY(
property_name => 'AUTO_REFRESH_MODE',
property_value_str => 'NEW');
END;
/BEGIN
DBMS_CACHE.SET_GLOBAL_PROPERTY(
property_name => 'MAX_REFRESH_WINDOW',
property_value_num => 20);
END;
/Usage Notes
-
You must be logged in as the
ADMINuser or haveEXECUTEprivilege on theDBMS_CACHEpackage to run this procedure. -
If both
GLOBAL_CACHE_SIZEandGLOBAL_CACHE_PERCENTare set, the larger value is used. -
If neither global quota property is explicitly set,
GLOBAL_CACHE_PERCENTdefaults to20. -
If both
MAX_CACHE_SIZEandMAX_CACHE_PERCENTare set, the larger value is used. -
If neither default quota property is explicitly set,
MAX_CACHE_PERCENTdefaults to20. -
If
MAX_CACHE_SIZEis set greater thanGLOBAL_CACHE_SIZE, the database raises an error. -
Manual caches and
AUTOcaches consume the same quota pool. -
The
MAX_REFRESH_WINDOWproperty specifies, in seconds, the maximum time allowed for refreshing Lake Caches. If the refresh exceeds the specified limit, the cache refresh exits normally, and any remaining eligible caches are queued for the next refresh cycle. -
When you refresh caches using the
DBMS_CACHE.REFRESHprocedure, the procedure parameter takes precedence over theAUTO_REFRESH_MODEproperty.See REFRESH Procedure for more information.
REFRESH Procedure
Use the DBMS_CACHE.REFRESH procedure to refresh all AUTO Lake Caches for a specified user.
Syntax
DBMS_CACHE.REFRESH (
owner IN VARCHAR2,
refresh_type IN VARCHAR2 DEFAULT ALL
);Parameters
| Parameter | Description |
|---|---|
owner |
Specifies the schema name. |
refresh_type |
Specifies the refresh option. Following are the valid
This parameter is optional and defaults to |
Example
BEGIN
DBMS_CACHE.REFRESH (
owner => 'SALES',
refresh_type => 'CURRENT');
END;
/Usage Notes
-
You must be logged in as the
ADMINuser or haveEXECUTEprivilege on theDBMS_CACHEpackage to run this procedure. -
If you do not specify a value for the
refresh_typeparameter, Oracle perform refresh based onauto_refresh_modevalue. The default value forauto_refresh_modeisALL. -
When the
MAX_REFRESH_WINDOWproperty is set, Oracle attempts to perform refresh in the specified window. If the refresh exceeds the specified limit, the cache refresh exits normally, and any remaining eligible caches are queued for the next refresh cycle. -
All AUTO caches in the database are managed by using an eviction algorithm similar to Least Recently Used (LRU). When under space pressure, caches that have been accessed least recently are automatically dropped during the refresh process to release the storage space.
GET_USER_PROPERTY Procedure
Use the DBMS_CACHE.GET_USER_PROPERTY procedure to retrieve automatic caching properties for a user.
Syntax
DBMS_CACHE.GET_USER_PROPERTY (
property_name IN VARCHAR2,
owner IN VARCHAR2 DEFAULT NULL,
property_value_str OUT VARCHAR2);
DBMS_CACHE.GET_USER_PROPERTY (
property_name IN VARCHAR2,
owner IN VARCHAR2 DEFAULT NULL,
property_value_num OUT NUMBER);Parameters
| Parameter | Description |
|---|---|
property_name |
Specifies the property name. Following are the valid values for
|
owner |
Specifies the schema name. This parameter is optional and defaults to the current schema. |
property_value_str |
Retrieves a STRING value for the specified property name. |
property_value_num |
Retrieves a NUMBER value for the specified property name. |
Example
SET SERVEROUTPUT ON;
DECLARE
l_auto_cache NUMBER;
BEGIN
DBMS_CACHE.GET_USER_PROPERTY(
property_name => 'AUTO_CACHE',
owner => 'HR',
property_value_num => l_auto_cache);
DBMS_OUTPUT.PUT_LINE('AUTO_CACHE=' || l_auto_cache);
END;
/Usage Notes
-
You must be logged in as the
ADMINuser or haveEXECUTEprivilege on theDBMS_CACHEpackage to run this procedure. -
MAX_CACHE_SIZEandMAX_CACHE_PERCENTare schema-level quota controls. They do not enable automatic caching by themselves. UseAUTO_CACHEto enable or disable automatic caching for the specified schema. -
If both
MAX_CACHE_SIZEandMAX_CACHE_PERCENTare set, the larger value is used. If neither schema-level quota property is explicitly set,MAX_CACHE_PERCENTdefaults to20.
SET_USER_PROPERTY Procedure
Use DBMS_CACHE.SET_USER_PROPERTY to set automatic-caching properties for a specified schema. Use AUTO_CACHE to enable or disable automatic caching for the schema. Use MAX_CACHE_SIZE and MAX_CACHE_PERCENT to set schema-level quota preferences within the global quota model.
Syntax
DBMS_CACHE.SET_USER_PROPERTY (
property_name IN VARCHAR2,
property_value_num IN NUMBER,
owner IN VARCHAR2 DEFAULT NULL);
DBMS_CACHE.SET_USER_PROPERTY (
property_name IN VARCHAR2,
property_value_str IN VARCHAR2,
owner IN VARCHAR2 DEFAULT NULL
);Parameters
| Parameter | Description |
|---|---|
property_name |
Specifies the property name. Following are the valid values for
|
property_value_num |
Provides a NUMBER value for the specified property name. |
property_value_str |
Provides a STRING value for the specified property name. |
owner |
Specifies the schema name. This parameter is optional and defaults to the current schema. |
Examples
Example to enable automatic caching for a schema:
BEGIN
DBMS_CACHE.SET_USER_PROPERTY(
property_name => 'AUTO_CACHE',
property_value_num => 1,
owner => 'SALES');
END;
/Example to set a schema-level cache quota:
BEGIN
DBMS_CACHE.SET_USER_PROPERTY(
property_name => 'MAX_CACHE_SIZE',
property_value_num => 5368709120,
owner => 'SALES');
END;
/Usage Notes
-
You must be logged in as the
ADMINuser or haveEXECUTEprivilege on theDBMS_CACHEpackage to run this procedure. -
User-level settings override global settings.
-
MAX_CACHE_SIZEandMAX_CACHE_PERCENTdo not enable automatic caching by themselves. -
If both
MAX_CACHE_SIZEandMAX_CACHE_PERCENTare set, the larger value is used. -
If neither schema-level quota property is explicitly set,
MAX_CACHE_PERCENTdefaults to20. -
If
MAX_CACHE_SIZEis set greater thanGLOBAL_CACHE_SIZE, the database raises an error. -
Manual policy always overrides automatic behavior.