Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Ownership transfer was a one-row UPDATE. Then we added least-privilege.

Originally published at nlqdb.com/blog Multi-tenant Postgres, one schema per tenant database. On day one, every query ran as the shared owner role, so "transfer this database to the user who just signed in" was honestly a one-row registry UPDATE — flip tenant_id , done. We wrote that down as a design decision, and it was the right one at the time. Least-privilege arrived; the transfer path didn't…

The ownership transfer of a database in a multi-tenant Postgres setup was initially a simple one-row UPDATE to the registry row, flipping the tenant_id. However, as the application evolved, least-privilege security measures were added, requiring a more complex process to ensure proper authorization. The transfer path updated only one location, the registry row, while other places like the role itself, grants, role membership, and policy literals needed to be updated as well. This discrepancy caused transferred databases to become unqueryable.

The error was initially difficult to diagnose, as it appeared as a generic "couldn't reach the database" message, masking the root cause. It took nine attempts to realize that the failure was not transient, but rather due to deterministic errors caused by the missing role. The solution involved updating every place where authorization state is stored, including the role existence, grants, role membership, and policy literals, in an idempotent manner.

This required a comprehensive audit of the codebase to identify and address all transfer paths. Additionally, a catch-all error branch must be implemented to log the specific error codes, providing clearer insights for debugging.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

More from Dev.to on urgent.news

Get the news by email. Yesterday's most-covered stories, every morning.

See today's edition · More options

More in Tech

More from Friday, 4 December 2026 →