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
问题描述
我正在使用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位编译)和在Ubuntu 11.10上运行3.2.2或3.2.1。
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中使用以下命令连接
Now, I can connect with below command with PostgreSQL
-
su postgres
su postgres
输入密码,我可以看到postgres =#
enter password and I can see postgres=#
我将以下详细信息放在config / database.yml中,并执行 rails db ,这工作正常。
I am placing below details in my config/database.yml and executing "rails db" it is working fine.
发展:
adapter: postgresql
encoding: utf8
reconnect: false
database: sample_app_db
pool: 5
username: postgres
password: passwordhere
host: localhost
我正在使用rvm访问我的rails环境。但是当我使用 rails s命令启动服务器并用 http:// localhost:3000访问url时,说-连接未建立。
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.
推荐答案
尝试这种方式,
sudo -u postgres createuser -D -P your-current-ubuntu-username
和
sudo -u postgres createdb -O your-current-ubuntu-username your-database
打开此文件 /etc/postgresql/9.1/main/pg_hba.conf
仅更改此行:
local all all peer
为此:
local all all md5
别忘了重启postgres服务器:
Don't forget to restart the postgres server:
sudo service postgresql restart
现在检查,与th是命令
Now check, with this command
psql -d your-database -U your-current-ubuntu-username -W
它应该工作
此解决方案适用于 postgresql-9.1
,这是安装方式
This solutions works for postgresql-9.1
, here is the way to install
sudo apt-get install postgresql-9.1
这篇关于rails 3.2.2(或3.2.1)+ Postgresql 9.1.3 + Ubuntu 11.10连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!