2

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?

2 Answers 2

1

Worked for me using user instead of username

Sign up to request clarification or add additional context in comments.

Comments

0

I think your problem caused by using user in your database.yml instead of username. When you don't provide a username, it defaults to your current user. Are you still su - postgres when trying to launch your app? That would explain that why when it can't find a username, it falls back to 'postgres'. Being in postgres' environment might be causing your $MYAPP_DATABASE_PASSWORD environment variable to be unset as well, depending on how you set it up.

1 Comment

Thanks, I used 'user:myapp' and 'user_name:myapp' at the same time and it worked. Thank you! :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.