rake db:create 失败,postgresql 8.4 的身份验证问题
首先,请原谅我的笨蛋。我真的试图找到解决方案,但现在我陷入困境并且完全无能为力。
我正在尝试在远程服务器上部署 Rails 3 应用程序;在我的本地虚拟机上开发时,没有显示任何问题。但是现在,当我尝试运行
rake db:create
它时,它失败了,并出现错误(这里是翻译的,因为我是法国人):
FATAL : password authentication failed for user <<mylogin>>
这是我的database.yml:
login: &login
adapter: postgresql
username: mylogin
password: mypassword
host: localhost
port: 5432
encoding: UTF8
development:
<<: *login
database: somesite_development
test:
<<: *login
database: somesite_test
production:
<<: *login
database: somesite_production
用户“mylogin”已使用命令行工具“createuser”在postgre端创建。它被授权创建数据库。 postgresql.conf 将服务器配置为在本地主机上侦听。 我已经用 pg_hba.conf 尝试了很多东西,但没有一个起作用 - 无论 127.0.0.1 上的用户“mylogin”使用什么方法(ident、密码、md5),身份验证失败 - 尽管我在连接/创建数据库时从未遇到过问题psql。
有什么线索吗?
编辑:好吧,发现我是多么愚蠢……我的用户密码根本就没有设置! 之后的分号
我想我忘记了ALTER USER xxxx WITH PASSWORD xxxx
; ...我通过请求“SELECT * FROM pg_shadow;”看到了这一点- 密码字段为空。因为这个愚蠢的错误,我浪费了三天的生命......
first things first, please excuse my utter noobness. I really tried to find a solution out there, but now i'm stuck and completely clueless.
i'm trying to deploy a rails 3 app on a distant server ; when developping on my local VM, no problem showed. But now, when i try to run
rake db:create
it fails, with error (here translated, since i'm french):
FATAL : password authentication failed for user <<mylogin>>
here's my database.yml :
login: &login
adapter: postgresql
username: mylogin
password: mypassword
host: localhost
port: 5432
encoding: UTF8
development:
<<: *login
database: somesite_development
test:
<<: *login
database: somesite_test
production:
<<: *login
database: somesite_production
the user "mylogin" has been created postgre-side with the command-line tool "createuser". It's authorized to create dbs.
postgresql.conf configures the server to listen on localhost.
I've tried many things with pg_hba.conf, none worked - whatever the method used (ident, password, md5) for user "mylogin" on 127.0.0.1, authentication fails - though i've never had problems connecting / creating dbs with psql.
any clue ?
EDIT: okay, found out how incredibly stupid i've been... the password for my user was simply not set !
I think i forgot the semicolon after
ALTER USER xxxx WITH PASSWORD xxxx ;
... i saw this by requesting "SELECT * FROM pg_shadow;" - the password field was empty. Three days of my life wasted because of this dumb mistake...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我也被这个问题困扰了很长一段时间,并访问了各种链接(包括本文中提供的链接)试图找到答案,但无济于事。然而,解决方案非常简单。虽然许多其他响应都在正确的轨道上,但这里是解决问题的确切步骤:
在您选择的文本编辑器中打开 pg_hba.conf 文件。 (它位于 /etc/postgresql//main)
导航到以下行:
#“local”仅适用于 Unix 域套接字连接
并粘贴到其下方:
这将信任所有尝试连接的 Unix 用户到本地计算机上的 psql 服务器。 (有关列功能的更多信息,请阅读页面顶部的文档)
保存 pg_hba.conf 文件并退出文本编辑器。
通过运行以下命令重新启动 Postgresql 服务器:
service postgresql restart
现在尝试通过运行以下命令启动 psql 服务器:
psql -d -U(或简称“psql”)
您应该能够毫无问题地登录。
*笔记:
所有这些都假设您有一个有效的 psql 用户名用于登录。如果您不按照下面的链接进行设置:
设置用户:
http://erikonrails.snowedin.net/?p=274
确保您拥有有效的 postgres 用户:
http://archives.postgresql.org/pgsql-novice/2002-08/msg00072.php< /a>
列出所有现有的 psql 用户:
如果您正在寻找“列出用户”或“显示用户”命令,请尝试:
“select * from pg_user;” (登录 psql 时)
祝你好运!
I was also stuck on this problem for a really long time, and went to a variety of links (including the ones offered in this post) to try and find the answer, but to no avail. However, the solution is very simple. While many of the other responses were on the right track here are the exact steps to solve the problem:
Open your pg_hba.conf file in a text editor of your choice. (It is located in /etc/postgresql//main)
Navigate to the line that reads:
# "local" is for Unix domain socket connections only
and paste below it:
This will trust all unix users trying to connect to the psql server on the local machine. (Read documentation at top of page for further info about function of columns)
Save the pg_hba.conf file and exit the text editor.
Restart the Postgresql server by running the command:
service postgresql restart
Now try and start a psql server by running:
psql -d -U (or "psql " for short)
You should be able log in with no problem.
*Note:
All this assumes that you have have a valid psql username for logging in. If you don't follow the links below to set one up:
Setting up a user:
http://erikonrails.snowedin.net/?p=274
Making sure you have a valid postgres user:
http://archives.postgresql.org/pgsql-novice/2002-08/msg00072.php
Listing all existing psql users:
If you are looking for a "LIST USERS" or "DISPLAY USERS" command then try:
"select * from pg_user;" (when logged in to psql)
Good luck!
好吧,发现我是多么愚蠢……我的用户密码根本就没有设置!我想我忘记了分号
……我通过请求“SELECT * FROM pg_shadow;”看到了这个- 密码字段为空。因为这个愚蠢的错误,我浪费了三天的生命......
okay, found out how incredibly stupid i've been... the password for my user was simply not set ! I think i forgot the semicolon after
... i saw this by requesting "SELECT * FROM pg_shadow;" - the password field was empty. Three days of my life wasted because of this dumb mistake...
我有同样的问题。就我而言,这是因为在我的 database.yml 文件中,用户名以大写字母开头,但在数据库中全部为小写。
解决方案:当从postgres命令行创建用户时,它会将所有字母转换为小写。要使用大写字母,必须使用双引号。
示例:
创建用户 AlbertEinstein;结果 = alberteinstein
vs
创建用户“AlbertEinstein”;结果=阿尔伯特爱因斯坦
I had same problem. In my case it was because in my database.yml file the username started with capital letter but in database it was all lower case.
Solution: When creating user from postgres command line, it converts all letters to lowercase. For using capital letters, double quotes must be used.
Example:
create user AlbertEinstein; result = alberteinstein
vs
create user "AlbertEinstein"; result = AlbertEinstein
以下是一些应该适合您的简明说明
http: //www.cyberciti.biz/faq/psql-fatal-ident-authentication-failed-for-user/。
基本上,您需要将本地主机的身份验证方法设置为“信任”。
Here are some concise instructions that should work for you
http://www.cyberciti.biz/faq/psql-fatal-ident-authentication-failed-for-user/.
Basically you need to set the authentication method for localhost to 'trust'.
你需要给postgresql中的“myuser”权限“可以创建数据库对象”。
在 pgadmin 中,它看起来像这样:
调用 rake db:create 后,您可以取消此权限。
You need to give "myuser" in postgresql the privilege "Can create database objects".
In pgadmin, it looks like this:
After calling rake db:create, you can take away this privilege.
就我而言,我发现
pg_hba.conf
文件中较晚的host
权限规则行覆盖了较早的local
行。我正确配置了local
行以使用 md5 身份验证,但host
行设置为ident
,我将其更改为md5
,请注意,使用
trust
是一种不安全的方法,因此您不应在任何生产风格的部署中使用它。In my case, I found that a later
host
permissions rule line in thepg_hba.conf
file had over-ridden the earlierlocal
line. I was correctly configuring thelocal
line to use md5 authentication but thehost
line was set toident
which I changed tomd5
As other have emphasized here, note that using
trust
is an insecure method, so you shouldn't use it in any production-style deployment.