Difference between revisions of "List users and roles: \du"
Jump to navigation
Jump to search
(46 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | + | List users and [[PostgreSQL: Role|Roles]] (Since the concepts of “users” and “groups” have been unified into “roles”, this command is now equivalent to \dg.) ) | |
+ | * https://www.postgresql.org/docs/current/app-psql.html | ||
− | <code>\du+</code> | + | Lists database roles. (Since the concepts of “users” and “groups” have been unified into “[[roles]]”, this command is now equivalent to <code>[[\dg]]</code>.) By default, only user-created roles are shown; supply the S modifier to include system roles. If pattern is specified, only those roles whose names match the pattern are listed. If the form <code>\du+</code> is used, additional information is shown about each role; currently this adds the comment for each role. |
+ | |||
+ | |||
+ | * <code> \du</code> | ||
+ | * <code>[[\du+]]</code> | ||
List [[roles]] using <code>\du</code> command: | List [[roles]] using <code>\du</code> command: | ||
− | postgres=# [[\du | + | Default [[PostgreSQL 12]] in [[Ubuntu 20.04]] |
− | List of roles | + | postgres=# \du |
+ | List of roles | ||
+ | Role name | Attributes | Member of | ||
+ | -----------+------------------------------------------------------------+----------- | ||
+ | postgres | Superuser, Create role, Create DB, Replication, Bypass [[RLS]] | {} | ||
+ | |||
+ | |||
+ | |||
+ | postgres=# \du | ||
+ | [[List of roles]] | ||
Role name | Attributes | [[Member of]] | Role name | Attributes | [[Member of]] | ||
----------------+------------------------------------------------------------+----------- | ----------------+------------------------------------------------------------+----------- | ||
YOUR_USER | Create DB | {} | YOUR_USER | Create DB | {} | ||
− | [[postgres]] | Superuser, Create role, Create DB, Replication, Bypass RLS | {} | + | YOUR_USER2 | [[Cannot login]] | {} |
− | + | YOUR_USER3 | | {} | |
+ | [[postgres]] | Superuser, Create role, Create DB, [[PostgreSQL replication|Replication]], [[Bypass RLS]] | {} | ||
− | <code> SELECT rolname FROM [[pg_roles]]; </code> | + | * <code> SELECT * FROM [[pg_roles]]; </code> |
+ | * <code> SELECT rolname FROM [[pg_roles]]; </code> | ||
==Related terms== | ==Related terms== | ||
− | * <code>[[\l]]</code> or <code>[[\list]]</code> | + | * <code>[[\l]]</code> or <code>[[\list]]</code> to [[list databases]] |
− | * <code>[[create role]]</code> | + | * Postgres: <code>[[create role]]</code> |
* <code>[[create user]]</code> | * <code>[[create user]]</code> | ||
* <code>[[.psqlrc]]</code> | * <code>[[.psqlrc]]</code> | ||
* <code>[[show users]]</code> | * <code>[[show users]]</code> | ||
+ | * <code>[[rds_superuser]], [[rds_master]], [[rdsadmin]]</code> | ||
+ | * <code>[[\dt]]</code> [[list tables]] | ||
+ | * <code>[[\ddp]]</code> lists default access [[privilege]] settings | ||
+ | * <code>[[\dn]]</code> | ||
+ | * [[ALTER USER]] YOUR_USER WITH PASSWORD 'your_new_password'; | ||
+ | * <code>SELECT pg_database_size('your_db_name');</code> | ||
+ | [[GRANT "your-defined_role" TO "your_username";]] | ||
− | ==See also== | + | == See also == |
− | * {{ | + | * {{CREATE USER}} |
+ | * {{Role}} | ||
+ | * {{GRANT}} | ||
* {{psql}} | * {{psql}} | ||
− | |||
[[Category: PostgreSQL]] | [[Category: PostgreSQL]] | ||
[[Category: SQL]] | [[Category: SQL]] |
Latest revision as of 17:48, 8 January 2024
List users and Roles (Since the concepts of “users” and “groups” have been unified into “roles”, this command is now equivalent to \dg.) )
Lists database roles. (Since the concepts of “users” and “groups” have been unified into “roles”, this command is now equivalent to \dg
.) By default, only user-created roles are shown; supply the S modifier to include system roles. If pattern is specified, only those roles whose names match the pattern are listed. If the form \du+
is used, additional information is shown about each role; currently this adds the comment for each role.
\du
\du+
List roles using \du
command:
Default PostgreSQL 12 in Ubuntu 20.04
postgres=# \du List of roles Role name | Attributes | Member of -----------+------------------------------------------------------------+----------- postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
postgres=# \du List of roles Role name | Attributes | Member of ----------------+------------------------------------------------------------+----------- YOUR_USER | Create DB | {} YOUR_USER2 | Cannot login | {} YOUR_USER3 | | {} postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
Related terms[edit]
\l
or\list
to list databases- Postgres:
create role
create user
.psqlrc
show users
rds_superuser, rds_master, rdsadmin
\dt
list tables\ddp
lists default access privilege settings\dn
- ALTER USER YOUR_USER WITH PASSWORD 'your_new_password';
SELECT pg_database_size('your_db_name');
GRANT "your-defined_role" TO "your_username";
See also[edit]
- CREATE USER, List users
\du
,\du+
- PostgreSQL: Database roles,
CREATE USER
,CREATE ROLE
,\du, \du+
,create user, Alter user
GRANT
,\ddp
,GRANT USAGE
,GRANT ALL PRIVILEGES
,GRANT SELECT
, View GRANTs on Redshift,has_table_privilege
,has_schema_privilege
,HAS_DATABASE_PRIVILEGE
,SCHEMA
, Privileges,GRANT EXECUTE
- PostgreSQL:
psql
,.psqlrc, .pgpass
,$HOME/.pg service.conf
,-U, -W, -d
, meta-commands:\du, \dg, \ddp, \dp, \list, \dn, \dt, \c, \l, \di, \q
,show users
,show
,su - postgres
,psql -c, \?, \connect, \conninfo
,--version, --help
, PL/pgSQL
Advertising: