无法在新数据库中将Postgres用户用于ubuntu 10.04服务器上的Rails 3 [英] Can't use postgres user in new database for rails 3 on ubuntu 10.04 server

查看:82
本文介绍了无法在新数据库中将Postgres用户用于ubuntu 10.04服务器上的Rails 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试安装Rails 3应用程序并在Ubuntu 10.04上运行。这是我的第一个postgres项目,我正在努力使postgres正常工作。它已全部安装,我可以使用 psql 进入。



我按照此处的指示进行操作设置名为'postgres'的postgres用户的密码:

 #在命令行
sudo -u postgres psql postgres

#in postgres
\密码postgres
退出

认为这将把postgres用户的密码设置为 postgres。但是,现在我无法以postgres用户身份登录。



我的数据库配置如下:

 开发:
适配器:postgresql
数据库:chronial_development
用户名:postgres
密码:postgres
池:5
超时:5000

测试:
适配器:postgresql
数据库:chronyl_test
用户名:postgres
密码:postgres
池:5
超时:5000

生产:
适配器:postgresql
数据库:chronial_production
用户名:postgres
密码:postgres
池: 5
超时:5000

我认为这样很好-我已经更改了(postgres用户)postgres的密码为 postgres,这在我的配置中。但是,当我执行 rake db:migrate 时,我得到

  rake中止了! 
致命:用户 postgres的身份验证失败

好的...也许不能像这样在数据库配置中指定密码?因此,我制作了一个〜/ .pgpass文件,其内容如下:

  *:*:*:postgres:postgres 

仍然收到相同的错误消息。



我使另一个名为 max的用户可以正常运行,但是配置文件(带有postgres)适用于该项目中的其他人,因此我需要让我使用该配置文件。是否可以从postgres帐户中删除密码?或以其他方式解决此问题?谢谢,最大



编辑-尝试了其他操作,但不幸的是,该方法无法正常工作。我在此页面上读到,重命名角色会清除其密码,

  #in psql 
=#alter role postgres重命名为postgres2;
注意:由于角色重命名

,MD5密码已清除!这听起来令人鼓舞!因此,我再次将其更改回了postgres。但是仍然没有运气。当我以 postgres2 的身份离开用户并更改配置以使用该用户名时,它也无法正常工作-我得到了 FATAL:用户的身份验证失败 postgres2 。为什么它适用于max但不适用于postgres / postgres2?与我的ubuntu env中的用户有关吗?我在Linux中的用户名也为 max。

解决方案

看起来您需要更改pg_hba.conf文件。在我的ubuntu 11.10机器中,它位于/etc/postgresql/9.1/main/pg_hba.conf



在它的底部,您需要查找并替换与md5相同。看起来像这样:

  local all md5 

我被卡住是因为对我来说(PostgreSQL 9.1和使用Rails 3.2.2),默认值是peer,这是不对的。在此处中查看对等身份验证和身份验证的含义。



这是针对PostgreSQL 9.1的,因此您可能必须搜索您的版本。



祝您好运! / p>

I'm trying to get a rails 3 app up and running on an ubuntu 10.04. It's my first postgres project and i'm struggling to get postgres working properly. It's all installed, and i can get into it with psql.

I followed the instructions here to set the password for the postgres user called 'postgres':

#on the command line
sudo -u postgres psql postgres

#in postgres
\password postgres
\quit

I thought that this would set the password for the postgres user to 'postgres'. But, now i can't log in as the postgres user.

My db config looks like this:

development:
  adapter: postgresql
  database: chronicle_development
  username: postgres
  password: postgres
  pool: 5
  timeout: 5000

test:
  adapter: postgresql
  database: chronicle_test
  username: postgres
  password: postgres
  pool: 5
  timeout: 5000

production:
  adapter: postgresql
  database: chronicle_production
  username: postgres
  password: postgres
  pool: 5
  timeout: 5000

I thought this would be fine - i've changed (postgres user) postgres's password to 'postgres' and this is in my config. But, when i do rake db:migrate i get

rake aborted!
FATAL:  Ident authentication failed for user "postgres"

Ok...maybe you can't specify the password in the db config like that? So, i made a ~/.pgpass file which has this:

*:*:*:postgres:postgres

Still get the same error message.

I've made another user called 'max' who can get in ok, but the config file (with postgres) works for the other guys on the project so i need to get mine working with that config file. Is it possible to remove the password from the postgres account? Or fix this some other way? thanks, max

EDIT - just tried something else, which didn't work unfortunately. I read on this page that renaming a role clears its password, so gave it a go.

#in psql
=# alter role postgres rename to postgres2;
NOTICE:  MD5 password cleared because of role rename

This sounded encouraging! So, i changed it back to postgres again. But still no luck. It also didn't work when i left the user as postgres2 and changed my config to have that username - i got FATAL: Ident authentication failed for user "postgres2". Why does it work for max but not for postgres/postgres2? Is it to do with users in my ubuntu env? my username in linux is also 'max'.

解决方案

Looks like you need to change your your pg_hba.conf file. In my ubuntu 11.10 machine, it is in /etc/postgresql/9.1/main/pg_hba.conf

In it, towards the bottom, you need to find and replace the ident to md5. It will look something like this:

local   all             all                                     md5

I got stuck because for me (postgresql 9.1 and using Rails 3.2.2), the default for that is peer which is not right. Check out what peer and ident authentication mean here.

That is for postgresql 9.1 so you may have to search for your version.

Good luck!

这篇关于无法在新数据库中将Postgres用户用于ubuntu 10.04服务器上的Rails 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