I am new to Ruby on rails. I've created two basic demo apps by tutorial learning by examples
and suddenly it stops working for my new sample app.
I have generated a controller Pages
and two actions home
and contact
and nothing fancy.
Now, I am not able to open any pages, except the default index.html rails page at localhost:3000
. The page at localhost:3000/pages/home
and localhost:3000/pages/contact
returns this error.
PG::Error
server closed the connection unexpectedly This probably means the
server terminated abnormally before or while processing the request.
and sometimes (usually when I restart postgresql),
PG::Error
server closed the connection unexpectedly This probably means the
server terminated abnormally before or while processing the request.
could not send startup packet: Broken pipe
This is my stack trace
activerecord (3.2.8)
lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in
initialize' activerecord (3.2.8)
new' activerecord (3.2.8)
lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in
lib/active_record/connection_adapters/postgresql_adapter.rb:1213:in
connect' activerecord (3.2.8)
initialize' activerecord (3.2.8)
lib/active_record/connection_adapters/postgresql_adapter.rb:329:in
lib/active_record/connection_adapters/postgresql_adapter.rb:28:in
new' activerecord (3.2.8)
postgresql_connection' activerecord (3.2.8)
lib/active_record/connection_adapters/postgresql_adapter.rb:28:in
lib/active_record/connection_adapters/abstract/connection_pool.rb:309:in
new_connection' activerecord (3.2.8)
checkout_new_connection' activerecord (3.2.8)
lib/active_record/connection_adapters/abstract/connection_pool.rb:319:in
lib/active_record/connection_adapters/abstract/connection_pool.rb:241:in
block (2 levels) in checkout' activerecord (3.2.8)
loop' activerecord (3.2.8)
lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in
lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in
block in checkout'
mon_synchronize' activerecord (3.2.8)
/home/jashwant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in
lib/active_record/connection_adapters/abstract/connection_pool.rb:233:in
checkout' activerecord (3.2.8)
block in connection'
lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in
/home/jashwant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in
mon_synchronize' activerecord (3.2.8)
connection' activerecord (3.2.8)
lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in
lib/active_record/connection_adapters/abstract/connection_pool.rb:404:in
retrieve_connection' activerecord (3.2.8)
retrieve_connection' activerecord (3.2.8)
lib/active_record/connection_adapters/abstract/connection_specification.rb:170:in
lib/active_record/connection_adapters/abstract/connection_specification.rb:144:in
connection' activerecord (3.2.8)
rescue in call' activerecord
lib/active_record/query_cache.rb:67:in
(3.2.8) lib/active_record/query_cache.rb:61:incall' activerecord
call' actionpack (3.2.8)
(3.2.8)
lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in
lib/action_dispatch/middleware/callbacks.rb:28:inblock in call'
run_3261957284442330683_call_599627944998934036__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in
__run_callback' activesupport (3.2.8)
_run_call_callbacks'
lib/active_support/callbacks.rb:385:in
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in
run_callbacks' actionpack (3.2.8)
call' actionpack
lib/action_dispatch/middleware/callbacks.rb:27:in
(3.2.8) lib/action_dispatch/middleware/reloader.rb:65:incall'
call' actionpack (3.2.8)
actionpack (3.2.8) lib/action_dispatch/middleware/remote_ip.rb:31:in
lib/action_dispatch/middleware/debug_exceptions.rb:16:incall'
call'
actionpack (3.2.8)
lib/action_dispatch/middleware/show_exceptions.rb:56:in
railties (3.2.8) lib/rails/rack/logger.rb:26:incall_app' railties
call' actionpack (3.2.8)
(3.2.8) lib/rails/rack/logger.rb:16:in
lib/action_dispatch/middleware/request_id.rb:22:incall' rack (1.4.1)
call' rack (1.4.1)
lib/rack/methodoverride.rb:21:in
lib/rack/runtime.rb:17:incall' activesupport (3.2.8)
call' rack
lib/active_support/cache/strategy/local_cache.rb:72:in
(1.4.1) lib/rack/lock.rb:15:incall' actionpack (3.2.8)
call' railties (3.2.8)
lib/action_dispatch/middleware/static.rb:62:in
lib/rails/engine.rb:479:incall' railties (3.2.8)
call' rack (1.4.1)
lib/rails/application.rb:223:in
lib/rack/content_length.rb:14:incall' railties (3.2.8)
call' rack (1.4.1)
lib/rails/rack/log_tailer.rb:17:in
lib/rack/handler/webrick.rb:59:inservice'
service'
/home/jashwant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in
/home/jashwant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:in
run'
block in start_thread'
/home/jashwant/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in
I am not using database for now. I tried to do rake db:migrate
but it returns the same error.
I am on Ubuntu 12.04 (as some bugs on google were related to ubuntu)
I have found similar questions on SO, but they are experiencing at some advance stage and thus involves some advance solutions.
Best Answer
Although, I am not using the database but specifying the port in configuration in
database.yml
solves the problem. By default, therails new <app_name> --database=postgresql
command does not put aport
there.Here's my config.