Repair ownership
Databases
Repair ownership
Reassign ownership of a database’s objects to the owner role after a restore.
POST
Repair ownership
Reassigns ownership of every table, sequence, view, and materialized view in the database to the database’s owner role. Idempotent — safe to run multiple times.
When to use this
Call this endpoint after you’ve restored apg_dump into your database and then see permission denied for table X (Postgres SQLSTATE 42501) when your application connects.
Why it happens: pg_dump / pg_restore runs as a superuser on the DBHost side. The restored tables end up owned by the superuser (or by whatever role name is baked into the dump — often postgres). Your application, however, connects as the owner role for your database, which doesn’t own the restored tables and therefore can’t read them.
New restores triggered through DBHost automatically run this repair step at the end. This endpoint exists for:
- Databases that were restored before the automatic repair existed.
- Clean-up after out-of-band
psql/pg_restoreactivity. - Any situation where your app role hits
permission deniedon tables you expect to own.
Path parameters
| Parameter | Type | Description |
|---|---|---|
id | uuid | Database ID |
What it does
For the target database only:ALTER SCHEMA public OWNER TO <owner>+ grantsUSAGE, CREATE.- Iterates every non-system schema and issues
ALTER TABLE/SEQUENCE/VIEW/MATERIALIZED VIEW ... OWNER TO <owner>. - Regrants the SQL-explorer role
SELECTon the restored tables so the dashboard explorer keeps working.
Response
200 OK
Errors
| Status | Code | Description |
|---|---|---|
| 401 | UNAUTHORIZED | Missing or invalid API key |
| 404 | DATABASE_NOT_FOUND | Database doesn’t exist, isn’t owned by this user, or isn’t in scope for this key |
| 500 | AGENT_ERROR | The VPS agent couldn’t connect to the database or reassign ownership |