有createuser
&dropuser
命令:
createuser - define a new PostgreSQL user account
dropuser - remove a PostgreSQL user account
有列出用户帐户的相应方法吗?
这两个命令不需要用户调用psql
也不了解使用它的细节。
有createuser
&dropuser
命令:
createuser - define a new PostgreSQL user account
dropuser - remove a PostgreSQL user account
有列出用户帐户的相应方法吗?
这两个命令不需要用户调用psql
也不了解使用它的细节。
Answers:
使用psql
外壳和:
\deu[+] [PATTERN]
如:
postgres=# \deu+
List of user mappings
Server | User name | FDW Options
--------+-----------+-------------
(0 rows)
对于所有用户:
postgres=# \du
List of roles
Role name | Attributes | Member of
------------+------------------------------------------------+-----------
chpert.net | | {}
postgres | Superuser, Create role, Create DB, Replication | {}
另外,例如MySQL,您可以执行以下操作:
$ psql -c "\du"
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
chpert | | {}
postgres | Superuser, Create role, Create DB, Replication | {}
test | | {}
要将输出限制为仅用户名,只需从psql
外壳或本地外壳/终端执行以下操作即可:
psql -c "SELECT u.usename AS "User Name" FROM pg_catalog.pg_user u;"
如前一个答案所指出的,快速方法显示3列;包括用户名,角色属性列表和角色组成员。
psql -c "\du"
最后,如在后续回答中所指出的那样,PostgreSQL命令在后台运行,该\du
命令通过调用以下命令显示那些“默认”列:
SELECT u.usename AS "User name",
u.usesysid AS "User ID",
CASE WHEN u.usesuper AND u.usecreatedb THEN CAST('superuser, create
database' AS pg_catalog.text)
WHEN u.usesuper THEN CAST('superuser' AS pg_catalog.text)
WHEN u.usecreatedb THEN CAST('create database' AS
pg_catalog.text)
ELSE CAST('' AS pg_catalog.text)
END AS "Attributes"
FROM pg_catalog.pg_user u
ORDER BY 1;
(当键入\ du时,psql在后台执行的操作)
最后一部分是从PostgreSQL邮件列表复制的。
SQL解决方案通常由psql \ du完成:
SELECT u.usename AS "User name",
u.usesysid AS "User ID",
CASE WHEN u.usesuper AND u.usecreatedb THEN CAST('superuser, create
database' AS pg_catalog.text)
WHEN u.usesuper THEN CAST('superuser' AS pg_catalog.text)
WHEN u.usecreatedb THEN CAST('create database' AS
pg_catalog.text)
ELSE CAST('' AS pg_catalog.text)
END AS "Attributes"
FROM pg_catalog.pg_user u
ORDER BY 1;
参考:https : //www.postgresql.org/message-id/1121195544.8208.242.camel@state.g2switchworks.com
psql -c '\du'