PSQL 9.3 ident authentication error on Fedora 21 - ruby-on-rails

[PSGQL 9.3, Fedora 21, Rails 4.2.0]
When I run any rails db command (rake db:migrate, rake db:create, etc), this error happen:
[dguedes#localhost clean_forum]$ rake db:create
FATAL: Ident authentication failed for user "dguedes"
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:436:in `new_connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `checkout_new_connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:565:in `retrieve_connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:87:in `connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/postgresql_database_tasks.rb:8:in `connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/postgresql_database_tasks.rb:17:in `create'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:93:in `create'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:275:in `block in each_current_configuration'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:274:in `each'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:274:in `each_current_configuration'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:106:in `create_current'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/home/dguedes/.rvm/rubies/ruby-2.2.0/bin/rake:33:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"UTF8", "database"=>"forum_development", "pool"=>5, "username"=>"dguedes", "password"=>"randompass", "host"=>"localhost"}
FATAL: Ident authentication failed for user "dguedes"
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:436:in `new_connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `checkout_new_connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:565:in `retrieve_connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:87:in `connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/postgresql_database_tasks.rb:8:in `connection'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/postgresql_database_tasks.rb:17:in `create'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:93:in `create'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:275:in `block in each_current_configuration'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:274:in `each'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:274:in `each_current_configuration'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:106:in `create_current'
/home/dguedes/.rvm/gems/ruby-2.2.0#rails4.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/home/dguedes/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/home/dguedes/.rvm/rubies/ruby-2.2.0/bin/rake:33:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"forum_test", "pool"=>5, "username"=>"dguedes", "password"=>"randompass", "host"=>"localhost"}
In postgres, I already created the role 'dguedes' with the correct password, and granted all privileges. For example:
bash-4.3$ psql -d forum_development -U dguedes
could not change directory to "/home/dguedes/Desktop/forum/clean_forum": Permission denied
Password for user dguedes:
psql (9.3.5)
Type "help" for help.
forum_development=# \du
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------+-----------
dguedes | Superuser, Create role, Create DB, Replication | {}
postgres | Superuser, Create role, Create DB, Replication | {}
forum_development=#
That shows that my role already have all the permissions.
My ph_hba.conf file:
# 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 ident
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres md5
#host replication postgres 127.0.0.1/32 ident
#host replication postgres ::1/128 ident
I restarted the server with the command 'systemctl stop postgresql-9.3' and
'systemctl start postgresql-9.3', but nothing happened.
And, finally, my 'database.yml' file:
development:
adapter: postgresql
encoding: UTF8
database: forum_development
pool: 5
username: dguedes
password: randompass
host: localhost
test:
adapter: postgresql
encoding: unicode
database: forum_test
pool: 5
username: dguedes
password: randompass
host: localhost
So, I can't figure the problem. I already try'd to reinstall postgre to clean everything but just don't worked. What looks wrong?

Couldn't create database for {"adapter"=>"postgresql",
"encoding"=>"UTF8", "database"=>"forum_development", "pool"=>5,
"username"=>"dguedes", "password"=>"XXXXXXX", "host"=>"localhost"}
FATAL: Ident authentication failed for user "dguedes"
You have ident configuration configured for all users on IP address localhost this meaus if you are not operating system user accout dguedes you cannot connect to postgresql as user postgresql username dguedes.
psql -d forum_development -U dguedes
here you connect via the "local" interface ( "local" is not the same as "localhost" ). Local is a unix domain socket (address /var/run/postgresql/5432 or something like that) this interface has md5 authentication for all users so anyone wantinng to connect as dguedes is asked for a password.
if you want to use this interface from you application the connection parameters string should not have host specified:
{"adapter"=>"postgresql", "encoding"=>"UTF8", "database"=>"forum_development",
"pool"=>5, "username"=>"dguedes", "password"=>"XXXXXXX" }
or optionally host should be specified explicitly empty, or NULL.
,"host"=>""
I see two other problems.
You expose your password in you log file above, so now would be a good time to change it.
In pg_hba.conf have disabled ident for the local postgres user. that's used by some maintenance tasks and should be re-enabled.

Related

How to fix PG::InvalidParameterValue: ERROR:

