# What to do when the database server is in another place

**URL:** <https://www.ruby-forum.com/t/what-to-do-when-the-database-server-is-in-another-place/159441>\
**Category:** Rails\
**Created:** [February 4, 2009, 3:59pm UTC](https://www.ruby-forum.com/t/what-to-do-when-the-database-server-is-in-another-place/159441 "2009-02-04T15:59:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![raimon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@raimon](https://www.ruby-forum.com/u/raimon)\
**Post date:** [February 4, 2009, 3:59pm UTC](https://www.ruby-forum.com/t/what-to-do-when-the-database-server-is-in-another-place/159441/1 "2009-02-04T15:59:44Z")

</div>

Hello,

I’m serving an application, that the database is in another place  
(far…).

Once connected, everything is ok, but when you try to login, normally,  
the Rails isn’t connected, and I’m getting an Status: 500 Internal  
Server Error.

If I wait 2 or 3 seconds, the connection with the databse has been  
established again and now all works perfect.

Is there a way for Rails to have always the connection opened ?

Maybe I should check for database connection on the first time and  
handle the error or the waiting page until the connection has been  
established.

Any ideas appreciated …

thanks,

r.

/!\ FAILSAFE /!\ Wed Feb 04 15:51:41 +0100 2009  
Status: 500 Internal Server Error  
PGError: server closed the connection unexpectedly  
This probably means the server terminated abnormally  
before or while processing the request.  
: SELECT \* FROM “sessions” WHERE (session\_id =  
E’059e8560022e9b60b603117a3895a6ae’) LIMIT 1  
/u/apps/scanner/releases/20090202165310/vendor/rails/activerecord/lib/active\_record/connection\_adapters/abstract\_adapter.rb:188:in  
`log' /u/apps/scanner/releases/20090202165310/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:503:in`execute’  
/u/apps/scanner/releases/20090202165310/vendor/rails/activerecord/lib/active\_record/connection\_adapters/postgresql\_adapter.rb:1000:in  
`select_raw' /u/apps/scanner/releases/20090202165310/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:987:in`select’  
/u/apps/scanner/releases/20090202165310/vendor/rails/activerecord/lib/active\_record/connection\_adapters/abstract/database\_statements.rb:7:in  
`select_all_without_query_cache' /u/apps/scanner/releases/20090202165310/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:62:in`select\_all’  
/u/apps/scanner/releases/20090202165310/vendor/rails/activerecord/lib/active\_record/base.rb:635:in  
`find_by_sql' /u/apps/scanner/releases/20090202165310/vendor/rails/activerecord/lib/active_record/base.rb:1490:in`find\_every’
