共用方式為


工作區系統數據表參考

這很重要

此系統資料表處於公開預覽狀態。

此頁面說明如何使用工作區系統數據表來監視 Azure Databricks 帳戶中的工作區。 數據表中的每個數據列都代表您帳戶中作用中工作區的最新已知狀態,包括元數據和生命周期狀態。

當與其他系統數據表聯結時,此數據表最有用。 您可以使用它來取得帳戶中工作區的可靠性、效能和成本匯總統計數據。

備註

數據表只包含您帳戶中目前所在的工作區。 取消工作區之後,其數據列會從工作區系統數據表中移除。

數據表路徑:此數據表位於 system.access.workspaces_latest

工作區數據表架構

欄位名稱 數據類型 說明 範例
account_id 字串 Databricks 帳戶的識別碼 0722779a-fd4e-49c1-a7a6-8417a97cf9ea
workspace_id 字串 Databricks 工作區的 ID '2274721051152826'
workspace_name 字串 工作區的易於理解名稱 麵團-re-mi
workspace_url 字串 工作區的 URL https://dough-re-mi-pizza.cloud.databricks.com/
create_time 時間戳記 創建工作區的時間戳(秒級精度) 2025-03-05 15:47
status 列舉 工作區的狀態。 若要建立工作區,它一開始會設定為 PROVISIONING 。 繼續檢查狀態,直到狀態為 RUNNING為止。 NOT_PROVISIONEDPROVISIONINGRUNNINGFAILEDBANNED

範例查詢

下列各節包含使用工作區系統數據表的範例 SQL 查詢。

哪些工作區目前正在運行?

下列查詢顯示您帳戶中目前處於RUNNING 狀態的所有工作區。

SELECT
    workspace_id,
    workspace_name,
    workspace_url,
    create_time
FROM
    system.access.workspaces_latest
WHERE
    status = "RUNNING";

哪些工作區的支出最高?

此查詢會計算您帳戶中在過去30天中花費最多的前10個工作區。

WITH
-- apply date filter
usage_with_ws_filtered_by_date AS (
  SELECT
    w.workspace_id,
    w.workspace_name,
    w.workspace_url,
    u.usage_quantity,
    u.usage_unit,
    u.sku_name,
    u.usage_end_time,
    u.cloud
  FROM
    system.billing.usage AS u NATURAL JOIN system.access.workspaces_latest AS w
  WHERE
    u.usage_date > DATE_ADD(CURRENT_DATE(), -30)
),
-- calc list priced usage in USD
prices AS (
  SELECT
    COALESCE(price_end_time, DATE_ADD(current_date, 1)) AS coalesced_price_end_time,
    *
  FROM
    system.billing.list_prices
  WHERE
    currency_code = 'USD'
),
list_priced_usd AS (
  SELECT
    COALESCE(u.usage_quantity * p.pricing.default, 0) as usage_usd,
    u.*
  FROM
    usage_with_ws_filtered_by_date as u
      LEFT JOIN prices AS p
        ON u.sku_name = p.sku_name
        AND u.cloud = p.cloud
        AND u.usage_unit = p.usage_unit
        AND (u.usage_end_time BETWEEN p.price_start_time AND p.coalesced_price_end_time)
)
-- calc total usage in USD
SELECT
  workspace_id,
  workspace_name,
  workspace_url,
  round(sum(usage_usd), 2) AS usage_usd
FROM
  list_priced_usd
GROUP BY
  1,
  2,
  3
ORDER BY
  4 DESC
limit 10;

我帳戶中的哪些作業最昂貴?

此查詢會計算過去 30 天內帳戶中前 10 個成本最高的作業。

with usage_with_cost AS (
  SELECT
    *,
    t1.usage_quantity * list_prices.pricing.default as list_cost
  FROM system.billing.usage t1
  INNER JOIN system.billing.list_prices list_prices on
      t1.cloud = list_prices.cloud and
      t1.sku_name = list_prices.sku_name and
      t1.usage_start_time >= list_prices.price_start_time and
      (t1.usage_end_time <= list_prices.price_end_time or list_prices.price_end_time is null)
),
most_expensive_jobs_30d AS (
  SELECT
    workspace_id,
    usage_metadata.job_id,
    SUM(list_cost) as list_cost
  FROM usage_with_cost
  WHERE
    usage_metadata.job_id IS NOT NULL
    AND usage_date >= CURRENT_DATE() - INTERVAL 30 DAYS
  GROUP BY ALL
  ORDER BY list_cost DESC
  LIMIT 100
),
latest_jobs AS (
  SELECT
    *,
    ROW_NUMBER() OVER (PARTITION BY workspace_id, job_id ORDER BY change_time DESC) as rn
  FROM system.lakeflow.jobs QUALIFY rn=1
)
SELECT
  t1.workspace_id,
  t2.workspace_name,
  t3.name as job_name,
  CONCAT(
    t2.workspace_url, '/jobs/', t1.job_id
  ) as job_url,
  t1.list_cost
FROM most_expensive_jobs_30d t1
LEFT JOIN  system.access.workspaces_latest t2 using (workspace_id)
LEFT JOIN latest_jobs t3 USING (workspace_id, job_id)
ORDER BY list_cost DESC
LIMIT 10;