Rails / Postgres connection issue (psql and pg working fine) - ruby-on-rails

My rails app connects to the database on my development machine, and in production just fine. I've cloned the project to a coworker's machine, and recreated the database locally from a pgdump. The same process works fine on my machine. But on his,
psql at the command line is having no trouble:
$ psql ROL2
psql (9.5.2)
Type "help" for help.
ROL2=#
And to test the pg gem (pg-0.18.4), I've written a simple ruby script to output our users' names:
#!/usr/bin/env ruby
require 'pg'
conn = PG.connect( dbname: 'ROL2' )
conn.exec( "SELECT * FROM users" ) do |result|
result.each do |row|
puts "#{row['first_name']} #{row['last_name']}"
end
end
No problem; works fine. But when I try connecting via the rails console or a task in the app:
$ rails db
psql: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
Here's the database.yml:
# LOCAL POSTGRES
development:
adapter: postgresql
encoding: utf8
host: localhost
port: 5432
database: ROL2
pool: 5
Ditto when I try to connect with a client (Postico). I've tried with both the postgres user and his username / password.
ROL2=# \du
List of roles
Role name | Attributes | Member of
-------------+------------------------------------------------------------+-----------
joeschmo | Superuser, Create role, Create DB | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
Why might Rails have trouble connecting to the database, even though psql and the pg gem are working fine?
Added: the error as it appears in the Rails development logs:
PG::ConnectionBad (server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
):
activerecord (4.2.4) lib/active_record/connection_adapters/postgresql_adapter.rb:655:in `initialize'
activerecord (4.2.4) lib/active_record/connection_adapters/postgresql_adapter.rb:655:in `new'
activerecord (4.2.4) lib/active_record/connection_adapters/postgresql_adapter.rb:655:in `connect'
activerecord (4.2.4) lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
activerecord (4.2.4) lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
activerecord (4.2.4) lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/Users/mac_osx_username/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.2.4) lib/active_record/connection_adapters/postgresql_adapter.rb:655:in `new'
activerecord (4.2.4) lib/active_record/connection_adapters/postgresql_adapter.rb:655:in `connect'
activerecord (4.2.4) lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
activerecord (4.2.4) lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
activerecord (4.2.4) lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/Users/mac_osx_username/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/Users/mac_osx_username/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
activerecord (4.2.4) lib/active_record/connection_handling.rb:113:in `retrieve_connection'
activerecord (4.2.4) lib/active_record/connection_handling.rb:87:in `connection'
activerecord (4.2.4) lib/active_record/migration.rb:383:in `connection'
activerecord (4.2.4) lib/active_record/migration.rb:370:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.4) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
activesupport (4.2.4) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
activesupport (4.2.4) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.2.1) lib/web_console/middleware.rb:39:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.4) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.4) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.4) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.4) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.2.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.4) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/static.rb:116:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.4) lib/rails/engine.rb:518:in `call'
railties (4.2.4) lib/rails/application.rb:165:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'

Since the database.yml includes host and port, Rails is probably trying to connect to the TCP socket, whereas your connections via psql and pg (since they don't specify host or port) are using the UNIX socket. PostgreSQL comes configured out of the box to not listen to the TCP socket, so look at the postgresql.conf and ensure it has listen_addresses uncommented. If it doesn't, you can try either taking host and port out of the database.yml or modifying the config to enable TCP connections and restarting PostgreSQL.

Related

Rails server not working on Cloud9

A Rails newbie here. I'm having problem with cloned Shopify app to develop on Cloud9. I need to run on rails s -b $IP -p $PORT to see a preview, but i can't access to first page at all. it showed 500 server error (full msg: A static HTML page can contain a simple dependency free script to set the top bar to a 500 server error. This page can be found in 'public/500.html'.)
I tried to find solution here and here. Both of them suggest to modify pg_hba.conf But I check my file and it's the same as them so I didn't modify it at all.
I did try to change my database.yml from host: localhost -> host: /var/run/postgresql but I got another error msg. It seems not a solution.
Could you help me?
Here's my log
icys#c_app:~/workspace (master) $ rails s -b $IP -p $PORT
=> Booting Thin
=> Rails 4.2.0 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on 0.0.0.0:8080, CTRL+C to stop
Started GET "/" for 171.96.244.172 at 2015-09-01 13:44:42 +0000
PG::ConnectionBad (fe_sendauth: no password supplied
):
activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
activerecord (4.2.0) lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:436:in `new_connection'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `checkout_new_connection'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:565:in `retrieve_connection'
activerecord (4.2.0) lib/active_record/connection_handling.rb:113:in `retrieve_connection'
activerecord (4.2.0) lib/active_record/connection_handling.rb:87:in `connection'
activerecord (4.2.0) lib/active_record/query_cache.rb:51:in `restore_query_cache_settings'
activerecord (4.2.0) lib/active_record/query_cache.rb:43:in `rescue in call'
activerecord (4.2.0) lib/active_record/query_cache.rb:31:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.1) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.1) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.1) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.1) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.1) lib/rack/content_length.rb:15:in `call'
thin (1.6.3) lib/thin/connection.rb:86:in `block in pre_process'
thin (1.6.3) lib/thin/connection.rb:84:in `catch'
thin (1.6.3) lib/thin/connection.rb:84:in `pre_process'
thin (1.6.3) lib/thin/connection.rb:53:in `process'
thin (1.6.3) lib/thin/connection.rb:39:in `receive_data'
eventmachine (1.0.7) lib/eventmachine.rb:187:in `run_machine'
eventmachine (1.0.7) lib/eventmachine.rb:187:in `run'
thin (1.6.3) lib/thin/backends/base.rb:73:in `start'
thin (1.6.3) lib/thin/server.rb:162:in `start'
rack (1.6.1) lib/rack/handler/thin.rb:19:in `run'
rack (1.6.1) lib/rack/server.rb:286:in `start'
railties (4.2.0) lib/rails/commands/server.rb:80:in `start'
railties (4.2.0) lib/rails/commands/commands_tasks.rb:80:in `block in server'
railties (4.2.0) lib/rails/commands/commands_tasks.rb:75:in `tap'
railties (4.2.0) lib/rails/commands/commands_tasks.rb:75:in `server'
railties (4.2.0) lib/rails/commands/commands_tasks.rb:39:in `run_command!'
railties (4.2.0) lib/rails/commands.rb:17:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Here's my database.yml
development:
adapter: postgresql
encoding: unicode
database: development
pool: 5
host: localhost
username: action
password:
Here's my pg_hba.conf
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5

