When I run rake:db migrate from my rails app, I get this output:
rake aborted!
PG::ConnectionBad: 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/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `initialize'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `new'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_handling.rb:87:in `connection'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/migration.rb:910:in `initialize'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `new'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `up'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/migration.rb:785:in `migrate'
/home/ubuntu/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
/home/ubuntu/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
/home/ubuntu/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
In my gemfile I have
gem 'pg'
and in my database.yml I have
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: fake_lunch_hub_development
test:
<<: *default
database: fake_lunch_hub_test
production:
<<: *default
database: fake_lunch_hub_production
username: fake_lunch_hub
password: <%= ENV['FAKE_LUNCH_HUB_DATABASE_PASSWORD'] %>
This setup used to connect to the database perfectly, but I did a lot of refactoring and renaming (the project is no longer called fake_lunch_hub) and I moved the project off of my local machine (mac) and onto an amazon EC2 instance (ubuntu).
There are many other questions on Stackoverflow that offer solutions using psql, but when I run the command
psql
I get this:
The program 'psql' can be found in the following packages:
* postgresql-client-common
* postgres-xc-client
Try: sudo apt-get install <selected package>
I'd rather not download a new postgres package because I already have it successfully downloaded from the gem.
How can I get that server started and accepting connections?
EDIT:
FULL SOLUTION:
sudo apt-get install postgres
sudo su
su postgres
createuser ubuntu
createuser fake_lunch_hub
createdb fake_lunch_hub
exit
exit
rails server
resolves the issues
The gem is just a way for Ruby/Rails to talk to a Postgres server. The gem itself does not contain its own server.
You'll still need to install one:
sudo apt-get install postgresql
Related
Recently I forked and cloned a repo I am contributing to and when I run rails s I get no errors, however when I run rake db:migrate I get this.
rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `initialize'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `new'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/connection_handling.rb:87:in `connection'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:910:in `initialize'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `new'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:807:in `up'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/migration.rb:785:in `migrate'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
/Users/taimurknaziri/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I checked out some other threads with other people who had the same problem however their solutions did not really have any luck for me.
I tried uninstalling and reinstalling PG as well as getting rid of the .PID file however it doesn't look like I seem to have one.
Any clues, pointers or advice? Thanks in advance.
This means either your database.yml file in config/ directory is not set up correctly for your environment, most likely development as it is the default or you do not have postgresql running.
If you do not have postgresql running either install it or start it up. You can check postgresql, more than likely with either:
sudo service postgresql status
or
ps -ef | grep postgres
If you do have postgresql running, then check your database.yml file and edit it appropriately, most likely something like:
development:
adapter: postgresql
encoding: unicode
database: database_name
host: localhost
username: user_name
password: password
I keep getting this error when i try to run my localhost using "$rails s":
(Mac OSX 10.8.3)
(ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0])
(Rails 3.2.11)
(psql (PostgreSQL) 9.2.2 ) **installed with homebrew
I have been doing a lot of uninstalling postgresql and reinstalling so I have a hunch that there may be conflicting libraries somewhere...i just dont know where to start.
I had Postgresql 9.1 and 9.2 in the same folder and just moved 9.1 into the trash.
Here is the output when I run "rails s" in the terminal
Danny$ rails s
^[b=> Booting Thin
=> Rails 3.2.11 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize': could not connect to server: Connection refused (PGError)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5433?
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5433?
could not connect to server: Connection refused
Is the server running on host "localhost" (fe80::1) and accepting
TCP/IP connections on port 5433?
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `new'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `connect'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:326:in `initialize'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block (2 levels) in checkout'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block in checkout'
from /Users/Danny/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checkout'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block in connection'
from /Users/Danny/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/model_schema.rb:308:in `clear_cache!'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-3.2.11/lib/active_record/railtie.rb:97:in `block (2 levels) in <class:Railtie>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:418:in `_run__3642716200177086041__prepare__4186317719333288752__callbacks'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `__run_callback'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/actionpack-3.2.11/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/actionpack-3.2.11/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/Danny/Dropbox/programming/coding/f_app/config/environment.rb:7:in `<top (required)>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in require'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
from /Users/Danny/Dropbox/programming/coding/f_app/config.ru:3:in `block in <main>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
from /Users/Danny/Dropbox/programming/coding/f_app/config.ru:in `new'
from /Users/Danny/Dropbox/programming/coding/f_app/config.ru:in `<main>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/builder.rb:40:in `eval'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/builder.rb:40:in `parse_file'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/server.rb:200:in `app'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/commands/server.rb:46:in `app'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/server.rb:304:in `wrapped_app'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.4.5/lib/rack/server.rb:254:in `start'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/commands/server.rb:70:in `start'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/commands.rb:55:in `block in <top (required)>'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/commands.rb:50:in `tap'
from /Users/Danny/.rvm/gems/ruby-2.0.0-p195/gems/railties-3.2.11/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
The error message is instrumental:
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5433?
port
You may be trying to connect to the wrong port.
Standard port is 5432. Check how (and whether at all) you started your postgres server:
postgres#db:~$ ps -auxww | grep ^postgres
... <stripped more lines>
postgres 1274 0.0 0.3 1437240 57308 ? S May27 5:01 /usr/lib/postgresql/9.1/bin/postgres -D /var/lib/postgresql/9.1/main -c config_file=/etc/postgresql/9.1/main/postgresql.conf
The manual has related information here.
In my example, settings from /etc/postgresql/9.1/main/postgresql.conf got used, which says (among many other settings):
port = 5432
Or run:
netstat -nlp | grep postgres
Or just look here (at least in Debian or Ubuntu):
ls -lA /var/run/postgresql/
PostgreSQL picks the next free port if you create a new database cluster. Since you installed repeatedly, you may have confused port numbers.
listen_addresses
Or you just forgot to allow TCP/IP connections. Related answers:
Run batch file with psql command without password
What's the difference between "local" and "localhost" connection types in pg_hba.conf?
no pg_hba.conf entry for host
This may resolve the issue :-
Get the hba.conf file address by using command SHOW config_file; and SHOW hba_file; in sql prompt
Now open hba.conf and add this host all all 0.0.0.0/0 trust
Now open postgresql.conf and add listen_address = '*'
In my case, the problem was caused by the upgrade of postgresql-9.4 to postgresql-9.5 in Ubuntu 16.04. Since, There were two versions installed at some point in time, the later installed version i.e. postgresql-9.5's config changed to default port of 5433 (instead of standard default 5432).
The problem occurred when my Rails project tried to connect to the default port of postgresql (since the port was not defined explicitly defined in database.yml file) and kept failing. Even after removal of postgresql-9.4 later.
Solution changing postgresql's config file
The solution is changing the port in the configuration of updated postgresql (9.5). To do this open the file /etc/postgresql/9.5/main/postgresql.conf and change the line
port = 5433 # (change requires restart)
to
port = 5432 # (change requires restart)
and then restart the server with sudo service postgresql restart.
Solution with changing Rails' `database.yml' file
Alternatively, you can change rails' database.yml file by explicitly mention the new port (that ie 5433) without changing the postgresql's config file. To do this, simply add a line like this
port: 5433
and restart the rails server.
sudo -u postgres pg_ctlcluster 9.3 main stop
followed by
sudo -u postgres pg_ctlcluster 9.3 main restart
worked for me
I got this error message hooking up to Jira (from the Jira side) and the solution was to change the "Hostname or IP address of the database server." to "localhost". If you're running locally you can't just put in your local ip address.
Also the next issue for a local install is the password always fails even though that's correct because pg_hba.conf needs to be edited so the authentication method is "trust".
In postgresql.conf, /var/lib/pgsql/data/postgresql.conf :
change the listen_addresses = 'localhost' to listen_addresses = '*'
enable the default port as 5432, port = 5432
Also in pg_hba.conf, /var/lib/pgsql/data/pg_hba.conf,
try the authentication method as trust
I have repeatedly tried to setup my rails app on an ec2 instance using nginx and unicorn. I have found that both nginx and unicorn are set up properly; however, on both machines my rails app does not want to start up in the production environment. The output of attempting to start up in production is:
/Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:129:in `establish_connection'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:26:in `block in on_load'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:25:in `each'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:25:in `on_load'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activerecord-3.2.8/lib/active_record/railtie.rb:74:in `block in <class:Railtie>'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `run'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `each'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/application.rb:136:in `initialize!'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/benvreed/Documents/rubydev/StudyPublic/config/environment.rb:5:in `<top (required)>'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
from /Users/benvreed/Documents/rubydev/StudyPublic/config.ru:4:in `block in <main>'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
from /Users/benvreed/Documents/rubydev/StudyPublic/config.ru:1:in `new'
from /Users/benvreed/Documents/rubydev/StudyPublic/config.ru:1:in `<main>'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/server.rb:46:in `app'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/server.rb:70:in `start'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:55:in `block in <top (required)>'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:50:in `tap'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Although, I clearly do specify the postgresql adapter in my database.yml file:
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On Mac 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'
#
development:
adapter: postgresql
encoding: unicode
host: localhost
database: study_development
pool: 5
# 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
#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
# The server defaults to notice.
#min_messages: warning
# 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:
adapter: postgresql
encoding: unicode
host: localhost
database: study_test
pool: 5
production:
adapter: postgresql
encoding: unicode
host: localhost
database: study_production
pool: 5
What's really strange is that it successfully runs in both the development and test environments. I have checked other issues on StackOverflow and most have said that it is a spacing issue; however, I have redone the database.yml file several times with the same result.
My unicorn and nginx files are standard configurations.
Any assistance would be greatly appreciated. I am at a stand still until this runs. Thanks in advance.
RAILS_ENV
When using the Rails Console by executing RAILS_ENV=production rails c, running RAILS_ENV produces:
NameError: uninitialized constant RAILS_ENV
from (irb):1
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
from /Users/benvreed/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Rails.env produces:
=> "production"
The adaptor in you database.yml should be pg, not postgresql.
production:
adapter: pg
encoding: unicode
host: localhost
database: study_development
My setup uses this:
production:
adapter: pg
encoding: utf8
reconnect: false
database: my_app_name_production
Your database.yml settings is ok. Nothing weird.
If the development mode runs without exceptions, thus the problem is not in the DB.
Try to check database.yml precisely: maybe invalid/unacceptable* characters present.
some symbols are so similar :) с and c
Forking error!
Maybe some caching or log problems It shows that nothing of the errors in our code.
My team resolve it.
delete the project
git clone the project
config the database.yml
start server
Everything is okay!
The same project the errors gone!
So we think it is env problems or cach or log.
see here: (https://stackoverflow.com/posts/18695551/edit)
Super stumped by why Postgres isn't working on a new app I just started. I've got it working for one app already. I'm using postgres.app, and it's running.
I started a new app with
rails new depot -d postgresql
and then I went into the database.yml file and changed username to my $USER (which is what it is for the other app, which is working). So now my database.yml file has this development section:
development:
adapter: postgresql
encoding: unicode
database: depot_development
pool: 5
username: <username>
password:
But when I run "rake db:create" or "rake db:create:all" I still got this error (in full, cause I don't know what's relevant):
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"depot_development", "pool"=>5, "username"=>"<username>", "password"=>nil}
could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in `initialize'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in `new'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in `connect'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:329:in `initialize'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:309:in `new_connection'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:319:in `checkout_new_connection'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:241:in `block (2 levels) in checkout'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in `loop'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in `block in checkout'
/Users/<username>/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:233:in `checkout'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in `block in connection'
/Users/<username>/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:404:in `retrieve_connection'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:170:in `retrieve_connection'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:144:in `connection'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:107:in `rescue in create_database'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:51:in `create_database'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:40:in `block (3 levels) in <top (required)>'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:40:in `each'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.8/lib/active_record/railties/databases.rake:40:in `block (2 levels) in <top (required)>'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/<username>/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/bin/rake:19:in `load'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194#global/bin/rake:19:in `<main>'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `eval'
/Users/<username>/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"depot_test", "pool"=>5, "username"=>"<username>", "password"=>nil}
I have tried
createdb depot_development
I have tried going into the psql environment and listing users (which included my username among them). In the same psql environment, I tried
CREATE DATABASE depot;
I've made sure that the pg gem is installed with bundle install, I've run "pg_ctl start", to which I got this response:
pg_ctl: no database directory specified and environment variable PGDATA unset
I ran "ps aux | grep postgres" to make sure postgres was running, to which I got this in return (which looks like it's doing OK, right?):
<username> 10390 0.4 0.0 2425480 180 s000 R+ 6:15PM 0:00.00 grep postgres
<username> 2907 0.0 0.0 2441604 464 ?? Ss 6:17PM 0:02.31 postgres: stats collector process
<username> 2906 0.0 0.0 2445520 1664 ?? Ss 6:17PM 0:02.33 postgres: autovacuum launcher process
<username> 2905 0.0 0.0 2445388 600 ?? Ss 6:17PM 0:09.25 postgres: wal writer process
<username> 2904 0.0 0.0 2445388 1252 ?? Ss 6:17PM 0:12.08 postgres: writer process
<username> 2902 0.0 0.0 2445388 3688 ?? S 6:17PM 0:00.54 /Applications/Postgres.app/Contents/MacOS/bin/postgres -D /Users/<username>/Library/Application Support/Postgres/var -p5432
The short of it, is I've been troubleshooting for a WHILE and have NO idea what's wrong. Any ideas? I'd really appreciate it, cause I'm pretty new to Rails, and this is a pretty disheartening roadblock.
Thanks!
EDIT -- Per request, posting the successful database.yml . It seems the difference is the inclusion of a password:
development:
adapter: postgresql
encoding: unicode
database: *******_development
pool: 5
username: *******
password: *******
EDIT2 -- When I add a password to the .yml file, then run rake db:create again, I get the same error. And I'm running Mac OSX Lion, and I did initdb and stuff when I first installed PostgreSQL.
In order to create a database , before starting the command pg_ctl start
you have to initialize the database cluster then only pg_ctl start shall be success full*
this can be done in many ways
if you are running on Linux / centos with postgres 9.1
service postgresql-9.1 initdb
service postgresql-9.1 start
or you can do like this
$ mkdir -p /var/pgsql/data; chown -R postgres /var/pgsql
$ su - postgres
$ initdb -D /var/pgsql/data
# Starting, testing:
$ postgres -D /var/pgsql/data > /var/pgsql/logfile 2>&1 &
$ createdb test
$ psql test
Initializing postgres initb differes from os to os and postgres versions , if the above command did not work please have a look at
Adding
host: localhost
to development works for me.
I'm trying to run rake db:create or rake db:setup but I get the following error. It's strange because rake db:create it's working fine from others folders with other Rails projects.
user:project user$ rake db:create
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord- 3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:991:in `initialize'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord- 3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:991:in `new'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:991:in `connect'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:260:in `initialize'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:27:in `new'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:27:in `postgresql_connection'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord- 3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:304:in `new_connection'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:323:in `checkout_new_connection'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord- 3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block (2 levels) in checkout'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord- 3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:261:in `loop'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:261:in `block in checkout'
/Users/user/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:260:in `checkout'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:162:in `connection'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:409:in `retrieve_connection'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:107:in `retrieve_connection'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:110:in `rescue in create_database'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0/lib/active_record/railties/databases.rake:54:in `create_database'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/activerecord- 3.1.0/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/user/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/user/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/user/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `load'
/Users/user/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "database"=>"project_test", "username"=>nil, "password"=>nil, "min_messages"=>"warning"}
This is my database.yml
development:
adapter: postgresql
database: project_development
username:
password:
min_messages: warning
test:
adapter: postgresql
database: project_test
username:
password:
min_messages: warning
production:
adapter: postgresql
database: project_production
username:
password:
min_messages: warning
Posgree is insatelled on /usr/local/var/postgres. Shouldn't rake try to look it in the same folder instead of /var/pgsql_socket/ ? (I don't have a /usr/local/var/pgsql_socket anyways)
Solved!
Solution was simple to update current installed gems.
Another solution to try is set host: localhost or whatever host you use on development settings on database.yml file.
I installed PG on Mac OS X via Homebrew (I didn't realize it came default in Mac OS X), and had the same problem. I may have made the problem worse by installing the pg gem before installing pg via Homebrew.
I solved this same problem by doing the following:
Make sure that all binaries are pointing to binaries in Cellar directory (/usr/local/Cellar on Mac OS X)
Uninstall pg gem gem uninstall pg
Reinstall with Homebrew configs gem install pg -- --with-pg-config=/usr/local/bin/pg_config (if you created a rails project with pg setup, this is explained in your database.yml config file)
And it worked!
First, you will need to create your user manually in Postgres, while granting privilege of database creation (AKA createdb) for this user.
To do so, first, open Postgres shell prompt
$ sudo -u postgres psql
Create your user
postgres=# create role Your_DB_username with createdb login password 'YOUR_PASSWORD';
Exit from Postgres shell
postgres=# \q
Do whatever db-related rake task:
$ rake db:create
And it will work!
The answer from zquintana above worked for me with a few small caveats.
My solution (using Homebrew):
If you have the gem installed gem uninstall pg
Remove old copy of postgresql brew uninstall postgresql
Re-install postgresql brew install postgresql
The install notes mention:
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
postgres -D /usr/local/var/postgres
So run ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Now re-install the gem with the Homebrew configs gem install pg -- --with-pg-config=/usr/local/bin/pg_config
Now run your rake db:create
In my case this was all I needed: https://dba.stackexchange.com/a/75221
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
I encountered an identical issue and was able to solve the error by:
using postgresapp.com (recommended by heroku in https://devcenter.heroku.com/articles/heroku-postgresql#local-setup),
adding to config/database.yml
host: localhost
resetting shared memory settings as recommended in troubleshooting section of http://postgresapp.com/documentation:
sudo sysctl -w kern.sysv.shmall=65536
sudo sysctl -w kern.sysv.shmmax=16777216
Also check you don't have an open connection such as a client or an application connected to the instance. If that happen you will see this in the error
Couldn't create database for {"adapter"=>"xxxx", "database"=>"xxxx", "host"=>"localhost", "username"=>"postgres", "password"=>"xxxxx", "pool"=>5, "timeout"=>5000}
rake aborted!
ActiveRecord::StatementInvalid: PG::ObjectInUse: ERROR: source database "template1" is being accessed by other users
DETAIL: There is 1 other session using the database.
Simple add host: localhost to your database.yml
For more detail please visit rake db:create:all fails to connect to PostgreSQL database
I was able to solve this by making sure that the name of my database in the database.yml file was in the following format: appname_development, appname_test, and appname_production. Here is my database.yml file as an example:
development:
adapter: postgresql
database: parallax_development
username:
password:
test:
adapter: postgresql
database: parallax_test
username:
password:
production:
adapter: postgresql
database: parallax_production
username:
password: