2.7. 权限 #
当你创建一个数据库对象时,你就成为它的所有者。默认情况下,只有对象的所有者才能对对象做任何操作。为了让其他用户能够使用它,必须授予权限。(也有一些用户拥有超级用户权限。这些用户总是可以访问任何对象。)
注意
要更改表、索引、序列或视图的所有者,请使用
ALTER TABLE 命令。
有多种不同的权限:SELECT、INSERT、UPDATE、DELETE、RULE、REFERENCES、TRIGGER、CREATE、TEMPORARY、EXECUTE、USAGE 和 ALL PRIVILEGES。关于
PostgreSQL 支持的各种权限类型的完整信息,请参阅
GRANT 参考页。后面的各节和各章还会向你展示这些权限是如何使用的。
修改或销毁对象的权利始终只属于该对象的拥有者。
要分配权限,使用 GRANT 命令。used. So, if joe is an existing user, and
accounts is an existing table, the privilege to
update the table can be granted with
GRANT UPDATE ON accounts TO joe;
The user executing this command must be the owner of the table. To grant a privilege to a group, use
GRANT SELECT ON accounts TO GROUP staff;
The special “user” name PUBLIC can
be used to grant a privilege to every user on the system. Writing
ALL in place of a specific privilege specifies that all
privileges will be granted.
要收回权限,使用名字同样贴切的
REVOKE command:
REVOKE ALL ON accounts FROM PUBLIC;
The special privileges of the table owner (i.e., the right to do
DROP, GRANT, REVOKE, etc)
are always implicit in being the owner,
and cannot be granted or revoked. But the table owner can choose
to revoke his own ordinary privileges, for example to make a
table read-only for himself as well as others.