postgresql psql: 致命: 用户密码验证失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19778510/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:10:26  来源:igfitidea点击:

psql: FATAL: password authentication failed for user

postgresql

提问by user753152

I am trying to connnect to Postgresql 9.1 database on remote ubuntu 12.04 server from my windows pc using putty.i have created user with password and when i run the command

我正在尝试使用 putty.i 从我的 windows pc 连接到远程 ubuntu 12.04 服务器上的 Postgresql 9.1 数据库。我已经使用密码创建了用户,当我运行命令时

psql -U opentaps -d opentaps (opentaps is the user i created for database opentaps) i get the below mesaage . psql: FATAL: password authentication failed for user "opentaps" i did try psql -U opentaps -d opentaps -h localhost but still same message after i supply the password . my password for the opentaps user is correct .also even when i try psql -U postgres -d postgres i get the same failure message .

psql -U opentaps -d opentaps(opentaps 是我为数据库 opentaps 创建的用户)我得到以下消息。psql:致命:用户“opentaps”的密码身份验证失败我确实尝试过 psql -U opentaps -d opentaps -h localhost 但在我提供密码后仍然是相同的消息。我的 opentaps 用户密码是正确的。即使我尝试 psql -U postgres -d postgres 我也收到相同的失败消息。

I made some changes in pg_hba.conf and it looks like this

我在 pg_hba.conf 中做了一些更改,它看起来像这样

https://docs.google.com/document/d/13ymGYj9e7YPFiaffwixLzsWJygp_OfBmgBi4Axgrg5A/edit?usp=sharing

https://docs.google.com/document/d/13ymGYj9e7YPFiaffwixLzsWJygp_OfBmgBi4Axgrg5A/edit?usp=sharing

also in postgresql.conf i made the change by uncomenting listen_addresses = '*' i know i am missing something here .need your help to know what else i need to change to connect to the server.

同样在 postgresql.conf 中,我通过取消注释 listen_addresses = '*' 进行了更改,我知道我在这里遗漏了一些东西。需要您的帮助才能知道我还需要更改什么才能连接到服务器。

thanks for your help

感谢您的帮助

回答by ntg

One hack around this is to edit pg_hba.conf

解决此问题的一个技巧是编辑 pg_hba.conf

sudo vi /etc/postgresql/9.3/main/pg_hba.conf

To temporarily

暂时

# Database administrative login by Unix domain socket
local   all             postgres                                   trust

Then go and

然后去

sudo -u postgres psql template1
ALTER USER postgres with encrypted password 'your_password';

then go back and set pg_hba.conf back to

然后返回并将 pg_hba.conf 设置回

# Database administrative login by Unix domain socket
local   all             postgres                                   md5

回答by Stephane Rolland

Be sure that you are logged in as the user opentapswhen you launch psqlfrom the command line.

从命令行opentaps启动时,请确保您以用户身份登录psql

you should also fill the .pgpassfile with correct information, with the following format:

您还应该.pgpass使用正确的信息填写文件,格式如下:

hostname:port:database:username:password

if no .pgpassfile has been created, you should create one. cf. postgresql docsfor reference

如果没有.pgpass创建文件,你应该创建一个。参见 postgresql文档供参考

回答by Jordan M.

A little late response but here it goes:

反应有点晚,但它是这样的:

First, your .pgpassfile should be in your Ubuntu user's home directory. If there isn't a file you can create it with nano ~/.pgpass

首先,您的.pgpass文件应该在您的 Ubuntu 用户的主目录中。如果没有文件,您可以创建它nano ~/.pgpass

Second, your file should contain this format hostname:port:database:username:password. Don't forget to chmod 0600 ~/.pgpassso you can disallow any access to world or group, as it says here.

其次,您的文件应该包含这种格式hostname:port:database:username:password。不要忘记,chmod 0600 ~/.pgpass这样你就可以禁止任何对世界或组的访问,正如它所说的here

Now, the command should be something like this: psql -h localhost -w -U opentaps -d opentaps -c "select * from mytable". Where:

现在,命令应该是这样的:psql -h localhost -w -U opentaps -d opentaps -c "select * from mytable"。在哪里:

-his your host.

-h是你的host

-wis to use your .pgpass file, in case you don't want to type your password. Ohterwise use -Wto force psql to prompt a password.

-w是使用您的 .pgpass 文件,以防您不想输入密码。或者用于-W强制 psql 提示密码。

-Uis your postgres username.

-U是你的 postgres 用户名。

-dis your database name.

-d是您的数据库名称。

and -cis to execute a string sql command.

并且-c是执行字符串sql命令。