database - 在创建数据库之前,Postgres 中如何存在 pg_roles 表?

标签 database postgresql database-connection roles

我正在研究 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 of pg_authid per cluster, not one per database.

关于database - 在创建数据库之前,Postgres 中如何存在 pg_roles 表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32151288/

相关文章:

php - 如何在codeigniter中将mysql数据库的多个表作为单个表进行查询(获取)

database - 存储时间序列数据,关系型还是非关系型?

database - 以 root 以外的其他用户身份运行 Linux 应用程序

SQL 优化 - 字符串中的字数统计 - Postgresql

database-connection - 存储数据库连接字符串

MySQL JOIN 需要 10 秒以上

postgresql - 通过 pgAdmin 从 *.sql 文件恢复 Postgres 数据库模式?

java - 用户缺少权限或找不到对象

python - 使用多个 SQL 语句更新数据库

php - MySQL权限表,从PHP访问以在另一个数据库中使用?