【问题标题】:postgres uses a database password or a user passwordpostgres 使用数据库密码或用户密码
【发布时间】:2019-01-01 03:04:03
【问题描述】:

我在本地 postgres 服务器中导入了一个 postgres 数据库。 我必须使用名为 setup.local 的文件连接到数据库(以允许 django 检索数据)。

需要指定:DB_HOST=localhostDB_NAMEDB_USERDB_PASSWORD

DB_HOST 毫无疑问是localhost。 DB_name 是我选择导入的那个 (psql imported_db < downloaded_DB)

DB_USER 是 my_name(或者我可以更改所有者 ALTER DATABASE imported_db OWNER TO other_name)。

对我来说,最重要的是我必须使用用户(my_name 或 other_name)密码而不是数据库密码(即使变量名是 DB_PASSWORD)。

所以问题: psql 数据库是否有密码或只是角色/用户有密码并使用它们来访问数据库?

安德烈亚

【问题讨论】:

  • 没有数据库密码。仅供用户使用

标签: postgresql passwords pg-hba.conf


【解决方案1】:

【讨论】:

    【解决方案2】:

    DB_HOST=localhost 是这里的关键。查看pg_hba.conf,您很可能会发现identlocalhost 连接。

    https://www.postgresql.org/docs/current/static/auth-methods.html#AUTH-IDENT

    当为本地(非 TCP/IP)连接指定 ident 时,peer 将使用身份验证(参见第 20.3.6 节)。

    https://www.postgresql.org/docs/current/static/auth-methods.html#AUTH-PEER

    对等身份验证方法通过获取客户端的 来自内核的操作系统用户名并将其用作允许的用户名 数据库用户名(带有可选的用户名映射)。这种方法是 仅支持本地连接。

    【讨论】:

      猜你喜欢
      • 2017-11-10
      • 1970-01-01
      • 2020-12-09
      • 2021-05-26
      • 1970-01-01
      • 2017-07-21
      • 2023-04-03
      • 1970-01-01
      • 2011-04-26
      相关资源
      最近更新 更多