--- id: 'storage-schema-design' title: 'Storage schema' description: 'Learn how Supabase Storage keeps bucket and object metadata in the storage schema in Postgres, which tables it holds, and why you treat them as read-only.' sidebar_label: 'Schema' tocVideo: ch2UGHMreB0 --- Knowing the Storage schema tells you what you can query directly and what you change only through the Storage API. For how to write policies on these tables, see [Storage access control](/docs/guides/storage/security/access-control). ## Tables Storage keeps metadata about your buckets and objects in a dedicated Postgres schema in your project called `storage`. The objects themselves are stored in a provider like S3. You can use [Row Level Security](/docs/guides/database/postgres/row-level-security) (RLS) policies on these tables for access control. The following diagram shows the schema. You can query these tables directly to retrieve information about your files without going through the Storage API. ```mermaid erDiagram accTitle: Storage schema tables accDescr: Three tables. Each row in buckets can own many rows in objects, joined on buckets.id and objects.bucket_id. The migrations table stands alone. buckets ||--o{ objects : "buckets_id:id" buckets { text id PK text name timestamptz created_at timestamptz updated_at boolean public bigint file_size_limit text[] allowed_mime_types text owner_id text versioning_status jsonb lifecycle_configuration } objects { uuid id PK text bucket_id FK text name timestamptz created_at timestamptz updated_at jsonb metadata text[] path_tokens text version text owner_id timestamptz archived_at boolean is_delete_marker boolean is_versioned } migrations { integer id PK varchar(100) name varchar(40) hash timestamp executed_at } ``` The schema centers on three tables. Each `buckets` row can own many `objects` rows by a one-to-many relationship that joins `buckets.id` to `objects.bucket_id`. | Table | Holds | | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- | | `buckets` | Bucket configuration: its `id` and `name`, whether the bucket is `public`, and constraints such as `file_size_limit` and `allowed_mime_types`. | | `objects` | Per-file metadata: the owning `bucket_id`, the object `name` and `path_tokens`, a `metadata` JSON blob, and version information. | | `migrations` | The schema migrations applied to the storage service. This table is standalone. | In a bucket with [object versioning](/docs/guides/storage/buckets/object-versioning) turned on, each version of an object is a separate `objects` row, and `archived_at` is `null` only for the current version. ## Modifying the schema Changing the `storage` schema or its records with SQL can leave objects that you can't access but are still billed for. Treat the schema and its records as read-only, and do all operations, including uploading, copying, moving, and deleting, **through the Storage API**. Changing the schema or its records with SQL causes problems that the Storage API avoids: - Deleting metadata doesn't remove the object from the underlying storage provider. - Changing the schema can conflict with Supabase updates to it and cause downtime. Supabase does encourage custom indexes, because they can significantly improve the performance of the RLS policies that enforce access control. ## Related resources - [Storage access control](/docs/guides/storage/security/access-control): write RLS policies on the `storage.objects` table. - [Storage ownership](/docs/guides/storage/security/ownership): how the `owner_id` column is set. - [Row Level Security](/docs/guides/database/postgres/row-level-security): how policies work in Postgres.