Skip to content

Updated

Storage schema

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.

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 (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.

buckets PK text id 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 PK uuid id FK text bucket_id 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 PK integer id varchar(100) name varchar(40) hash timestamp executed_at buckets_id:id

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.

TableHolds
bucketsBucket configuration: its id and name, whether the bucket is public, and constraints such as file_size_limit and allowed_mime_types.
objectsPer-file metadata: the owning bucket_id, the object name and path_tokens, a metadata JSON blob, and version information.
migrationsThe schema migrations applied to the storage service. This table is standalone.

In a bucket with 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 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.