Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
5.6. Privileges
Prev UpChapter 5. Data DefinitionHome Next

5.6. Privileges

When an object is created, it is assigned an owner. The owner is normally the role that executed the creation statement. For most kinds of objects, the initial state is that only the owner (or a superuser) can do anything with the object. To allow other roles to use it,privileges must be granted.

There are different kinds of privileges:SELECT,INSERT,UPDATE,DELETE,TRUNCATE,REFERENCES,TRIGGER,CREATE,CONNECT,TEMPORARY,EXECUTE, andUSAGE. The privileges applicable to a particular object vary depending on the object's type (table, function, etc). For complete information on the different types of privileges supported byPostgreSQL, refer to theGRANT reference page. The following sections and chapters will also show you how those privileges are used.

The right to modify or destroy an object is always the privilege of the owner only.

An object can be assigned to a new owner with anALTER command of the appropriate kind for the object, e.g.,ALTER TABLE. Superusers can always do this; ordinary roles can only do it if they are both the current owner of the object (or a member of the owning role) and a member of the new owning role.

To assign privileges, theGRANT command is used. For example, ifjoe is an existing role, andaccounts is an existing table, the privilege to update the table can be granted with:

GRANT UPDATE ON accounts TO joe;

WritingALL in place of a specific privilege grants all privileges that are relevant for the object type.

The specialrole namePUBLIC can be used to grant a privilege to every role on the system. Also,group roles can be set up to help manage privileges when there are many users of a database — for details seeChapter 21.

To revoke a privilege, use the fittingly namedREVOKE command:

REVOKE ALL ON accounts FROM PUBLIC;

The special privileges of the object owner (i.e., the right to doDROP,GRANT,REVOKE, etc.) are always implicit in being the owner, and cannot be granted or revoked. But the object owner can choose to revoke their own ordinary privileges, for example to make a table read-only for themselves as well as others.

Ordinarily, only the object's owner (or a superuser) can grant or revoke privileges on an object. However, it is possible to grant a privilegewith grant option, which gives the recipient the right to grant it in turn to others. If the grant option is subsequently revoked then all who received the privilege from that recipient (directly or through a chain of grants) will lose the privilege. For details see theGRANT andREVOKE reference pages.


Prev Up Next
5.5. Modifying Tables Home 5.7. Row Security Policies
epubpdf
Go to PostgreSQL 9.6
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp