# Storage layout

> Tables, segments, versions and how space is reclaimed.

---

LLMS index: [llms.txt](/llms.txt)

---

> [!NOTE]
> Object versioning, multipart uploads, and SSE-S3/SSE-C encryption are part of the core `pgsilo` MVP. Object Lock retention/legal hold, bucket lifecycle rules, hard bucket quotas, and object annotations are **Preview** features in the MVP release.

`pgsilo` stores all bucket metadata, object versions, byte segments, multipart parts, annotations, and IAM state in PostgreSQL (schema 14). Understanding the boundary between object visibility, logical quota accounting, and PostgreSQL physical space reclamation is essential for capacity planning.

## Segment layout and multipart publication {#segments-and-multipart}

Object payloads are split into fixed-size `bytea` segments stored in `silo.object_segments`. The default segment size (`SILO_PG_SEGMENT_SIZE`) is **8 MiB**, configurable from **1 MiB to 64 MiB** at initial database setup. Streaming S3 reads and range requests fetch only the required segments without buffering the entire object in gateway memory.

The default maximum object size (`SILO_PG_MAX_OBJECT_SIZE`) is **256 MiB**, configurable from **1 MiB to 1 GiB** at initialization. Completed multipart uploads obey the same ceiling.

Unfinished multipart parts consume physical table space in PostgreSQL, but they do not count toward a bucket's committed logical quota until `CompleteMultipartUpload` atomically validates part order, checksums, quota, and Object Lock rules and publishes the assembled version. Clean up abandoned uploads with `AbortMultipartUpload` or an `AbortIncompleteMultipartUpload` lifecycle rule.

## Versions and delete markers {#versions-and-delete-markers}

| Bucket versioning state / operation | Storage behavior |
| --- | --- |
| Unversioned `PUT` overwrite | Replaces the current unversioned body and unlinks its previous annotation set |
| Versioned `PUT` overwrite | Publishes a new `version_id` and retains historical versions |
| Versioned `DELETE` without `versionId` | Inserts a delete marker as the latest version; historical bodies remain stored and count toward quota |
| `DELETE` with explicit `versionId` | Permanently removes that version (unless blocked by Object Lock retention or legal hold) |
| Suspended versioning (`Suspended`) | New writes use `null`-version semantics while preserving existing historical versions |
| Current version is a delete marker | Standard `GET` / `HEAD` without `versionId` returns `404 NoSuchKey` |
{.wide}

Each published version carries an external `version_id` (UUID) and an internal `object_id` (`bigint`). Independent S3 HTTP requests never share a database snapshot, whereas SQL queries via `silo_api` can read object bodies and application tables within a single transaction snapshot.

## Object Lock and retention (Preview) {#object-lock}

Shared database mutation logic enforces `GOVERNANCE` retention, `COMPLIANCE` retention, and `legal hold` across both S3 HTTP requests and `silo_api` SQL calls. Object-lock buckets require versioning to be enabled at bucket creation.

- Bypassing `GOVERNANCE` retention requires an S3 request with `x-amz-bypass-governance-retention: true` and `s3:BypassGovernanceRetention` permission (plus `UPDATE` on the bucket ACL relation under `iam_and_pg`).
- Neither `COMPLIANCE` retention nor an active `legal hold` can be bypassed through S3 or SQL.
- `silo_api` SQL functions inherit default bucket retention on `put_object` / `copy_object` and enforce lock checks on `delete_object`, but expose no governance bypass parameter.
- Object Lock protects against untrusted S3 and SQL callers; it cannot prevent a PostgreSQL superuser or the trusted database owner (`silo_owner`) from modifying underlying database tables directly.

## Server-side encryption {#encryption}

