简体   繁体   English

rails 3.2.2(或3.2.1)+ Postgresql 9.1.3 + Ubuntu 11.10连接错误

[英]rails 3.2.2 (or 3.2.1) + Postgresql 9.1.3 + Ubuntu 11.10 Connection error

I am using PostgreSQL 9.1.3 (PostgreSQL 9.1.3 on x86_64-pc-linux-gnu, compiled by gcc-4.6.real (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1, 64-bit) and rails either 3.2.2 or 3.2.1 on ubuntu 11.10. 我正在使用PostgreSQL 9.1.3(在x86_64-pc-linux-gnu上的PostgreSQL 9.1.3,由gcc-4.6.real(Ubuntu / Linaro 4.6.1-9ubuntu3)4.6.1,64位编译)和rails 3.2 ubuntu 11.10上的.2或3.2.1。

Now, I can connect with below command with PostgreSQL 现在,我可以使用PostgreSQL连接下面的命令

  1. su postgres su postgres

    enter password and I can see postgres=# 输入密码,我可以看到postgres =#

  2. I am placing below details in my config/database.yml and executing " rails db " it is working fine. 我将以下详细信息放在我的config / database.yml中并执行“ rails db ”它工作正常。

    development:

     adapter: postgresql encoding: utf8 reconnect: false database: sample_app_db pool: 5 username: postgres password: passwordhere host: localhost 

I am using rvm to access my rails environment. 我正在使用rvm来访问我的rails环境。 but when I start server using "rails s" command and hit url with "http://localhost:3000", say - connection not establish. 但是当我使用“rails s”命令启动服务器并使用“http:// localhost:3000”命中url时,请说 - connection not established。

try this way, 试试这种方式,

sudo -u postgres createuser -D -P your-current-ubuntu-username

and

sudo -u postgres createdb -O your-current-ubuntu-username your-database

open up this file /etc/postgresql/9.1/main/pg_hba.conf 打开这个文件/etc/postgresql/9.1/main/pg_hba.conf

change this line only: 仅更改此行:

local   all             all                                     peer

to this: 对此:

local   all             all                                     md5

Don't forget to restart the postgres server: 别忘了重新启动postgres服务器:

sudo service postgresql restart

Now check, with this command 现在使用此命令检查

psql -d your-database -U your-current-ubuntu-username -W

it should work 它应该工作

This solutions works for postgresql-9.1 , here is the way to install 这个解决方案适用于postgresql-9.1 ,这是安装的方法

sudo apt-get install postgresql-9.1

I'd like to propose a slightly different approach which utilizes the file socket instead. 我想提出一种稍微不同的方法,它使用文件套接字代替。

By allowing your Ubuntu user access to the database, everything should work without special connection parameters. 通过允许您的Ubuntu用户访问数据库,一切都应该没有特殊的连接参数。

In the Ubuntu command line: 在Ubuntu命令行中:

createuser -U postgres your-current-ubuntu-username

see the Manpage of createuser for details. 有关详细信息,请参阅createuser的Manpage

In your database.yml: 在您的database.yml中:

development:
  adapter: postgresql
  encoding: unicode
  database: sample-app_development
  pool: 5
  username: your-current-ubuntu-username
  password:

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

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