Sub topic 11
Reading the system.access.audit table
This chapter assumes you can write basic SQL and have read the earlier chapters on system tables and what audit logs record. You also need SELECT on system.access.audit, as granted earlier in the tutorial.
One row per event
system.access.audit stores one row for each auditable action in your Databricks account. Examples are a user requesting table metadata, a grant being changed, or a login. The table is account-wide, so it includes events from every workspace attached to the metastore's account.
To see the current columns, describe the table:
DESCRIBE TABLE system.access.audit;The columns you will use most
| Column | What it holds |
|---|---|
| `event_time` | Timestamp of the event (UTC). |
| `event_date` | Date of the event. The table is partitioned by date, so filter on it. |
| `workspace_id` | The workspace where the event occurred. Account-level events have no workspace. |
| `user_identity` | A struct. `user_identity.email` is the actor. |
| `service_name` | The area that produced the event, such as `unityCatalog` or `accounts`. |
| `action_name` | What was done, such as `getTable` or `createTable`. |
| `request_params` | A map of string keys to string values. The keys depend on the action. |
| `response` | A struct with `status_code`, `error_message`, and `result`. |
| `source_ip_address` | Where the request came from. |
A row's meaning comes from service_name and action_name together. The keys inside request_params change with the action. For example, full_name_arg identifies the table in getTable events, and other actions use different keys.
Discover what exists before you filter
You rarely know the exact action names up front. List them for Unity Catalog and see how often each occurs:
SELECT
action_name,
count(*) AS event_count
FROM system.access.audit
WHERE service_name = 'unityCatalog'
AND event_date >= current_date() - INTERVAL 7 DAYS
GROUP BY action_name
ORDER BY event_count DESC
LIMIT 50;Next, pick one action and read a few full rows to learn its request_params keys. Then write a targeted filter, like this one for a single table:
SELECT
event_time,
user_identity.email AS user_email,
action_name,
request_params.full_name_arg AS table_name,
response.status_code
FROM system.access.audit
WHERE service_name = 'unityCatalog'
AND action_name = 'getTable'
AND request_params.full_name_arg = 'main.sales.daily_revenue'
AND event_date >= current_date() - INTERVAL 7 DAYS
ORDER BY event_time DESC;Reading the response
response.status_code follows HTTP conventions. A value of 200 means the request succeeded. Values of 400 and above mean it failed, for example 403 for a permission denial. A failed event still tells you who tried what, so it is useful for security review. The response.error_message field often explains the reason.
Common mistakes
- Treating a read of metadata as a read of data. A
getTableevent means someone requested table metadata. It does not prove they queried the rows. - Guessing
request_paramskeys. A wrong key returnsNULLand silently drops rows from your filter. Inspect sample rows first. - Ignoring time lag. Events can arrive after the action. Do not treat a missing recent event as proof that nothing happened.
- Forgetting that the table covers many workspaces. Add
workspace_idto the filter when you only care about one.
Exercise
A query on system.access.audit filters on requestparams.fullname_arg = 'main.sales.orders' and returns no rows, but you know people use the table. Name two likely causes.
Show answer
First, the action you filtered on may not use the fullnamearg key. Other actions put the table name under different requestparams keys, so the filter yields NULL and matches nothing. Second, the eventdate range may be too narrow, or the servicename and actionname filters may not match the real values. List the actions with a GROUP BY on action_name and inspect sample rows to confirm the keys.