| Path | Behavior |
| --- | --- |
| `SSE-C` | Client supplies the encryption key over HTTPS on every read, write, copy, or part upload |
| `SSE-S3` (`AES256`) | Uses the gateway's static KMS key (`MINIO_KMS_SECRET_KEY` / `MINIO_KMS_SECRET_KEY_FILE`) for explicit header requests and default bucket encryption |
| `SSE-KMS` (external KMS) | Not implemented in the PostgreSQL backend |
| Public SQL API (`silo_api`) | Rejects reading encrypted bodies and rejects plaintext writes to default-encrypted buckets (`SQLSTATE 0A000`) |
| Annotations and ZIP extraction | Inherit the parent object version's SSE-C or SSE-S3 encryption |
{.wide}

SSE encrypts object segment payloads and annotation bodies; it does not encrypt bucket names, object keys, or PostgreSQL catalog metadata. Back up your static `MINIO_KMS_SECRET_KEY` alongside database backups—restoring PostgreSQL tables without the static KMS key leaves SSE-S3 payloads permanently unreadable.

## Hard bucket quotas (Preview) {#hard-bucket-quotas}

Hard bucket quotas are enforced atomically in PostgreSQL (`silo.bucket_quota`) rather than through asynchronous gateway estimates. Billable logical usage (`billableBytes`) equals the sum of committed object version bodies across all retained versions plus their linked annotation payloads.

| Operation | Effect on logical bucket quota |
| --- | --- |
| Overwrite in a versioned bucket | Both the new version and retained old versions count toward quota |
| `DELETE` without `versionId` in a versioned bucket | Adds a zero-byte delete marker; retained historical versions still count |
| `DELETE` with `versionId` | Immediately decrements that version's body bytes and linked annotation bytes |
| Replace or delete an annotation | Immediately applies the net byte difference |
| `CompleteMultipartUpload` | Checks total assembled object size against remaining quota at commit |
{.wide}

For example, four retained 256 MiB versions consume a full 1 GiB bucket quota even when only one key is visible in `ListObjectsV2`. Physical overhead from incomplete multipart uploads, PostgreSQL indexes, WAL segments, and dead MVCC tuples is not bounded by logical bucket quota.

Configure and inspect quotas with `mcli`:

```bash
mcli quota set pg/attachments --size 1GiB
mcli quota info pg/attachments
```

## Lifecycle rules, background cleanup, and `VACUUM` {#lifecycle-and-vacuum}

- **Lifecycle worker (Preview)**: writable gateways coordinate through PostgreSQL leases (`silo.TryLifecycleLock`) to expire current/noncurrent versions, remove expired delete markers, and abort incomplete multipart uploads. Remote storage tiering is not supported.
- **Annotation orphan reaper**: unlinking annotations (via unversioned overwrite, version deletion, or force bucket deletion) releases logical quota immediately and enqueues orphan payload rows for bounded batch deletion by a writable gateway. Always keep at least one writable `silo server` gateway connected to the PostgreSQL primary—even if applications only use `silo_api` over SQL—so background cleanup and native-auth heartbeats continue running.
- **PostgreSQL physical space reclamation**: deleting objects or draining the annotation cleanup queue marks PostgreSQL tuples as dead for `autovacuum` reuse; it does not immediately shrink OS filesystem files. Long-running SQL transactions hold back `VACUUM` horizon and delay space reuse. Monitor logical bucket usage, annotation cleanup backlog, dead tuple ratios, physical database size, and WAL retention separately.

## Force bucket deletion {#force-delete}

Standard `DeleteBucket` (`DELETE /{bucket}`) requires an empty bucket. Sending `x-minio-force-delete: true` (any non-empty header value, including `"false"`, triggers the permission check) requires both `s3:DeleteBucket` and `s3:ForceDeleteBucket` (plus `DELETE` and `UPDATE` under `iam_and_pg`) and removes all versions, delete markers, and incomplete uploads in a single transaction. Object-lock buckets reject force deletion with HTTP 405 even when empty. SQL `silo_api.drop_bucket` has no force option.

---

Backlinks:

- [Architecture](/docs/s3/architecture/)
- [Compatibility](/docs/s3/compatibility/)
- [Reference](/docs/s3/reference/)
- [Versioning](/docs/s3/tutorial/versioning/)