Every time I try to run
bundle exec rake db:create db:migrate
I get this error:
PG::InvalidParameterValue: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
HINT: Use the same encoding as in the template database, or use template0 as template.
: CREATE DATABASE "ruby-getting-started_development" ENCODING = 'unicode'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:484:in `block in log'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:478:in `log'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql/schema_statements.rb:78:in `create_database'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/postgresql_database_tasks.rb:15:in `create'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:93:in `create'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:276:in `block in each_current_configuration'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:275:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:275:in `each_current_configuration'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:106:in `create_current'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/bin/rake:23:in `load'
/usr/local/rvm/gems/ruby-2.3.0/bin/rake:23:in `<main>'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"ruby-getting-started_development"}
PG::InvalidParameterValue: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
HINT: Use the same encoding as in the template database, or use template0 as template.
: CREATE DATABASE "ruby-getting-started_test" ENCODING = 'unicode'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:484:in `block in log'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:478:in `log'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql/schema_statements.rb:78:in `create_database'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/postgresql_database_tasks.rb:15:in `create'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:93:in `create'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:276:in `block in each_current_configuration'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:275:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:275:in `each_current_configuration'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:106:in `create_current'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/bin/rake:23:in `load'
/usr/local/rvm/gems/ruby-2.3.0/bin/rake:23:in `<main>'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"ruby-getting-started_test"}
rake aborted!
ActiveRecord::NoDatabaseError: FATAL: database "ruby-getting-started_development" does not exist
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:661:in `rescue in connect'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_handling.rb:87:in `connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/migration.rb:916:in `initialize'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/migration.rb:823:in `new'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/migration.rb:823:in `up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/migration.rb:801:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
PG::ConnectionBad: FATAL: database "ruby-getting-started_development" does not exist
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_handling.rb:87:in `connection'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/migration.rb:916:in `initialize'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/migration.rb:823:in `new'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/migration.rb:823:in `up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/migration.rb:801:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.8/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
This is what my database.yml file looks like
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On OS X with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
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
development:
<<: *default
database: ruby-getting-started_development
# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
# When left blank, postgres will use the default role. This is
# the same name as the operating system user that initialized the database.
#username: ruby-getting-started
# The password associated with the postgres role (username).
#password:
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost
# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
#port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: ruby-getting-started_test
# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="postgres://myuser:mypass#localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
database: ruby-getting-started_production
username: ruby-getting-started
password: <%= ENV['RUBY-GETTING-STARTED_DATABASE_PASSWORD'] %>
Does anyone know how to fix it?
Similar question asked here. That answer also applies to your question.
Every DB you create in postgres copies template1 DB (it is system DB). The issue you have is that, the encoding of template1 DB is not unicode. So you have two options, (a) change encoding of template1 to unicode or (b) use template0 to create new databases in postgres. template0 is a system database without the encoding information, so it uses the encoding specified. Below solution uses option-b.
Make the below change to your database.yml file:
development:
<<: *default
database: ruby-getting-started_development
template: template0

Rails 4.2.4 with RVM 1.26.11 Environment Variable [ Not Set / Unable To Read ]

I am trying to use the RVM .ruby-env file to set an environment variable to hold the database password for my project. When I then go to create the database via the RAILS_ENV=production rake db:create command I get an error specifying that the password isn't set: "password"=>nil}.
.ruby-env is located in the root directory of my rails project, and to all accounts as per the RVM website:
This variable will be set when entering the project directory and reverted to its previous value when exiting the project directory.
.ruby-env contents:
VT_DATABASE_PASSWORD=testing1234
config/database.yml contents:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
host: localhost
production:
<<: *default
database: vagrant_test_production
username: lotus
password: <%= ENV['VT_DATABASE_PASSWORD'] %>
Command and error:
vagrant#vagrant-ubuntu-trusty-64:/vagrant/vagrant_test$ RAILS_ENV=production rake db:create
fe_sendauth: no password supplied
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:655:in `initialize'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:655:in `new'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:655:in `connect'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:87:in `connection'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/tasks/postgresql_database_tasks.rb:8:in `connection'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/tasks/postgresql_database_tasks.rb:17:in `create'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:93:in `create'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:275:in `block in each_current_configuration'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:274:in `each'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:274:in `each_current_configuration'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/tasks/database_tasks.rb:106:in `create_current'
/home/vagrant/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/home/vagrant/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/home/vagrant/.rvm/rubies/ruby-2.2.1/bin/rake:33:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "host"=>"localhost", "database"=>"vagrant_test_production", "username"=>"lotus", "password"=>nil}
I think you are just having problems with
ENV['VT_DATABASE_PASSWORD']
the value is just nil (null)
try to add these lines to your config/secrets.yml
production:
VT_DATABASE_PASSWORD: "your db password"
Otherwise you can just try to add the password to the database.yml (that file is not suppose to be in any repository so it's not public

Postgresql - can't create a role

Hello i'm tryng to create a datbase in a ruby on rails application but i've got this error
FATAL: role "giovanni" does not exist
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:661:in `rescue in connect'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:436:in `new_connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `checkout_new_connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/usr/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/usr/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:565:in `retrieve_connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:87:in `connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/tasks/postgresql_database_tasks.rb:8:in `connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/tasks/postgresql_database_tasks.rb:17:in `create'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:93:in `create'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:275:in `block in each_current_configuration'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:274:in `each'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:274:in `each_current_configuration'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:106:in `create_current'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/var/lib/gems/2.1.0/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"app_angular_rails_development"}
FATAL: role "giovanni" does not exist
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:661:in `rescue in connect'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:436:in `new_connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `checkout_new_connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/usr/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/usr/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:565:in `retrieve_connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:87:in `connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/tasks/postgresql_database_tasks.rb:8:in `connection'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/tasks/postgresql_database_tasks.rb:17:in `create'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:93:in `create'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:275:in `block in each_current_configuration'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:274:in `each'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:274:in `each_current_configuration'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:106:in `create_current'
/var/lib/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/var/lib/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/var/lib/gems/2.1.0/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"app_angular_rails_test"}
It seems that there isn't a role called "giovanni" in my local computer so i tried to create one by log in in the postgresql console and insert the query for create one user:
sudo -u postgress -i
CREATE ROLE giovanni WITH PASSWORD 'password' CREATEDB LOGIN CREATEROLE CREATEUSER SUPERUSER;
but i recive this error:
ERROR: conflicting or redundant options
I tried to rewrite this query in some other ways following the official documentation of the database but it didn't worked
You can try to create a user with createuser program, it has the same functionality as CREATE ROLE (in fact, it calls this command) but can be run from the command shell.
$ createuser giovanni
Shall the new role be a superuser? (y/n) y
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) y
CREATE USER
or with command line options:
$ createuser -P -s -e giovanni
Enter password for new role: xyzzy
Enter it again: xyzzy
CREATE ROLE giovanni PASSWORD 'xyzzy' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;
CREATE ROLE
It is because you are using CREATEUSER and CREATEROLE both. Chnage your query to CREATE ROLE test WITH SUPERUSER LOGIN CREATEDB CREATEROLE ENCRYPTED PASSWORD 'password';
This is what i usually do to set up postgres,create DB and its role to be use in database.yml on ubuntu terminal
add-apt-repository ppa:pitti/postgresql
##or use sudo apt-get install postgresql instead of repository
apt-get -y update
apt-get -y install postgresql libpq-dev
sudo -u postgres psql
# \password
# create user blog with password 'secret';
# create database blog_production owner blog;
# \q
use the above role in database.yml
development:
adapter: postgresql
encoding: unicode
database: blog_production
pool: 5
host: localhost
username: blog
password:secret
once its done,you just need to run bundle exec rake db:setup....and you will have all the tables in your db ready.

Rails - Creating postgres database on server throws error "could not connect to server: Connection refused"

I've been trying to get my app running for a couple of days now, and all previous problems were answered by searching, but I can't find a solution for this problem.
So I managed to deploy my app to a webhost following this guide: https://gorails.com/deploy/ubuntu/14.04
now I've come to the step were I need to perform the following action:
RAILS_ENV=production bundle exec rake db:create
I do this SSHing to deploy#[server IP] and going into the current folder, but it throws the following error:
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `initialize'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `new'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `connect'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:548:in `initialize'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/home/deploy/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/home/deploy/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_handling.rb:53:in `connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/postgresql_database_tasks.rb:8:in `connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/postgresql_database_tasks.rb:17:in `create'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:73:in `create'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:87:in `block in create_current'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:183:in `block in each_current_configuration'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:182:in `each'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:182:in `each_current_configuration'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:86:in `create_current'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/railties/databases.rake:20:in `block (2 levels) in <top (required)>'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:240:in `call'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:240:in `block in execute'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:235:in `each'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:235:in `execute'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/deploy/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:165:in `invoke'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:150:in `invoke_task'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `each'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `block in top_level'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:115:in `run_with_threads'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:100:in `top_level'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:78:in `block in run'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:176:in `standard_exception_handling'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:75:in `run'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/bin/rake:33:in `<top (required)>'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/bin/rake:23:in `load'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/bin/rake:23:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"dbblog", "pool"=>5, "username"=>"postgres", "password"=>"[removed]", "host"=>"localhost"}
this is the database.yml:
production:
adapter: postgresql
encoding: unicode
database: dbblog
pool: 5
username: postgres
password: [password removed!]
host: localhost
I used the same host as the writer of the guide author, and followed the same steps, so I don't get what I'm doing wrong.
I hope somebody can help me and thanks in advance!
First thing to check is whether your local Postgres instance is running at all:
ps -ef | grep postgres
And then if so, on what port it's running. 5432 is the default, so if you didn't do anything special in terms of config, that's where it should be running.
Also: Is the server where you're doing the rake the same one on which Postgres is running?

