About Default and Custom Contexts

Discover how the database uses both default and custom end-user contexts to manage session attributes and enforce fine-grained access control for applications.

Context attributes extend the end-user security context beyond identity and roles. They are JSON name-value pairs organized by named namespaces that an application can use in data grant predicates, SQL queries, and application logic. The application passes these context attributes to the database as part of the EndUserSecurityContext payload.

Requirement for a context definition in the database

Before an application can pass context attributes at runtime, you must create a corresponding END USER CONTEXT schema object in the database using the CREATE END USER CONTEXT command. This definition specifies the end-user context name, its allowed attributes, their data types, and optional PL/SQL handler logic.

If the application sends a context attribute that does not have a corresponding end-user context definition, the attribute is ignored. Data grant predicates that reference the attribute through the ORA_END_USER_CONTEXT function do not receive its value.

Oracle AI Database supports two categories of end-user contexts:

Default (System-Defined) Contexts

Two predefined, system-managed end-user contexts are always available in every end-user security context and do not require explicit instantiation. You cannot modify attributes in these end-user contexts directly; the database initializes them based on the user identity propagated from IAM.

Custom (User-Defined) Contexts

In addition to system contexts, you can create your own end-user contexts using JSON schema definitions.

Custom contexts allow different applications to define and manage their own attributes without conflict. For example:

You can configure each attribute in a custom context with either a static default value or a lazy-loading event handler (PL/SQL callback), which is invoked the first time the attribute is read. You must create custom contexts in the database before you can use them at runtime. Instantiation occurs automatically on first reference and does not require an explicit command.

Size limits

When defining custom contexts and attributes, ensure you stay within the following system limits: