What fixed it for me: in config/database.yml I added the line, user:myapp, and took care to restart server as root user.
Original problem:
I am having problems with setting up PostGreSQL on my Ubuntu 12.04 VPS (hosted on DigitalOcean) with my Rails 4 App (Development Environment).
[email protected]$ su - postgres
[email protected] $ psql
I have created a role 'myapp' (same name as my Rails app), with a password that I set in ~/.bashrc. Role 'myapp'
postgres# create role 'myapp' with password '12345';
postgres# alter role 'myapp' with superuser;
postgres# alter role 'myapp' with LOGIN;
postgres# \q
[email protected] $ exit
[email protected]$ cd myapp/
[email protected]$ rake db:setup
...created my tables, etc...no trouble there
myapp/config/database.yml
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
user: myapp
password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>
development:
<<: *default
database: myapp_development
...
pg_hba.conf:
local all postgres trust #md5 I already tried
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
I restarted postgresql [email protected]$ service postgresql restart It seems to restart fine...
But when I visit my site at the ip.address,
PG::ConnectionBad
fe_sendauth: no password supplied
I check my logs var/log/postgresql/postgresql.main...
2014-11-21 17:24:40 UTC LOG: database system was shut down at 2014-11-21 17:24:39 UTC
2014-11-21 17:24:40 UTC LOG: database system is ready to accept connections
2014-11-21 17:24:40 UTC LOG: autovacuum launcher started
2014-11-21 17:24:41 UTC LOG: incomplete startup packet
2014-11-21 17:24:46 UTC FATAL: password authentication failed for user "postgres"
2014-11-21 17:24:46 UTC FATAL: password authentication failed for user "postgres"
2014-11-21 17:24:46 UTC LOG: incomplete startup packet
I don't know the password for "postgres" and I saw from other posts it should be blank. I've already changed the role I wanted to be named after my appname. The PostgreSQL documentation online don't address this, or I can't seem to find it. I've checked like all the Stack Overflow posts concerning postgresql and haven't found a fix. What do I do?