Rails 4.0.4, ruby 2.1.0, Ubuntu 12.04 rake db:create fails, postgresql making me sad

Using Ubuntu 12.04
I know the problem isn't exactly new, but I googled extensively, check stackoverflow, followed solutions that were suggested to the letter - alas, to no avail.
I have an app in Rails 4.0.4, Ruby 2.1.0, which I would like to deploy to Heroku. I have: installed pg 0.15.1 (tried 0.17.1 as well) gem,
sudo apt-get installed postgresql,
added host: localhost to database.yaml file,
edited /etc/postgresql/9.1/main/postgresql.conf and uncommented listen_addresses = 'localhost',
added user 'postgres' password 'blah' to psql database,
tried rake db:create - but failed spectacularly.
Please advise.
FATAL: password authentication failed for user "postgresql"
FATAL: password authentication failed for user "postgresql"
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:848:in `initialize'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:848:in `new'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:848:in `connect'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:556:in `initialize'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/usr/local/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/usr/local/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_handling.rb:53:in `connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/tasks/postgresql_database_tasks.rb:8:in `connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/tasks/postgresql_database_tasks.rb:17:in `create'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/tasks/database_tasks.rb:73:in `create'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/tasks/database_tasks.rb:87:in `block in create_current'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/tasks/database_tasks.rb:183:in `block in each_current_configuration'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/tasks/database_tasks.rb:182:in `each'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/tasks/database_tasks.rb:182:in `each_current_configuration'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/tasks/database_tasks.rb:86:in `create_current'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/railties/databases.rake:20:in `block (2 levels) in <top (required)>'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/task.rb:240:in `call'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/task.rb:240:in `block in execute'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/task.rb:235:in `each'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/task.rb:235:in `execute'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/task.rb:165:in `invoke'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:150:in `invoke_task'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `each'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `block in top_level'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:115:in `run_with_threads'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:100:in `top_level'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:78:in `block in run'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:176:in `standard_exception_handling'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:75:in `run'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "database"=>"development", "pool"=>5, "timeout"=>5000, "host"=>"localhost", "user"=>"postgresql", "password"=>"blah"}
FATAL: password authentication failed for user "postgresql"
FATAL: password authentication failed for user "postgresql"
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:848:in `initialize'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:848:in `new'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:848:in `connect'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:556:in `initialize'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/usr/local/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/usr/local/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_handling.rb:53:in `connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/tasks/postgresql_database_tasks.rb:8:in `connection'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/tasks/postgresql_database_tasks.rb:17:in `create'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/tasks/database_tasks.rb:73:in `create'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/tasks/database_tasks.rb:87:in `block in create_current'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/tasks/database_tasks.rb:183:in `block in each_current_configuration'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/tasks/database_tasks.rb:182:in `each'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/tasks/database_tasks.rb:182:in `each_current_configuration'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/tasks/database_tasks.rb:86:in `create_current'
/usr/local/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/railties/databases.rake:20:in `block (2 levels) in <top (required)>'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/task.rb:240:in `call'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/task.rb:240:in `block in execute'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/task.rb:235:in `each'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/task.rb:235:in `execute'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/task.rb:165:in `invoke'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:150:in `invoke_task'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `each'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:106:in `block in top_level'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:115:in `run_with_threads'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:100:in `top_level'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:78:in `block in run'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:176:in `standard_exception_handling'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/lib/rake/application.rb:75:in `run'
/usr/local/lib/ruby/gems/2.1.0/gems/rake-10.2.2/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "database"=>"test", "pool"=>5, "timeout"=>5000, "host"=>"localhost", "user"=>"postgresql", "password"=>"blah"}
To create user in psql I used: sudo -u postgres psql template1 and then inside the psql alter user command which I can't find anywhere :(
My database.yaml:
test:
adapter: postgresql
database: test
pool: 5
timeout: 5000
host: localhost
production:
adapter: postgresql
database: production
pool: 5
timeout: 5000
host: localhost
development:
adapter: postgresql
database: development
pool: 5
timeout: 5000
host: localhost
Solved with this database.yaml:
development:
encoding: unicode
adapter: postgresql
database: development
pool: 5
timeout: 5000
host: localhost
port: 5432
username: postgres
password: blah
test:
encoding: unicode
adapter: postgresql
database: test
pool: 5
timeout: 5000
host: localhost
port: 5432
username: postgres
password: blah
production:
encoding: unicode
adapter: postgresql
database: production
pool: 5
timeout: 5000
host: localhost
port: 5432
username: postgres
password: blah

Resources