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

一笑奈何 提交于 2019-12-20 09:45:55

问题


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.

Now, I can connect with below command with PostgreSQL

  1. su postgres

    enter password and I can see postgres=#

  2. I am placing below details in my config/database.yml and executing "rails db" it is working fine.

    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. but when I start server using "rails s" command and hit url with "http://localhost:3000", say - connection not establish.


回答1:


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

change this line only:

local   all             all                                     peer

to this:

local   all             all                                     md5

Don't forget to restart the postgres server:

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

sudo apt-get install postgresql-9.1



回答2:


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.

In the Ubuntu command line:

createuser -U postgres your-current-ubuntu-username

see the Manpage of createuser for details.

In your database.yml:

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


来源:https://stackoverflow.com/questions/9797640/rails-3-2-2-or-3-2-1-postgresql-9-1-3-ubuntu-11-10-connection-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!