简体   繁体   English

为什么 postgres 以 hostname = /var/run/postgresql 运行?

[英]Why is postgres running with hostname = /var/run/postgresql?

I've been trying to get pg to connect to my local postgres instance using我一直在尝试让pg使用连接到我的本地 postgres 实例

const pool = new Pool({
  user: "my_user",
  host: "localhost",
  database: "my_db",
  password: "password",
  port: 5432,
});

but it never worked, and I repeatedly got an error saying error: Ident authentication failed for user "my_user" .但它从来没有奏效,而且我反复收到错误error: Ident authentication failed for user "my_user" I fiddled around with postgres users/roles for a while to make sure my_user owned the db and the tables, but then I noticed psql -d my_db -U my_user -h localhost failed with the same error as above.我摆弄了一段时间的 postgres 用户/角色,以确保my_user拥有数据库和表,但后来我注意到psql -d my_db -U my_user -h localhost失败并出现与上述相同的错误。 After some searching I found that using经过一番搜索,我发现使用

host: "/var/run/postgresql"

fixed the problem, but I'm not sure I understand why.解决了这个问题,但我不确定我明白为什么。 Should I be able to use localhost ?我应该能够使用localhost吗? It seems like it's the default for most people setting these things up.这似乎是大多数人设置这些东西的默认设置。 I'm on Fedora 33, and only just installed postgres, so maybe it has something to do with it being a fresh install?我在 Fedora 33 上,只安装了 postgres,所以也许它与全新安装有关?

You have your pg_hba.conf set up to use "ident" authentication for connections coming from localhost.您已将 pg_hba.conf 设置为对来自 localhost 的连接使用“ident”身份验证。 I don't think is a very common configuration.我不认为这是一个非常常见的配置。 I don't think that would be the default and I don't know why you would have edited it to make it do that, but apparently that is what has happened.我不认为这是默认设置,我不知道您为什么要对其进行编辑以使其做到这一点,但显然这就是发生的事情。 (In my hands, merely installing the database software on fedora 33 doesn't automatically create the database, you have to something to make that happen. If you followed a tutorial, please link to it) (在我的手中,仅仅在fedora 33上安装数据库软件并不会自动创建数据库,你必须做一些事情才能做到这一点。如果你按照教程,请链接到它)

If you want to use "ident" authentication, then look in the log file to see why it is failing, and then fix it (maybe you need to install oidentd?).如果你想使用“ident”身份验证,那么在日志文件中查看它失败的原因,然后修复它(也许你需要安装 oidentd?)。 If you don't want to use it, then edit pg_hba so you are not using "ident".如果您不想使用它,请编辑 pg_hba,以免使用“ident”。

It is possible that PostgreSQL is not configured to allow this user to connect via TCP, only UNIX sockets. PostgreSQL 可能未配置为允许此用户通过 TCP 进行连接,仅 UNIX ZFFE33A3F6E35505FZABA01D1 Check the pg_hba.conf of your Postgres install - it should contain an entry that allows my_user to access my_db from host 127.0.0.1/32.检查 Postgres 安装的 pg_hba.conf - 它应该包含一个允许 my_user 从主机 127.0.0.1/32 访问 my_db 的条目。 Broader allowances may be used in its place.可以使用更广泛的津贴来代替它。

The file will usually contain many helpful examples that are commented out by default, but if in doubt, consult the manual: https://www.postgresql.org/docs/current/auth-pg-hba-conf.html该文件通常包含许多默认注释掉的有用示例,但如果有疑问,请参阅手册: https://www.postgresql.org/docs/current/auth-pg-hba-conf.ZFC35FDC70D5FC69D23EZ8C

The defaults that Postgres is shipped with may depend on the Linux distribution / package repository that you use. Postgres 附带的默认值可能取决于您使用的 Linux 分发/package 存储库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM