---
title: ANALYZE TABLE … COMPUTE STORAGE METRICS
description: Compute storage size metrics for cost analysis with ANALYZE TABLE … COMPUTE STORAGE METRICS in Databricks Runtime 18.0 and above, including the `USING INVENTORY` clause in Databricks Runtime 19 and above.
canonical_url: https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-analyze-compute-storage-metrics
---

# ANALYZE TABLE … COMPUTE STORAGE METRICS

**Applies to:** ![check marked yes](https://docs.databricks.com/gcp/en/images/icons/check.png) Databricks Runtime 18.0 and above

The `ANALYZE TABLE … COMPUTE STORAGE METRICS` command computes total storage size metrics for tables. It shows detailed storage breakdown for cost analysis and optimization. For query performance optimization, see [ANALYZE TABLE … COMPUTE STATISTICS](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-analyze-compute-statistics.md).

By default, the command scans the table's files directly. On large tables, add the `USING INVENTORY` clause to read from a pre-generated cloud storage inventory report instead, which lowers both the time and the cost of computing storage metrics. See [Use an inventory report](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-analyze-compute-storage-metrics.md#inv-report).

## Syntax

```
ANALYZE TABLE table_name COMPUTE STORAGE METRICS
  [ USING INVENTORY LOCATION inventory_path
    CONF conf_name ]
```

## Parameters

* **[table\_name](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-names.md#table-name)**

  Identifies the table to be analyzed. The name must not include a [temporal specification or options specification](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-names.md#table-name) or path.
  If the table cannot be found Databricks raises a [TABLE\_OR\_VIEW\_NOT\_FOUND error condition](https://docs.databricks.com/gcp/en/error-messages/table-or-view-not-found-error-class.md).

* **`USING INVENTORY`**

  Optional. Reads storage metrics from a pre-generated cloud storage inventory report instead of scanning the table's files. See [Use an inventory report](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-analyze-compute-storage-metrics.md#inv-report). Takes two sub-parameters:

  * **`LOCATION inventory_path`**

    A STRING literal with the full cloud storage path to the inventory report, including any prefix. This path must match the destination you configured when you set up the inventory report on the source bucket or container, and it must be backed by an external location that you have access to. See [Use an inventory report](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-analyze-compute-storage-metrics.md#inv-report).

    For example, `'gs://your-destination-bucket/your-prefix/'`.

  * **`CONF conf_name`**

    Required. A STRING literal that identifies which inventory report configuration on the source bucket or container to use.

    Use the inventory report's configuration UUID, not its display name. To list the report configurations for a bucket and find the UUID, run the following command, replacing `us-central1` and `my-project` with the location and project ID of the source bucket:

    ```bash
    gcloud storage insights inventory-reports list --location=us-central1 --project=my-project
    ```

## Description

Computes total storage size metrics for a specific table. This command returns comprehensive storage information including total bytes, active bytes, vacuumable bytes, and time travel bytes, along with the associated number of files for each category.

Use this command to identify large or unused tables, optimize storage costs, and understand why the total storage size differs from the active table size. This is useful for platform administrators who need to analyze storage patterns across multiple tables or track storage changes over time.

## Output metrics

The command returns three columns: `metric_name`, `metric_value`, and `metric_description`. One row is returned for each of the following metrics:

| `metric_name`           | Description                                                                                                                                                                                                                                                     |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `total_bytes`           | The total storage size, in bytes, for the table. This equals transaction log size + active bytes + vacuumable bytes + time travel bytes.                                                                                                                        |
| `num_total_files`       | The total number of files, including delta log files, active files, vacuumable files, and time travel files.                                                                                                                                                    |
| `active_bytes`          | The size of data files, in bytes, actively referenced by the table (same as `sizeInBytes`).                                                                                                                                                                     |
| `num_active_files`      | The total number of files actively referenced by the table.                                                                                                                                                                                                     |
| `vacuumable_bytes`      | The size of data, in bytes, that you can remove by running [VACUUM](https://docs.databricks.com/gcp/en/sql/language-manual/delta-vacuum.md) or enabling [predictive optimization](https://docs.databricks.com/gcp/en/optimizations/predictive-optimization.md). |
| `num_vacuumable_files`  | The number of vacuumable files.                                                                                                                                                                                                                                 |
| `time_travel_bytes`     | The size of historical data, in bytes, used for rollbacks and [time travel](https://docs.databricks.com/gcp/en/tables/history.md) operations. Also known as tombstoned bytes or failsafe bytes.                                                                 |
| `num_time_travel_files` | The number of files used for time travel.                                                                                                                                                                                                                       |

## Details

* By default, the command uses a recursive list approach to compute storage information. Execution time is typically within minutes, but can take up to several hours for very large tables.
* This command works for both Unity Catalog managed and external tables.
* The command computes storage metrics at runtime. Results are not stored in Unity Catalog and are not reflected in `DESCRIBE EXTENDED` output, which shows only the active table size.
* To track storage changes over time, run this command periodically and store the results in a table. Run this command in a loop across multiple tables to analyze storage patterns across your data estate. See [Compute storage metrics for all tables in a catalog](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-analyze-compute-storage-metrics.md#example-all-tables).

## <a id="inv-report" />Use an inventory report

**Applies to:** ![check marked yes](https://docs.databricks.com/gcp/en/images/icons/check.png) Databricks Runtime 19 and above

Use the `USING INVENTORY` clause on large tables to lower the time and cost of computing storage metrics, by reading a pre-generated cloud storage inventory report instead of scanning the table's files. Databricks recommends this clause for tables consisting of 100,000 or more files, or for tables that are heavily partitioned over multiple keys. For smaller tables, or tables without a configured inventory report, use the command without this clause.

The `USING INVENTORY` clause works for Unity Catalog managed and external tables. It runs on classic compute only. For more limitations, see [USING INVENTORY limitations](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-analyze-compute-storage-metrics.md#inv-limitations).

> [!IMPORTANT]
>
> Use inventory reports only on tables where metric staleness is acceptable.
>
> Metrics computed with this clause reflect the table's state as of the most recent inventory report, not its current state. Because cloud providers generate inventory reports on a schedule, results might be up to 24 hours stale. The results might differ from the values the command returns without this clause.
>
> If the most recent inventory report is too stale, the command returns an error instead of computing metrics. See [Stale inventory report errors](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-analyze-compute-storage-metrics.md#inv-stale).

For information on the metrics the command returns, see [Output metrics](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-analyze-compute-storage-metrics.md#output-metrics).

### Prerequisites

The `USING INVENTORY` clause has the following prerequisites:

* **Privileges to configure for the first time**: Metastore admins have the required Databricks privileges by default. If you are not an admin, to set up inventory reports and register their destination as an external location, you must have the following permissions:
  * Cloud provider permissions to configure inventory reports on the source bucket or container.
  * One of the following Databricks privileges to register the inventory destination as an external location:
    * The `CREATE EXTERNAL LOCATION` privilege on both the metastore and the storage credential it references.
    * The `MANAGE` privilege on the external location.

- **A configured inventory report**: Configure a [GCS inventory report](https://docs.cloud.google.com/storage/docs/insights/inventory-reports) on each source bucket that holds the tables you want to analyze. Use these settings:
  * **File format**: Apache Parquet
  * **Destination path**: `{report-config-id}/{date}` — GCS inventory reports require this exact path format to generate correctly
  * **Scheduling options**: Run every day
  * **Metadata fields**: Include `bucket`, `name`, `size`, `updated`, and `timeDeleted` (used as-is in both the gcloud CLI and the console). Without them, the command can't compute correct output.

> [!TIP]
>
> Databricks recommends selecting all available metadata fields for future flexibility.
>
> Databricks also recommends configuring a 14-day lifecycle policy on the inventory destination bucket to automatically delete old reports. This improves command performance and reduces storage costs. See [AWS lifecycle management](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html), [Azure lifecycle management](https://learn.microsoft.com/en-us/azure/storage/blobs/lifecycle-management-policy-configure?tabs=azure-portal), or [GCP lifecycle management](https://docs.cloud.google.com/storage/docs/lifecycle).

* **An external location for the inventory report**: You must have read access in Databricks to the inventory report's destination path.

  * If the path isn't in an existing external location, register it as an external location first. See [Connect to a Google Cloud Storage (GCS) external location](https://docs.databricks.com/gcp/en/connect/unity-catalog/cloud-storage/external-locations-gcs.md).

* **Privileges to run the command**: You must have the `READ FILES` privilege on the external location in Databricks that backs the inventory report destination, in addition to your existing privileges on the table you analyze.

> [!NOTE]
>
> Cloud providers take up to 48 hours (AWS) or 24 hours (Azure, GCP) to generate the first inventory report after initial configuration.

To find the source bucket or container for a table, run [DESCRIBE TABLE EXTENDED](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-describe-table.md) and check the `Location` field in the output. For materialized views and streaming tables, you must use `DESCRIBE EXTENDED` to find the actual storage location. You must verify that your inventory report is configured on that source bucket or container.

### <a id="inv-stale" />Stale inventory report errors

The command searches for the most recent complete inventory report generated in the last 14 days. If it finds no report in that window, the command doesn't compute metrics and returns an `ANALYZE_TABLE_COMPUTE_STORAGE_METRICS_INVENTORY_CONTENTS_NOT_VALID` error with a message similar to the following:

```text
No inventory reports found in the last 14 days (window: 2026-07-08 to 2026-07-22).
1 report directory(s) exist but fall outside the lookback window.
Ensure a recent inventory report has been generated.
```

To resolve this error, confirm that the source bucket or container generates inventory reports on the schedule you configured, then run the command again after a new report is generated. See [Prerequisites](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-analyze-compute-storage-metrics.md#prerequisites).

## Table type considerations

For materialized views and streaming tables, `total_bytes` includes the size of the table and associated metadata. The `active_bytes` metric excludes the table's `vacuumable_bytes` and `time_travel_bytes`.

For shallow clones, `total_bytes` includes only the clone's own metadata and Delta log files, excluding source table files. `active_bytes` is zero because the clone references the source table's data files.

## Examples

### Compute storage metrics

To compute storage metrics, run the following command:

```sql
ANALYZE TABLE main.my_schema.my_table COMPUTE STORAGE METRICS;
```

The command returns output, such as the following:

```
metric_name              metric_value  metric_description
-----------------------  ------------  --------------------------------------------------
total_bytes                5368709120  Total bytes on disk
num_total_files                  1250  Total files on disk
active_bytes               4294967296  Bytes in current snapshot
num_active_files                 1000  Files in current snapshot
vacuumable_bytes            805306368  Bytes eligible for vacuum
num_vacuumable_files              150  Files eligible for vacuum
time_travel_bytes           268435456  Bytes reachable by time travel (excluding active)
num_time_travel_files             100  Files reachable by time travel (excluding active)
```

The output shows:

* **Total storage**: 5.37 GB across 1,250 files
* **Active data**: 4.29 GB in 1,000 files (current table version)
* **Vacuumable data**: 805 MB in 150 files (`VACUUM` can reclaim this storage size)
* **Time travel data**: 268 MB in 100 files (for historical queries)

### Compute storage metrics using an inventory report

The following example computes the same metrics from an inventory report instead of scanning the table's files:

```sql
ANALYZE TABLE main.my_schema.my_table COMPUTE STORAGE METRICS
USING INVENTORY LOCATION 'gs://your-destination-bucket/your-prefix/'
CONF 'report-config-id';
```

Because inventory reports reflect the table's state at the time the report was generated (up to 24 hours earlier), the output may differ from a direct scan. For example:

```
metric_name              metric_value  metric_description
-----------------------  ------------  --------------------------------------------------
total_bytes                5100273664  Total bytes on disk
num_total_files                  1232  Total files on disk
active_bytes               4076863488  Bytes in current snapshot
num_active_files                  984  Files in current snapshot
vacuumable_bytes            771751936  Bytes eligible for vacuum
num_vacuumable_files              148  Files eligible for vacuum
time_travel_bytes           251658240  Bytes reachable by time travel (excluding active)
num_time_travel_files             100  Files reachable by time travel (excluding active)
```

See [Use an inventory report](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-analyze-compute-storage-metrics.md#inv-report).

### <a id="example-all-tables" />Compute storage metrics for all tables in a catalog

To compute storage metrics for every table in a catalog, all using inventory reports at the same destination, use a loop. The following example lists the tables using an [information schema](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-information-schema.md), which every catalog automatically includes:

```python
%python
tables = spark.sql("""
  SELECT table_catalog, table_schema, table_name
  FROM main.information_schema.tables
  WHERE table_type IN (
    'MANAGED', 'EXTERNAL',
    'STREAMING_TABLE', 'MATERIALIZED_VIEW',
    'MANAGED_SHALLOW_CLONE', 'EXTERNAL_SHALLOW_CLONE'
  )
""").collect()

for t in tables:
    full_name = f"{t.table_catalog}.{t.table_schema}.{t.table_name}"
    result = spark.sql(f"""
      ANALYZE TABLE {full_name} COMPUTE STORAGE METRICS
      USING INVENTORY LOCATION 'gs://your-destination-bucket/your-prefix/'
      CONF 'report-config-id'
    """)
    result.show()
```

## <a id="inv-limitations" />USING INVENTORY limitations

The `USING INVENTORY` clause has the following limitations:

* This clause runs on classic compute only. It isn't supported on serverless compute or Databricks SQL warehouses.
* This clause supports catalog tables only, including both managed and external tables. It doesn't support path-based Delta Lake tables, which raise an error: [ANALYZE\_TABLE\_COMPUTE\_STORAGE\_METRICS\_NOT\_SUPPORTED error condition](https://docs.databricks.com/gcp/en/error-messages/analyze-table-compute-storage-metrics-not-supported-error-class.md).
* If object versioning is enabled on the source bucket or container, results aren't guaranteed to be correct.
* If a table's storage location changes, reconfigure the inventory report at the new source bucket or container. The original location no longer generates reports for the table. For example, converting an external table to a managed table changes the table's storage location. See [Convert external or foreign Delta Lake tables to Unity Catalog managed tables](https://docs.databricks.com/gcp/en/tables/convert-to-managed.md).

If your tables span multiple source buckets, each bucket has its own configuration UUID to track.

## Notebook: Compute storage metrics for multiple tables

The following notebook runs `ANALYZE TABLE ... COMPUTE STORAGE METRICS ... USING INVENTORY` across a set of Unity Catalog tables and stores the results in a Delta Lake table. Use it to analyze storage across many tables at once.

#### Compute storage metrics for multiple tables notebook

[Get notebook](https://docs.databricks.com/notebooks/source/delta/analyze-compute.html)

## Related statements

* [ANALYZE TABLE … COMPUTE STATISTICS](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-analyze-compute-statistics.md)
* [VACUUM](https://docs.databricks.com/gcp/en/sql/language-manual/delta-vacuum.md)
* [Predictive optimization for Unity Catalog managed tables](https://docs.databricks.com/gcp/en/optimizations/predictive-optimization.md)
* [Work with table history](https://docs.databricks.com/gcp/en/tables/history.md)
* [Convert external or foreign Delta Lake tables to Unity Catalog managed tables](https://docs.databricks.com/gcp/en/tables/convert-to-managed.md)
* [External locations](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-external-locations.md)
