我正在研究 Postgres,在阅读时我发现您可以检查用户名(在命令行中使用 createuser
命令时使用)是否已经存在于 pg_roles
表通过输入:
psql postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='USR_NAME'"
进入命令行。我只是想知道,如果我还没有创建自己的数据库,怎么会有像 pg_roles
这样的现有表,它们存储在哪里/它们是如何创建的?
最佳答案
实际上,pg_roles
是一个 View 。 The documentation:
This is simply a publicly readable view of
pg_authid
that blanks out the password field.
并且pg_authid
不依赖于任何特定的数据库。它是在您创建数据库集群时创建的。 The documentation once more:
Because user identities are cluster-wide,
pg_authid
is shared across all databases of a cluster: there is only one copy ofpg_authid
per cluster, not one per database.
关于database - 在创建数据库之前,Postgres 中如何存在 pg_roles 表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32151288/