PostgreSQL Error [42501]: ERROR: must be owner of relation table

PostgreSQL Error [42501]: ERROR: must be owner of relation table

我正在维护一个数据库 'db',其中大约有 100 个 tables.I 有一个超级用户 'A' 并且 'A' 是所有 tables。如何在不继承 'A' 的所有权限的情况下,向特定于单个 table 的新用户 'B' 授予更改权限。

我尝试提供 Grant A to B;。此授予选项给出了从 'A' 到 'B' 的所有权限。我希望上述场景仅限于一个特定的 table。 这可能吗?

The documentation最近得到这个解释:

The right to modify or destroy an object is inherent in being the object's owner, and cannot be granted or revoked in itself. (However, like all privileges, that right can be inherited by members of the owning role; see Section 21.3.)

所以唯一可以 运行 ALTER TABLE 的人是:

  • 超级用户

  • table所有者

  • table 所有者角色的成员

所以 GRANT a TO b 是授予某人特权的唯一方法。

您也许可以使用属于 aSECURITY DEFINER 函数,但要小心。