rails 3.2.2(或3.2.1)+ Postgresql 9.1.3 + 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。
现在,我可以使用PostgreSQL连接下面的命令
-
su postgres
输入密码,我可以看到postgres =#
-
我在config / database.yml中放置了以下细节并执行“ rails db ”它工作正常。
development:
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时,请说 – connection not established。
试试这种方式,
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服务器:
sudo service postgresql restart
现在使用此命令检查
psql -d your-database -U your-current-ubuntu-username -W
它应该工作
这个解决方案适用于postgresql-9.1
,这是安装的方法
sudo apt-get install postgresql-9.1
我想提出一种稍微不同的方法,它使用文件套接字代替。
通过允许您的Ubuntu用户访问数据库,一切都应该没有特殊的连接参数。
在Ubuntu命令行中:
createuser -U postgres your-current-ubuntu-username
有关详细信息,请参阅createuser的Manpage 。
在您的database.yml中:
development: adapter: postgresql encoding: unicode database: sample-app_development pool: 5 username: your-current-ubuntu-username password: