Repository navigation
Description
Bug report
Describe the bug
After upgrading a self-hosted instance from v1.73.0 to v1.77.3, storage-api reports healthy, lists buckets and objects fine, but every write fails with HTTP 500:
{"statusCode":"500","error":"DatabaseError","message":"database error, code: 42P10"}Stack (from the container logs): StoragePgDB.upsertObject → runQuery → mapPgError → DatabaseError 42P10. PostgreSQL 42P10 is invalid_column_reference: there is no unique or exclusion constraint matching the ON CONFLICT specification.
Affected: standard REST uploads (POST /object/{bucket}/{key}), with and without x-upsert, on every bucket (with or without allowed_mime_types). TUS and S3 multipart go through the same upsertObject, so they should be affected too.
Root cause
- feat: support addressing objects by versionId #1341 (shipped in v1.72.0 / v1.72.1, 2026-08-27) introduced the tenant migrations
0065-objects-key-version-index,0066-objects-current-version-index,0067-objects-null-version-index. In that version the indexes were defined withoutCOLLATE "C":CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS idx_objects_current_version ON storage.objects (bucket_id, name) WHERE archived_at IS NULL;
- fix: add COLLATE "C" to name in versioned-object indexes #1352 (v1.72.2+, 2026-08-31) fixed this by adding
COLLATE "C"in place in the same three migration files. Instances that had already applied 0065–0067 from v1.72.0/v1.72.1 never got the collated definition: the runner does not re-apply an already-executed id (and refreshes the hash on mismatch), andCREATE INDEX IF NOT EXISTSwould be a no-op anyway. - feat: drop bucketid_objname and add version list test coverage #1353 (v1.77.0) drops
bucketid_objname(migration0072) and switches the upsert arbiter to the new partial index (src/storage/database/pg.ts,upsertObject):On an instance whoseconst conflictTarget = await this.hasMigration("objects-current-version-index") ? 'ON CONFLICT (bucket_id, name COLLATE "C") WHERE archived_at IS NULL' : "ON CONFLICT (name, bucket_id)";
idx_objects_current_versionis(bucket_id, name)without the collation, PostgreSQL cannot infer an arbiter for(bucket_id, name COLLATE "C") WHERE archived_at IS NULL, and the old(bucket_id, name)unique index that used to arbitrate is gone → 42P10 on every insert.
So any self-hosted instance that ran v1.72.0 or v1.72.1 at some point (applied 0065–0067 before #1352) breaks on upgrade to ≥ v1.77.0, while a fresh install is fine. Rolling the image back to < v1.77.0 does not help either: bucketid_objname is already dropped and the old code targets it.
State observed on the broken instance
$ select id, name, executed_at from storage.migrations where id between 65 and 72;
65 | objects-key-version-index | 2026-08-29 ← applied from v1.72.1
66 | objects-current-version-index | 2026-08-29
67 | objects-null-version-index | 2026-08-29
68..71 | (lifecycle, list-objects-with-versions, delete-marker index) | 2026-09-15
72 | drop-bucketid-objname-index | 2026-09-15 ← v1.77.3
$ select indexdef from pg_indexes where schemaname='storage' and tablename='objects';
CREATE UNIQUE INDEX idx_objects_current_version ON storage.objects USING btree (bucket_id, name) WHERE (archived_at IS NULL)
CREATE UNIQUE INDEX idx_objects_null_version ON storage.objects USING btree (bucket_id, name) WHERE (NOT is_versioned)
CREATE UNIQUE INDEX objects_bucket_id_name_version_key ON storage.objects USING btree (bucket_id, name, version) NULLS NOT DISTINCT
-- bucketid_objname: gone (0072)
To Reproduce
- Self-hosted Supabase (docker compose),
supabase/storage-api:v1.72.1,STORAGE_BACKEND=file, PostgreSQL 17. Start once so 0065–0067 are applied. - Bump to
supabase/storage-api:v1.77.3(0068–0072 apply, container healthy). POST /storage/v1/object/{bucket}/test.txtwith the service role → 500 / 42P10.GET,list,DELETEstill work.
Expected behavior
Uploads keep working after the upgrade, i.e. the migration chain must guarantee the collated unique indexes exist before 0072 drops bucketid_objname.
Workaround applied
Recreate the three indexes with the definitions shipped in /app/migrations/tenant/0065–0067 (create the new one concurrently before dropping the old one so uniqueness is never lost):
CREATE UNIQUE INDEX CONCURRENTLY objects_bucket_id_name_version_key_c
ON storage.objects (bucket_id, name COLLATE "C", version) NULLS NOT DISTINCT;
CREATE UNIQUE INDEX CONCURRENTLY idx_objects_current_version_c
ON storage.objects (bucket_id, name COLLATE "C") WHERE archived_at IS NULL;
CREATE UNIQUE INDEX CONCURRENTLY idx_objects_null_version_c
ON storage.objects (bucket_id, name COLLATE "C") WHERE NOT is_versioned;
DROP INDEX CONCURRENTLY storage.objects_bucket_id_name_version_key;
ALTER INDEX storage.objects_bucket_id_name_version_key_c RENAME TO objects_bucket_id_name_version_key;
DROP INDEX CONCURRENTLY storage.idx_objects_current_version;
ALTER INDEX storage.idx_objects_current_version_c RENAME TO idx_objects_current_version;
DROP INDEX CONCURRENTLY storage.idx_objects_null_version;
ALTER INDEX storage.idx_objects_null_version_c RENAME TO idx_objects_null_version;Uploads, upserts, duplicate detection (400), listing and deletes are back to normal right after.
Suggested fix
A new tenant migration (or a guard in 0072) that checks pg_get_indexdef() of the three indexes and, when name COLLATE "C" is missing, recreates them with the SQL above — so that instances which applied 0065–0067 from v1.72.0/v1.72.1 are healed before bucketid_objname is dropped. Editing already-shipped migration files (#1352) cannot reach those instances.
System information
- Storage: v1.73.0 → v1.77.3 (issue introduced by v1.77.0 / feat: drop bucketid_objname and add version list test coverage #1353 on top of feat: support addressing objects by versionId #1341→fix: add COLLATE "C" to name in versioned-object indexes #1352 history)
- Self-hosted, docker compose,
STORAGE_BACKEND=file,supabase/postgres:17.6.1.171 - Migration history: 0065–0067 applied on 2026-08-29 from v1.72.1
Activity
TylerHillery commentedon Sep 22, 2026
Thanks for the detailed report.
This affects self-hosted installations that applied migrations 0065–0067 while running Storage v1.72.0–v1.72.3. The index definitions were corrected in v1.72.4, but previously applied migrations were not replayed. The failure becomes visible after upgrading to v1.77.0+, when the legacy bucketid_objname index is removed.
We don’t plan to add an automatic repair migration given the limited affected release window and the operational cost of rebuilding these indexes for every installation. Self-hosted users who have not run those versions should skip them and go directly to v1.72.4+. If migrations 0065–0067 were already applied by an affected version, later upgrades do not repair the indexes. Manual repair is required before upgrading to v1.77.0+.
First, confirm the definitions are missing COLLATE "C":
Then, outside a transaction, replace them:
Verify uploads and upserts work, then remove the backups:
Run each concurrent command separately and not inside a transaction. Please let me know if you have any additional questions.
feat(profiles): profile photos for developers and logos for companies
feat(profiles): profile photos for developers and logos for companies
feat(profiles): profile photos for developers and logos for companies