- results which may be misleading when the defaults have been overridden.
+ privileges that will be assumed when an object's ACL entry is null.
to those already granted, if any.
- There is also an option to grant privileges on all objects of the same
- type within one or more schemas. This functionality is currently supported
- only for tables, sequences, functions, and procedures. ALL
- TABLES also affects views and foreign tables, just like the
- specific-object GRANT command. ALL
- FUNCTIONS also affects aggregate functions, but not procedures,
- again just like the specific-object GRANT command.
-
-
The key word PUBLIC indicates that the
privileges are to be granted to all roles, including those that might
options for the object, too.
- PostgreSQL grants default privileges on some types of objects to
- PUBLIC. No privileges are granted to
- PUBLIC by default on
- tables,
- table columns,
- sequences,
- foreign data wrappers,
- foreign servers,
- large objects,
- schemas,
- or tablespaces.
- For other types of objects, the default privileges
- granted to PUBLIC are as follows:
- CONNECT and TEMPORARY (create
- temporary tables) privileges for databases;
- EXECUTE privilege for functions and procedures; and
- USAGE privilege for languages and data types
- (including domains).
- The object owner can, of course, REVOKE
- both default and expressly granted privileges. (For maximum
- security, issue the REVOKE in the same transaction that
- creates the object; then there is no window in which another user
- can use the object.)
- Also, these initial default privilege settings can be changed using the
-
- command.
-
-
The possible privileges are:
SELECT
-
- Allows from
- any column, or the specific columns listed, of the specified table,
- view, or sequence.
- Also allows the use of
- TO.
- This privilege is also needed to reference existing column values in
- or
- .
- For sequences, this privilege also allows the use of the
- currval function.
- For large objects, this privilege allows the object to be read.
-
-
-
-
-
INSERT
-
- Allows of a new
- row into the specified table. If specific columns are listed,
- only those columns may be assigned to in the INSERT
- command (other columns will therefore receive default values).
- Also allows FROM.
-
-
-
-
-
UPDATE
-
- Allows of any
- column, or the specific columns listed, of the specified table.
- (In practice, any nontrivial UPDATE command will require
- SELECT privilege as well, since it must reference table
- columns to determine which rows to update, and/or to compute new
- values for columns.)
- SELECT ... FOR UPDATE
- and SELECT ... FOR SHARE
- also require this privilege on at least one column, in addition to the
- SELECT privilege. For sequences, this
- privilege allows the use of the nextval and
- setval functions.
- For large objects, this privilege allows writing or truncating the
- object.
-
-
-
-
-
DELETE
-
- Allows of a row
- from the specified table.
- (In practice, any nontrivial DELETE command will require
- SELECT privilege as well, since it must reference table
- columns to determine which rows to delete.)
-
-
-
-
-
TRUNCATE
-
- Allows on
- the specified table.
-
-
-
-
-
REFERENCES
-
- Allows creation of a foreign key constraint referencing the specified
- table, or specified column(s) of the table. (See the
- statement.)
-
-
-
-
-
TRIGGER
-
- Allows the creation of a trigger on the specified table. (See the
- statement.)
-
-
-
-
-
CREATE
-
- For databases, allows new schemas and publications to be created within the database.
-
- For schemas, allows new objects to be created within the schema.
- To rename an existing object, you must own the object and
- have this privilege for the containing schema.
-
- For tablespaces, allows tables, indexes, and temporary files to be
- created within the tablespace, and allows databases to be created that
- have the tablespace as their default tablespace. (Note that revoking
- this privilege will not alter the placement of existing objects.)
-
-
-
-
-
CONNECT
-
- Allows the user to connect to the specified database. This
- privilege is checked at connection startup (in addition to checking
- any restrictions imposed by pg_hba.conf).
-
-
-
-
-
TEMPORARY
- TEMP
-
- Allows temporary tables to be created while using the specified database.
-
-
-
-
-
EXECUTE
+ USAGE
- Allows the use of the specified function or procedure and the use of
- any operators that are implemented on top of the function. This is the
- only type of privilege that is applicable to functions and procedures.
- The FUNCTION syntax also works for aggregate
- functions. Alternatively, use ROUTINE to refer to a function,
- aggregate function, or procedure regardless of what it is.
+ Specific types of privileges, as defined in .
- USAGE
+ TEMP
- For procedural languages, allows the use of the specified language for
- the creation of functions in that language. This is the only type
- of privilege that is applicable to procedural languages.
-
- For schemas, allows access to objects contained in the specified
- schema (assuming that the objects' own privilege requirements are
- also met). Essentially this allows the grantee to look up
- objects within the schema. Without this permission, it is still
- possible to see the object names, e.g. by querying the system tables.
- Also, after revoking this permission, existing backends might have
- statements that have previously performed this lookup, so this is not
- a completely secure way to prevent object access.
-
- For sequences, this privilege allows the use of the
- currval and nextval functions.
-
- For types and domains, this privilege allows the use of the type or
- domain in the creation of tables, functions, and other schema objects.
- (Note that it does not control general usage
of the type,
- such as values of the type appearing in queries. It only prevents
- objects from being created that depend on the type. The main purpose of
- the privilege is controlling which users create dependencies on a type,
- which could prevent the owner from changing the type later.)
-
- For foreign-data wrappers, this privilege allows creation of
- new servers using the foreign-data wrapper.
-
- For servers, this privilege allows creation of foreign tables using
- the server. Grantees may also create, alter, or drop their own
- user mappings associated with that server.
+ Alternative spelling for TEMPORARY.
ALL PRIVILEGES
- Grant all of the available privileges at once.
+ Grant all of the privileges available for the object's type.
The PRIVILEGES key word is optional in
PostgreSQL, though it is required by
strict SQL.
+
- The privileges required by other commands are listed on the
- reference page of the respective command.
+ The FUNCTION syntax works for plain functions,
+ aggregate functions, and window functions, but not for procedures;
+ use PROCEDURE for those.
+ Alternatively, use ROUTINE to refer to a function,
+ aggregate function, window function, or procedure regardless of its
+ precise type.
+
+
+ There is also an option to grant privileges on all objects of the same
+ type within one or more schemas. This functionality is currently supported
+ only for tables, sequences, functions, and procedures. ALL
+ TABLES also affects views and foreign tables, just like the
+ specific-object GRANT command. ALL
+ FUNCTIONS also affects aggregate and window functions, but not
+ procedures, again just like the specific-object GRANT
+ command. Use ALL ROUTINES to include procedures.
- Use 's \dp command
- to obtain information about existing privileges for tables and
- columns. For example:
-=> \dp mytable
- Access privileges
- Schema | Name | Type | Access privileges | Column access privileges
---------+---------+-------+-----------------------+--------------------------
- public | mytable | table | miriam=arwdDxt/miriam | col1:
- : =r/miriam : miriam_rw=rw/miriam
- : admin=arw/miriam
-(1 row)
-
- The entries shown by \dp are interpreted thus:
-
-rolename=xxxx -- privileges granted to a role
- =xxxx -- privileges granted to PUBLIC
-
- r -- SELECT ("read")
- w -- UPDATE ("write")
- a -- INSERT ("append")
- d -- DELETE
- D -- TRUNCATE
- x -- REFERENCES
- t -- TRIGGER
- X -- EXECUTE
- U -- USAGE
- C -- CREATE
- c -- CONNECT
- T -- TEMPORARY
- arwdDxt -- ALL PRIVILEGES (for tables, varies for other objects)
- * -- grant option for preceding privilege
-
- /yyyy -- role that granted this privilege
-
-
- The above example display would be seen by user miriam after
- creating table mytable and doing:
-
-GRANT SELECT ON mytable TO PUBLIC;
-GRANT SELECT, UPDATE, INSERT ON mytable TO admin;
-GRANT SELECT (col1), UPDATE (col1) ON mytable TO miriam_rw;
-
-
-
- For non-table objects there are other \d commands
- that can display their privileges.
-
-
- If the Access privileges
column is empty for a given object,
- it means the object has default privileges (that is, its privileges column
- is null). Default privileges always include all privileges for the owner,
- and can include some privileges for PUBLIC depending on the
- object type, as explained above. The first GRANT or
- REVOKE on an object
- will instantiate the default privileges (producing, for example,
- {miriam=arwdDxt/miriam}) and then modify them per the
- specified request. Similarly, entries are shown in Column access
- privileges only for columns with nondefault privileges.
- (Note: for this purpose, default privileges
always means the
- built-in default privileges for the object's type. An object whose
- privileges have been affected by an ALTER DEFAULT PRIVILEGES
- command will always be shown with an explicit privilege entry that
- includes the effects of the ALTER.)
-
-
- Notice that the owner's implicit grant options are not marked in the
- access privileges display. A * will appear only when
- grant options have been explicitly granted to someone.
+ See for more information about specific
+ privilege types, as well as how to inspect objects' privileges.