Postgres won't connect to server in Ruby on Rails app using c9.io

A few days ago, I was able to successfully install Postgresql and create/migrate my databases over from SQLite (in preparation for deploying my Rails 4 app)...or so I thought.
I restarted my server, but when I try to access my app, I get this error:
PG::ConnectionBad
could not connect to server: Connection refused
Is the server running locally and accepting connections on Unix domain socket
"/var/run/postgresql/.s.PGSQL.5432"?
I've seen several similar answered questions on SO, but they all involve Macs. Since i'm using the Cloud 9 IDE instead, I thought there might be differences (for instance, the mentions of localhost are probably not relevant, because that's not how I access the app currently on c9.io.)
According to the answers on the other questions, I tried this in my terminal:
sudo ps auxw | grep post
which gave me:
ubuntu 2527 0.0 0.0 10552 888 pts/5 S+ 15:21 0:00 grep --color=auto post
then I tried:
sudo find / -name .s.PGSQL.5432 -ls
and I got:
5286 0 lrwxrwxrwx 1 root root 26 May 11 15:13 /var/pgsql_socket/.s.PGSQL.5432 -> /private/tmp/.s.PGSQL.5432
5183 0 srwxrwxrwx 1 postgres postgres 0 May 10 22:18 /run/postgresql/.s.PGSQL.5432
yamilethmedina#wheels_registration:~/workspace (master|MERGING) $ psql
psql: could not connect to server: Connection refused
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Here is the full trace of my server:
Started GET "/" for 12.43.117.2 at 2015-05-11 16:35:48 +0000
PG::ConnectionBad (could not connect to server: Connection refused
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
):
activerecord (4.1.6) lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `initialize'
activerecord (4.1.6) lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `new'
activerecord (4.1.6) lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
activerecord (4.1.6) lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
activerecord (4.1.6) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
activerecord (4.1.6) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
activerecord (4.1.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
activerecord (4.1.6) lib/active_record/connection_handling.rb:113:in `retrieve_connection'
activerecord (4.1.6) lib/active_record/connection_handling.rb:87:in `connection'
activerecord (4.1.6) lib/active_record/migration.rb:388:in `check_pending!'
activerecord (4.1.6) lib/active_record/migration.rb:377:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.6) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.6) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.6) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.6) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.6) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.6) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.1.6) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.1.6) lib/rails/engine.rb:514:in `call'
railties (4.1.6) lib/rails/application.rb:144:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Rendered /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/_source.erb (1.1ms)
Rendered /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.8ms)
Rendered /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.9ms)
Rendered /usr/local/rvm/gems/ruby-2.1.5#rails4/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (45.7ms)
My entire github repo just in case:
https://github.com/yamilethmedina/wheels_registration.git
It doesn't look like postgresql is running. Perhaps it is not set to auto start. One reason for this can be if postgresql wasn't cleanly shutdown on the last run, and leaves a pid file laying around.
Try
sudo service postgresql start
and see if it comes back, and just make sure that you shut the vm down (so the stop scripts can run) as opposed to just powering it off.

Postgresql Bad Connection when starting Rails Server

I recently installed Ruby (version: 2.0.0p598) and Rails (version: 4.1.8) on my Windows 8 computer. Everything seemed to work fine when starting up a freshly created app on rails server...
However now I want to create a rails app using postgresql as my database. I created the app with the following line of code. rails new -T -d postgresql app_name
When I start up the server and load up the browser I get PG::ConnectionBad & fe_sendauth: no password supplied
I thought this was caused by postgresql not being installed on my computer so I did so with the Windows Postgreql installer however when I try psql --version in the terminal I get 'psql' is not recognized as an internal or external command, operable program or batch file.
I thought I already installed postgresql... so why is it not recognizing it?
I've checked my gemfile and gem 'pg' is there and I bundled as well.
Also here is my logs
Started GET "/" for 127.0.0.1 at 2015-03-26 21:45:24 -0400
PG::ConnectionBad (fe_sendauth: no password supplied
):
activerecord (4.1.8) lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `initialize'
activerecord (4.1.8) lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `new'
activerecord (4.1.8) lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
activerecord (4.1.8) lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
activerecord (4.1.8) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
activerecord (4.1.8) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
activerecord (4.1.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
activerecord (4.1.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
activerecord (4.1.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
activerecord (4.1.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.1.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
activerecord (4.1.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.1.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
activerecord (4.1.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
activerecord (4.1.8) lib/active_record/connection_handling.rb:113:in `retrieve_connection'
activerecord (4.1.8) lib/active_record/connection_handling.rb:87:in `connection'
activerecord (4.1.8) lib/active_record/query_cache.rb:51:in `restore_query_cache_settings'
activerecord (4.1.8) lib/active_record/query_cache.rb:43:in `rescue in call'
activerecord (4.1.8) lib/active_record/query_cache.rb:32:in `call'
activerecord (4.1.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
activerecord (4.1.8) lib/active_record/migration.rb:380:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.8) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.8) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.8) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.8) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.8) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.8) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.8) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.8) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.1.8) lib/action_dispatch/middleware/static.rb:84:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.1.8) lib/rails/engine.rb:514:in `call'
railties (4.1.8) lib/rails/application.rb:144:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
Rendered C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/_source.erb (2.0ms)
Rendered C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.0ms)
Rendered C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (3.0ms)
Rendered C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/actionpack-4.1.8/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (237.7ms)

Getting Puma Postgres Server to Work in Development to Cooperate with Heroku, or does going back to Sqlite make sense?

I got using puma instead of rails s to work fine for awhile, but then while developing and making code changes and refreshing at some point the refresh wasn't working, delaying for a long time. I assumed it had crashed or something, so I killed the puma server, but then it said 'gracefully shutting down' for several minutes so I killed the terminal window. Then, in a new window when I tried to use puma it said the host was already taken, so the process was still running. Unable to find where it was, I restarted my computer. Upon restart, I now get the error An unhandled lowlevel error occured. The application logs may have details. or PG::ConnectionBad fe_sendauth: no password supplied, depending on whether I run puma or RAILS_ENV=development puma.
Neither of these responses seem to make sense, and this error I see others having on rake db:migrate. So I tried migrating the database and got the same error PG::ConnectionBad: fe_sendauth: no password supplied
And in the logs when trying to run the server: Rack app error: #<RuntimeError: Missingsecret_key_basefor 'production' environment, set this value inconfig/secrets.yml>
Now this makes the least sense to me, as why is puma running production environment by default and requiring a special command to run in development?
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
Is dependent on Heroku to pass the secret_key_base is my assumption, so it doesn't work for development. But then even RAILS_ENV=development puma throws
PG::ConnectionBad
fe_sendauth: no password supplied
And a trace that doesn't appear to help me:
activerecord (4.1.7) lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `initialize'
activerecord (4.1.7) lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `new'
activerecord (4.1.7) lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
activerecord (4.1.7) lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
activerecord (4.1.7) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
activerecord (4.1.7) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/Users/lasernite/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/Users/lasernite/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
activerecord (4.1.7) lib/active_record/connection_handling.rb:113:in `retrieve_connection'
activerecord (4.1.7) lib/active_record/connection_handling.rb:87:in `connection'
activerecord (4.1.7) lib/active_record/migration.rb:388:in `check_pending!'
activerecord (4.1.7) lib/active_record/migration.rb:377:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.7) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.7) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.7) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.7) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.7) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.7) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.7) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.7) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.7) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.1.7) lib/action_dispatch/middleware/static.rb:84:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
rack-timeout (0.2.0) lib/rack/timeout.rb:108:in `call'
railties (4.1.7) lib/rails/engine.rb:514:in `call'
railties (4.1.7) lib/rails/application.rb:144:in `call'
puma (2.11.0) lib/puma/configuration.rb:82:in `call'
puma (2.11.0) lib/puma/server.rb:507:in `handle_request'
puma (2.11.0) lib/puma/server.rb:375:in `process_client'
puma (2.11.0) lib/puma/server.rb:262:in `block in run'
puma (2.11.0) lib/puma/thread_pool.rb:104:in `call'
puma (2.11.0) lib/puma/thread_pool.rb:104:in `block in spawn_thread'
I'm stuck on where to try and resolve this error.
Please give any insight you can. Thanks!
Is your "config/secrets.yml" file listed in .gitignore? Heroku needs that file. Remove or comment it out from .gitignore. I had the same problem and that was my issue.
Also, see this post for the same answer:
How to solve error "Missing `secret_key_base` for 'production' environment" (Rails 4.1)
Good luck!

Rails 4 Action Controller: Exception caught Mysql2::Error

Rails 4 Action Controller: Exception caught Mysql2::Error
Trying to open "Lynda.com Essential Ruby on rails 4" exercise files app on localhost:3000/ and this is what i get:
Mysql2::Error
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Thanks!!
Update: 25/01
These are my logs:
Started GET "/" for 127.0.0.1 at 2014-01-22 15:46:18 +0200
Mysql2::Error (Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)):
mysql2 (0.3.13) lib/mysql2/client.rb:58:in `connect'
mysql2 (0.3.13) lib/mysql2/client.rb:58:in `initialize'
activerecord (4.0.0) lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
activerecord (4.0.0) lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract /connection_pool.rb:440:in `new_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract /connection_pool.rb:450:in `checkout_new_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract /connection_pool.rb:421:in `acquire_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract /connection_pool.rb:356:in `block in checkout'
/home/ggeorgiev/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211:in ` mon_synchronize'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract /connection_pool.rb:355:in `checkout'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract /connection_pool.rb:265:in `block in connection'
/home/ggeorgiev/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
activerecord (4.0.0) lib/active_record/connection_handling.rb:79:in `retrieve_connection'
activerecord (4.0.0) lib/active_record/connection_handling.rb:53:in `connection'
activerecord (4.0.0) lib/active_record/migration.rb:792:in `current_version'
activerecord (4.0.0) lib/active_record/migration.rb:800:in `needs_migration?'
activerecord (4.0.0) lib/active_record/migration.rb:379:in `check_pending!'
activerecord (4.0.0) lib/active_record/migration.rb:366:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__4564087381787545460__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/home/ggeorgiev/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/ggeorgiev/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/ggeorgiev/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
Rendered /home/ggeorgiev/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.0/lib /action_dispatch/middleware/templates/rescues/_source.erb (0.7ms)
Rendered /home/ggeorgiev/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.0/lib /action_dispatch/middleware/templates/rescues/_trace.erb (1.6ms)
Rendered /home/ggeorgiev/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.0/lib /action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.1ms)
Rendered /home/ggeorgiev/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.0/lib /action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (16.2ms)
The server has not started. You could start it from System Preference.
System Preference -> Mysql -> Start Server.
Or else you could start it from the terminal. The command varies depending on how you installed MySQL. Try this first:
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
If that fails:
cd /usr/local/mysql
sudo ./bin/mysqld_safe
(Enter your password, if necessary)
(Press Control-Z)
bg
If that doesn't work then try below
mysql.server start
mysqladmin variables | grep socket
For me it gave,
| socket | /tmp/mysql.sock
Then add a line to your config/database.yml
development:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
socket: /tmp/mysql.sock
Hope that solves your problem.

Resources